use of org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer in project Denizen-For-Bukkit by DenizenScript.
the class Handler method getPlayerProfile.
@Override
public PlayerProfile getPlayerProfile(Player player) {
GameProfile gameProfile = ((CraftPlayer) player).getProfile();
Property property = Iterables.getFirst(gameProfile.getProperties().get("textures"), null);
return new PlayerProfile(gameProfile.getName(), gameProfile.getId(), property != null ? property.getValue() : null, property != null ? property.getSignature() : null);
}
use of org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer in project Denizen-For-Bukkit by DenizenScript.
the class AdvancementHelperImpl method update.
@Override
public void update(Player player) {
ServerPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
nmsPlayer.connection.send(new ClientboundUpdateAdvancementsPacket(true, Collections.emptySet(), Collections.emptySet(), Collections.emptyMap()));
PlayerAdvancements data = nmsPlayer.getAdvancements();
// save progress
data.save();
// clear progress
data.reload(DedicatedServer.getServer().getAdvancements());
// load progress and update client
data.flushDirty(nmsPlayer);
}
use of org.bukkit.craftbukkit.v1_18_R1.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_18_R1.entity.CraftPlayer in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelperImpl method sendHidePacket.
/*
Hide Entity
*/
@Override
public void sendHidePacket(Player pl, Entity entity) {
if (entity instanceof Player) {
pl.hidePlayer(Denizen.getInstance(), (Player) entity);
return;
}
CraftPlayer craftPlayer = (CraftPlayer) pl;
ServerPlayer entityPlayer = craftPlayer.getHandle();
if (entityPlayer.connection != null && !craftPlayer.equals(entity)) {
ChunkMap tracker = ((ServerLevel) craftPlayer.getHandle().level).getChunkSource().chunkMap;
net.minecraft.world.entity.Entity other = ((CraftEntity) entity).getHandle();
ChunkMap.TrackedEntity entry = tracker.entityMap.get(other.getId());
if (entry != null) {
entry.removePlayer(entityPlayer);
}
if (Denizen.supportsPaper) {
// Workaround for Paper issue
entityPlayer.connection.send(new ClientboundRemoveEntitiesPacket(other.getId()));
}
}
}
use of org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelperImpl method getDamageTo.
@Override
public double getDamageTo(LivingEntity attacker, Entity target) {
MobType monsterType;
if (target instanceof LivingEntity) {
monsterType = ((CraftLivingEntity) target).getHandle().getMobType();
} else {
monsterType = MobType.UNDEFINED;
}
double damage = 0;
AttributeInstance attrib = attacker.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE);
if (attrib != null) {
damage = attrib.getValue();
}
if (attacker.getEquipment() != null && attacker.getEquipment().getItemInMainHand() != null) {
damage += EnchantmentHelper.getDamageBonus(CraftItemStack.asNMSCopy(attacker.getEquipment().getItemInMainHand()), monsterType);
}
if (damage <= 0) {
return 0;
}
if (target != null) {
DamageSource source;
if (attacker instanceof Player) {
source = DamageSource.playerAttack(((CraftPlayer) attacker).getHandle());
} else {
source = DamageSource.mobAttack(((CraftLivingEntity) attacker).getHandle());
}
net.minecraft.world.entity.Entity nmsTarget = ((CraftEntity) target).getHandle();
if (nmsTarget.isInvulnerableTo(source)) {
return 0;
}
if (!(nmsTarget instanceof net.minecraft.world.entity.LivingEntity)) {
return damage;
}
net.minecraft.world.entity.LivingEntity livingTarget = (net.minecraft.world.entity.LivingEntity) nmsTarget;
damage = CombatRules.getDamageAfterAbsorb((float) damage, (float) livingTarget.getArmorValue(), (float) livingTarget.getAttributeValue(Attributes.ARMOR_TOUGHNESS));
int enchantDamageModifier = EnchantmentHelper.getDamageProtection(livingTarget.getArmorSlots(), source);
if (enchantDamageModifier > 0) {
damage = CombatRules.getDamageAfterMagicAbsorb((float) damage, (float) enchantDamageModifier);
}
}
return damage;
}
Aggregations