Created
March 23, 2014 20:12
-
-
Save aadnk/9729162 to your computer and use it in GitHub Desktop.
Prevent certain chunks from being processed by certain players.
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
package com.comphenix.example; | |
import org.bukkit.plugin.java.JavaPlugin; | |
import com.comphenix.protocol.PacketType; | |
import com.comphenix.protocol.ProtocolLibrary; | |
import com.comphenix.protocol.events.PacketAdapter; | |
import com.comphenix.protocol.events.PacketContainer; | |
import com.comphenix.protocol.events.PacketEvent; | |
public class ArtificalChunkErrors extends JavaPlugin { | |
@Override | |
public void onEnable() { | |
ProtocolLibrary.getProtocolManager().addPacketListener( | |
new PacketAdapter(this, PacketType.Play.Server.MAP_CHUNK, PacketType.Play.Server.MAP_CHUNK_BULK) { | |
@Override | |
public void onPacketSending(PacketEvent event) { | |
PacketContainer packet = event.getPacket(); | |
if (event.getPacketType() == PacketType.Play.Server.MAP_CHUNK) { | |
processChunk(event, packet); | |
} else { | |
processChunkBulk(event, packet); | |
} | |
} | |
}); | |
} | |
private void processChunk(PacketEvent event, PacketContainer packet) { | |
if (filterChunk(event.getPlayer().getName(), packet.getIntegers().read(0), packet.getIntegers().read(1))) { | |
event.setCancelled(true); | |
} | |
} | |
private void processChunkBulk(PacketEvent event, PacketContainer packet) { | |
// This is the trick - we actually move the chunk millions of miles away ... | |
int[] chunkX = packet.getIntegerArrays().read(0); | |
int[] chunkZ = packet.getIntegerArrays().read(1); | |
String name = event.getPlayer().getName(); | |
for (int i = 0; i < chunkZ.length; i++) { | |
if (filterChunk(name, chunkX[i], chunkZ[i])) { | |
chunkX[i] = Integer.MAX_VALUE; | |
chunkZ[i] = Integer.MAX_VALUE; | |
} | |
} | |
} | |
protected boolean filterChunk(String name, int chunkX, int chunkZ) { | |
// Remove the (0,0) chunk for a specific player | |
return "aadnk".equals(name) && chunkX == 0 && chunkZ == 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment