Skip to content

Commit

Permalink
Added flying stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Chipley committed Nov 7, 2013
1 parent bf29eb8 commit 8484d6f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/com/Chipmunk9998/Spectate/PlayerState.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class PlayerState {
public int level;
public float exp;
public int slot;
public boolean allowFlight;
public boolean isFlying;
public GameMode mode;
public Location location;

Expand All @@ -37,6 +39,8 @@ public PlayerState(Player p) {
level = p.getLevel();
exp = p.getExp();
slot = p.getInventory().getHeldItemSlot();
allowFlight = p.getAllowFlight();
isFlying = p.isFlying();
mode = p.getGameMode();
location = p.getLocation();

Expand Down
31 changes: 25 additions & 6 deletions src/com/Chipmunk9998/Spectate/api/SpectateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ public void run() {
p.damage(difference);

}else if (getTarget(p).getHealth() > p.getHealth()) {

p.setHealth(getTarget(p).getHealth());

}

}
Expand Down Expand Up @@ -140,6 +140,16 @@ public void run() {

p.getInventory().setHeldItemSlot(getTarget(p).getInventory().getHeldItemSlot());

if (getTarget(p).isFlying()) {

if (!p.isFlying()) {

p.setFlying(true);

}

}

}

}
Expand Down Expand Up @@ -207,7 +217,7 @@ public void startSpectating(Player p, Player target, boolean saveState) {
multiInvStates.put(p, new PlayerState(p));

}

String playerListName = p.getPlayerListName();

if (getSpectateAngle(p) == SpectateAngle.FIRST_PERSON) {
Expand All @@ -221,7 +231,7 @@ public void startSpectating(Player p, Player target, boolean saveState) {
}

p.setPlayerListName(playerListName);

p.setHealth(target.getHealth());

p.teleport(target);
Expand All @@ -247,6 +257,7 @@ public void startSpectating(Player p, Player target, boolean saveState) {
p.setFoodLevel(target.getFoodLevel());

setExperienceCooldown(p, Integer.MAX_VALUE);
p.setAllowFlight(true);

setSpectating(p, true);
setBeingSpectated(target, true);
Expand Down Expand Up @@ -679,7 +690,7 @@ private void setSpectating(Player p, boolean spectating) {

}

public void clickEnable(final Player player) {
public void disableScroll(final Player player, long ticks) {

if (!isClick.contains(player.getName())) {

Expand All @@ -693,13 +704,19 @@ public void run() {

}

}, 5L);
}, ticks);

}

}

public Location getSpectateLocation(Player p) {

if (getSpectateAngle(p) == SpectateAngle.FIRST_PERSON) {

return (getTarget(p).getLocation());

}

Location playerLoc = getTarget(p).getLocation();

Expand Down Expand Up @@ -797,6 +814,8 @@ private void loadFinalState(PlayerState state, Player toPlayer) {
toPlayer.setLevel(state.level);
toPlayer.setExp(state.exp);
toPlayer.getInventory().setHeldItemSlot(state.slot);
toPlayer.setAllowFlight(state.allowFlight);
toPlayer.setFlying(state.isFlying);
toPlayer.setGameMode(state.mode);

for (Player onlinePlayers : plugin.getServer().getOnlinePlayers()) {
Expand Down

0 comments on commit 8484d6f

Please sign in to comment.