use guava's bytestream

This commit is contained in:
DNx5 2015-09-20 16:06:56 +07:00
parent d826777701
commit b27079026b

View File

@ -1,14 +1,11 @@
package fr.xephi.authme.plugin.manager; package fr.xephi.authme.plugin.manager;
import java.io.ByteArrayInputStream; import com.google.common.io.ByteArrayDataInput;
import java.io.DataInputStream; import com.google.common.io.ByteStreams;
import java.io.IOException; import fr.xephi.authme.AuthMe;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener; import org.bukkit.plugin.messaging.PluginMessageListener;
import fr.xephi.authme.AuthMe;
public class BungeeCordMessage implements PluginMessageListener { public class BungeeCordMessage implements PluginMessageListener {
public AuthMe plugin; public AuthMe plugin;
@ -19,19 +16,16 @@ public class BungeeCordMessage implements PluginMessageListener {
@Override @Override
public void onPluginMessageReceived(String channel, Player player, public void onPluginMessageReceived(String channel, Player player,
byte[] message) { byte[] message) {
if (!channel.equals("BungeeCord")) { if (!channel.equals("BungeeCord")) {
return; return;
} }
try { ByteArrayDataInput in = ByteStreams.newDataInput(message);
final DataInputStream in = new DataInputStream(new ByteArrayInputStream(message)); String subChannel = in.readUTF();
String subchannel = in.readUTF(); if (subChannel.equals("IP")) { // We need only the IP channel
if (subchannel.equals("IP")) { // We need only the IP channel String ip = in.readUTF();
String ip = in.readUTF(); // Put the IP (only the ip not the port) in the hashMap
plugin.realIp.put(player.getName().toLowerCase(), ip); plugin.realIp.put(player.getName().toLowerCase(), ip);
// Put the IP (only the ip not the port) in the hashmap
}
} catch (IOException ex) {
} }
} }