mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-28 13:15:30 +01:00
Fixes for alias/nicknames in web UI (esp handling player icons),
HeroChat fixes
This commit is contained in:
parent
b108cad2d3
commit
06785be5f3
@ -40,27 +40,34 @@ public class Client {
|
||||
public String source;
|
||||
public String playerName;
|
||||
public String message;
|
||||
|
||||
public ChatMessage(String source, String playerName, String message) {
|
||||
public String account;
|
||||
public String channel;
|
||||
public ChatMessage(String source, String channel, String playerName, String message, String playeraccount) {
|
||||
this.source = source;
|
||||
this.playerName = ChatColor.stripColor(playerName);
|
||||
this.message = ChatColor.stripColor(message);
|
||||
this.account = playeraccount;
|
||||
this.channel = channel;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PlayerJoinMessage extends Stamped {
|
||||
public String type = "playerjoin";
|
||||
public String playerName;
|
||||
public PlayerJoinMessage(String playerName) {
|
||||
public String account;
|
||||
public PlayerJoinMessage(String playerName, String playeraccount) {
|
||||
this.playerName = ChatColor.stripColor(playerName);
|
||||
this.account = playeraccount;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PlayerQuitMessage extends Stamped {
|
||||
public String type = "playerquit";
|
||||
public String playerName;
|
||||
public PlayerQuitMessage(String playerName) {
|
||||
public String account;
|
||||
public PlayerQuitMessage(String playerName, String playeraccount) {
|
||||
this.playerName = ChatColor.stripColor(playerName);
|
||||
this.account = playeraccount;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,17 +15,19 @@ public class DynmapPlayerChatListener extends PlayerListener {
|
||||
@Override
|
||||
public void onPlayerChat(PlayerChatEvent event) {
|
||||
if(event.isCancelled()) return;
|
||||
plugin.mapManager.pushUpdate(new Client.ChatMessage("player", event.getPlayer().getDisplayName(), event.getMessage()));
|
||||
plugin.mapManager.pushUpdate(new Client.ChatMessage("player", "",
|
||||
event.getPlayer().getDisplayName(), event.getMessage(),
|
||||
event.getPlayer().getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
plugin.mapManager.pushUpdate(new Client.PlayerJoinMessage(event.getPlayer().getDisplayName()));
|
||||
plugin.mapManager.pushUpdate(new Client.PlayerJoinMessage(event.getPlayer().getDisplayName(), event.getPlayer().getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
plugin.mapManager.pushUpdate(new Client.PlayerQuitMessage(event.getPlayer().getDisplayName()));
|
||||
plugin.mapManager.pushUpdate(new Client.PlayerQuitMessage(event.getPlayer().getDisplayName(), event.getPlayer().getName()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -411,7 +411,7 @@ public class DynmapPlugin extends JavaPlugin {
|
||||
}
|
||||
|
||||
public void webChat(String name, String message) {
|
||||
mapManager.pushUpdate(new Client.ChatMessage("web", name, message));
|
||||
mapManager.pushUpdate(new Client.ChatMessage("web", null, name, message, null));
|
||||
Log.info("[WEB]" + name + ": " + message);
|
||||
/* Let HeroChat take a look - only broadcast to players if it doesn't handle it */
|
||||
if(hchand.sendWebMessageToHeroChat(name, message) == false)
|
||||
|
@ -38,6 +38,7 @@ public class HeroChatHandler {
|
||||
private static Class channelchatevent;
|
||||
private static Method getsource;
|
||||
private static Method getmessage;
|
||||
private static Method issentbyplayer;
|
||||
private static boolean isgood = false;
|
||||
private Event evt;
|
||||
|
||||
@ -48,6 +49,7 @@ public class HeroChatHandler {
|
||||
.forName("com.herocraftonline.dthielke.herochat.event.ChannelChatEvent");
|
||||
getsource = channelchatevent.getMethod("getSource", new Class[0]);
|
||||
getmessage = channelchatevent.getMethod("getMessage", new Class[0]);
|
||||
issentbyplayer = channelchatevent.getMethod("isSentByPlayer", new Class[0]);
|
||||
isgood = true;
|
||||
} catch (ClassNotFoundException cnfx) {
|
||||
} catch (NoSuchMethodException nsmx) {
|
||||
@ -78,6 +80,14 @@ public class HeroChatHandler {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSentByPlayer() {
|
||||
try {
|
||||
return (Boolean) issentbyplayer.invoke(evt);
|
||||
} catch (Exception x) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Reflection-based access wrapper for ChannelEvent from HeroChat */
|
||||
@ -213,9 +223,15 @@ public class HeroChatHandler {
|
||||
/* Match on name or nickname of channel */
|
||||
if (hcchannels.contains(c.getName()) ||
|
||||
hcchannels.contains(c.getNick())) {
|
||||
plugin.mapManager.pushUpdate(new Client.ChatMessage(
|
||||
"player", "[" + c.getNick() + "] "
|
||||
+ cce.getSource(), cce.getMessage()));
|
||||
if(cce.isSentByPlayer()) { /* Player message? */
|
||||
org.bukkit.entity.Player p = plugin.getServer().getPlayer(cce.getSource());
|
||||
if(p != null)
|
||||
plugin.mapManager.pushUpdate(new Client.ChatMessage("player",
|
||||
c.getNick(),
|
||||
p.getDisplayName(),
|
||||
cce.getMessage(),
|
||||
p.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package org.dynmap.web;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
public class HttpRequest {
|
||||
public String method;
|
||||
@ -10,4 +11,5 @@ public class HttpRequest {
|
||||
public String version;
|
||||
public Map<String, String> fields = new HashMap<String, String>();
|
||||
public InputStream body;
|
||||
public InetSocketAddress rmtaddr;
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
import org.dynmap.Log;
|
||||
import org.dynmap.debug.Debug;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
public class HttpServerConnection extends Thread {
|
||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||
@ -120,13 +121,14 @@ public class HttpServerConnection extends Thread {
|
||||
if (socket == null)
|
||||
return;
|
||||
socket.setSoTimeout(5000);
|
||||
InetSocketAddress rmtaddr = (InetSocketAddress)socket.getRemoteSocketAddress(); /* Get remote address */
|
||||
InputStream in = socket.getInputStream();
|
||||
BufferedOutputStream out = new BufferedOutputStream(socket.getOutputStream(), 40960);
|
||||
|
||||
printOut = new PrintStream(out, false);
|
||||
while (true) {
|
||||
HttpRequest request = new HttpRequest();
|
||||
|
||||
request.rmtaddr = rmtaddr;
|
||||
if (!readRequestHeader(in, request)) {
|
||||
socket.close();
|
||||
return;
|
||||
|
@ -40,7 +40,8 @@ public class SendMessageHandler implements HttpHandler {
|
||||
|
||||
JSONObject o = (JSONObject)parser.parse(reader);
|
||||
final Message message = new Message();
|
||||
message.name = String.valueOf(o.get("name"));
|
||||
//message.name = String.valueOf(o.get("name")); //Can't trust client....we don't need to on internal web server
|
||||
message.name = request.rmtaddr.getAddress().getHostAddress();
|
||||
message.message = String.valueOf(o.get("message"));
|
||||
|
||||
final long now = System.currentTimeMillis();
|
||||
|
@ -12,7 +12,8 @@ componentconstructors['chat'] = function(dynmap, configuration) {
|
||||
$(dynmap).bind('worldupdate', function(event, update) {
|
||||
swtch(update.type, {
|
||||
chat: function() {
|
||||
$(dynmap).trigger('chat', [{source: update.source, name: update.playerName, text: update.message}]);
|
||||
$(dynmap).trigger('chat', [{source: update.source, name: update.playerName, text: update.message, account: update.account,
|
||||
channel: update.channel}]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -50,20 +50,29 @@ componentconstructors['chatbox'] = function(dynmap, configuration) {
|
||||
|
||||
$(dynmap).bind('chat', function(event, message) {
|
||||
var playerName = message.name;
|
||||
var playerAccount = message.account;
|
||||
var messageRow = $('<div/>')
|
||||
.addClass('messagerow');
|
||||
|
||||
var playerIconContainer = $('<span/>')
|
||||
.addClass('messageicon');
|
||||
|
||||
if (message.source === 'player' && configuration.showplayerfaces) {
|
||||
getMinecraftHead(playerName, 16, function(head) {
|
||||
if (message.source === 'player' && configuration.showplayerfaces &&
|
||||
playerAccount) {
|
||||
getMinecraftHead(playerAccount, 16, function(head) {
|
||||
messageRow.icon = $(head)
|
||||
.addClass('playerIcon')
|
||||
.appendTo(playerIconContainer);
|
||||
});
|
||||
}
|
||||
|
||||
var playerChannelContainer = '';
|
||||
if (message.channel) {
|
||||
playerChannelContainer = $('<span/>').addClass('messagetext')
|
||||
.text('[' + message.channel + '] ')
|
||||
.appendTo(messageRow);
|
||||
}
|
||||
|
||||
if (message.source === 'player' && configuration.showworld) {
|
||||
var playerWorldContainer = $('<span/>')
|
||||
.addClass('messagetext')
|
||||
@ -79,7 +88,7 @@ componentconstructors['chatbox'] = function(dynmap, configuration) {
|
||||
.addClass('messagetext')
|
||||
.text(message.text);
|
||||
|
||||
messageRow.append(playerIconContainer,playerNameContainer,playerMessageContainer);
|
||||
messageRow.append(playerIconContainer,playerChannelContainer,playerNameContainer,playerMessageContainer);
|
||||
addrow(messageRow);
|
||||
});
|
||||
};
|
Loading…
Reference in New Issue
Block a user