Cleaned up join/quit messages (not being send as chat messages)

This commit is contained in:
FrozenCow 2011-04-05 22:58:46 +02:00
parent e1e13df4b2
commit b47bbee4e8
6 changed files with 47 additions and 26 deletions

View File

@ -29,23 +29,30 @@ public class Client {
public static class ChatMessage extends Stamped {
public String type = "chat";
public String source;
public String playerName;
public String message;
public ChatMessage(String playerName, String message) {
public ChatMessage(String source, String playerName, String message) {
this.source = source;
this.playerName = playerName;
this.message = message;
}
}
public static class WebChatMessage extends Stamped {
public String type = "webchat";
public static class PlayerJoinMessage extends Stamped {
public String type = "playerjoin";
public String playerName;
public String message;
public WebChatMessage(String playerName, String message) {
public PlayerJoinMessage(String playerName) {
this.playerName = playerName;
}
}
public static class PlayerQuitMessage extends Stamped {
public String type = "playerquit";
public String playerName;
public PlayerQuitMessage(String playerName) {
this.playerName = playerName;
this.message = message;
}
}

View File

@ -15,21 +15,17 @@ public class DynmapPlayerChatListener extends PlayerListener {
@Override
public void onPlayerChat(PlayerChatEvent event) {
if(event.isCancelled()) return;
plugin.mapManager.pushUpdate(new Client.ChatMessage(event.getPlayer().getName(), event.getMessage()));
plugin.mapManager.pushUpdate(new Client.ChatMessage("player", event.getPlayer().getName(), event.getMessage()));
}
@Override
public void onPlayerJoin(PlayerJoinEvent event) {
String joinMessage = plugin.configuration.getNode("web").getString("joinmessage", "%playername% joined");
joinMessage = joinMessage.replaceAll("%playername%", event.getPlayer().getName());
plugin.mapManager.pushUpdate(new Client.ChatMessage("Server", joinMessage));
plugin.mapManager.pushUpdate(new Client.PlayerJoinMessage(event.getPlayer().getName()));
}
@Override
public void onPlayerQuit(PlayerQuitEvent event) {
String quitMessage = plugin.configuration.getNode("web").getString("quitmessage", "%playername% quit");
quitMessage = quitMessage.replaceAll("%playername%", event.getPlayer().getName());
plugin.mapManager.pushUpdate(new Client.ChatMessage("Server", quitMessage));
plugin.mapManager.pushUpdate(new Client.PlayerQuitMessage(event.getPlayer().getName()));
}
}

View File

@ -382,7 +382,7 @@ public class DynmapPlugin extends JavaPlugin {
}
public void webChat(String name, String message) {
mapManager.pushUpdate(new Client.WebChatMessage(name, message));
mapManager.pushUpdate(new Client.ChatMessage("web", name, message));
log.info("[WEB]" + name + ": " + message);
getServer().broadcastMessage("[WEB]" + name + ": " + message);
}

View File

@ -12,10 +12,7 @@ componentconstructors['chat'] = function(dynmap, configuration) {
$(dynmap).bind('worldupdate', function(event, update) {
swtch(update.type, {
chat: function() {
$(dynmap).trigger('chat', [{source: 'player', name: update.playerName, text: update.message}]);
},
webchat: function() {
$(dynmap).trigger('chat', [{source: 'web', name: update.playerName, text: update.message}]);
$(dynmap).trigger('chat', [{source: update.source, name: update.playerName, text: update.message}]);
}
});
});

View File

@ -27,6 +27,27 @@ componentconstructors['chatbox'] = function(dynmap, configuration) {
.appendTo(chat);
}
var addrow = function(row) {
setTimeout(function() { row.remove(); }, (configuration.messagettl * 1000));
messagelist.append(row);
messagelist.show();
messagelist.scrollTop(messagelist.scrollHeight());
};
$(dynmap).bind('playerjoin', function(event, playername) {
addrow($('<div/>')
.addClass('messagerow')
.text(dynmap.options.joinmessage.replace('%playername%', playername))
);
});
$(dynmap).bind('playerquit', function(event, playername) {
addrow($('<div/>')
.addClass('messagerow')
.text(dynmap.options.quitmessage.replace('%playername%', playername))
);
});
$(dynmap).bind('chat', function(event, message) {
var playerName = message.name;
var messageRow = $('<div/>')
@ -59,12 +80,6 @@ componentconstructors['chatbox'] = function(dynmap, configuration) {
.text(message.text);
messageRow.append(playerIconContainer,playerNameContainer,playerMessageContainer);
//messageRow.append(playerIconContainer,playerWorldContainer,playerGroupContainer,playerNameContainer,playerMessageContainer);
setTimeout(function() { messageRow.remove(); }, (configuration.messagettl * 1000));
messagelist.append(messageRow);
messagelist.show();
//var scrollHeight = jQuery(me.messagelist).attr('scrollHeight');
messagelist.scrollTop(messagelist.scrollHeight());
addrow(messageRow);
});
};

View File

@ -375,6 +375,12 @@ DynMap.prototype = {
swtch(update.type, {
tile: function() {
me.onTileUpdated(update.name);
},
playerjoin: function() {
$(me).trigger('playerjoin', [ update.playerName ]);
},
playerquit: function() {
$(me).trigger('playerquit', [ update.playerName ]);
}
});
}