Skip to content

Commit

Permalink
Merge pull request #1 from FoxMinecraft/banana/npc-skin-fix
Browse files Browse the repository at this point in the history
Remove XP bar when playing replays; Add an action transformer when di…
  • Loading branch information
IllusionTheDev committed Oct 4, 2021
2 parents 51a47af + 48549d6 commit fec6205
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
12 changes: 11 additions & 1 deletion src/main/java/me/jumper251/replay/replaysystem/Replay.java
Expand Up @@ -13,6 +13,7 @@

import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;

public class Replay {

Expand All @@ -27,6 +28,8 @@ public class Replay {

private boolean isRecording, isPlaying;

private Consumer<Replayer> replayPreStartCallback;

public Replay() {
this.id = StringUtils.getRandomString(6);
this.data = new ReplayData();
Expand Down Expand Up @@ -60,9 +63,12 @@ public void play(Player watcher) {
}

}

private void startReplay(Player watcher) {
this.replayer = new Replayer(this, watcher);
if (replayPreStartCallback != null) {
replayPreStartCallback.accept(replayer);
}
this.replayer.start();
this.isPlaying = true;
}
Expand Down Expand Up @@ -114,4 +120,8 @@ public ReplayInfo getReplayInfo() {
public void setReplayInfo(ReplayInfo replayInfo) {
this.replayInfo = replayInfo;
}

public void setReplayPreStartCallback(Consumer<Replayer> callback) {
replayPreStartCallback = callback;
}
}
Expand Up @@ -19,6 +19,7 @@
import org.bukkit.scheduler.BukkitRunnable;

import java.util.*;
import java.util.function.Function;


public class Replayer {
Expand All @@ -45,6 +46,8 @@ public class Replayer {

private boolean silent;

private Function<ActionData, ActionData> actionTransformer;

public Replayer(Replay replay, Player watcher) {
this.replay = replay;
this.watcher = watcher;
Expand Down Expand Up @@ -115,7 +118,8 @@ public void run() {
Replayer.this.currentTicks++;
}

updateXPBar();
// Disable the XP bar animation
// updateXPBar();
} else {

stop();
Expand All @@ -136,6 +140,10 @@ public void executeTick(int tick, boolean reversed) {
List<ActionData> list = data.getActions().get(tick);
for (ActionData action : list) {

if (actionTransformer != null) {
action = actionTransformer.apply(action);
}

utils.handleAction(action, data, reversed);

if (action.getType() == ActionType.CUSTOM) {
Expand Down Expand Up @@ -220,6 +228,10 @@ public ReplayingUtils getUtils() {
public ReplaySession getSession() {
return session;
}

public void setActionTransformer(Function<ActionData, ActionData> transformer) {
this.actionTransformer = transformer;
}

public boolean isPaused() {
return paused;
Expand Down
@@ -1,20 +1,36 @@
package me.jumper251.replay.replaysystem.utils.entities;

import com.comphenix.packetwrapper.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

import org.bukkit.Location;
import org.bukkit.entity.Player;

import com.comphenix.packetwrapper.WrapperPlayServerAnimation;
import com.comphenix.packetwrapper.WrapperPlayServerBed;
import com.comphenix.packetwrapper.WrapperPlayServerEntityDestroy;
import com.comphenix.packetwrapper.WrapperPlayServerEntityEquipment;
import com.comphenix.packetwrapper.WrapperPlayServerEntityHeadRotation;
import com.comphenix.packetwrapper.WrapperPlayServerEntityLook;
import com.comphenix.packetwrapper.WrapperPlayServerEntityMetadata;
import com.comphenix.packetwrapper.WrapperPlayServerEntityTeleport;
import com.comphenix.packetwrapper.WrapperPlayServerNamedEntitySpawn;
import com.comphenix.packetwrapper.WrapperPlayServerPlayerInfo;
import com.comphenix.packetwrapper.WrapperPlayServerScoreboardTeam;
import com.comphenix.packetwrapper.WrapperPlayServerScoreboardTeam.Mode;
import com.comphenix.packetwrapper.v15.WrapperPlayServerRelEntityMoveLook;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.*;
import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.EnumWrappers;
import com.comphenix.protocol.wrappers.PlayerInfoData;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedGameProfile;

import me.jumper251.replay.replaysystem.utils.NPCManager;
import me.jumper251.replay.utils.MathUtils;
import me.jumper251.replay.utils.StringUtils;
import org.bukkit.Location;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;


public class PacketNPC implements INPC {
Expand Down Expand Up @@ -255,6 +271,7 @@ public void addToTeam(String team) {
public void updateSkin() {
WrapperPlayServerPlayerInfo remove = getInfoRemovePacket();
WrapperPlayServerPlayerInfo add = getInfoAddPacket();

for (Player player : Arrays.asList(this.visible)) {
if (player != null) {
remove.sendPacket(player);
Expand Down

0 comments on commit fec6205

Please sign in to comment.