Skip to content

Instantly share code, notes, and snippets.

@aadnk
Created January 17, 2013 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aadnk/4555590 to your computer and use it in GitHub Desktop.
Save aadnk/4555590 to your computer and use it in GitHub Desktop.
Require a permission to see signs, item frames and painting.
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);
}
}
}
);
}
}
@xBlazeTECH
Copy link

I tried this in eclipse and it gave the error:
Packet82UpdateSign cannot be resolved to a type.

I was just wondering how to fix this. If it an easy solution, I apologize, this is my first time working with packets.

Copy link

ghost commented Oct 14, 2013

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment