LibsDisguises/src/me/libraryaddict/disguise/LibsDisguises.java

61 lines
3.1 KiB
Java
Raw Normal View History

2013-05-17 23:05:19 +02:00
package me.libraryaddict.disguise;
import java.util.List;
import me.libraryaddict.disguise.DisguiseTypes.Disguise;
import me.libraryaddict.disguise.DisguiseTypes.PlayerDisguise;
import net.minecraft.server.v1_5_R3.WatchableObject;
2013-05-17 23:05:19 +02:00
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import com.comphenix.protocol.Packets;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ConnectionSide;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier;
public class LibsDisguises extends JavaPlugin {
public void onEnable() {
getCommand("disguise").setExecutor(new DisguiseCommand());
ProtocolLibrary.getProtocolManager().addPacketListener(
new PacketAdapter(this, ConnectionSide.SERVER_SIDE, ListenerPriority.NORMAL, Packets.Server.NAMED_ENTITY_SPAWN,
Packets.Server.ENTITY_METADATA) {
@Override
2013-05-17 23:05:19 +02:00
public void onPacketSending(PacketEvent event) {
StructureModifier<Object> mods = event.getPacket().getModifier();
try {
Player observer = event.getPlayer();
org.bukkit.entity.Entity entity = event.getPacket().getEntityModifier(observer.getWorld()).read(0);
if (entity instanceof Player) {
Player watched = (Player) entity;
if (DisguiseAPI.isDisguised(watched.getName())) {
Disguise disguise = DisguiseAPI.getDisguise(watched);
if (event.getPacketID() == Packets.Server.NAMED_ENTITY_SPAWN) {
if (disguise.getType().isPlayer()) {
2013-05-17 23:05:19 +02:00
String name = (String) mods.read(1);
if (!name.equals(((PlayerDisguise) disguise).getName())) {
event.setCancelled(true);
DisguiseAPI.disguiseToPlayer(watched, observer, disguise);
2013-05-17 23:05:19 +02:00
}
} else {
event.setCancelled(true);
DisguiseAPI.disguiseToPlayer(watched, observer, disguise);
2013-05-17 23:05:19 +02:00
}
} else if (!disguise.getType().isPlayer()) {
if (disguise.hasWatcher()) {
mods.write(1, disguise.getWatcher().convert((List<WatchableObject>) mods.read(1)));
}
2013-05-17 23:05:19 +02:00
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}