mirror of
https://github.com/Xiao-MoMi/Custom-Nameplates.git
synced 2025-12-23 08:59:30 +00:00
We need more work
This commit is contained in:
@@ -83,10 +83,10 @@ public abstract class AbstractCNPlayer implements CNPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String updatePlayerPlaceholder(PlayerPlaceholder placeholder) {
|
private String updatePlayerPlaceholder(PlayerPlaceholder placeholder) {
|
||||||
TimeStampData<String> value = getRawValue(placeholder);
|
TimeStampData<String> value = getRawPlayerValue(placeholder);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
value = new TimeStampData<>(placeholder.request(this), MainTask.getTicks(), true);
|
value = new TimeStampData<>(placeholder.request(this), MainTask.getTicks(), true);
|
||||||
setValue(placeholder, value);
|
setPlayerValue(placeholder, value);
|
||||||
return value.data();
|
return value.data();
|
||||||
}
|
}
|
||||||
if (value.ticks() != MainTask.getTicks()) {
|
if (value.ticks() != MainTask.getTicks()) {
|
||||||
@@ -119,7 +119,7 @@ public abstract class AbstractCNPlayer implements CNPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String updateSharedPlaceholder(SharedPlaceholder placeholder) {
|
private String updateSharedPlaceholder(SharedPlaceholder placeholder) {
|
||||||
TimeStampData<String> value = getRawValue(placeholder);
|
TimeStampData<String> value = getRawSharedValue(placeholder);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
String latest;
|
String latest;
|
||||||
if (MainTask.hasRequested(placeholder.countId())) {
|
if (MainTask.hasRequested(placeholder.countId())) {
|
||||||
@@ -128,7 +128,7 @@ public abstract class AbstractCNPlayer implements CNPlayer {
|
|||||||
latest = placeholder.request();
|
latest = placeholder.request();
|
||||||
}
|
}
|
||||||
value = new TimeStampData<>(latest, MainTask.getTicks(), true);
|
value = new TimeStampData<>(latest, MainTask.getTicks(), true);
|
||||||
setValue(placeholder, value);
|
setSharedValue(placeholder, value);
|
||||||
return value.data();
|
return value.data();
|
||||||
}
|
}
|
||||||
if (value.ticks() != MainTask.getTicks()) {
|
if (value.ticks() != MainTask.getTicks()) {
|
||||||
@@ -266,86 +266,98 @@ public abstract class AbstractCNPlayer implements CNPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValue(Placeholder placeholder, TimeStampData<String> value) {
|
public void setPlayerValue(PlayerPlaceholder placeholder, TimeStampData<String> value) {
|
||||||
cachedValues.put(placeholder.countId(), value);
|
cachedValues.put(placeholder.countId(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setValue(Placeholder placeholder, String value) {
|
public void setSharedValue(SharedPlaceholder placeholder, TimeStampData<String> value) {
|
||||||
TimeStampData<String> previous = cachedValues.get(placeholder.countId());
|
cachedValues.put(placeholder.countId(), value);
|
||||||
int currentTicks = MainTask.getTicks();
|
|
||||||
boolean changed = false;
|
|
||||||
if (previous != null) {
|
|
||||||
if (previous.ticks() == currentTicks) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
String data = previous.data();
|
|
||||||
if (!data.equals(value)) {
|
|
||||||
changed = true;
|
|
||||||
previous.data(value);
|
|
||||||
previous.updateTicks(true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
changed= true;
|
|
||||||
previous = new TimeStampData<>(value, currentTicks, true);
|
|
||||||
cachedValues.put(placeholder.countId(), previous);
|
|
||||||
}
|
|
||||||
return changed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setRelationalValue(Placeholder placeholder, CNPlayer another, TimeStampData<String> value) {
|
public void setRelationalValue(RelationalPlaceholder placeholder, CNPlayer another, TimeStampData<String> value) {
|
||||||
WeakHashMap<CNPlayer, TimeStampData<String>> map = cachedRelationalValues.computeIfAbsent(placeholder.countId(), k -> new WeakHashMap<>());
|
WeakHashMap<CNPlayer, TimeStampData<String>> map = cachedRelationalValues.computeIfAbsent(placeholder.countId(), k -> new WeakHashMap<>());
|
||||||
map.put(another, value);
|
map.put(another, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public boolean setPlayerValue(PlayerPlaceholder placeholder, String value) {
|
||||||
|
// TimeStampData<String> previous = cachedValues.get(placeholder.countId());
|
||||||
|
// int currentTicks = MainTask.getTicks();
|
||||||
|
// boolean changed = false;
|
||||||
|
// if (previous != null) {
|
||||||
|
// if (previous.ticks() == currentTicks) {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// String data = previous.data();
|
||||||
|
// if (!data.equals(value)) {
|
||||||
|
// changed = true;
|
||||||
|
// previous.data(value);
|
||||||
|
// previous.updateTicks(true);
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// changed= true;
|
||||||
|
// previous = new TimeStampData<>(value, currentTicks, true);
|
||||||
|
// cachedValues.put(placeholder.countId(), previous);
|
||||||
|
// }
|
||||||
|
// return changed;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public boolean setRelationalValue(RelationalPlaceholder placeholder, CNPlayer another, String value) {
|
||||||
|
// WeakHashMap<CNPlayer, TimeStampData<String>> map = cachedRelationalValues.computeIfAbsent(placeholder.countId(), k -> new WeakHashMap<>());
|
||||||
|
// TimeStampData<String> previous = map.get(another);
|
||||||
|
// int currentTicks = MainTask.getTicks();
|
||||||
|
// boolean changed = false;
|
||||||
|
// if (previous != null) {
|
||||||
|
// if (previous.ticks() == currentTicks) {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// String data = previous.data();
|
||||||
|
// if (!data.equals(value)) {
|
||||||
|
// changed = true;
|
||||||
|
// previous.data(value);
|
||||||
|
// previous.updateTicks(true);
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// changed= true;
|
||||||
|
// previous = new TimeStampData<>(value, currentTicks, true);
|
||||||
|
// map.put(another, previous);
|
||||||
|
// }
|
||||||
|
// return changed;
|
||||||
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setRelationalValue(Placeholder placeholder, CNPlayer another, String value) {
|
public @NotNull String getCachedSharedValue(SharedPlaceholder placeholder) {
|
||||||
WeakHashMap<CNPlayer, TimeStampData<String>> map = cachedRelationalValues.computeIfAbsent(placeholder.countId(), k -> new WeakHashMap<>());
|
return updateSharedPlaceholder(placeholder);
|
||||||
TimeStampData<String> previous = map.get(another);
|
|
||||||
int currentTicks = MainTask.getTicks();
|
|
||||||
boolean changed = false;
|
|
||||||
if (previous != null) {
|
|
||||||
if (previous.ticks() == currentTicks) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
String data = previous.data();
|
|
||||||
if (!data.equals(value)) {
|
|
||||||
changed = true;
|
|
||||||
previous.data(value);
|
|
||||||
previous.updateTicks(true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
changed= true;
|
|
||||||
previous = new TimeStampData<>(value, currentTicks, true);
|
|
||||||
map.put(another, previous);
|
|
||||||
}
|
|
||||||
return changed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getCachedValue(Placeholder placeholder) {
|
public @NotNull String getCachedPlayerValue(PlayerPlaceholder placeholder) {
|
||||||
return Optional.ofNullable(cachedValues.get(placeholder.countId())).map(TimeStampData::data).orElse(placeholder.id());
|
return updatePlayerPlaceholder(placeholder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String getCachedRelationalValue(RelationalPlaceholder placeholder, CNPlayer another) {
|
||||||
|
return updateRelationalPlaceholder(placeholder, another);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public TimeStampData<String> getRawValue(Placeholder placeholder) {
|
public TimeStampData<String> getRawPlayerValue(PlayerPlaceholder placeholder) {
|
||||||
return cachedValues.get(placeholder.countId());
|
return cachedValues.get(placeholder.countId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getCachedRelationalValue(Placeholder placeholder, CNPlayer another) {
|
public TimeStampData<String> getRawSharedValue(SharedPlaceholder placeholder) {
|
||||||
WeakHashMap<CNPlayer, TimeStampData<String>> map = cachedRelationalValues.get(placeholder.countId());
|
return cachedValues.get(placeholder.countId());
|
||||||
if (map == null) {
|
|
||||||
return placeholder.id();
|
|
||||||
}
|
|
||||||
return Optional.ofNullable(map.get(another)).map(TimeStampData::data).orElse(placeholder.id());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public TimeStampData<String> getRawRelationalValue(Placeholder placeholder, CNPlayer another) {
|
public TimeStampData<String> getRawRelationalValue(RelationalPlaceholder placeholder, CNPlayer another) {
|
||||||
WeakHashMap<CNPlayer, TimeStampData<String>> map = cachedRelationalValues.get(placeholder.countId());
|
WeakHashMap<CNPlayer, TimeStampData<String>> map = cachedRelationalValues.get(placeholder.countId());
|
||||||
if (map == null) {
|
if (map == null) {
|
||||||
return null;
|
return null;
|
||||||
@@ -431,12 +443,12 @@ public abstract class AbstractCNPlayer implements CNPlayer {
|
|||||||
}
|
}
|
||||||
tracker = new Tracker(another);
|
tracker = new Tracker(another);
|
||||||
trackers.put(another, tracker);
|
trackers.put(another, tracker);
|
||||||
for (Placeholder placeholder : activePlaceholders()) {
|
// for (Placeholder placeholder : activePlaceholders()) {
|
||||||
if (placeholder instanceof RelationalPlaceholder relationalPlaceholder) {
|
// if (placeholder instanceof RelationalPlaceholder relationalPlaceholder) {
|
||||||
String value = relationalPlaceholder.request(this, another);
|
// String value = relationalPlaceholder.request(this, another);
|
||||||
setRelationalValue(placeholder, another, value);
|
// setRelationalValue(relationalPlaceholder, another, value);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return tracker;
|
return tracker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ import net.momirealms.customnameplates.api.feature.TimeStampData;
|
|||||||
import net.momirealms.customnameplates.api.feature.tag.TeamView;
|
import net.momirealms.customnameplates.api.feature.tag.TeamView;
|
||||||
import net.momirealms.customnameplates.api.network.Tracker;
|
import net.momirealms.customnameplates.api.network.Tracker;
|
||||||
import net.momirealms.customnameplates.api.placeholder.Placeholder;
|
import net.momirealms.customnameplates.api.placeholder.Placeholder;
|
||||||
|
import net.momirealms.customnameplates.api.placeholder.PlayerPlaceholder;
|
||||||
|
import net.momirealms.customnameplates.api.placeholder.RelationalPlaceholder;
|
||||||
import net.momirealms.customnameplates.api.placeholder.SharedPlaceholder;
|
import net.momirealms.customnameplates.api.placeholder.SharedPlaceholder;
|
||||||
import net.momirealms.customnameplates.api.requirement.Requirement;
|
import net.momirealms.customnameplates.api.requirement.Requirement;
|
||||||
import net.momirealms.customnameplates.api.util.Vector3;
|
import net.momirealms.customnameplates.api.util.Vector3;
|
||||||
@@ -201,16 +203,16 @@ public interface CNPlayer {
|
|||||||
* @return the cached data as a string
|
* @return the cached data as a string
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
String getCachedValue(Placeholder placeholder);
|
String getCachedSharedValue(SharedPlaceholder placeholder);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the cached {@link TimeStampData} for a given placeholder.
|
* Retrieves the cached data for a given placeholder.
|
||||||
*
|
*
|
||||||
* @param placeholder the placeholder to retrieve data for
|
* @param placeholder the placeholder to retrieve data for
|
||||||
* @return the cached TickStampData, or null if none exists
|
* @return the cached data as a string
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@NotNull
|
||||||
TimeStampData<String> getRawValue(Placeholder placeholder);
|
String getCachedPlayerValue(PlayerPlaceholder placeholder);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the cached relational data between this player and another for a given placeholder.
|
* Retrieves the cached relational data between this player and another for a given placeholder.
|
||||||
@@ -220,7 +222,25 @@ public interface CNPlayer {
|
|||||||
* @return the relational data as a string
|
* @return the relational data as a string
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
String getCachedRelationalValue(Placeholder placeholder, CNPlayer another);
|
String getCachedRelationalValue(RelationalPlaceholder placeholder, CNPlayer another);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the cached {@link TimeStampData} for a given placeholder.
|
||||||
|
*
|
||||||
|
* @param placeholder the placeholder to retrieve data for
|
||||||
|
* @return the cached TickStampData, or null if none exists
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
TimeStampData<String> getRawPlayerValue(PlayerPlaceholder placeholder);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the cached {@link TimeStampData} for a given placeholder.
|
||||||
|
*
|
||||||
|
* @param placeholder the placeholder to retrieve data for
|
||||||
|
* @return the cached TickStampData, or null if none exists
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
TimeStampData<String> getRawSharedValue(SharedPlaceholder placeholder);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the cached relational {@link TimeStampData} for a given placeholder.
|
* Retrieves the cached relational {@link TimeStampData} for a given placeholder.
|
||||||
@@ -230,7 +250,7 @@ public interface CNPlayer {
|
|||||||
* @return the cached relational TickStampData, or null if none exists
|
* @return the cached relational TickStampData, or null if none exists
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
TimeStampData<String> getRawRelationalValue(Placeholder placeholder, CNPlayer another);
|
TimeStampData<String> getRawRelationalValue(RelationalPlaceholder placeholder, CNPlayer another);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caches the specified {@link TimeStampData} for the given placeholder.
|
* Caches the specified {@link TimeStampData} for the given placeholder.
|
||||||
@@ -238,16 +258,15 @@ public interface CNPlayer {
|
|||||||
* @param placeholder the placeholder to cache
|
* @param placeholder the placeholder to cache
|
||||||
* @param value the value to cache
|
* @param value the value to cache
|
||||||
*/
|
*/
|
||||||
void setValue(Placeholder placeholder, TimeStampData<String> value);
|
void setPlayerValue(PlayerPlaceholder placeholder, TimeStampData<String> value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caches the specified value for the given placeholder.
|
* Caches the specified {@link TimeStampData} for the given placeholder.
|
||||||
*
|
*
|
||||||
* @param placeholder the placeholder to cache
|
* @param placeholder the placeholder to cache
|
||||||
* @param value the value to cache
|
* @param value the value to cache
|
||||||
* @return true if the value was changed, false otherwise
|
|
||||||
*/
|
*/
|
||||||
boolean setValue(Placeholder placeholder, String value);
|
void setSharedValue(SharedPlaceholder placeholder, TimeStampData<String> value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caches the specified relational {@link TimeStampData} for a given placeholder and player.
|
* Caches the specified relational {@link TimeStampData} for a given placeholder and player.
|
||||||
@@ -256,17 +275,26 @@ public interface CNPlayer {
|
|||||||
* @param another the other player
|
* @param another the other player
|
||||||
* @param value the value to cache
|
* @param value the value to cache
|
||||||
*/
|
*/
|
||||||
void setRelationalValue(Placeholder placeholder, CNPlayer another, TimeStampData<String> value);
|
void setRelationalValue(RelationalPlaceholder placeholder, CNPlayer another, TimeStampData<String> value);
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Caches the specified relational value for a given placeholder and player.
|
// * Caches the specified value for the given placeholder.
|
||||||
*
|
// *
|
||||||
* @param placeholder the relational placeholder
|
// * @param placeholder the placeholder to cache
|
||||||
* @param another the other player
|
// * @param value the value to cache
|
||||||
* @param value the value to cache
|
// * @return true if the value was changed, false otherwise
|
||||||
* @return true if the value was changed, false otherwise
|
// */
|
||||||
*/
|
// boolean setPlayerValue(PlayerPlaceholder placeholder, String value);
|
||||||
boolean setRelationalValue(Placeholder placeholder, CNPlayer another, String value);
|
|
||||||
|
// /**
|
||||||
|
// * Caches the specified relational value for a given placeholder and player.
|
||||||
|
// *
|
||||||
|
// * @param placeholder the relational placeholder
|
||||||
|
// * @param another the other player
|
||||||
|
// * @param value the value to cache
|
||||||
|
// * @return true if the value was changed, false otherwise
|
||||||
|
// */
|
||||||
|
// boolean setRelationalValue(RelationalPlaceholder placeholder, CNPlayer another, String value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a feature to the player
|
* Adds a feature to the player
|
||||||
|
|||||||
@@ -55,18 +55,24 @@ public class PreParsedDynamicText {
|
|||||||
for (String id : detectedPlaceholders) {
|
for (String id : detectedPlaceholders) {
|
||||||
Placeholder placeholder = manager.getPlaceholder(id);
|
Placeholder placeholder = manager.getPlaceholder(id);
|
||||||
placeholders.add(placeholder);
|
placeholders.add(placeholder);
|
||||||
if (placeholder instanceof RelationalPlaceholder) {
|
if (placeholder instanceof RelationalPlaceholder relationalPlaceholder) {
|
||||||
convertor.add((owner) -> (viewer) -> owner.getCachedRelationalValue(placeholder, viewer));
|
convertor.add((owner) -> (viewer) -> owner.getCachedRelationalValue(relationalPlaceholder, viewer));
|
||||||
} else if (placeholder instanceof PlayerPlaceholder playerPlaceholder) {
|
} else if (placeholder instanceof PlayerPlaceholder playerPlaceholder) {
|
||||||
convertor.add((owner) -> (viewer) -> {
|
convertor.add((owner) -> (viewer) -> {
|
||||||
if (owner != null) {
|
if (owner != null) {
|
||||||
return owner.getCachedValue(placeholder);
|
return owner.getCachedPlayerValue(playerPlaceholder);
|
||||||
} else {
|
} else {
|
||||||
return playerPlaceholder.request(null);
|
return playerPlaceholder.request(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (placeholder instanceof SharedPlaceholder sharedPlaceholder) {
|
} else if (placeholder instanceof SharedPlaceholder sharedPlaceholder) {
|
||||||
convertor.add((owner) -> (viewer) -> sharedPlaceholder.getLatestValue());
|
convertor.add((owner) -> (viewer) -> {
|
||||||
|
if (owner != null) {
|
||||||
|
return owner.getCachedSharedValue(sharedPlaceholder);
|
||||||
|
} else {
|
||||||
|
return sharedPlaceholder.request();
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
convertor.add((owner) -> (viewer) -> id);
|
convertor.add((owner) -> (viewer) -> id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -584,10 +584,10 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
|
|||||||
List<RelationalPlaceholder> delayedPlaceholdersToUpdate = new ObjectArrayList<>();
|
List<RelationalPlaceholder> delayedPlaceholdersToUpdate = new ObjectArrayList<>();
|
||||||
for (Placeholder placeholder : player.activePlaceholdersToRefresh()) {
|
for (Placeholder placeholder : player.activePlaceholdersToRefresh()) {
|
||||||
if (placeholder instanceof PlayerPlaceholder playerPlaceholder) {
|
if (placeholder instanceof PlayerPlaceholder playerPlaceholder) {
|
||||||
TimeStampData<String> previous = player.getRawValue(placeholder);
|
TimeStampData<String> previous = player.getRawPlayerValue(playerPlaceholder);
|
||||||
if (previous == null) {
|
if (previous == null) {
|
||||||
String value = playerPlaceholder.request(player);
|
String value = playerPlaceholder.request(player);
|
||||||
player.setValue(placeholder, new TimeStampData<>(value, MainTask.getTicks(), true));
|
player.setPlayerValue(playerPlaceholder, new TimeStampData<>(value, MainTask.getTicks(), true));
|
||||||
featuresToNotifyUpdates.addAll(player.activeFeatures(placeholder));
|
featuresToNotifyUpdates.addAll(player.activeFeatures(placeholder));
|
||||||
} else {
|
} else {
|
||||||
if (previous.ticks() > MainTask.getTicks() - getRefreshInterval(placeholder.countId())) {
|
if (previous.ticks() > MainTask.getTicks() - getRefreshInterval(placeholder.countId())) {
|
||||||
@@ -609,7 +609,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
|
|||||||
} else if (placeholder instanceof RelationalPlaceholder relationalPlaceholder) {
|
} else if (placeholder instanceof RelationalPlaceholder relationalPlaceholder) {
|
||||||
delayedPlaceholdersToUpdate.add(relationalPlaceholder);
|
delayedPlaceholdersToUpdate.add(relationalPlaceholder);
|
||||||
} else if (placeholder instanceof SharedPlaceholder sharedPlaceholder) {
|
} else if (placeholder instanceof SharedPlaceholder sharedPlaceholder) {
|
||||||
TimeStampData<String> previous = player.getRawValue(placeholder);
|
TimeStampData<String> previous = player.getRawSharedValue(sharedPlaceholder);
|
||||||
if (previous == null) {
|
if (previous == null) {
|
||||||
String value;
|
String value;
|
||||||
// if the shared placeholder has been updated by other players
|
// if the shared placeholder has been updated by other players
|
||||||
@@ -618,7 +618,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
|
|||||||
} else {
|
} else {
|
||||||
value = sharedPlaceholder.request();
|
value = sharedPlaceholder.request();
|
||||||
}
|
}
|
||||||
player.setValue(placeholder, new TimeStampData<>(value, MainTask.getTicks(), true));
|
player.setSharedValue(sharedPlaceholder, new TimeStampData<>(value, MainTask.getTicks(), true));
|
||||||
featuresToNotifyUpdates.addAll(player.activeFeatures(placeholder));
|
featuresToNotifyUpdates.addAll(player.activeFeatures(placeholder));
|
||||||
} else {
|
} else {
|
||||||
// The placeholder has been refreshed by other codes
|
// The placeholder has been refreshed by other codes
|
||||||
|
|||||||
@@ -21,18 +21,15 @@ import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
|||||||
import me.clip.placeholderapi.expansion.Relational;
|
import me.clip.placeholderapi.expansion.Relational;
|
||||||
import net.momirealms.customnameplates.api.CNPlayer;
|
import net.momirealms.customnameplates.api.CNPlayer;
|
||||||
import net.momirealms.customnameplates.api.CustomNameplates;
|
import net.momirealms.customnameplates.api.CustomNameplates;
|
||||||
import net.momirealms.customnameplates.api.feature.TimeStampData;
|
|
||||||
import net.momirealms.customnameplates.api.placeholder.Placeholder;
|
import net.momirealms.customnameplates.api.placeholder.Placeholder;
|
||||||
import net.momirealms.customnameplates.api.placeholder.PlayerPlaceholder;
|
import net.momirealms.customnameplates.api.placeholder.PlayerPlaceholder;
|
||||||
|
import net.momirealms.customnameplates.api.placeholder.RelationalPlaceholder;
|
||||||
|
import net.momirealms.customnameplates.api.placeholder.SharedPlaceholder;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class NameplatesExpansion extends PlaceholderExpansion implements Relational {
|
public class NameplatesExpansion extends PlaceholderExpansion implements Relational {
|
||||||
|
|
||||||
private final CustomNameplates plugin;
|
private final CustomNameplates plugin;
|
||||||
@@ -64,14 +61,10 @@ public class NameplatesExpansion extends PlaceholderExpansion implements Relatio
|
|||||||
@Override
|
@Override
|
||||||
public @Nullable String onRequest(OfflinePlayer player, @NotNull String params) {
|
public @Nullable String onRequest(OfflinePlayer player, @NotNull String params) {
|
||||||
Placeholder placeholder = plugin.getPlaceholderManager().getRegisteredPlaceholder("%np_" + params + "%");
|
Placeholder placeholder = plugin.getPlaceholderManager().getRegisteredPlaceholder("%np_" + params + "%");
|
||||||
|
CNPlayer cnPlayer = player == null ? null : plugin.getPlayer(player.getUniqueId());
|
||||||
if (placeholder instanceof PlayerPlaceholder playerPlaceholder) {
|
if (placeholder instanceof PlayerPlaceholder playerPlaceholder) {
|
||||||
CNPlayer cnPlayer = player == null ? null : plugin.getPlayer(player.getUniqueId());
|
|
||||||
if (placeholder.children().isEmpty()) {
|
|
||||||
return playerPlaceholder.request(cnPlayer);
|
|
||||||
}
|
|
||||||
if (cnPlayer != null) {
|
if (cnPlayer != null) {
|
||||||
cnPlayer.forceUpdatePlaceholders(Set.of(placeholder), Collections.emptySet());
|
return cnPlayer.getCachedPlayerValue(playerPlaceholder);
|
||||||
return cnPlayer.getCachedValue(placeholder);
|
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
return playerPlaceholder.request(null);
|
return playerPlaceholder.request(null);
|
||||||
@@ -79,6 +72,12 @@ public class NameplatesExpansion extends PlaceholderExpansion implements Relatio
|
|||||||
plugin.getPluginLogger().warn("%nameplates_" + params + "% contains a placeholder that requires a player as the parameter");
|
plugin.getPluginLogger().warn("%nameplates_" + params + "% contains a placeholder that requires a player as the parameter");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (placeholder instanceof SharedPlaceholder sharedPlaceholder) {
|
||||||
|
if (cnPlayer != null) {
|
||||||
|
return cnPlayer.getCachedSharedValue(sharedPlaceholder);
|
||||||
|
} else {
|
||||||
|
return sharedPlaceholder.request();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -91,9 +90,8 @@ public class NameplatesExpansion extends PlaceholderExpansion implements Relatio
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Placeholder placeholder = plugin.getPlaceholderManager().getRegisteredPlaceholder("%rel_np_" + params + "%");
|
Placeholder placeholder = plugin.getPlaceholderManager().getRegisteredPlaceholder("%rel_np_" + params + "%");
|
||||||
if (placeholder != null) {
|
if (placeholder instanceof RelationalPlaceholder relationalPlaceholder) {
|
||||||
cnPlayer1.forceUpdatePlaceholders(Set.of(placeholder), Set.of(cnPlayer2));
|
return cnPlayer1.getCachedRelationalValue(relationalPlaceholder, cnPlayer2);
|
||||||
return Optional.ofNullable(cnPlayer1.getRawRelationalValue(placeholder, cnPlayer2)).map(TimeStampData::data).orElse(placeholder.id());
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
# Project settings
|
# Project settings
|
||||||
# Rule: [major update].[feature update].[bug fix]
|
# Rule: [major update].[feature update].[bug fix]
|
||||||
project_version=3.0.11
|
|
||||||
config_version=32
|
config_version=32
|
||||||
project_group=net.momirealms
|
project_group=net.momirealms
|
||||||
|
|
||||||
@@ -51,5 +50,9 @@ fastutil_version=8.5.15
|
|||||||
#systemProp.socks.proxyPort=7890
|
#systemProp.socks.proxyPort=7890
|
||||||
#systemProp.http.proxyHost=127.0.0.1
|
#systemProp.http.proxyHost=127.0.0.1
|
||||||
#systemProp.http.proxyPort=7890
|
#systemProp.http.proxyPort=7890
|
||||||
#systemProp.https.proxyHost=127.0.0.1
|
systemProp.socks.proxyHost=127.0.0.1
|
||||||
#systemProp.https.proxyPort=7890
|
systemProp.socks.proxyPort=7890
|
||||||
|
systemProp.http.proxyHost=127.0.0.1
|
||||||
|
systemProp.http.proxyPort=7890
|
||||||
|
systemProp.https.proxyHost=127.0.0.1
|
||||||
|
systemProp.https.proxyPort=7890
|
||||||
Reference in New Issue
Block a user