use of com.comphenix.protocol.events.PacketEvent in project MyPet by xXKeyleXx.
the class ProtocolLibHook method registerEnderDragonRotationFixLegacy.
private void registerEnderDragonRotationFixLegacy() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(MyPetApi.getPlugin(), getFixedPackets()) {
@Override
public void onPacketSending(PacketEvent event) {
if ((checkTemporaryPlayers && event.isPlayerTemporary()) || event.isCancelled()) {
return;
}
PacketContainer packet = event.getPacket();
final Entity entity = packet.getEntityModifier(event).readSafely(0);
if (entity instanceof MyPetBukkitEntity && ((MyPetBukkitEntity) entity).getPetType() == MyPetType.EnderDragon) {
switch(packet.getType().name()) {
case "ENTITY_TELEPORT":
case "ENTITY_HEAD_ROTATION":
{
byte angle = packet.getBytes().read(0);
angle += Byte.MAX_VALUE;
packet.getBytes().write(0, angle);
break;
}
case "ENTITY_LOOK":
case "ENTITY_MOVE_LOOK":
case "REL_ENTITY_MOVE_LOOK":
case "VEHICLE_MOVE":
byte angle = packet.getBytes().read(3);
angle += Byte.MAX_VALUE;
packet.getBytes().write(3, angle);
break;
}
}
}
});
}
use of com.comphenix.protocol.events.PacketEvent in project MyPet by xXKeyleXx.
the class ProtocolLibHook method registerEnderDragonFix.
private static void registerEnderDragonFix() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(MyPetApi.getPlugin(), PacketType.Play.Server.ENTITY_LOOK, PacketType.Play.Server.ENTITY_MOVE_LOOK, PacketType.Play.Server.ENTITY_TELEPORT) {
@Override
public void onPacketSending(PacketEvent event) {
PacketContainer packet = event.getPacket();
final Entity entity = packet.getEntityModifier(event).readSafely(0);
// Now - are we dealing with an invisible slime?
if (entity != null && entity instanceof MyPetBukkitEntity && ((MyPetBukkitEntity) entity).getPetType() == MyPetType.EnderDragon) {
if (packet.getType() == PacketType.Play.Server.ENTITY_LOOK) {
// MyPetLogger.write("ENTITY_LOOK: " + packet.getBytes().getValues());
byte angle = packet.getBytes().read(3);
angle += Byte.MAX_VALUE;
packet.getBytes().write(3, angle);
} else if (packet.getType() == PacketType.Play.Server.ENTITY_MOVE_LOOK) {
// MyPetLogger.write("ENTITY_MOVE_LOOK: " + packet.getBytes().getValues());
byte angle = packet.getBytes().read(3);
angle += Byte.MAX_VALUE;
packet.getBytes().write(3, angle);
} else if (packet.getType() == PacketType.Play.Server.ENTITY_TELEPORT) {
// MyPetLogger.write("ENTITY_TELEPORT: " + packet.getBytes().getValues());
byte angle = packet.getBytes().read(1);
angle += Byte.MAX_VALUE;
packet.getBytes().write(1, angle);
}
}
}
});
}
use of com.comphenix.protocol.events.PacketEvent in project MyPet by xXKeyleXx.
the class ProtocolLibHook method registerEnderDragonFix_post_1_9.
private static void registerEnderDragonFix_post_1_9() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(MyPetApi.getPlugin(), PacketType.Play.Server.ENTITY_LOOK, PacketType.Play.Server.ENTITY_MOVE_LOOK, PacketType.Play.Server.ENTITY_TELEPORT) {
@Override
public void onPacketSending(PacketEvent event) {
PacketContainer packet = event.getPacket();
final Entity entity = packet.getEntityModifier(event).readSafely(0);
if (entity != null && entity instanceof MyPetBukkitEntity && ((MyPetBukkitEntity) entity).getPetType() == MyPetType.EnderDragon) {
if (packet.getType() == PacketType.Play.Server.ENTITY_LOOK) {
// MyPetLogger.write("ENTITY_LOOK: " + packet.getBytes().getValues());
byte angle = packet.getBytes().read(0);
angle += Byte.MAX_VALUE;
packet.getBytes().write(0, angle);
} else if (packet.getType() == PacketType.Play.Server.ENTITY_MOVE_LOOK) {
// MyPetLogger.write("ENTITY_MOVE_LOOK: " + packet.getBytes().getValues());
byte angle = packet.getBytes().read(0);
angle += Byte.MAX_VALUE;
packet.getBytes().write(0, angle);
} else if (packet.getType() == PacketType.Play.Server.ENTITY_TELEPORT) {
// MyPetLogger.write("ENTITY_TELEPORT: " + packet.getBytes().getValues());
byte angle = packet.getBytes().read(1);
angle += Byte.MAX_VALUE;
packet.getBytes().write(1, angle);
}
}
}
});
}
use of com.comphenix.protocol.events.PacketEvent in project VehiclesPlus2.0 by legofreak107.
the class Main method onEnable.
@Override
public void onEnable() {
ChunkUnload cu = new ChunkUnload(this);
EntityDamage ed = new EntityDamage(this);
EntityDismount edi = new EntityDismount(this);
InventoryClick ic = new InventoryClick(this);
InventoryClose icl = new InventoryClose(this, ic);
PlayerDropItem pdi = new PlayerDropItem(this);
PlayerInteract pi = new PlayerInteract(this);
PlayerInteractAtEntity piae = new PlayerInteractAtEntity(this);
PlayerJoin pj = new PlayerJoin(this);
PlayerQuit pq = new PlayerQuit(this);
SignChange sc = new SignChange(this);
VehicleExit ve = new VehicleExit(this);
Bukkit.getPluginManager().registerEvents(cu, this);
Bukkit.getPluginManager().registerEvents(ed, this);
Bukkit.getPluginManager().registerEvents(edi, this);
Bukkit.getPluginManager().registerEvents(ic, this);
Bukkit.getPluginManager().registerEvents(icl, this);
Bukkit.getPluginManager().registerEvents(pdi, this);
Bukkit.getPluginManager().registerEvents(pi, this);
Bukkit.getPluginManager().registerEvents(piae, this);
Bukkit.getPluginManager().registerEvents(pj, this);
Bukkit.getPluginManager().registerEvents(pq, this);
Bukkit.getPluginManager().registerEvents(sc, this);
Bukkit.getPluginManager().registerEvents(ve, this);
if (getCustomSettingsConfig().contains("Garage.maxCarsSpawnedPerPlayer")) {
maxCars = getCustomSettingsConfig().getInt("Garage.maxCarsSpawnedPerPlayer");
} else {
getCustomSettingsConfig().set("Garage.maxCarsSpawnedPerPlayer", 3);
saveCustomSettingsConfig();
}
if (getCustomSettingsConfig().contains("Items.upgrades")) {
repairMenuItem = genItem(getCustomSettingsConfig().getInt("Items.upgrades.repairMenuItem.id"), Short.parseShort(getCustomSettingsConfig().get("Items.upgrades.repairMenuItem.data").toString()), getCustomSettingsConfig().getBoolean("Items.upgrades.repairMenuItem.unbreakable"));
upgradeMenuItem = genItem(getCustomSettingsConfig().getInt("Items.upgrades.upgradeMenuItem.id"), Short.parseShort(getCustomSettingsConfig().get("Items.upgrades.upgradeMenuItem.data").toString()), getCustomSettingsConfig().getBoolean("Items.upgrades.upgradeMenuItem.unbreakable"));
engineUpgradeItem = genItem(getCustomSettingsConfig().getInt("Items.upgrades.engineUpgradeItem.id"), Short.parseShort(getCustomSettingsConfig().get("Items.upgrades.engineUpgradeItem.data").toString()), getCustomSettingsConfig().getBoolean("Items.upgrades.engineUpgradeItem.unbreakable"));
steeringUpgradeItem = genItem(getCustomSettingsConfig().getInt("Items.upgrades.steeringUpgradeItem.id"), Short.parseShort(getCustomSettingsConfig().get("Items.upgrades.steeringUpgradeItem.data").toString()), getCustomSettingsConfig().getBoolean("Items.upgrades.steeringUpgradeItem.unbreakable"));
gearboxUpgradeItem = genItem(getCustomSettingsConfig().getInt("Items.upgrades.gearboxUpgradeItem.id"), Short.parseShort(getCustomSettingsConfig().get("Items.upgrades.gearboxUpgradeItem.data").toString()), getCustomSettingsConfig().getBoolean("Items.upgrades.gearboxUpgradeItem.unbreakable"));
fuelUpgradeItem = genItem(getCustomSettingsConfig().getInt("Items.upgrades.fuelUpgradeItem.id"), Short.parseShort(getCustomSettingsConfig().get("Items.upgrades.fuelUpgradeItem.data").toString()), getCustomSettingsConfig().getBoolean("Items.upgrades.fuelUpgradeItem.unbreakable"));
engineRepairItem = genItem(getCustomSettingsConfig().getInt("Items.upgrades.engineRepairItem.id"), Short.parseShort(getCustomSettingsConfig().get("Items.upgrades.engineRepairItem.data").toString()), getCustomSettingsConfig().getBoolean("Items.upgrades.engineRepairItem.unbreakable"));
wheelRepairItem = genItem(getCustomSettingsConfig().getInt("Items.upgrades.wheelRepairItem.id"), Short.parseShort(getCustomSettingsConfig().get("Items.upgrades.wheelRepairItem.data").toString()), getCustomSettingsConfig().getBoolean("Items.upgrades.wheelRepairItem.unbreakable"));
} else {
getCustomSettingsConfig().set("Items.upgrades.repairMenuItem.id", 1);
getCustomSettingsConfig().set("Items.upgrades.repairMenuItem.data", 0);
getCustomSettingsConfig().set("Items.upgrades.repairMenuItem.unbreakable", false);
getCustomSettingsConfig().set("Items.upgrades.upgradeMenuItem.id", 1);
getCustomSettingsConfig().set("Items.upgrades.upgradeMenuItem.data", 0);
getCustomSettingsConfig().set("Items.upgrades.upgradeMenuItem.unbreakable", false);
getCustomSettingsConfig().set("Items.upgrades.engineUpgradeItem.id", 1);
getCustomSettingsConfig().set("Items.upgrades.engineUpgradeItem.data", 0);
getCustomSettingsConfig().set("Items.upgrades.engineUpgradeItem.unbreakable", false);
getCustomSettingsConfig().set("Items.upgrades.steeringUpgradeItem.id", 1);
getCustomSettingsConfig().set("Items.upgrades.steeringUpgradeItem.data", 0);
getCustomSettingsConfig().set("Items.upgrades.steeringUpgradeItem.unbreakable", false);
getCustomSettingsConfig().set("Items.upgrades.gearboxUpgradeItem.id", 1);
getCustomSettingsConfig().set("Items.upgrades.gearboxUpgradeItem.data", 0);
getCustomSettingsConfig().set("Items.upgrades.gearboxUpgradeItem.unbreakable", false);
getCustomSettingsConfig().set("Items.upgrades.fuelUpgradeItem.id", 1);
getCustomSettingsConfig().set("Items.upgrades.fuelUpgradeItem.data", 0);
getCustomSettingsConfig().set("Items.upgrades.fuelUpgradeItem.unbreakable", false);
getCustomSettingsConfig().set("Items.upgrades.engineRepairItem.id", 1);
getCustomSettingsConfig().set("Items.upgrades.engineRepairItem.data", 0);
getCustomSettingsConfig().set("Items.upgrades.engineRepairItem.unbreakable", false);
getCustomSettingsConfig().set("Items.upgrades.wheelRepairItem.id", 1);
getCustomSettingsConfig().set("Items.upgrades.wheelRepairItem.data", 0);
getCustomSettingsConfig().set("Items.upgrades.wheelRepairItem.unbreakable", false);
repairMenuItem = new ItemStack(Material.STONE, 1);
upgradeMenuItem = new ItemStack(Material.STONE, 1);
engineUpgradeItem = new ItemStack(Material.STONE, 1);
steeringUpgradeItem = new ItemStack(Material.STONE, 1);
gearboxUpgradeItem = new ItemStack(Material.STONE, 1);
fuelUpgradeItem = new ItemStack(Material.STONE, 1);
engineRepairItem = new ItemStack(Material.STONE, 1);
wheelRepairItem = new ItemStack(Material.STONE, 1);
saveCustomSettingsConfig();
}
Bukkit.getPluginManager().registerEvents(this, this);
if (!setupEconomy()) {
this.getLogger().severe("Disabled due to no Vault dependency found!");
Bukkit.getPluginManager().disablePlugin(this);
return;
}
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
Bike.plugin = this;
Plane.plugin = this;
Car.plugin = this;
Helicopter.plugin = this;
Boat.plugin = this;
sal.plugin = this;
enable();
protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.LOWEST, PacketType.Play.Client.STEER_VEHICLE) {
@Override
public void onPacketReceiving(PacketEvent event) {
if (event.getPacketType().equals(PacketType.Play.Client.STEER_VEHICLE)) {
PacketPlayInSteerVehicle ppisv = (PacketPlayInSteerVehicle) event.getPacket().getHandle();
for (Seat s2 : seatInfo.values()) {
ArmorStand vp = s2.parent;
Location locvp = vp.getLocation().clone();
Location fbvp = locvp.add(locvp.getDirection().setY(0).normalize().multiply(s2.offset.getX()));
float zvp = (float) (fbvp.getZ() + (s2.offset.getZ() * Math.sin(Math.toRadians(fbvp.getYaw() + 90 * 0))));
float xvp = (float) (fbvp.getX() + (s2.offset.getZ() * Math.cos(Math.toRadians(fbvp.getYaw() + 90 * 0))));
Vehicle v = vehicleInfo.get(vp);
EntityArmorStand seat = ((CraftArmorStand) s2.seat).getHandle();
seat.setLocation(xvp, vp.getLocation().getY() + s2.offset.getY(), zvp, fbvp.getYaw(), fbvp.getPitch());
EntityArmorStand s3 = ((CraftArmorStand) v.skinHolder).getHandle();
s3.setLocation(vp.getLocation().getX(), vp.getLocation().getY(), vp.getLocation().getZ(), fbvp.getYaw(), fbvp.getPitch());
}
Player p = event.getPlayer();
if (p.getVehicle() instanceof ArmorStand) {
ArmorStand a = (ArmorStand) p.getVehicle();
if (seatInfo.containsKey(a)) {
Seat s = seatInfo.get(a);
if (s.steer) {
ArmorStand a2 = s.parent;
Vehicle v = vehicleInfo.get(a2);
if (v.type == VehicleType.CAR) {
Car.Car(ppisv, p);
} else if (v.type == VehicleType.PLANE) {
Plane.Plane(ppisv, p);
} else if (v.type == VehicleType.BIKE) {
Bike.Bike(ppisv, p);
} else if (v.type == VehicleType.HELICOPTER) {
Helicopter.Helicopter(ppisv, p);
} else if (v.type == VehicleType.BOAT) {
Boat.Boat(ppisv, p);
}
}
}
}
}
}
});
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
public void run() {
for (Vehicle v : vehicleInfo.values()) {
if (v.type == VehicleType.CAR) {
for (Seat s : v.seats) {
for (Entity e : s.seat.getPassengers()) {
if (e instanceof Player) {
return;
}
}
}
Car.CarNonDriveable(v);
}
}
for (Seat s2 : seatInfo.values()) {
ArmorStand vp = s2.parent;
Location locvp = vp.getLocation().clone();
Location fbvp = locvp.add(locvp.getDirection().setY(0).normalize().multiply(s2.offset.getX()));
float zvp = (float) (fbvp.getZ() + (s2.offset.getZ() * Math.sin(Math.toRadians(fbvp.getYaw() + 90 * 0))));
float xvp = (float) (fbvp.getX() + (s2.offset.getZ() * Math.cos(Math.toRadians(fbvp.getYaw() + 90 * 0))));
EntityArmorStand seat = ((CraftArmorStand) s2.seat).getHandle();
seat.setLocation(xvp, vp.getLocation().getY() + s2.offset.getY(), zvp, fbvp.getYaw(), fbvp.getPitch());
Vehicle v = vehicleInfo.get(vp);
if (v.holder.getLocation().getBlock().getType() == Material.STATIONARY_WATER && v.type != VehicleType.BOAT) {
v.setHealth(0);
} else if (v.holder.getLocation().getBlock().getType() == Material.STATIONARY_WATER && v.type == VehicleType.BOAT) {
v.holder.setGravity(false);
}
EntityArmorStand s3 = ((CraftArmorStand) v.skinHolder).getHandle();
s3.setLocation(vp.getLocation().getX(), vp.getLocation().getY(), vp.getLocation().getZ(), fbvp.getYaw(), fbvp.getPitch());
}
}
}, 0L, 1L);
}
use of com.comphenix.protocol.events.PacketEvent in project VoxelGamesLibv2 by VoxelGamesLib.
the class SignPlaceholders method init.
public void init() {
registerPlaceholders();
Bukkit.getWorlds().stream().flatMap(w -> Arrays.stream(w.getLoadedChunks())).flatMap(s -> Arrays.stream(s.getTileEntities())).filter(s -> s instanceof Sign).map(s -> (Sign) s).forEach(s -> lastSeenSigns.put(s.getLocation(), s));
// modify update packets
protocolManager.addPacketListener(new PacketAdapter(voxelGamesLib, PacketType.Play.Server.TILE_ENTITY_DATA) {
@Override
public void onPacketSending(@Nonnull PacketEvent event) {
int action = event.getPacket().getIntegers().read(0);
// 9 = set sign text action
if (action != 9) {
return;
}
NbtCompound data = (NbtCompound) event.getPacket().getNbtModifier().read(0);
// read data
Component[] lines = new Component[4];
String[] rawLines = new String[4];
for (int i = 0; i < lines.length; i++) {
lines[i] = ComponentSerializers.JSON.deserialize(data.getString("Text" + (i + 1)));
rawLines[i] = ChatUtil.toPlainText(lines[i]);
}
// sometimes its a double, sometimes its an int...
double x;
double y;
double z;
try {
x = data.getDouble("x");
y = data.getDouble("y");
z = data.getDouble("z");
} catch (ClassCastException ex) {
x = data.getInteger("x");
y = data.getInteger("y");
z = data.getInteger("z");
}
Location loc = new Location(event.getPlayer().getWorld(), x, y, z);
if (event.getPlayer().getLocation().distanceSquared(loc) > 200 * 200) {
return;
}
Block b = loc.getBlock();
if (!(b.getState() instanceof Sign)) {
return;
}
Sign sign = (Sign) b.getState();
lastSeenSigns.put(loc, sign);
Optional<User> user = userHandler.getUser(event.getPlayer().getUniqueId());
if (!user.isPresent()) {
return;
}
// call sign placeholders
modifySign(user.get(), loc, rawLines, lines);
// modify packet
for (int i = 0; i < lines.length; i++) {
data.put("Text" + (i + 1), ComponentSerializers.JSON.serialize(lines[i]));
}
}
});
// update task
new BukkitRunnable() {
@Override
public void run() {
lastSeenSigns.forEach((loc, sign) -> sign.update());
}
}.runTaskTimer(voxelGamesLib, 20, 20);
}
Aggregations