Skip to content

Commit

Permalink
Globalchat Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Calenria committed Jun 8, 2015
1 parent 5387af9 commit e07984d
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 59 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ Simple Global Chat (BungeeCord part)

Downloads:

[Letzter Erfolgreicher Build](https://github.com/Calenria/SimpleChat-Bungee/releases/download/v0.4.2/SimpleChat-Bungee.jar)
[Letzter Erfolgreicher Build](https://github.com/Calenria/SimpleChat-Bungee/releases/download/v0.4.3/SimpleChat-Bungee.jar)

[Bukkit Plugin](https://github.com/Calenria/SimpleChat/releases/download/v0.4.2/SimpleChat.jar)
[Bukkit Plugin](https://github.com/Calenria/SimpleChat/releases/download/v0.4.3/SimpleChat.jar)
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: SimpleChat
version: 0.4.2
version: 0.4.3
main: com.github.calenria.scbungee.SimpleChat
author: Calenria
138 changes: 82 additions & 56 deletions src/com/github/calenria/scbungee/SimpleChatListener.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.github.calenria.scbungee;

import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;

import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.config.ServerInfo;
Expand Down Expand Up @@ -39,73 +43,84 @@ public void onDisconnect(PlayerDisconnectEvent event) {

@EventHandler
public void onPluginMessage(PluginMessageEvent event) {
String pluginMessage = new String(event.getData());
String rawMessage = new String(event.getData());
if (SimpleChat.debug) {
BungeeCord.getInstance().getLogger().info("Recived plugin message: " + pluginMessage);
BungeeCord.getInstance().getLogger().info("Tag: " + event.getTag() + " Recived plugin message: " + rawMessage);
}
if (!event.getTag().equals("SimpleChat")) {

if (!event.getTag().equals("BungeeCord")) {
if (SimpleChat.debug) {
BungeeCord.getInstance().getLogger().info("Kein BungeeCord, Verwerfe Tag: " + event.getTag());
}
return;
}

StringTokenizer st = new StringTokenizer(pluginMessage, "@#@");
String type = st.nextToken();
if (type.equals("login") && st.hasMoreTokens()) {
String playerName = st.nextToken();
if (st.hasMoreTokens()) {
String tabListName = st.nextToken();
ProxiedPlayer pPlayer = BungeeCord.getInstance().getPlayer(playerName);
if (pPlayer != null) {
String server = pPlayer.getServer().getInfo().getName().substring(0, 1);
tabListName = ChatColor.translateAlternateColorCodes('&', server + " " + tabListName);
if (tabListName.length() >= 16) {
tabListName = tabListName.substring(0, 16);
ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
String subchannel = in.readUTF();

if (subchannel.equals("SimpleChat")) {
String pluginMessage = in.readUTF();
StringTokenizer st = new StringTokenizer(pluginMessage, "@#@");
String type = st.nextToken();
if (type.equals("login") && st.hasMoreTokens()) {
String playerName = st.nextToken();
if (st.hasMoreTokens()) {
String tabListName = st.nextToken();
ProxiedPlayer pPlayer = BungeeCord.getInstance().getPlayer(playerName);
if (pPlayer != null) {
String server = pPlayer.getServer().getInfo().getName().substring(0, 1);
tabListName = ChatColor.translateAlternateColorCodes('&', server + " " + tabListName);
if (tabListName.length() >= 16) {
tabListName = tabListName.substring(0, 16);
}
pPlayer.setDisplayName(tabListName);
}
pPlayer.setDisplayName(tabListName);
}

Map<String, ServerInfo> servers = BungeeCord.getInstance().getServers();
for (Entry<String, ServerInfo> server : servers.entrySet()) {
sendPluginMessage("@#@ping@#@ping", server);
}
Map<String, ServerInfo> servers = BungeeCord.getInstance().getServers();
for (Entry<String, ServerInfo> server : servers.entrySet()) {
sendPluginMessage("@#@ping@#@ping", server);
}

}
} else if (type.equals("pm") && st.hasMoreTokens()) {
@SuppressWarnings("unused")
String serverName = st.nextToken();
@SuppressWarnings("unused")
String channel = st.nextToken();
String from = st.nextToken();
String to = st.nextToken();
String message = st.nextToken();
while (st.hasMoreTokens()) {
message += "@" + st.nextToken();
}
ProxiedPlayer fromPlayer = BungeeCord.getInstance().getPlayer(from);
ProxiedPlayer toPlayer = BungeeCord.getInstance().getPlayer(to);
if (toPlayer != null) {
toPlayer.sendMessage(message);
if (fromPlayer != null) {
fromPlayer.sendMessage(message);
sendPluginMessage("@#@wp@#@" + fromPlayer.getName() + "@#@" + toPlayer.getName(), toPlayer.getServer());
}
} else {
if (fromPlayer != null) {
fromPlayer.sendMessage(ChatColor.translateAlternateColorCodes('&',
"&4Fehler beim Ermitteln des Chat Partners. Offline oder Verschrieben? (" + to + ")"));
} else if (type.equals("pm") && st.hasMoreTokens()) {
@SuppressWarnings("unused")
String serverName = st.nextToken();
@SuppressWarnings("unused")
String channel = st.nextToken();
String from = st.nextToken();
String to = st.nextToken();
String message = st.nextToken();
while (st.hasMoreTokens()) {
message += "@" + st.nextToken();
}
}

} else {
String serverName = st.nextToken();
Map<String, ServerInfo> servers = BungeeCord.getInstance().getServers();
for (Entry<String, ServerInfo> server : servers.entrySet()) {
if (!server.getKey().equals(serverName) && !type.equals("spy")) {
sendPluginMessage(pluginMessage, server);
ProxiedPlayer fromPlayer = BungeeCord.getInstance().getPlayer(from);
ProxiedPlayer toPlayer = BungeeCord.getInstance().getPlayer(to);
if (toPlayer != null) {
toPlayer.sendMessage(message);
if (fromPlayer != null) {
fromPlayer.sendMessage(message);
sendPluginMessage("@#@wp@#@" + fromPlayer.getName() + "@#@" + toPlayer.getName(), toPlayer.getServer());
}
} else {
if (fromPlayer != null) {
fromPlayer.sendMessage(ChatColor.translateAlternateColorCodes('&',
"&4Fehler beim Ermitteln des Chat Partners. Offline oder Verschrieben? (" + to + ")"));
}
}
if (type.equals("spy")) {
sendPluginMessage(pluginMessage, server);

} else {
String serverName = st.nextToken();
Map<String, ServerInfo> servers = BungeeCord.getInstance().getServers();
for (Entry<String, ServerInfo> server : servers.entrySet()) {
if (!server.getKey().equals(serverName) && !type.equals("spy")) {
sendPluginMessage(pluginMessage, server);
}
if (type.equals("spy")) {
sendPluginMessage(pluginMessage, server);
}
}
}

}
}

Expand All @@ -116,7 +131,14 @@ private void sendPluginMessage(String pluginMessage, Entry<String, ServerInfo> s
List<ProxiedPlayer> pPlayers = new ArrayList<ProxiedPlayer>(server.getValue().getPlayers());
if (!pPlayers.isEmpty()) {
ProxiedPlayer pPlayer = pPlayers.get(0);
pPlayer.sendData("SimpleChat", pluginMessage.getBytes());
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("SimpleChat");
out.writeUTF(pluginMessage);
if (SimpleChat.debug) {
BungeeCord.getInstance().getLogger()
.info("[perUser] Sending Message to: " + pPlayers.get(0).getName() + " Message: " + out.toByteArray().toString());
}
pPlayer.getServer().sendData("BungeeCord", out.toByteArray());
} else {
BungeeCord.getInstance().getLogger().info("No Player found on Server: " + server.getKey());
}
Expand All @@ -126,7 +148,11 @@ private void sendPluginMessage(String pluginMessage, Server server) {
if (SimpleChat.debug) {
BungeeCord.getInstance().getLogger().info("[perServer] Sending Message to: " + server.getInfo().getName());
}
server.sendData("SimpleChat", pluginMessage.getBytes());

ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("SimpleChat");
out.writeUTF(pluginMessage);
server.sendData("BungeeCord", out.toByteArray());
}

private void sendAll(String msg) {
Expand Down

0 comments on commit e07984d

Please sign in to comment.