Skip to content

Commit

Permalink
fix teleport
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiao-MoMi committed Oct 10, 2024
1 parent 63075ad commit 7512a97
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,26 @@
/**
* Listener for handling player change worlds
*/
public interface WorldChangeListener {
public interface PlayerListener {

/**
* Called when a player changes the world
*
* @param player the player who changes the world
*/
void onChangeWorld(CNPlayer player);

/**
* Called when a player respawns
*
* @param player the player who respawns
*/
void onRespawn(CNPlayer player);

/**
* Called when a player teleports
*
* @param player the player who respawns
*/
void onTeleport(CNPlayer player);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
import net.momirealms.customnameplates.api.CustomNameplates;
import net.momirealms.customnameplates.api.feature.CarouselText;
import net.momirealms.customnameplates.api.feature.JoinQuitListener;
import net.momirealms.customnameplates.api.feature.RespawnListener;
import net.momirealms.customnameplates.api.feature.WorldChangeListener;
import net.momirealms.customnameplates.api.feature.PlayerListener;
import net.momirealms.customnameplates.api.feature.tag.NameTagConfig;
import net.momirealms.customnameplates.api.feature.tag.TagRenderer;
import net.momirealms.customnameplates.api.feature.tag.UnlimitedTagManager;
Expand All @@ -53,7 +52,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

public class UnlimitedTagManagerImpl implements UnlimitedTagManager, JoinQuitListener, WorldChangeListener, RespawnListener {
public class UnlimitedTagManagerImpl implements UnlimitedTagManager, JoinQuitListener, PlayerListener {

private final CustomNameplates plugin;
private final LinkedHashMap<String, NameTagConfig> configs = new LinkedHashMap<>();
Expand Down Expand Up @@ -106,10 +105,12 @@ public void togglePreviewing(CNPlayer player, boolean preview) {

@Override
public void onChangeWorld(CNPlayer player) {
if (player.isTempPreviewing() || player.isToggleablePreviewing()) {
onRemovePlayer(player, player);
onAddPlayer(player, player);
}
plugin.getScheduler().async().execute(() -> {
if (player.isOnline() && (player.isTempPreviewing() || player.isToggleablePreviewing())) {
onRemovePlayer(player, player);
onAddPlayer(player, player);
}
});
}

@Override
Expand All @@ -122,6 +123,16 @@ public void onRespawn(CNPlayer player) {
}, 50, TimeUnit.MILLISECONDS);
}

@Override
public void onTeleport(CNPlayer player) {
plugin.getScheduler().asyncLater(() -> {
if (player.isOnline() && (player.isTempPreviewing() || player.isToggleablePreviewing())) {
onRemovePlayer(player, player);
onAddPlayer(player, player);
}
}, 50, TimeUnit.MILLISECONDS);
}

@Override
public int previewDuration() {
return previewDuration;
Expand Down
2 changes: 1 addition & 1 deletion bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies {

tasks {
shadowJar {
archiveFileName = "CustomNameplates-Bukkit-${rootProject.properties["project_version"]}.jar"
archiveFileName = "CustomNameplates-${rootProject.properties["project_version"]}.jar"
destinationDirectory.set(file("$rootDir/target"))
relocate("net.kyori", "net.momirealms.customnameplates.libraries")
relocate("org.incendo", "net.momirealms.customnameplates.libraries")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import net.momirealms.customnameplates.api.event.NameplatesReloadEvent;
import net.momirealms.customnameplates.api.feature.ChatListener;
import net.momirealms.customnameplates.api.feature.JoinQuitListener;
import net.momirealms.customnameplates.api.feature.RespawnListener;
import net.momirealms.customnameplates.api.feature.WorldChangeListener;
import net.momirealms.customnameplates.api.feature.PlayerListener;
import net.momirealms.customnameplates.api.helper.AdventureHelper;
import net.momirealms.customnameplates.api.helper.VersionHelper;
import net.momirealms.customnameplates.backend.feature.actionbar.ActionBarManagerImpl;
Expand Down Expand Up @@ -57,10 +56,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.*;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.InputStream;
Expand All @@ -83,8 +79,7 @@ public class BukkitCustomNameplates extends CustomNameplates implements Listener
private final JavaPlugin bootstrap;

private final List<JoinQuitListener> joinQuitListeners = new ArrayList<>();
private final List<WorldChangeListener> worldChangeListeners = new ArrayList<>();
private final List<RespawnListener> respawnListeners = new ArrayList<>();
private final List<PlayerListener> playerListeners = new ArrayList<>();

private boolean loaded = false;

Expand Down Expand Up @@ -168,8 +163,7 @@ public void enable() {
this.joinQuitListeners.add((JoinQuitListener) actionBarManager);
this.joinQuitListeners.add((JoinQuitListener) bossBarManager);
this.joinQuitListeners.add((JoinQuitListener) unlimitedTagManager);
this.worldChangeListeners.add((WorldChangeListener) unlimitedTagManager);
this.respawnListeners.add((RespawnListener) unlimitedTagManager);
this.playerListeners.add((PlayerListener) unlimitedTagManager);
this.chatManager.registerListener((ChatListener) bubbleManager);

Bukkit.getPluginManager().registerEvents(this, getBootstrap());
Expand Down Expand Up @@ -367,7 +361,7 @@ public void onQuit(PlayerQuitEvent event) {
public void onChangeWorld(PlayerChangedWorldEvent event) {
CNPlayer cnPlayer = getPlayer(event.getPlayer().getUniqueId());
if (cnPlayer != null) {
for (WorldChangeListener listener : worldChangeListeners) {
for (PlayerListener listener : playerListeners) {
listener.onChangeWorld(cnPlayer);
}
}
Expand All @@ -377,12 +371,22 @@ public void onChangeWorld(PlayerChangedWorldEvent event) {
public void onRespawn(PlayerRespawnEvent event) {
CNPlayer cnPlayer = getPlayer(event.getPlayer().getUniqueId());
if (cnPlayer != null) {
for (RespawnListener listener : respawnListeners) {
for (PlayerListener listener : playerListeners) {
listener.onRespawn(cnPlayer);
}
}
}

@EventHandler(ignoreCancelled = true)
public void onTeleport(PlayerTeleportEvent event) {
CNPlayer cnPlayer = getPlayer(event.getPlayer().getUniqueId());
if (cnPlayer != null) {
for (PlayerListener listener : playerListeners) {
listener.onTeleport(cnPlayer);
}
}
}

public BukkitSenderFactory getSenderFactory() {
return senderFactory;
}
Expand Down

0 comments on commit 7512a97

Please sign in to comment.