mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-28 13:15:30 +01:00
Merge pull request #159 from mikeprimm/master
Fix player faces when nicknames used, partial fix for HeroChat
This commit is contained in:
commit
5b5b217be2
@ -18,14 +18,16 @@ public class Client {
|
||||
public String world;
|
||||
public double x, y, z;
|
||||
public int health;
|
||||
public String account;
|
||||
|
||||
public Player(String name, String world, double x, double y, double z, int health) {
|
||||
public Player(String name, String world, double x, double y, double z, int health, String account) {
|
||||
this.name = ChatColor.stripColor(name);
|
||||
this.world = world;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.health = health;
|
||||
this.account = account;
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,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)
|
||||
|
@ -10,6 +10,7 @@ import org.bukkit.event.Event;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
import org.bukkit.event.server.ServerListener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class HeroChatHandler {
|
||||
private static final String DEF_CHANNEL = "Global";
|
||||
@ -18,8 +19,8 @@ public class HeroChatHandler {
|
||||
|
||||
private List<String> hcchannels;
|
||||
private String hcwebinputchannel;
|
||||
private HeroChatChannel hcwebinputchan;
|
||||
private DynmapPlugin plugin;
|
||||
private HeroChatChannel hcwebinputchan;
|
||||
|
||||
private class OurPluginListener extends ServerListener {
|
||||
@Override
|
||||
@ -38,6 +39,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 +50,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 +81,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 */
|
||||
@ -199,23 +210,27 @@ public class HeroChatHandler {
|
||||
* plugin that may not be present....)
|
||||
*/
|
||||
HeroChatChannel c = ce.getChannel();
|
||||
/* If channel name or nickname matches out web channel, remember it */
|
||||
if((c != null) && (hcwebinputchannel != null) &&
|
||||
((c.getName().equals(hcwebinputchannel)) ||
|
||||
c.getNick().equals(hcwebinputchannel))) {
|
||||
hcwebinputchan = c;
|
||||
}
|
||||
if (ce.isCancelled())
|
||||
return;
|
||||
if((hcwebinputchannel != null) && ((hcwebinputchannel.equals(c.getName())) ||
|
||||
(hcwebinputchannel.equals(c.getNick())))) {
|
||||
hcwebinputchan = c;
|
||||
}
|
||||
if (HeroChatChannelChatEvent.isInstance(event)) {
|
||||
HeroChatChannelChatEvent cce = new HeroChatChannelChatEvent(
|
||||
event);
|
||||
/* 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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -233,9 +248,15 @@ public class HeroChatHandler {
|
||||
/* And get channel to send web messages */
|
||||
hcwebinputchannel = cfg.getNode("web").getString(
|
||||
"herochatwebchannel", DEF_CHANNEL);
|
||||
/* Set up to hear when HeroChat is enabled */
|
||||
server.getPluginManager().registerEvent(Event.Type.PLUGIN_ENABLE,
|
||||
Plugin hc = server.getPluginManager().getPlugin("HeroChat");
|
||||
if(hc != null) {
|
||||
activateHeroChat(hc);
|
||||
}
|
||||
else {
|
||||
/* Set up to hear when HeroChat is enabled */
|
||||
server.getPluginManager().registerEvent(Event.Type.PLUGIN_ENABLE,
|
||||
new OurPluginListener(), Event.Priority.Normal, plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -252,7 +273,6 @@ public class HeroChatHandler {
|
||||
Log.severe("Cannot load HeroChat channel event class!");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Register event handler */
|
||||
plugin.getServer().getPluginManager().registerEvent(Event.Type.CUSTOM_EVENT,
|
||||
new OurEventListener(), Event.Priority.Monitor, plugin);
|
||||
|
@ -99,7 +99,8 @@ class JsonTimerTask extends TimerTask {
|
||||
for (int i = 0; i < players.length; i++) {
|
||||
Player p = players[i];
|
||||
Location pl = p.getLocation();
|
||||
update.players[i] = new Client.Player(p.getDisplayName(), pl.getWorld().getName(), pl.getX(), pl.getY(), pl.getZ(), showHealth?p.getHealth():-1);
|
||||
update.players[i] = new Client.Player(p.getDisplayName(), pl.getWorld().getName(), pl.getX(), pl.getY(), pl.getZ(), showHealth?p.getHealth():-1,
|
||||
p.getName());
|
||||
}
|
||||
|
||||
update.updates = mapManager.getWorldUpdates(world.getName(), current - (jsonInterval + 10000));
|
||||
|
@ -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;
|
||||
|
@ -76,7 +76,8 @@ public class ClientUpdateHandler implements HttpHandler {
|
||||
for(int i=0;i<players.length;i++) {
|
||||
Player p = players[i];
|
||||
Location pl = p.getLocation();
|
||||
update.players[i] = new Client.Player(p.getDisplayName(), pl.getWorld().getName(), pl.getX(), pl.getY(), pl.getZ(), showHealth?p.getHealth():-1);
|
||||
update.players[i] = new Client.Player(p.getDisplayName(), pl.getWorld().getName(), pl.getX(), pl.getY(), pl.getZ(), showHealth?p.getHealth():-1,
|
||||
p.getName());
|
||||
}
|
||||
|
||||
update.updates = mapManager.getWorldUpdates(worldName, since);
|
||||
|
@ -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);
|
||||
});
|
||||
};
|
@ -453,7 +453,8 @@ DynMap.prototype = {
|
||||
var player = me.players[update.name] = {
|
||||
name: update.name,
|
||||
location: new Location(me.worlds[update.world], parseFloat(update.x), parseFloat(update.y), parseFloat(update.z)),
|
||||
health: update.health
|
||||
health: update.health,
|
||||
account: update.account
|
||||
};
|
||||
|
||||
$(me).trigger('playeradded', [ player ]);
|
||||
@ -486,7 +487,7 @@ DynMap.prototype = {
|
||||
})
|
||||
.appendTo(me.playerlist);
|
||||
if (me.options.showplayerfacesinmenu) {
|
||||
getMinecraftHead(player.name, 16, function(head) {
|
||||
getMinecraftHead(player.account, 16, function(head) {
|
||||
$('img', playerIconContainer).remove();
|
||||
$(head).appendTo(playerIconContainer);
|
||||
});
|
||||
|
@ -15,7 +15,7 @@ componentconstructors['playermarkers'] = function(dynmap, configuration) {
|
||||
.text(player.name));
|
||||
|
||||
if (configuration.showplayerfaces) {
|
||||
getMinecraftHead(player.name, 32, function(head) {
|
||||
getMinecraftHead(player.account, 32, function(head) {
|
||||
$(head)
|
||||
.addClass('playericon')
|
||||
.prependTo(div);
|
||||
|
Loading…
Reference in New Issue
Block a user