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;
|
2013-05-19 05:44:13 +02:00
|
|
|
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) {
|
2013-05-20 13:00:59 +02:00
|
|
|
@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) {
|
2013-05-20 13:00:59 +02:00
|
|
|
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);
|
2013-05-20 13:00:59 +02:00
|
|
|
DisguiseAPI.disguiseToPlayer(watched, observer, disguise);
|
2013-05-17 23:05:19 +02:00
|
|
|
}
|
2013-05-20 13:00:59 +02:00
|
|
|
} else {
|
|
|
|
event.setCancelled(true);
|
|
|
|
DisguiseAPI.disguiseToPlayer(watched, observer, disguise);
|
2013-05-17 23:05:19 +02:00
|
|
|
}
|
|
|
|
} else if (!disguise.getType().isPlayer()) {
|
2013-05-20 13:00:59 +02:00
|
|
|
if (disguise.hasWatcher()) {
|
2013-05-19 05:44:13 +02:00
|
|
|
mods.write(1, disguise.getWatcher().convert((List<WatchableObject>) mods.read(1)));
|
2013-05-20 13:00:59 +02:00
|
|
|
}
|
2013-05-17 23:05:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|