use of org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer in project Denizen-For-Bukkit by DenizenScript.
the class AdvancementHelperImpl method grantPartial.
@Override
public void grantPartial(com.denizenscript.denizen.nms.util.Advancement advancement, Player player, int len) {
if (advancement.length <= 1) {
grant(advancement, player);
return;
}
if (advancement.temporary) {
Advancement nmsAdvancement = asNMSCopy(advancement);
AdvancementProgress progress = new AdvancementProgress();
Map<String, Criterion> criteria = new HashMap<>();
String[][] requirements = new String[advancement.length][];
for (int i = 0; i < advancement.length; i++) {
criteria.put(IMPOSSIBLE_KEY + i, new Criterion(new ImpossibleTrigger.TriggerInstance()));
requirements[i] = new String[] { IMPOSSIBLE_KEY + i };
}
progress.update(IMPOSSIBLE_CRITERIA, IMPOSSIBLE_REQUIREMENTS);
for (int i = 0; i < len; i++) {
// complete impossible criteria
progress.grantProgress(IMPOSSIBLE_KEY + i);
}
PacketHelperImpl.send(player, new ClientboundUpdateAdvancementsPacket(false, Collections.singleton(nmsAdvancement), Collections.emptySet(), Collections.singletonMap(nmsAdvancement.getId(), progress)));
} else {
Advancement nmsAdvancement = getAdvancementDataWorld().advancements.advancements.get(asResourceLocation(advancement.key));
for (int i = 0; i < len; i++) {
((CraftPlayer) player).getHandle().getAdvancements().award(nmsAdvancement, IMPOSSIBLE_KEY + i);
}
}
}
use of org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer in project Denizen-For-Bukkit by DenizenScript.
the class PlayerHelperImpl method deTrackEntity.
@Override
public void deTrackEntity(Player player, Entity entity) {
ServerPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
ServerLevel world = (ServerLevel) nmsPlayer.level;
ChunkMap.TrackedEntity tracker = world.getChunkProvider().chunkMap.G.get(entity.getEntityId());
if (tracker == null) {
return;
}
sendEntityDestroy(player, entity);
tracker.removePlayer(nmsPlayer);
}
use of org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer 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.server.v1_16_R3.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.e(customId);
nmsEntity.a_(customUUID);
}
EntityTag entity = new EntityTag(nmsEntity.getBukkitEntity());
for (Mechanism mechanism : mechanisms) {
entity.safeAdjustDuplicate(mechanism);
}
nmsEntity.dead = false;
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) -> {
EntityPlayer nmsPlayer = ((CraftPlayer) player.getPlayerEntity()).getHandle();
PlayerConnection conn = nmsPlayer.playerConnection;
final EntityTrackerEntry tracker = new EntityTrackerEntry(world.getHandle(), nmsEntity, 1, true, conn::sendPacket, Collections.singleton(nmsPlayer));
tracker.b(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.b(((CraftPlayer) player.getPlayerEntity()).getHandle());
wasOnline = true;
}
tracker.a();
} 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.a();
}
}
};
fake.triggerDestroyPacket = () -> {
for (TrackerData tracker : trackers) {
if (tracker.player.isOnline()) {
tracker.tracker.a(((CraftPlayer) tracker.player.getPlayerEntity()).getHandle());
}
}
trackers.clear();
};
return fake;
}
use of org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer in project Denizen-For-Bukkit by DenizenScript.
the class ProfileEditorImpl method updatePlayer.
@Override
protected void updatePlayer(Player player, final boolean isSkinChanging) {
final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
final UUID uuid = player.getUniqueId();
PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(entityPlayer.getId());
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
if (!p.getUniqueId().equals(uuid)) {
PacketHelperImpl.sendPacket(p, destroyPacket);
}
}
new BukkitRunnable() {
@Override
public void run() {
PacketPlayOutPlayerInfo playerInfo = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, entityPlayer);
PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(entityPlayer);
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
PacketHelperImpl.sendPacket(player, playerInfo);
if (!player.getUniqueId().equals(uuid)) {
PacketHelperImpl.sendPacket(player, spawnPacket);
} else {
if (isSkinChanging) {
((CraftServer) Bukkit.getServer()).getHandle().moveToWorld(entityPlayer, (WorldServer) entityPlayer.world, true, player.getLocation(), false);
}
player.updateInventory();
}
}
}
}.runTaskLater(NMSHandler.getJavaPlugin(), 5);
}
use of org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer in project Denizen-For-Bukkit by DenizenScript.
the class PlayerHelperImpl method stopSound.
@Override
public void stopSound(Player player, String sound, SoundCategory category) {
ResourceLocation soundKey = sound == null ? null : new ResourceLocation(sound);
net.minecraft.sounds.SoundSource nmsCategory = category == null ? null : net.minecraft.sounds.SoundSource.valueOf(category.name());
((CraftPlayer) player).getHandle().connection.send(new ClientboundStopSoundPacket(soundKey, nmsCategory));
}
Aggregations