use of net.minecraft.server.network.ServerGamePacketListenerImpl in project Denizen-For-Bukkit by DenizenScript.
the class PlayerHelperImpl method setFlyKickCooldown.
@Override
public void setFlyKickCooldown(Player player, int ticks) {
ticks = 80 - ticks;
ServerGamePacketListenerImpl conn = ((CraftPlayer) player).getHandle().connection;
if (conn instanceof AbstractListenerPlayInImpl) {
conn = ((AbstractListenerPlayInImpl) conn).oldListener;
}
try {
FLY_TICKS.setInt(conn, ticks);
VEHICLE_FLY_TICKS.setInt(conn, ticks);
} catch (IllegalAccessException e) {
Debug.echoError(e);
}
}
use of net.minecraft.server.network.ServerGamePacketListenerImpl in project Denizen-For-Bukkit by DenizenScript.
the class PlayerHelperImpl method setFlyKickCooldown.
@Override
public void setFlyKickCooldown(Player player, int ticks) {
ticks = 80 - ticks;
ServerGamePacketListenerImpl conn = ((CraftPlayer) player).getHandle().connection;
if (conn instanceof AbstractListenerPlayInImpl) {
conn = ((AbstractListenerPlayInImpl) conn).oldListener;
}
try {
FLY_TICKS.setInt(conn, ticks);
VEHICLE_FLY_TICKS.setInt(conn, ticks);
} catch (IllegalAccessException e) {
Debug.echoError(e);
}
}
use of net.minecraft.server.network.ServerGamePacketListenerImpl in project Denizen-For-Bukkit by DenizenScript.
the class PlayerHelperImpl method sendEntitySpawn.
@Override
public FakeEntity sendEntitySpawn(List<PlayerTag> players, DenizenEntityType entityType, LocationTag location, ArrayList<Mechanism> mechanisms, int customId, UUID customUUID, boolean autoTrack) {
CraftWorld world = ((CraftWorld) location.getWorld());
net.minecraft.world.entity.Entity nmsEntity;
if (entityType.isCustom()) {
if (entityType.customEntityType == CustomEntityType.ITEM_PROJECTILE) {
org.bukkit.inventory.ItemStack itemStack = new ItemStack(Material.STONE);
for (Mechanism mechanism : mechanisms) {
if (mechanism.matches("item") && mechanism.requireObject(ItemTag.class)) {
itemStack = mechanism.valueAsType(ItemTag.class).getItemStack();
}
}
nmsEntity = new EntityItemProjectileImpl(world.getHandle(), location, CraftItemStack.asNMSCopy(itemStack));
} else if (entityType.customEntityType == CustomEntityType.FAKE_PLAYER) {
String name = null;
String skin = null;
for (Mechanism mechanism : new ArrayList<>(mechanisms)) {
if (mechanism.matches("name")) {
name = mechanism.getValue().asString();
mechanisms.remove(mechanism);
} else if (mechanism.matches("skin")) {
skin = mechanism.getValue().asString();
mechanisms.remove(mechanism);
}
if (name != null && skin != null) {
break;
}
}
nmsEntity = ((CraftFakePlayerImpl) CustomEntityHelperImpl.spawnFakePlayer(location, name, skin, false)).getHandle();
} else {
throw new IllegalArgumentException("entityType");
}
} else {
nmsEntity = world.createEntity(location, entityType.getBukkitEntityType().getEntityClass());
}
if (customUUID != null) {
nmsEntity.setId(customId);
nmsEntity.setUUID(customUUID);
}
EntityTag entity = new EntityTag(nmsEntity.getBukkitEntity());
entity.isFake = true;
entity.isFakeValid = true;
for (Mechanism mechanism : mechanisms) {
entity.safeAdjustDuplicate(mechanism);
}
nmsEntity.unsetRemoved();
FakeEntity fake = new FakeEntity(players, location, entity.getBukkitEntity().getEntityId());
fake.entity = new EntityTag(entity.getBukkitEntity());
fake.entity.isFake = true;
fake.entity.isFakeValid = true;
List<TrackerData> trackers = new ArrayList<>();
fake.triggerSpawnPacket = (player) -> {
ServerPlayer nmsPlayer = ((CraftPlayer) player.getPlayerEntity()).getHandle();
ServerGamePacketListenerImpl conn = nmsPlayer.connection;
final ServerEntity tracker = new ServerEntity(world.getHandle(), nmsEntity, 1, true, conn::send, Collections.singleton(nmsPlayer.connection));
tracker.addPairing(nmsPlayer);
final TrackerData data = new TrackerData();
data.player = player;
data.tracker = tracker;
trackers.add(data);
if (autoTrack) {
new BukkitRunnable() {
boolean wasOnline = true;
@Override
public void run() {
if (!fake.entity.isFakeValid) {
cancel();
return;
}
if (player.isOnline()) {
if (!wasOnline) {
tracker.addPairing(((CraftPlayer) player.getPlayerEntity()).getHandle());
wasOnline = true;
}
tracker.sendChanges();
} else if (wasOnline) {
wasOnline = false;
}
}
}.runTaskTimer(Denizen.getInstance(), 1, 1);
}
};
for (PlayerTag player : players) {
fake.triggerSpawnPacket.accept(player);
}
fake.triggerUpdatePacket = () -> {
for (TrackerData tracker : trackers) {
if (tracker.player.isOnline()) {
tracker.tracker.sendChanges();
}
}
};
fake.triggerDestroyPacket = () -> {
for (TrackerData tracker : trackers) {
if (tracker.player.isOnline()) {
tracker.tracker.removePairing(((CraftPlayer) tracker.player.getPlayerEntity()).getHandle());
}
}
trackers.clear();
};
return fake;
}
use of net.minecraft.server.network.ServerGamePacketListenerImpl in project Denizen-For-Bukkit by DenizenScript.
the class DenizenNetworkManagerImpl method setNetworkManager.
public static void setNetworkManager(Player player) {
ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
ServerGamePacketListenerImpl playerConnection = entityPlayer.connection;
setNetworkManager(playerConnection, new DenizenNetworkManagerImpl(entityPlayer, playerConnection.connection));
}
use of net.minecraft.server.network.ServerGamePacketListenerImpl in project Denizen-For-Bukkit by DenizenScript.
the class PlayerHelperImpl method sendEntitySpawn.
@Override
public FakeEntity sendEntitySpawn(List<PlayerTag> players, DenizenEntityType entityType, LocationTag location, ArrayList<Mechanism> mechanisms, int customId, UUID customUUID, boolean autoTrack) {
CraftWorld world = ((CraftWorld) location.getWorld());
net.minecraft.world.entity.Entity nmsEntity;
if (entityType.isCustom()) {
if (entityType.customEntityType == CustomEntityType.ITEM_PROJECTILE) {
org.bukkit.inventory.ItemStack itemStack = new ItemStack(Material.STONE);
for (Mechanism mechanism : mechanisms) {
if (mechanism.matches("item") && mechanism.requireObject(ItemTag.class)) {
itemStack = mechanism.valueAsType(ItemTag.class).getItemStack();
}
}
nmsEntity = new EntityItemProjectileImpl(world.getHandle(), location, CraftItemStack.asNMSCopy(itemStack));
} else if (entityType.customEntityType == CustomEntityType.FAKE_PLAYER) {
String name = null;
String skin = null;
for (Mechanism mechanism : new ArrayList<>(mechanisms)) {
if (mechanism.matches("name")) {
name = mechanism.getValue().asString();
mechanisms.remove(mechanism);
} else if (mechanism.matches("skin")) {
skin = mechanism.getValue().asString();
mechanisms.remove(mechanism);
}
if (name != null && skin != null) {
break;
}
}
nmsEntity = ((CraftFakePlayerImpl) CustomEntityHelperImpl.spawnFakePlayer(location, name, skin, false)).getHandle();
} else {
throw new IllegalArgumentException("entityType");
}
} else {
nmsEntity = world.createEntity(location, entityType.getBukkitEntityType().getEntityClass());
}
if (customUUID != null) {
nmsEntity.setId(customId);
nmsEntity.setUUID(customUUID);
}
EntityTag entity = new EntityTag(nmsEntity.getBukkitEntity());
entity.isFake = true;
entity.isFakeValid = true;
for (Mechanism mechanism : mechanisms) {
entity.safeAdjustDuplicate(mechanism);
}
nmsEntity.unsetRemoved();
FakeEntity fake = new FakeEntity(players, location, entity.getBukkitEntity().getEntityId());
fake.entity = new EntityTag(entity.getBukkitEntity());
fake.entity.isFake = true;
fake.entity.isFakeValid = true;
List<TrackerData> trackers = new ArrayList<>();
fake.triggerSpawnPacket = (player) -> {
ServerPlayer nmsPlayer = ((CraftPlayer) player.getPlayerEntity()).getHandle();
ServerGamePacketListenerImpl conn = nmsPlayer.connection;
final ServerEntity tracker = new ServerEntity(world.getHandle(), nmsEntity, 1, true, conn::send, Collections.singleton(nmsPlayer.connection));
tracker.addPairing(nmsPlayer);
final TrackerData data = new TrackerData();
data.player = player;
data.tracker = tracker;
trackers.add(data);
if (autoTrack) {
new BukkitRunnable() {
boolean wasOnline = true;
@Override
public void run() {
if (!fake.entity.isFakeValid) {
cancel();
return;
}
if (player.isOnline()) {
if (!wasOnline) {
tracker.addPairing(((CraftPlayer) player.getPlayerEntity()).getHandle());
wasOnline = true;
}
tracker.sendChanges();
} else if (wasOnline) {
wasOnline = false;
}
}
}.runTaskTimer(Denizen.getInstance(), 1, 1);
}
};
for (PlayerTag player : players) {
fake.triggerSpawnPacket.accept(player);
}
fake.triggerUpdatePacket = () -> {
for (TrackerData tracker : trackers) {
if (tracker.player.isOnline()) {
tracker.tracker.sendChanges();
}
}
};
fake.triggerDestroyPacket = () -> {
for (TrackerData tracker : trackers) {
if (tracker.player.isOnline()) {
tracker.tracker.removePairing(((CraftPlayer) tracker.player.getPlayerEntity()).getHandle());
}
}
trackers.clear();
};
return fake;
}
Aggregations