Skip to content

Commit

Permalink
Add PlayerAnimation.START_ELYTRA
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jun 29, 2018
1 parent e4f0596 commit 23f03c1
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion main/src/main/java/net/citizensnpcs/Citizens.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ public void onDisable() {

@Override
public void onEnable() {
CitizensAPI.setImplementation(this);
config = new Settings(getDataFolder());
setupTranslator();
CitizensAPI.setImplementation(this);
// Disable if the server is not using the compatible Minecraft version
String mcVersion = Util.getMinecraftRevision();
compatible = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.citizensnpcs.commands;

import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import net.citizensnpcs.Citizens;
import net.citizensnpcs.api.command.Command;
Expand Down Expand Up @@ -28,6 +29,7 @@ public void citizens(CommandContext args, CommandSender sender, NPC npc) throws
Messaging.send(sender, " <7>-- <c>Written by fullwall and aPunch");
Messaging.send(sender, " <7>-- <c>Source Code: http://github.com/CitizensDev");
Messaging.send(sender, " <7>-- <c>Website: " + plugin.getDescription().getWebsite());
Messaging.log(((Player) sender).getInventory().getItemInOffHand());
}

@Command(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,7 @@ public void run(NPC npc) throws CommandException {
public void flyable(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
boolean flyable = args.argsLength() == 2 ? args.getString(1).equals("true") : !npc.isFlyable();
npc.setFlyable(flyable);
flyable = npc.isFlyable(); // may not have applied, eg bats always
// flyable
flyable = npc.isFlyable(); // may not have applied, eg bats always flyable
Messaging.sendTr(sender, flyable ? Messages.FLYABLE_SET : Messages.FLYABLE_UNSET, npc.getName());
}

Expand Down
4 changes: 4 additions & 0 deletions main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ private void updateFlyableState() {
if (Util.isAlwaysFlyable(type)) {
data().setPersistent(NPC.FLYABLE_METADATA, true);
}
if (type == EntityType.PLAYER) {
Player player = (Player) getEntity();
player.getInventory().getExtraContents();
}
}

private static final String NPC_METADATA_MARKER = "NPC";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;

import com.google.common.collect.Lists;
Expand All @@ -19,11 +23,13 @@
import net.citizensnpcs.api.astar.pathfinder.BlockExaminer;
import net.citizensnpcs.api.astar.pathfinder.ChunkBlockSource;
import net.citizensnpcs.api.astar.pathfinder.FlyingBlockExaminer;
import net.citizensnpcs.api.astar.pathfinder.MinecraftBlockExaminer;
import net.citizensnpcs.api.astar.pathfinder.Path;
import net.citizensnpcs.api.astar.pathfinder.VectorGoal;
import net.citizensnpcs.api.astar.pathfinder.VectorNode;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.PlayerAnimation;

public class FlyingAStarNavigationStrategy extends AbstractPathStrategy {
private final NPC npc;
Expand Down Expand Up @@ -114,6 +120,18 @@ public boolean update() {
npc.getEntity().getWorld().playEffect(vector.toLocation(npc.getEntity().getWorld()), Effect.ENDER_SIGNAL,
0);
}
if (npc.getEntity().getType() == EntityType.PLAYER) {
ItemStack stack = ((Player) npc.getEntity()).getInventory().getChestplate();
if (!MinecraftBlockExaminer.canStandOn(current.getBlock().getRelative(BlockFace.DOWN))) {
try {
if (stack != null && stack.getType() == Material.ELYTRA) {
PlayerAnimation.START_ELYTRA.play((Player) npc.getEntity());
}
} catch (Exception ex) {
// 1.8 compatibility
}
}
}

double d0 = vector.getX() + 0.5D - current.getX();
double d1 = vector.getY() + 0.1D - current.getY();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,5 @@ public boolean handle(LivingEntity attacker, LivingEntity bukkitTarget) {
}
};
private static final Location HANDLE_LOCATION = new Location(null, 0, 0, 0);

private static final Location TARGET_LOCATION = new Location(null, 0, 0, 0);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum PlayerAnimation {
SIT,
SLEEP,
SNEAK,
START_ELYTRA,
START_USE_MAINHAND_ITEM,
START_USE_OFFHAND_ITEM,
STOP_SITTING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public void run() {
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
radius);
break;
case START_ELYTRA:
player.M();
break;
case START_USE_MAINHAND_ITEM:
player.c(EnumHand.MAIN_HAND);
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public void run() {
}
}.runTaskTimer(CitizensAPI.getPlugin(), 0, 1);
break;
case START_ELYTRA:
player.M();
break;
case SLEEP:
PacketPlayOutBed packet = new PacketPlayOutBed(player,
new BlockPosition((int) player.locX, (int) player.locY, (int) player.locZ));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public void run() {
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
radius);
break;
case START_ELYTRA:
player.N();
break;
case START_USE_MAINHAND_ITEM:
player.c(EnumHand.MAIN_HAND);
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
Expand Down

0 comments on commit 23f03c1

Please sign in to comment.