mirror of
https://github.com/Xiao-MoMi/Custom-Nameplates.git
synced 2025-12-19 15:09:23 +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) {
|
||||
TimeStampData<String> value = getRawValue(placeholder);
|
||||
TimeStampData<String> value = getRawPlayerValue(placeholder);
|
||||
if (value == null) {
|
||||
value = new TimeStampData<>(placeholder.request(this), MainTask.getTicks(), true);
|
||||
setValue(placeholder, value);
|
||||
setPlayerValue(placeholder, value);
|
||||
return value.data();
|
||||
}
|
||||
if (value.ticks() != MainTask.getTicks()) {
|
||||
@@ -119,7 +119,7 @@ public abstract class AbstractCNPlayer implements CNPlayer {
|
||||
}
|
||||
|
||||
private String updateSharedPlaceholder(SharedPlaceholder placeholder) {
|
||||
TimeStampData<String> value = getRawValue(placeholder);
|
||||
TimeStampData<String> value = getRawSharedValue(placeholder);
|
||||
if (value == null) {
|
||||
String latest;
|
||||
if (MainTask.hasRequested(placeholder.countId())) {
|
||||
@@ -128,7 +128,7 @@ public abstract class AbstractCNPlayer implements CNPlayer {
|
||||
latest = placeholder.request();
|
||||
}
|
||||
value = new TimeStampData<>(latest, MainTask.getTicks(), true);
|
||||
setValue(placeholder, value);
|
||||
setSharedValue(placeholder, value);
|
||||
return value.data();
|
||||
}
|
||||
if (value.ticks() != MainTask.getTicks()) {
|
||||
@@ -266,86 +266,98 @@ public abstract class AbstractCNPlayer implements CNPlayer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Placeholder placeholder, TimeStampData<String> value) {
|
||||
public void setPlayerValue(PlayerPlaceholder placeholder, TimeStampData<String> value) {
|
||||
cachedValues.put(placeholder.countId(), value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setValue(Placeholder 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;
|
||||
public void setSharedValue(SharedPlaceholder placeholder, TimeStampData<String> value) {
|
||||
cachedValues.put(placeholder.countId(), value);
|
||||
}
|
||||
|
||||
@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<>());
|
||||
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
|
||||
public boolean setRelationalValue(Placeholder 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;
|
||||
public @NotNull String getCachedSharedValue(SharedPlaceholder placeholder) {
|
||||
return updateSharedPlaceholder(placeholder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getCachedValue(Placeholder placeholder) {
|
||||
return Optional.ofNullable(cachedValues.get(placeholder.countId())).map(TimeStampData::data).orElse(placeholder.id());
|
||||
public @NotNull String getCachedPlayerValue(PlayerPlaceholder placeholder) {
|
||||
return updatePlayerPlaceholder(placeholder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getCachedRelationalValue(RelationalPlaceholder placeholder, CNPlayer another) {
|
||||
return updateRelationalPlaceholder(placeholder, another);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public TimeStampData<String> getRawValue(Placeholder placeholder) {
|
||||
public TimeStampData<String> getRawPlayerValue(PlayerPlaceholder placeholder) {
|
||||
return cachedValues.get(placeholder.countId());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public @NotNull String getCachedRelationalValue(Placeholder placeholder, CNPlayer another) {
|
||||
WeakHashMap<CNPlayer, TimeStampData<String>> map = cachedRelationalValues.get(placeholder.countId());
|
||||
if (map == null) {
|
||||
return placeholder.id();
|
||||
}
|
||||
return Optional.ofNullable(map.get(another)).map(TimeStampData::data).orElse(placeholder.id());
|
||||
public TimeStampData<String> getRawSharedValue(SharedPlaceholder placeholder) {
|
||||
return cachedValues.get(placeholder.countId());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@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());
|
||||
if (map == null) {
|
||||
return null;
|
||||
@@ -431,12 +443,12 @@ public abstract class AbstractCNPlayer implements CNPlayer {
|
||||
}
|
||||
tracker = new Tracker(another);
|
||||
trackers.put(another, tracker);
|
||||
for (Placeholder placeholder : activePlaceholders()) {
|
||||
if (placeholder instanceof RelationalPlaceholder relationalPlaceholder) {
|
||||
String value = relationalPlaceholder.request(this, another);
|
||||
setRelationalValue(placeholder, another, value);
|
||||
}
|
||||
}
|
||||
// for (Placeholder placeholder : activePlaceholders()) {
|
||||
// if (placeholder instanceof RelationalPlaceholder relationalPlaceholder) {
|
||||
// String value = relationalPlaceholder.request(this, another);
|
||||
// setRelationalValue(relationalPlaceholder, another, value);
|
||||
// }
|
||||
// }
|
||||
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.network.Tracker;
|
||||
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.requirement.Requirement;
|
||||
import net.momirealms.customnameplates.api.util.Vector3;
|
||||
@@ -201,16 +203,16 @@ public interface CNPlayer {
|
||||
* @return the cached data as a string
|
||||
*/
|
||||
@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
|
||||
* @return the cached TickStampData, or null if none exists
|
||||
* @return the cached data as a string
|
||||
*/
|
||||
@Nullable
|
||||
TimeStampData<String> getRawValue(Placeholder placeholder);
|
||||
@NotNull
|
||||
String getCachedPlayerValue(PlayerPlaceholder 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
|
||||
*/
|
||||
@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.
|
||||
@@ -230,7 +250,7 @@ public interface CNPlayer {
|
||||
* @return the cached relational TickStampData, or null if none exists
|
||||
*/
|
||||
@Nullable
|
||||
TimeStampData<String> getRawRelationalValue(Placeholder placeholder, CNPlayer another);
|
||||
TimeStampData<String> getRawRelationalValue(RelationalPlaceholder placeholder, CNPlayer another);
|
||||
|
||||
/**
|
||||
* Caches the specified {@link TimeStampData} for the given placeholder.
|
||||
@@ -238,16 +258,15 @@ public interface CNPlayer {
|
||||
* @param placeholder the placeholder 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 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.
|
||||
@@ -256,17 +275,26 @@ public interface CNPlayer {
|
||||
* @param another the other player
|
||||
* @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.
|
||||
*
|
||||
* @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(Placeholder placeholder, CNPlayer another, String value);
|
||||
// /**
|
||||
// * Caches the specified value for the given placeholder.
|
||||
// *
|
||||
// * @param placeholder the placeholder to cache
|
||||
// * @param value the value to cache
|
||||
// * @return true if the value was changed, false otherwise
|
||||
// */
|
||||
// boolean setPlayerValue(PlayerPlaceholder placeholder, 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
|
||||
|
||||
@@ -55,18 +55,24 @@ public class PreParsedDynamicText {
|
||||
for (String id : detectedPlaceholders) {
|
||||
Placeholder placeholder = manager.getPlaceholder(id);
|
||||
placeholders.add(placeholder);
|
||||
if (placeholder instanceof RelationalPlaceholder) {
|
||||
convertor.add((owner) -> (viewer) -> owner.getCachedRelationalValue(placeholder, viewer));
|
||||
if (placeholder instanceof RelationalPlaceholder relationalPlaceholder) {
|
||||
convertor.add((owner) -> (viewer) -> owner.getCachedRelationalValue(relationalPlaceholder, viewer));
|
||||
} else if (placeholder instanceof PlayerPlaceholder playerPlaceholder) {
|
||||
convertor.add((owner) -> (viewer) -> {
|
||||
if (owner != null) {
|
||||
return owner.getCachedValue(placeholder);
|
||||
return owner.getCachedPlayerValue(playerPlaceholder);
|
||||
} else {
|
||||
return playerPlaceholder.request(null);
|
||||
}
|
||||
});
|
||||
} 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 {
|
||||
convertor.add((owner) -> (viewer) -> id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user