-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c16cda0
commit 1a43dd4
Showing
5 changed files
with
44 additions
and
51 deletions.
There are no files selected for viewing
21 changes: 5 additions & 16 deletions
21
bungeecord/src/main/java/top/catowncraft/autoworldmap/bungee/handler/VoxelMapHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,19 @@ | ||
package top.catowncraft.autoworldmap.bungee.handler; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.buffer.Unpooled; | ||
import net.md_5.bungee.api.connection.ProxiedPlayer; | ||
import net.md_5.bungee.api.event.PluginMessageEvent; | ||
import net.md_5.bungee.api.plugin.Listener; | ||
import net.md_5.bungee.event.EventHandler; | ||
import top.catowncraft.autoworldmap.common.SharedConstant; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import top.catowncraft.autoworldmap.common.helper.PacketCreator; | ||
|
||
public class VoxelMapHandler implements Listener { | ||
@EventHandler | ||
public void onPluginMessage(PluginMessageEvent event) { | ||
if (event.getSender() instanceof ProxiedPlayer) { | ||
if (event.getTag().equals(SharedConstant.VOXEL_MAP_CHANNEL)) { | ||
ProxiedPlayer player = (ProxiedPlayer) event.getSender(); | ||
byte[] serverName = player.getServer().getInfo().getName().getBytes(StandardCharsets.UTF_8); | ||
ByteBuf buf = Unpooled.buffer(); | ||
buf.writeByte(0); | ||
buf.writeByte(serverName.length); | ||
buf.writeBytes(serverName); | ||
byte[] voxelArray = buf.array(); | ||
buf.release(); | ||
player.sendData(SharedConstant.VOXEL_MAP_CHANNEL, voxelArray); | ||
} | ||
if (event.getSender() instanceof ProxiedPlayer && event.getTag().equals(SharedConstant.VOXEL_MAP_CHANNEL)) { | ||
ProxiedPlayer player = (ProxiedPlayer) event.getSender(); | ||
player.sendData(SharedConstant.VOXEL_MAP_CHANNEL, | ||
PacketCreator.voxelMap(player.getServer().getInfo().getName())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
common/src/main/java/top/catowncraft/autoworldmap/common/helper/PacketCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package top.catowncraft.autoworldmap.common.helper; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.buffer.Unpooled; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.zip.CRC32; | ||
|
||
public class PacketCreator { | ||
public static byte[] voxelMap(String serverName) { | ||
byte[] serverNameByte = serverName.getBytes(StandardCharsets.UTF_8); | ||
ByteBuf buf = Unpooled.buffer(); | ||
buf.writeByte(0); | ||
buf.writeByte(serverNameByte.length); | ||
buf.writeBytes(serverNameByte); | ||
byte[] voxelArray = buf.array(); | ||
buf.release(); | ||
return voxelArray; | ||
} | ||
|
||
public static ByteBuf xaeroMap(String serverName) { | ||
byte[] serverNameByte = serverName.getBytes(StandardCharsets.UTF_8); | ||
CRC32 crc32 = new CRC32(); | ||
crc32.update(serverNameByte, 0, serverNameByte.length); | ||
ByteBuf buf = Unpooled.buffer(); | ||
buf.writeByte(0); | ||
buf.writeInt((int) crc32.getValue()); | ||
return buf; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters