68 lines
3.1 KiB
Java
68 lines
3.1 KiB
Java
package eu.univento.core.listeners;
|
|
|
|
import com.google.common.io.ByteArrayDataOutput;
|
|
import com.google.common.io.ByteStreams;
|
|
import eu.univento.core.Core;
|
|
import eu.univento.core.api.player.CustomPlayer;
|
|
import eu.univento.core.api.player.WarnReason;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.plugin.messaging.PluginMessageListener;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
public class PluginMessenger implements PluginMessageListener {
|
|
|
|
@Override
|
|
public void onPluginMessageReceived(String channel, Player player, byte[] data) {
|
|
CustomPlayer p = CustomPlayer.getPlayer(player);
|
|
if (channel.equals("WDL|INIT")) {
|
|
String version = null;
|
|
if(data.length == 0) version = "vor 1.8d";
|
|
else try {
|
|
version = new String(data, "UTF-8");
|
|
} catch (UnsupportedEncodingException e) {
|
|
e.printStackTrace();
|
|
}
|
|
Core.getCommons().getLoggingHandler().getCore().info(p.getName() + " hat WDL installiert. Version : " + version);
|
|
p.sendMessage(p.getDatabasePlayer().getMessage("Prefix") + p.getDatabasePlayer().getMessage("Hack.WorldDownloader"));
|
|
}
|
|
if(channel.equals("WDL|CONTROL")) {
|
|
p.sendPluginMessage(Core.getInstance(), "WDL|CONTROL", createWDLPacket(0, false, false, false, false));
|
|
}
|
|
if (channel.equals("PERMISSIONSREPL") && new String(data).contains("mod.worlddownloader")) {
|
|
//TODO: change to real warn reason
|
|
p.warn(WarnReason.SPAM, null, "https://players.univento.eu/" + p.getUniqueId().toString() + "/hacks");
|
|
p.sendMessage(p.getDatabasePlayer().getMessage("Prefix") + p.getDatabasePlayer().getMessage("Hack.WorldDownloader"));
|
|
}
|
|
if(channel.equals("5zig_Set")) {
|
|
try {
|
|
String version = new String(data, "UTF-8");
|
|
Core.getCommons().getLoggingHandler().getCore().info(p.getName() + " hat den 5zig Mod Version : " + version);
|
|
//https://gist.github.com/5zig/35e0854504edda418f4b shows why
|
|
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
|
|
dataOutput.writeByte(0x01 | 0x02 | 0x02 | 0x04 | 0x08 | 0x010);
|
|
p.sendPluginMessage(Core.getInstance(), "5zig_Set", dataOutput.toByteArray());
|
|
p.sendPluginMessage(Core.getInstance(), "5zig_Set", new byte[]{0x01 | 0x02 | 0x04 | 0x08 | 0x10});
|
|
} catch (UnsupportedEncodingException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
|
|
//TODO:
|
|
private byte[] createWDLPacket(int saveRadius, boolean cacheChunks, boolean saveEntities, boolean saveTileEntities, boolean saveContainers) {
|
|
ByteArrayDataOutput output = ByteStreams.newDataOutput();
|
|
|
|
output.writeInt(1);
|
|
|
|
output.writeBoolean(cacheChunks);
|
|
output.writeInt(saveRadius);
|
|
output.writeBoolean(saveEntities);
|
|
output.writeBoolean(saveTileEntities);
|
|
output.writeBoolean(saveContainers);
|
|
output.writeBoolean(false);
|
|
|
|
return output.toByteArray();
|
|
}
|
|
}
|