Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove XP bar when playing replays; Add an action transformer when di… #1

Merged
merged 1 commit into from Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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