9
0
mirror of https://github.com/Xiao-MoMi/Custom-Nameplates.git synced 2025-12-25 09:59:16 +00:00

fix folia again

This commit is contained in:
XiaoMoMi
2024-10-15 01:58:53 +08:00
parent aee8ebf9ae
commit 46d922ab15
3 changed files with 76 additions and 14 deletions

View File

@@ -110,7 +110,7 @@ public class UnlimitedTagManagerImpl implements UnlimitedTagManager, JoinQuitLis
onRemovePlayer(player, player);
onAddPlayer(player, player);
}
}, 100, TimeUnit.MILLISECONDS);
}, VersionHelper.isFolia() ? 500 : 50, TimeUnit.MILLISECONDS);
}
@Override
@@ -120,7 +120,7 @@ public class UnlimitedTagManagerImpl implements UnlimitedTagManager, JoinQuitLis
onRemovePlayer(player, player);
onAddPlayer(player, player);
}
}, 100, TimeUnit.MILLISECONDS);
}, VersionHelper.isFolia() ? 500 : 50, TimeUnit.MILLISECONDS);
}
@Override
@@ -130,7 +130,7 @@ public class UnlimitedTagManagerImpl implements UnlimitedTagManager, JoinQuitLis
onRemovePlayer(player, player);
onAddPlayer(player, player);
}
}, 100, TimeUnit.MILLISECONDS);
}, VersionHelper.isFolia() ? 500 : 50, TimeUnit.MILLISECONDS);
}
@Override

View File

@@ -24,6 +24,7 @@ import net.momirealms.customnameplates.api.feature.JoinQuitListener;
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.api.util.Vector3;
import net.momirealms.customnameplates.backend.feature.actionbar.ActionBarManagerImpl;
import net.momirealms.customnameplates.backend.feature.advance.AdvanceManagerImpl;
import net.momirealms.customnameplates.backend.feature.background.BackgroundManagerImpl;
@@ -40,6 +41,7 @@ import net.momirealms.customnameplates.bukkit.compatibility.NameplatesExpansion;
import net.momirealms.customnameplates.bukkit.compatibility.cosmetic.MagicCosmeticsHook;
import net.momirealms.customnameplates.bukkit.requirement.BukkitRequirementManager;
import net.momirealms.customnameplates.bukkit.scheduler.BukkitSchedulerAdapter;
import net.momirealms.customnameplates.bukkit.util.SimpleLocation;
import net.momirealms.customnameplates.common.dependency.Dependency;
import net.momirealms.customnameplates.common.dependency.DependencyManagerImpl;
import net.momirealms.customnameplates.common.event.EventManager;
@@ -51,6 +53,7 @@ import net.momirealms.customnameplates.common.plugin.logging.PluginLogger;
import net.momirealms.customnameplates.common.plugin.scheduler.AbstractJavaScheduler;
import net.momirealms.customnameplates.common.plugin.scheduler.SchedulerAdapter;
import net.momirealms.customnameplates.common.plugin.scheduler.SchedulerTask;
import net.momirealms.customnameplates.common.util.Pair;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@@ -85,8 +88,8 @@ public class BukkitCustomNameplates extends CustomNameplates implements Listener
private final List<JoinQuitListener> joinQuitListeners = new ArrayList<>();
private final List<PlayerListener> playerListeners = new ArrayList<>();
private final ConcurrentHashMap<String, String> foliaWorldRecorder = new ConcurrentHashMap<>();
private SchedulerTask foliaWorldTask;
private final ConcurrentHashMap<String, SimpleLocation> foliaLocationTracker = new ConcurrentHashMap<>();
private SchedulerTask foliaTrackerTask;
private boolean loaded = false;
@@ -225,21 +228,33 @@ public class BukkitCustomNameplates extends CustomNameplates implements Listener
}
if (VersionHelper.isFolia()) {
this.foliaWorldTask = getScheduler().asyncRepeating(() -> {
this.foliaTrackerTask = getScheduler().asyncRepeating(() -> {
for (CNPlayer player : getOnlinePlayers()) {
String name = player.name();
String previousWorld = this.foliaWorldRecorder.get(name);
if (previousWorld != null) {
SimpleLocation previousLocation = this.foliaLocationTracker.get(name);
if (previousLocation != null) {
String currentWorld = player.world();
if (!currentWorld.equals(previousWorld)) {
this.foliaWorldRecorder.put(name, currentWorld);
if (!currentWorld.equals(previousLocation.world())) {
previousLocation.world(currentWorld);
previousLocation.position(player.position());
for (PlayerListener listener : this.playerListeners) {
listener.onChangeWorld(player);
}
continue;
}
Vector3 previousPos = previousLocation.position();
Vector3 currentPos = player.position();
previousLocation.world(currentWorld);
previousLocation.position(currentPos);
double distance = Math.sqrt(Math.pow((currentPos.x() - previousPos.x()), 2) + Math.pow((currentPos.y() - previousPos.y()), 2) + Math.pow(currentPos.z() - previousPos.z(), 2));
if (distance > 64) {
for (PlayerListener listener : this.playerListeners) {
listener.onTeleport(player);
}
}
}
}
}, 100, 100, TimeUnit.MILLISECONDS);
}, 200, 200, TimeUnit.MILLISECONDS);
}
}
@@ -247,7 +262,7 @@ public class BukkitCustomNameplates extends CustomNameplates implements Listener
public void disable() {
if (!this.loaded) return;
if (this.scheduledMainTask != null) this.scheduledMainTask.cancel();
if (foliaWorldTask != null) foliaWorldTask.cancel();
if (foliaTrackerTask != null) foliaTrackerTask.cancel();
if (configManager != null) this.configManager.disable();
if (actionBarManager != null) this.actionBarManager.disable();
if (bossBarManager != null) this.bossBarManager.disable();
@@ -380,7 +395,7 @@ public class BukkitCustomNameplates extends CustomNameplates implements Listener
listener.onPlayerJoin(user);
}
if (VersionHelper.isFolia()) {
foliaWorldRecorder.put(player.getName(), player.getWorld().getName());
foliaLocationTracker.put(player.getName(), new SimpleLocation(user.world(), user.position()));
}
}
@@ -397,7 +412,7 @@ public class BukkitCustomNameplates extends CustomNameplates implements Listener
}
entityIDFastLookup.remove(cnPlayer.entityID());
if (VersionHelper.isFolia()) {
foliaWorldRecorder.remove(player.getName());
foliaLocationTracker.remove(player.getName());
}
}

View File

@@ -0,0 +1,47 @@
/*
* Copyright (C) <2024> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customnameplates.bukkit.util;
import net.momirealms.customnameplates.api.util.Vector3;
public class SimpleLocation {
private String world;
private Vector3 position;
public SimpleLocation(String world, Vector3 position) {
this.world = world;
this.position = position;
}
public String world() {
return world;
}
public void world(String world) {
this.world = world;
}
public Vector3 position() {
return position;
}
public void position(Vector3 position) {
this.position = position;
}
}