use of org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer in project MyPet by xXKeyleXx.
the class PlatformHelper method getPlayerLanguage.
public String getPlayerLanguage(Player player) {
if (!(player instanceof CraftPlayer)) {
return "en_US";
}
EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
Object lang = ReflectionUtil.getFieldValue(EntityPlayer_locale_FIELD, entityPlayer);
if (lang == null) {
return "en_US";
}
return lang.toString();
}
use of org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer in project MyPet by xXKeyleXx.
the class PlatformHelper method getPlayerLanguage.
public String getPlayerLanguage(Player player) {
if (!(player instanceof CraftPlayer)) {
return "en_US";
}
EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
try {
Field field = entityPlayer.getClass().getDeclaredField("locale");
String lang = field.get(entityPlayer).toString();
if (lang == null) {
return "en_US";
}
return lang;
} catch (Exception e) {
return "en_US";
}
}
use of org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer in project MyPet by xXKeyleXx.
the class PlatformHelper method playParticleEffect.
/**
* @param location the {@link Location} around which players must be to see the effect
* @param effectName list of effects: https://gist.github.com/riking/5759002
* @param offsetX the amount to be randomly offset by in the X axis
* @param offsetY the amount to be randomly offset by in the Y axis
* @param offsetZ the amount to be randomly offset by in the Z axis
* @param speed the speed of the particles
* @param count the number of particles
* @param radius the radius around the location
*/
public void playParticleEffect(Location location, String effectName, float offsetX, float offsetY, float offsetZ, float speed, int count, int radius, int... data) {
EnumParticle effect;
try {
effect = EnumParticle.valueOf(effectName);
} catch (IllegalArgumentException e) {
effect = EnumParticle.a(effectName);
}
Validate.notNull(location, "Location cannot be null");
Validate.notNull(effect, "Effect cannot be null");
Validate.notNull(location.getWorld(), "World cannot be null");
PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(effect, false, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count, data);
radius = radius * radius;
for (Player player : location.getWorld().getPlayers()) {
if ((int) MyPetApi.getPlatformHelper().distanceSquared(player.getLocation(), location) <= radius) {
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
}
}
use of org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer in project MyPet by xXKeyleXx.
the class EntityMyPet method handlePlayerInteraction.
// Obfuscated Method handler ------------------------------------------------------------------------------------
/**
* Is called when player rightclicks this MyPet
* return:
* true: there was a reaction on rightclick
* false: no reaction on rightclick
*/
public boolean handlePlayerInteraction(final EntityHuman entityhuman, EnumHand enumhand, final ItemStack itemStack) {
if (itemStack != null && itemStack.getItem() == Items.LEAD) {
((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutAttachEntity(this, null));
if (!entityhuman.abilities.canInstantlyBuild) {
new BukkitRunnable() {
public void run() {
((EntityPlayer) entityhuman).updateInventory(entityhuman.defaultContainer);
}
}.runTaskLater(MyPetApi.getPlugin(), 5);
}
}
if (enumhand == EnumHand.OFF_HAND) {
return true;
}
Player owner = this.getOwner().getPlayer();
if (isMyPet() && myPet.getOwner().equals(entityhuman)) {
if (Configuration.Skilltree.Skill.Ride.RIDE_ITEM.compare(itemStack)) {
if (myPet.getSkills().isSkillActive(Ride.class) && canMove()) {
if (Permissions.hasExtendedLegacy(owner, "MyPet.extended.ride")) {
((CraftPlayer) owner).getHandle().startRiding(this);
return true;
} else {
getOwner().sendMessage(Translation.getString("Message.No.CanUse", myPet.getOwner().getLanguage()));
}
}
}
if (Configuration.Skilltree.Skill.CONTROL_ITEM.compare(itemStack)) {
if (myPet.getSkills().isSkillActive(de.Keyle.MyPet.skill.skills.Control.class)) {
return true;
}
}
if (itemStack != null) {
if (itemStack.getItem() == Items.NAME_TAG && itemStack.hasName()) {
if (Permissions.hasLegacy(getOwner(), "MyPet.command.name") && Permissions.hasExtended(getOwner(), "MyPet.extended.nametag")) {
final String name = itemStack.getName();
getMyPet().setPetName(name);
EntityMyPet.super.setCustomName("-");
myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Command.Name.New", myPet.getOwner()), name));
if (!entityhuman.abilities.canInstantlyBuild) {
--itemStack.count;
}
if (itemStack.count <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
}
new BukkitRunnable() {
public void run() {
updateNameTag();
}
}.runTaskLater(MyPetApi.getPlugin(), 1L);
return true;
}
}
if (canEat(itemStack) && canUseItem()) {
if (owner != null && !Permissions.hasExtendedLegacy(owner, "MyPet.extended.feed")) {
return false;
}
if (this.petTargetSelector.hasGoal("DuelTarget")) {
BehaviorDuelTarget duelTarget = (BehaviorDuelTarget) this.petTargetSelector.getGoal("DuelTarget");
if (duelTarget.getDuelOpponent() != null) {
return true;
}
}
boolean used = false;
double saturation = Configuration.HungerSystem.HUNGER_SYSTEM_SATURATION_PER_FEED;
if (saturation > 0) {
if (myPet.getSaturation() < 100) {
MyPetFeedEvent feedEvent = new MyPetFeedEvent(getMyPet(), CraftItemStack.asCraftMirror(itemStack), saturation, MyPetFeedEvent.Result.Eat);
Bukkit.getPluginManager().callEvent(feedEvent);
if (!feedEvent.isCancelled()) {
saturation = feedEvent.getSaturation();
double missingSaturation = 100 - myPet.getSaturation();
myPet.setSaturation(myPet.getSaturation() + saturation);
saturation = Math.max(0, saturation - missingSaturation);
used = true;
}
}
}
if (saturation > 0) {
if (getHealth() < getMaxHealth()) {
MyPetFeedEvent feedEvent = new MyPetFeedEvent(getMyPet(), CraftItemStack.asCraftMirror(itemStack), saturation, MyPetFeedEvent.Result.Heal);
Bukkit.getPluginManager().callEvent(feedEvent);
if (!feedEvent.isCancelled()) {
saturation = feedEvent.getSaturation();
float missingHealth = getMaxHealth() - getHealth();
this.heal(Math.min((float) saturation, missingHealth), RegainReason.EATING);
used = true;
}
}
}
if (used) {
if (!entityhuman.abilities.canInstantlyBuild) {
if (--itemStack.count <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
}
}
MyPetApi.getPlatformHelper().playParticleEffect(myPet.getLocation().get().add(0, getHeadHeight(), 0), "HEART", 0.5F, 0.5F, 0.5F, 0.5F, 5, 20);
return true;
}
}
}
} else {
if (itemStack != null) {
if (itemStack.getItem() == Items.NAME_TAG) {
if (itemStack.hasName()) {
EntityMyPet.super.setCustomName("-");
new BukkitRunnable() {
public void run() {
updateNameTag();
}
}.runTaskLater(MyPetApi.getPlugin(), 1L);
return false;
}
}
}
}
return false;
}
use of org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer in project MyPet by xXKeyleXx.
the class PlatformHelper method playParticleEffect.
/**
* @param location the {@link Location} around which players must be to see the effect
* @param effectName list of effects: https://gist.github.com/riking/5759002
* @param offsetX the amount to be randomly offset by in the X axis
* @param offsetY the amount to be randomly offset by in the Y axis
* @param offsetZ the amount to be randomly offset by in the Z axis
* @param speed the speed of the particles
* @param count the number of particles
* @param radius the radius around the location
*/
public void playParticleEffect(Location location, String effectName, float offsetX, float offsetY, float offsetZ, float speed, int count, int radius, int... data) {
EnumParticle effect;
try {
effect = EnumParticle.valueOf(effectName);
} catch (IllegalArgumentException e) {
effect = EnumParticle.a(effectName);
}
Validate.notNull(location, "Location cannot be null");
Validate.notNull(effect, "Effect cannot be null");
Validate.notNull(location.getWorld(), "World cannot be null");
PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(effect, false, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count, data);
radius = radius * radius;
for (Player player : location.getWorld().getPlayers()) {
if ((int) MyPetApi.getPlatformHelper().distanceSquared(player.getLocation(), location) <= radius) {
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
}
}
Aggregations