Created
January 17, 2013 12:21
-
-
Save aadnk/4555590 to your computer and use it in GitHub Desktop.
Require a permission to see signs, item frames and painting.
This file contains hidden or 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.Location; | |
import org.bukkit.Material; | |
import org.bukkit.entity.ItemFrame; | |
import org.bukkit.plugin.java.JavaPlugin; | |
import com.comphenix.protocol.Packets; | |
import com.comphenix.protocol.ProtocolLibrary; | |
import com.comphenix.protocol.ProtocolManager; | |
import com.comphenix.protocol.events.ConnectionSide; | |
import com.comphenix.protocol.events.PacketAdapter; | |
import com.comphenix.protocol.events.PacketEvent; | |
public class SignPermission extends JavaPlugin { | |
@Override | |
public void onEnable() { | |
final ProtocolManager manager = ProtocolLibrary.getProtocolManager(); | |
manager.addPacketListener( | |
new PacketAdapter(this, ConnectionSide.SERVER_SIDE, | |
Packets.Server.VEHICLE_SPAWN, | |
Packets.Server.ENTITY_METADATA) { | |
@Override | |
public void onPacketSending(PacketEvent event) { | |
if (!event.getPlayer().hasPermission("cansee.itemframe")) { | |
// Handle the spawn packet and the metadata packet | |
if (event.getPacketID() == Packets.Server.VEHICLE_SPAWN) { | |
Packet17SpawnObjectVehicle spawnFrame = new Packet17SpawnObjectVehicle(event.getPacket()); | |
// Use getX(), getY() and getZ() to get the coordinates. | |
if (spawnFrame.getType() == Packet17SpawnObjectVehicle.ObjectTypes.ITEM_FRAME) { | |
// Excellent - disable it | |
event.setCancelled(true); | |
} | |
// The packet that updates the content of the item frame | |
} else { | |
Packet28EntityMetadata metadata = new Packet28EntityMetadata(event.getPacket()); | |
if (metadata.getEntity(event) instanceof ItemFrame) { | |
event.setCancelled(true); | |
} | |
} | |
} | |
} | |
}); | |
manager.addPacketListener( | |
new PacketAdapter(this, ConnectionSide.SERVER_SIDE, | |
Packets.Server.ENTITY_PAINTING) { | |
@Override | |
public void onPacketSending(PacketEvent event) { | |
if (!event.getPlayer().hasPermission("cansee.painting")) { | |
//Packet19SpawnPainting spawnPainting = new Packet19SpawnPainting(event.getPacket()); | |
// We'll just cancel it all - but you can get the coordindates of the painting | |
event.setCancelled(true); | |
} | |
} | |
} | |
); | |
manager.addPacketListener( | |
new PacketAdapter(this, ConnectionSide.SERVER_SIDE, | |
Packets.Server.UPDATE_SIGN) { | |
@Override | |
public void onPacketSending(PacketEvent event) { | |
if (!event.getPlayer().hasPermission("cansee.sign")) { | |
Packet82UpdateSign spawnPainting = new Packet82UpdateSign(event.getPacket()); | |
Location loc = new Location( | |
event.getPlayer().getWorld(), | |
spawnPainting.getX(), spawnPainting.getY(), spawnPainting.getZ()); | |
// Don't update the sign | |
event.setCancelled(true); | |
// Send the fake block update | |
event.getPlayer().sendBlockChange(loc, Material.AIR, (byte)0); | |
} | |
} | |
} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Well, I'm a little late (around three months late) but, you need to reference the PacketWrapper package in your project to be able to access the simplifies packet classes.