Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6fe8625722 | ||
|
|
43e006f49d | ||
|
|
8d63ad9c74 | ||
|
|
5c2411e420 | ||
|
|
a57cfb0842 | ||
|
|
e4d7fb4346 | ||
|
|
9a9865c424 | ||
|
|
f6b8ce253f | ||
|
|
144b358768 | ||
|
|
0fd7ac1a79 | ||
|
|
67f0e60327 | ||
|
|
d10eb6de67 |
No files matched your search
@@ -11,7 +11,7 @@
|
||||

|
||||

|
||||
|
||||
## How to build
|
||||
## How to Build
|
||||
|
||||
#### Command Line
|
||||
Install JDK 17 & 21. \
|
||||
@@ -22,10 +22,17 @@ Execute ".\gradlew build" and get the artifact under /target folder
|
||||
Import the project and execute gradle build action. \
|
||||
Get the artifact under /target folder
|
||||
|
||||
## Support the developer
|
||||
## How to Contribute
|
||||
|
||||
Polymart: https://polymart.org/resource/customnameplates.2543 \
|
||||
Afdian: https://afdian.com/@xiaomomi
|
||||
#### Translations
|
||||
Clone this project and create a new language file in the /common/src/main/resources/translations directory. \
|
||||
Once your changes are ready, open a pull request for review. We appreciate your works!
|
||||
|
||||
## Support the Developer
|
||||
|
||||
Polymart: https://polymart.org/resource/customnameplates.2543/ \
|
||||
BuiltByBit: https://builtbybit.com/resources/customnameplates.36359/ \
|
||||
Afdian: https://afdian.com/@xiaomomi/
|
||||
|
||||
## CustomNameplates API
|
||||
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
package net.momirealms.customnameplates.api;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenCustomHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||
@@ -34,6 +32,7 @@ import net.momirealms.customnameplates.api.placeholder.SharedPlaceholder;
|
||||
import net.momirealms.customnameplates.api.requirement.Requirement;
|
||||
import net.momirealms.customnameplates.api.storage.data.PlayerData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -56,11 +55,11 @@ public abstract class AbstractCNPlayer implements CNPlayer {
|
||||
|
||||
private final TeamView teamView = new TeamView();
|
||||
|
||||
private final Int2ObjectOpenHashMap<TimeStampData<String>> cachedValues = new Int2ObjectOpenHashMap<>(64);
|
||||
private final Int2ObjectOpenHashMap<WeakHashMap<CNPlayer, TimeStampData<String>>> cachedRelationalValues = new Int2ObjectOpenHashMap<>(64);
|
||||
private final Map<Integer, TimeStampData<String>> cachedValues = new ConcurrentHashMap<>(128);
|
||||
private final Map<Integer, WeakHashMap<CNPlayer, TimeStampData<String>>> cachedRelationalValues = new ConcurrentHashMap<>(128);
|
||||
|
||||
private final Int2ObjectOpenHashMap<TimeStampData<Boolean>> cachedRequirements = new Int2ObjectOpenHashMap<>(128);
|
||||
private final Int2ObjectOpenHashMap<WeakHashMap<CNPlayer, TimeStampData<Boolean>>> cachedRelationalRequirements = new Int2ObjectOpenHashMap<>(128);
|
||||
private final Map<Integer, TimeStampData<Boolean>> cachedRequirements = new Int2ObjectOpenHashMap<>(32);
|
||||
private final Map<Integer, WeakHashMap<CNPlayer, TimeStampData<Boolean>>> cachedRelationalRequirements = new Int2ObjectOpenHashMap<>(32);
|
||||
|
||||
private final Set<Feature> activeFeatures = new CopyOnWriteArraySet<>();
|
||||
private final Map<Placeholder, Set<Feature>> placeholder2Features = new ConcurrentHashMap<>();
|
||||
@@ -83,6 +82,68 @@ public abstract class AbstractCNPlayer implements CNPlayer {
|
||||
return placeholderWithChildren.stream().distinct().toList();
|
||||
}
|
||||
|
||||
private String updatePlayerPlaceholder(PlayerPlaceholder placeholder) {
|
||||
TimeStampData<String> value = getRawPlayerValue(placeholder);
|
||||
if (value == null) {
|
||||
value = new TimeStampData<>(placeholder.request(this), MainTask.getTicks(), true);
|
||||
setPlayerValue(placeholder, value);
|
||||
return value.data();
|
||||
}
|
||||
if (value.ticks() != MainTask.getTicks()) {
|
||||
String newValue = placeholder.request(this);
|
||||
value.updateTicks(!value.data().equals(newValue));
|
||||
value.data(newValue);
|
||||
}
|
||||
return value.data();
|
||||
}
|
||||
|
||||
private void updateRelationalPlaceholder(RelationalPlaceholder placeholder, Collection<CNPlayer> others) {
|
||||
for (CNPlayer another : others) {
|
||||
updateRelationalPlaceholder(placeholder, another);
|
||||
}
|
||||
}
|
||||
|
||||
private String updateRelationalPlaceholder(RelationalPlaceholder placeholder, CNPlayer another) {
|
||||
TimeStampData<String> value = getRawRelationalValue(placeholder, another);
|
||||
if (value == null) {
|
||||
value = new TimeStampData<>(placeholder.request(this, another), MainTask.getTicks(), true);
|
||||
setRelationalValue(placeholder, another, value);
|
||||
return value.data();
|
||||
}
|
||||
if (value.ticks() != MainTask.getTicks()) {
|
||||
String newValue = placeholder.request(this, another);
|
||||
value.updateTicks(!value.data().equals(newValue));
|
||||
value.data(newValue);
|
||||
}
|
||||
return value.data();
|
||||
}
|
||||
|
||||
private String updateSharedPlaceholder(SharedPlaceholder placeholder) {
|
||||
TimeStampData<String> value = getRawSharedValue(placeholder);
|
||||
if (value == null) {
|
||||
String latest;
|
||||
if (MainTask.hasRequested(placeholder.countId())) {
|
||||
latest = placeholder.getLatestValue();
|
||||
} else {
|
||||
latest = placeholder.request();
|
||||
}
|
||||
value = new TimeStampData<>(latest, MainTask.getTicks(), true);
|
||||
setSharedValue(placeholder, value);
|
||||
return value.data();
|
||||
}
|
||||
if (value.ticks() != MainTask.getTicks()) {
|
||||
String latest;
|
||||
if (MainTask.hasRequested(placeholder.countId())) {
|
||||
latest = placeholder.getLatestValue();
|
||||
} else {
|
||||
latest = placeholder.request();
|
||||
}
|
||||
value.updateTicks(!value.data().equals(latest));
|
||||
value.data(latest);
|
||||
}
|
||||
return value.data();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forceUpdatePlaceholders(Set<Placeholder> placeholders, Collection<CNPlayer> others) {
|
||||
if (placeholders.isEmpty()) return;
|
||||
@@ -93,54 +154,11 @@ public abstract class AbstractCNPlayer implements CNPlayer {
|
||||
placeholderWithChildren = placeholderWithChildren.stream().distinct().toList();
|
||||
for (Placeholder placeholder : placeholderWithChildren) {
|
||||
if (placeholder instanceof PlayerPlaceholder playerPlaceholder) {
|
||||
TimeStampData<String> value = getValue(placeholder);
|
||||
if (value == null) {
|
||||
value = new TimeStampData<>(playerPlaceholder.request(this), MainTask.getTicks(), true);
|
||||
setValue(placeholder, value);
|
||||
continue;
|
||||
}
|
||||
if (value.ticks() != MainTask.getTicks()) {
|
||||
String newValue = playerPlaceholder.request(this);
|
||||
value.updateTicks(!value.data().equals(newValue));
|
||||
value.data(newValue);
|
||||
}
|
||||
} else if (placeholder instanceof RelationalPlaceholder relational) {
|
||||
for (CNPlayer player : others) {
|
||||
TimeStampData<String> value = getRelationalValue(placeholder, player);
|
||||
if (value == null) {
|
||||
value = new TimeStampData<>(relational.request(this, player), MainTask.getTicks(), true);
|
||||
setRelationalValue(placeholder, player, value);
|
||||
continue;
|
||||
}
|
||||
if (value.ticks() != MainTask.getTicks()) {
|
||||
String newValue = relational.request(this, player);
|
||||
value.updateTicks(!value.data().equals(newValue));
|
||||
value.data(newValue);
|
||||
}
|
||||
}
|
||||
updatePlayerPlaceholder(playerPlaceholder);
|
||||
} else if (placeholder instanceof RelationalPlaceholder relationalPlaceholder) {
|
||||
updateRelationalPlaceholder(relationalPlaceholder, others);
|
||||
} else if (placeholder instanceof SharedPlaceholder sharedPlaceholder) {
|
||||
TimeStampData<String> value = getValue(placeholder);
|
||||
if (value == null) {
|
||||
String latest;
|
||||
if (MainTask.hasRequested(sharedPlaceholder.countId())) {
|
||||
latest = sharedPlaceholder.getLatestValue();
|
||||
} else {
|
||||
latest = sharedPlaceholder.request();
|
||||
}
|
||||
value = new TimeStampData<>(latest, MainTask.getTicks(), true);
|
||||
setValue(placeholder, value);
|
||||
continue;
|
||||
}
|
||||
if (value.ticks() != MainTask.getTicks()) {
|
||||
String latest;
|
||||
if (MainTask.hasRequested(sharedPlaceholder.countId())) {
|
||||
latest = sharedPlaceholder.getLatestValue();
|
||||
} else {
|
||||
latest = sharedPlaceholder.request();
|
||||
}
|
||||
value.updateTicks(!value.data().equals(latest));
|
||||
value.data(latest);
|
||||
}
|
||||
updateSharedPlaceholder(sharedPlaceholder);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -248,84 +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 getData(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 TimeStampData<String> getValue(Placeholder placeholder) {
|
||||
public @NotNull String getCachedRelationalValue(RelationalPlaceholder placeholder, CNPlayer another) {
|
||||
return updateRelationalPlaceholder(placeholder, another);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public TimeStampData<String> getRawPlayerValue(PlayerPlaceholder placeholder) {
|
||||
return cachedValues.get(placeholder.countId());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public @NotNull String getRelationalData(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> getRelationalValue(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;
|
||||
@@ -411,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,9 @@ 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;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -200,16 +203,16 @@ public interface CNPlayer {
|
||||
* @return the cached data as a string
|
||||
*/
|
||||
@NotNull
|
||||
String getData(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> getValue(Placeholder placeholder);
|
||||
@NotNull
|
||||
String getCachedPlayerValue(PlayerPlaceholder placeholder);
|
||||
|
||||
/**
|
||||
* Retrieves the cached relational data between this player and another for a given placeholder.
|
||||
@@ -219,7 +222,25 @@ public interface CNPlayer {
|
||||
* @return the relational data as a string
|
||||
*/
|
||||
@NotNull
|
||||
String getRelationalData(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.
|
||||
@@ -229,7 +250,7 @@ public interface CNPlayer {
|
||||
* @return the cached relational TickStampData, or null if none exists
|
||||
*/
|
||||
@Nullable
|
||||
TimeStampData<String> getRelationalValue(Placeholder placeholder, CNPlayer another);
|
||||
TimeStampData<String> getRawRelationalValue(RelationalPlaceholder placeholder, CNPlayer another);
|
||||
|
||||
/**
|
||||
* Caches the specified {@link TimeStampData} for the given placeholder.
|
||||
@@ -237,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.
|
||||
@@ -255,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
|
||||
@@ -402,4 +431,11 @@ public interface CNPlayer {
|
||||
* @return team view
|
||||
*/
|
||||
TeamView teamView();
|
||||
|
||||
/**
|
||||
* Check if the player is initialized
|
||||
*
|
||||
* @return initialized or not
|
||||
*/
|
||||
boolean isInitialized();
|
||||
}
|
||||
@@ -217,7 +217,7 @@ public abstract class ConfigManager implements ConfigLoader, Reloadable {
|
||||
// Other settings
|
||||
delaySend = config.getInt("other-settings.send-delay", 0);
|
||||
defaultPlaceholderRefreshInterval = config.getInt("other-settings.default-placeholder-refresh-interval", 1);
|
||||
defaultConditionRefreshInterval = config.getInt("other-settings.ddefault-condition-refresh-interval", 1);
|
||||
defaultConditionRefreshInterval = config.getInt("other-settings.default-condition-refresh-interval", 20);
|
||||
catchOtherActionBar = config.getBoolean("other-settings.catch-other-plugin-actionbar", true);
|
||||
otherActionBarStayTime = config.getInt("other-settings.other-actionbar-stay-time", 3000);
|
||||
displaySystemChat = config.getBoolean("other-settings.display-system-actionbar", true);
|
||||
|
||||
@@ -40,7 +40,8 @@ import net.momirealms.customnameplates.common.locale.TranslationManager;
|
||||
import net.momirealms.customnameplates.common.plugin.NameplatesPlugin;
|
||||
import net.momirealms.customnameplates.common.plugin.scheduler.SchedulerTask;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -20,7 +20,6 @@ package net.momirealms.customnameplates.api;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@@ -23,7 +23,10 @@ import net.momirealms.customnameplates.api.CNPlayer;
|
||||
import net.momirealms.customnameplates.api.CustomNameplates;
|
||||
import net.momirealms.customnameplates.api.placeholder.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class PreParsedDynamicText {
|
||||
@@ -52,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.getRelationalData(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.getData(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);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ package net.momirealms.customnameplates.api.feature.advance;
|
||||
import com.google.gson.JsonObject;
|
||||
import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -76,6 +76,7 @@ public abstract class AbstractTag implements Tag {
|
||||
|
||||
@Override
|
||||
public void show(CNPlayer viewer) {
|
||||
if (!renderer.isValid()) return;
|
||||
if (!isShown()) throw new IllegalStateException("This tag is currently hidden");
|
||||
viewers.add(viewer);
|
||||
resetViewerArray();
|
||||
|
||||
@@ -35,6 +35,13 @@ public interface TagRenderer {
|
||||
*/
|
||||
void hatOffset(double hatOffset);
|
||||
|
||||
/**
|
||||
* Checks if the tag is valid
|
||||
*
|
||||
* @return valid or not
|
||||
*/
|
||||
boolean isValid();
|
||||
|
||||
/**
|
||||
* Called every tick to update the state of the tags managed by this renderer.
|
||||
*/
|
||||
|
||||
@@ -21,7 +21,9 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class TeamView {
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ package net.momirealms.customnameplates.api.network;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||
import net.momirealms.customnameplates.api.CNPlayer;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ package net.momirealms.customnameplates.api.placeholder;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||
import net.momirealms.customnameplates.api.CustomNameplates;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
@@ -586,7 +586,7 @@ public class AdvanceManagerImpl implements AdvanceManager {
|
||||
}
|
||||
registerCharacterFontData(id, bitmapCache, (properties) -> {
|
||||
int ascent = (int) properties.get("shift_y");
|
||||
String filePath = custom ? ConfigManager.namespace() + ":font/" + file : "minecraft:font/" + codePoints + ".png";
|
||||
String filePath = custom ? ConfigManager.namespace() + ":font/" + file : "minecraft:font/" + codePoints + ".png";
|
||||
plugin.getConfigManager().saveResource("tmp/" + codePoints + ".json");
|
||||
StringBuilder jsonContent = new StringBuilder();
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(new File(plugin.getDataDirectory().toFile(), "tmp" + File.separator + codePoints + ".json")))) {
|
||||
@@ -933,7 +933,7 @@ public class AdvanceManagerImpl implements AdvanceManager {
|
||||
.advance(dataMap)
|
||||
.fontProviderFunction(function)
|
||||
.build();
|
||||
charFontWidthDataMap.put(id, fontWidthData);
|
||||
this.charFontWidthDataMap.put(id, fontWidthData);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1021,8 +1021,8 @@ public class AdvanceManagerImpl implements AdvanceManager {
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
this.textWidthCache.invalidateAll();
|
||||
this.configFontWidthDataMap.clear();
|
||||
this.textWidthCache.cleanUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1218,6 +1218,7 @@ public class AdvanceManagerImpl implements AdvanceManager {
|
||||
return totalAdvance;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
@Override
|
||||
public List<Tuple<String, Key, Boolean>> miniMessageToIterable(String text) {
|
||||
if (AdventureHelper.legacySupport) text = AdventureHelper.legacyToMiniMessage(text);
|
||||
@@ -1227,6 +1228,7 @@ public class AdvanceManagerImpl implements AdvanceManager {
|
||||
return iterableTexts;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
private void nodeToIterableTexts(ElementNode node, List<Tuple<String, Key, Boolean>> list, Key font, boolean bold) {
|
||||
if (node instanceof ValueNode valueNode) {
|
||||
String text = valueNode.value();
|
||||
|
||||
@@ -28,7 +28,10 @@ import net.momirealms.customnameplates.api.util.ConfigUtils;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class BackgroundManagerImpl implements BackgroundManager {
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ import net.momirealms.customnameplates.api.helper.AdventureHelper;
|
||||
import net.momirealms.customnameplates.api.placeholder.Placeholder;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
@@ -110,6 +110,7 @@ public abstract class AbstractChatManager implements ChatManager {
|
||||
@Override
|
||||
public void onChat(CNPlayer player, String message, String channel) {
|
||||
String text = message;
|
||||
plugin.debug(() -> player.name() + " says [" + message + "]");
|
||||
for (EmojiProvider provider : emojiProviders) {
|
||||
text = provider.replace(player, text);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class ImageManagerImpl implements ImageManager {
|
||||
|
||||
@@ -138,7 +138,7 @@ public class NameplateManagerImpl implements NameplateManager {
|
||||
}
|
||||
|
||||
private void saveDefaultNameplates() {
|
||||
String[] png_list = new String[]{"cat", "egg", "cheems", "wither", "xmas", "halloween", "hutao", "starsky", "trident", "rabbit"};
|
||||
String[] png_list = new String[]{"egg", "xmas", "halloween", "hutao", "starsky", "trident", "rabbit", "sign", "game", "enter", "panda", "angel", "banner"};
|
||||
String[] part_list = new String[]{"_left.png", "_middle.png", "_right.png", ".yml"};
|
||||
for (String name : png_list) {
|
||||
for (String part : part_list) {
|
||||
|
||||
@@ -32,7 +32,6 @@ import net.momirealms.customnameplates.api.placeholder.Placeholder;
|
||||
import net.momirealms.customnameplates.api.util.Vector3;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ public class TagRendererImpl implements TagRenderer {
|
||||
private Tag[] tagArray;
|
||||
private Tag[] rTagsArray;
|
||||
private double hatOffset;
|
||||
private boolean valid = true;
|
||||
|
||||
public TagRendererImpl(UnlimitedTagManager manager, CNPlayer owner) {
|
||||
this.owner = owner;
|
||||
@@ -68,8 +69,15 @@ public class TagRendererImpl implements TagRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return valid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick() {
|
||||
if (!isValid()) return;
|
||||
|
||||
Set<CNPlayer> playersToUpdatePassengers = new ObjectOpenHashSet<>();
|
||||
Set<CNPlayer> tagTranslationUpdates = new ObjectOpenHashSet<>();
|
||||
|
||||
@@ -135,6 +143,7 @@ public class TagRendererImpl implements TagRenderer {
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
this.valid = false;
|
||||
for (Tag tag : this.tagArray) {
|
||||
tag.hide();
|
||||
if (tag instanceof Feature feature) {
|
||||
|
||||
@@ -140,8 +140,8 @@ public class UnlimitedTagManagerImpl implements UnlimitedTagManager, JoinQuitLis
|
||||
|
||||
@Override
|
||||
public void onPlayerJoin(CNPlayer player) {
|
||||
plugin.debug(() -> player.name() + " joined the server");
|
||||
TagRendererImpl sender = new TagRendererImpl(this, player);
|
||||
sender.onTick();
|
||||
TagRendererImpl previous = tagRenderers.put(player.uuid(), sender);
|
||||
if (previous != null) {
|
||||
previous.destroy();
|
||||
|
||||
@@ -584,10 +584,10 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
|
||||
List<RelationalPlaceholder> delayedPlaceholdersToUpdate = new ObjectArrayList<>();
|
||||
for (Placeholder placeholder : player.activePlaceholdersToRefresh()) {
|
||||
if (placeholder instanceof PlayerPlaceholder playerPlaceholder) {
|
||||
TimeStampData<String> previous = player.getValue(placeholder);
|
||||
TimeStampData<String> previous = player.getRawPlayerValue(playerPlaceholder);
|
||||
if (previous == null) {
|
||||
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));
|
||||
} else {
|
||||
if (previous.ticks() > MainTask.getTicks() - getRefreshInterval(placeholder.countId())) {
|
||||
@@ -609,7 +609,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
|
||||
} else if (placeholder instanceof RelationalPlaceholder relationalPlaceholder) {
|
||||
delayedPlaceholdersToUpdate.add(relationalPlaceholder);
|
||||
} else if (placeholder instanceof SharedPlaceholder sharedPlaceholder) {
|
||||
TimeStampData<String> previous = player.getValue(placeholder);
|
||||
TimeStampData<String> previous = player.getRawSharedValue(sharedPlaceholder);
|
||||
if (previous == null) {
|
||||
String value;
|
||||
// if the shared placeholder has been updated by other players
|
||||
@@ -618,7 +618,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
|
||||
} else {
|
||||
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));
|
||||
} else {
|
||||
// The placeholder has been refreshed by other codes
|
||||
@@ -649,7 +649,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
|
||||
|
||||
for (RelationalPlaceholder placeholder : delayedPlaceholdersToUpdate) {
|
||||
for (CNPlayer nearby : player.nearbyPlayers()) {
|
||||
TimeStampData<String> previous = player.getRelationalValue(placeholder, nearby);
|
||||
TimeStampData<String> previous = player.getRawRelationalValue(placeholder, nearby);
|
||||
if (previous == null) {
|
||||
String value = placeholder.request(player, nearby);
|
||||
player.setRelationalValue(placeholder, nearby, new TimeStampData<>(value, MainTask.getTicks(), true));
|
||||
|
||||
@@ -32,7 +32,10 @@ import net.momirealms.customnameplates.common.util.ListUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class AbstractRequirementManager implements RequirementManager {
|
||||
|
||||
@@ -63,6 +66,7 @@ public abstract class AbstractRequirementManager implements RequirementManager {
|
||||
}
|
||||
|
||||
private void registerInternalRequirements() {
|
||||
this.registerRequirement((args, interval) -> new LaggyRequirement(interval, (int) args), "laggy");
|
||||
this.registerRequirement((args, interval) -> {
|
||||
Section section = ConfigUtils.safeCast(args, Section.class);
|
||||
if (section == null) return Requirement.empty();
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.backend.requirement.builtin;
|
||||
|
||||
import net.momirealms.customnameplates.api.CNPlayer;
|
||||
import net.momirealms.customnameplates.api.ConfigManager;
|
||||
import net.momirealms.customnameplates.backend.requirement.AbstractRequirement;
|
||||
|
||||
public class LaggyRequirement extends AbstractRequirement {
|
||||
|
||||
private final int time;
|
||||
|
||||
public LaggyRequirement(int refreshInterval, int time) {
|
||||
super(refreshInterval);
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSatisfied(CNPlayer p1, CNPlayer p2) {
|
||||
if (!ConfigManager.debug()) return true;
|
||||
long time1 = System.currentTimeMillis();
|
||||
while (true) {
|
||||
if (System.currentTimeMillis() - time1 > time) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type() {
|
||||
return "laggy";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return type().hashCode() + time * 17;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof LaggyRequirement that)) return false;
|
||||
return time == that.time;
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,7 @@ other-settings:
|
||||
display-system-actionbar: true # Should the plugin display system actionbar and temporarily hide the custom actionbar?
|
||||
hide-team-names: true # Hide the team name sent by other plugins or vanilla team system
|
||||
unsafe-chat-event: false # Listen for canceled(unsafe) chat events from unknown plugins
|
||||
default-condition-refresh-interval: 1 # Set default condition refresh interval
|
||||
default-condition-refresh-interval: 20 # Set default condition refresh interval
|
||||
default-placeholder-refresh-interval: 1 # Set default placeholder refresh interval
|
||||
placeholder-refresh-interval: # Custom placeholder refresh intervals for performance optimization
|
||||
"%player_name%": 100
|
||||
|
||||
@@ -4,18 +4,33 @@ conditional-text:
|
||||
priority_1:
|
||||
text: '%np_background_other_actionbar%' # hides the money hud when a player rides something or dives in water
|
||||
conditions:
|
||||
'||':
|
||||
is-passenger: true
|
||||
'!=':
|
||||
value1: '%player_remaining_air%'
|
||||
value2: "300"
|
||||
'!gamemode': survival
|
||||
condition_or:
|
||||
type: "||"
|
||||
refresh-interval: 1
|
||||
value:
|
||||
condition_passenger:
|
||||
type: is-passenger
|
||||
refresh-interval: 1
|
||||
value: true
|
||||
condition_air:
|
||||
type: "!="
|
||||
refresh-interval: 1
|
||||
value:
|
||||
value1: '%player_remaining_air%'
|
||||
value2: "300"
|
||||
condition_gamemode:
|
||||
type: "!gamemode"
|
||||
refresh-interval: 1
|
||||
value: survival
|
||||
priority_2:
|
||||
text: '%np_static_money_hud%%np_offset_-179%%np_static_other_actionbar%' # displays the money hud + other plugin's actionbar message
|
||||
conditions:
|
||||
'!equals':
|
||||
value1: '%np_actionbar%'
|
||||
value2: ""
|
||||
condition_other_actionbar:
|
||||
type: "!equals"
|
||||
refresh-interval: 1
|
||||
value:
|
||||
value1: '%np_actionbar%'
|
||||
value2: ""
|
||||
priority_3:
|
||||
text: '%np_static_money_hud%' # displays the money hud only
|
||||
weather:
|
||||
@@ -131,30 +146,31 @@ switch-text:
|
||||
switch: "%np_equipped_nameplate%"
|
||||
default: ""
|
||||
case:
|
||||
'wither': "<gradient:#FF0000:#000000:%np_gradient_3%>"
|
||||
'halloween': "<gradient:#FF0000:#000000:%np_gradient_3%>"
|
||||
'hutao': "<gradient:#FFFFFF:#FF4500:%np_gradient_3%>"
|
||||
'rabbit': "<gradient:#FFFFFF:#DB7093:%np_gradient_3%>"
|
||||
'starsky': "<gradient:#FFFFF0:#696969:%np_gradient_3%>"
|
||||
'trident': "<gradient:#E1FFFF:#008B8B:%np_gradient_10%>"
|
||||
'cheems': "<gradient:#C0C0C0:#F5F5F5:%np_gradient_5%>"
|
||||
'egg': "<gradient:#FFFFFF:#FFA500:%np_gradient_5%>"
|
||||
'cat': "<gradient:#FFFFFF:#1E90FF:%np_gradient_5%>"
|
||||
'xmas': "<gradient:#FFFFFF:#FF4500:%np_gradient_5%>"
|
||||
'xmas': "<WHITE>"
|
||||
'angel': "<#8B4513>"
|
||||
'sign': "<BLACK>"
|
||||
'banner': "<WHITE>"
|
||||
'enter': "<WHITE>"
|
||||
nameplate_color_suffix:
|
||||
switch: "%np_equipped_nameplate%"
|
||||
default: ""
|
||||
case:
|
||||
'wither': "</gradient>"
|
||||
'halloween': "</gradient>"
|
||||
'hutao': "</gradient>"
|
||||
'rabbit': "</gradient>"
|
||||
'starsky': "</gradient>"
|
||||
'trident': "</gradient>"
|
||||
'cheems': "</gradient>"
|
||||
'egg': "</gradient>"
|
||||
'cat': "</gradient>"
|
||||
'xmas': "</gradient>"
|
||||
'xmas': "</WHITE>"
|
||||
'angel': "</#8B4513>"
|
||||
'sign': "</WHITE>"
|
||||
'enter': "</WHITE>"
|
||||
world:
|
||||
switch: '%player_world%'
|
||||
case:
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
display-name: Angel
|
||||
left:
|
||||
image: angel_left
|
||||
height: 16
|
||||
ascent: 14
|
||||
middle:
|
||||
image: angel_middle
|
||||
height: 16
|
||||
ascent: 14
|
||||
right:
|
||||
image: angel_right
|
||||
height: 16
|
||||
ascent: 14
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1006 B |
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1,13 @@
|
||||
display-name: Banner
|
||||
left:
|
||||
image: banner_left
|
||||
height: 16
|
||||
ascent: 13
|
||||
middle:
|
||||
image: banner_middle
|
||||
height: 16
|
||||
ascent: 13
|
||||
right:
|
||||
image: banner_right
|
||||
height: 16
|
||||
ascent: 13
|
||||
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1000 B |
|
After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 396 B |
|
Before Width: | Height: | Size: 194 B |
|
Before Width: | Height: | Size: 391 B |
|
Before Width: | Height: | Size: 1.3 KiB |
@@ -1,13 +1,13 @@
|
||||
display-name: Sad Cat
|
||||
display-name: Enter
|
||||
left:
|
||||
image: cat_left
|
||||
image: enter_left
|
||||
height: 16
|
||||
ascent: 12
|
||||
middle:
|
||||
image: cat_middle
|
||||
image: enter_middle
|
||||
height: 16
|
||||
ascent: 12
|
||||
right:
|
||||
image: cat_right
|
||||
image: enter_right
|
||||
height: 16
|
||||
ascent: 12
|
||||
|
After Width: | Height: | Size: 957 B |
|
After Width: | Height: | Size: 958 B |
|
After Width: | Height: | Size: 1.0 KiB |
@@ -1,13 +1,13 @@
|
||||
display-name: Thank you, Cheems
|
||||
display-name: Video Game Console
|
||||
left:
|
||||
image: cheems_left
|
||||
image: game_left
|
||||
height: 16
|
||||
ascent: 12
|
||||
middle:
|
||||
image: cheems_middle
|
||||
image: game_middle
|
||||
height: 16
|
||||
ascent: 12
|
||||
right:
|
||||
image: cheems_right
|
||||
image: game_right
|
||||
height: 16
|
||||
ascent: 12
|
||||
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 958 B |
|
After Width: | Height: | Size: 1.0 KiB |
@@ -1,13 +1,13 @@
|
||||
display-name: Wither Rose
|
||||
display-name: Panda
|
||||
left:
|
||||
image: wither_left
|
||||
image: panda_left
|
||||
height: 16
|
||||
ascent: 12
|
||||
middle:
|
||||
image: wither_middle
|
||||
image: panda_middle
|
||||
height: 16
|
||||
ascent: 12
|
||||
right:
|
||||
image: wither_right
|
||||
image: panda_right
|
||||
height: 16
|
||||
ascent: 12
|
||||
|
Before Width: | Height: | Size: 957 B After Width: | Height: | Size: 997 B |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1015 B |
|
Before Width: | Height: | Size: 928 B After Width: | Height: | Size: 999 B |
@@ -0,0 +1,13 @@
|
||||
display-name: Oak Sign
|
||||
left:
|
||||
image: sign_left
|
||||
height: 16
|
||||
ascent: 14
|
||||
middle:
|
||||
image: sign_middle
|
||||
height: 16
|
||||
ascent: 14
|
||||
right:
|
||||
image: sign_right
|
||||
height: 16
|
||||
ascent: 14
|
||||
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1023 B |
|
After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
@@ -52,6 +52,11 @@ public class BukkitCNPlayer extends AbstractCNPlayer {
|
||||
this.player = new WeakReference<>(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInitialized() {
|
||||
return player != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player player() {
|
||||
return player.get();
|
||||
|
||||
@@ -207,6 +207,7 @@ public class BukkitPlatform implements Platform {
|
||||
// for skin plugin compatibility
|
||||
registerPacketConsumer((player, event, packet) -> {
|
||||
try {
|
||||
if (!player.isInitialized()) return;
|
||||
UUID pUUID = player.uuid();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<UUID> uuids = (List<UUID>) Reflections.field$ClientboundPlayerInfoRemovePacket$profileIds.get(packet);
|
||||
@@ -228,7 +229,6 @@ public class BukkitPlatform implements Platform {
|
||||
try {
|
||||
EnumSet<?> enums = (EnumSet<?>) Reflections.field$ClientboundPlayerInfoUpdatePacket$actions.get(packet);
|
||||
if (enums == null) return;
|
||||
UUID pUUID = player.uuid();
|
||||
boolean add_player = enums.contains(Reflections.enum$ClientboundPlayerInfoUpdatePacket$Action$ADD_PLAYER);
|
||||
boolean update_gamemode = enums.contains(Reflections.enum$ClientboundPlayerInfoUpdatePacket$Action$UPDATE_GAME_MODE);
|
||||
if (add_player || update_gamemode) {
|
||||
@@ -239,8 +239,9 @@ public class BukkitPlatform implements Platform {
|
||||
if (uuid == null) continue;
|
||||
|
||||
// for skin plugin compatibility
|
||||
if (add_player && uuid.equals(pUUID)) {
|
||||
if (player.isTempPreviewing() || player.isToggleablePreviewing() || CustomNameplates.getInstance().getUnlimitedTagManager().isAlwaysShow()) {
|
||||
if (add_player && player.isInitialized()) {
|
||||
UUID pUUID = player.uuid();
|
||||
if (uuid.equals(pUUID) && (player.isTempPreviewing() || player.isToggleablePreviewing() || CustomNameplates.getInstance().getUnlimitedTagManager().isAlwaysShow())) {
|
||||
Tracker tracker = player.addPlayerToTracker(player);
|
||||
tracker.setScale(player.scale());
|
||||
tracker.setCrouching(player.isCrouching());
|
||||
|
||||
@@ -21,18 +21,15 @@ import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.expansion.Relational;
|
||||
import net.momirealms.customnameplates.api.CNPlayer;
|
||||
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.PlayerPlaceholder;
|
||||
import net.momirealms.customnameplates.api.placeholder.RelationalPlaceholder;
|
||||
import net.momirealms.customnameplates.api.placeholder.SharedPlaceholder;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public class NameplatesExpansion extends PlaceholderExpansion implements Relational {
|
||||
|
||||
private final CustomNameplates plugin;
|
||||
@@ -64,14 +61,10 @@ public class NameplatesExpansion extends PlaceholderExpansion implements Relatio
|
||||
@Override
|
||||
public @Nullable String onRequest(OfflinePlayer player, @NotNull String params) {
|
||||
Placeholder placeholder = plugin.getPlaceholderManager().getRegisteredPlaceholder("%np_" + params + "%");
|
||||
CNPlayer cnPlayer = player == null ? null : plugin.getPlayer(player.getUniqueId());
|
||||
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) {
|
||||
cnPlayer.forceUpdatePlaceholders(Set.of(placeholder), Collections.emptySet());
|
||||
return cnPlayer.getData(placeholder);
|
||||
return cnPlayer.getCachedPlayerValue(playerPlaceholder);
|
||||
} else {
|
||||
try {
|
||||
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");
|
||||
}
|
||||
}
|
||||
} else if (placeholder instanceof SharedPlaceholder sharedPlaceholder) {
|
||||
if (cnPlayer != null) {
|
||||
return cnPlayer.getCachedSharedValue(sharedPlaceholder);
|
||||
} else {
|
||||
return sharedPlaceholder.request();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -91,9 +90,8 @@ public class NameplatesExpansion extends PlaceholderExpansion implements Relatio
|
||||
return null;
|
||||
}
|
||||
Placeholder placeholder = plugin.getPlaceholderManager().getRegisteredPlaceholder("%rel_np_" + params + "%");
|
||||
if (placeholder != null) {
|
||||
cnPlayer1.forceUpdatePlaceholders(Set.of(placeholder), Set.of(cnPlayer2));
|
||||
return Optional.ofNullable(cnPlayer1.getRelationalValue(placeholder, cnPlayer2)).map(TimeStampData::data).orElse(placeholder.id());
|
||||
if (placeholder instanceof RelationalPlaceholder relationalPlaceholder) {
|
||||
return cnPlayer1.getCachedRelationalValue(relationalPlaceholder, cnPlayer2);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -235,6 +235,9 @@ public class NameplatesExtraExpansion extends PlaceholderExpansion {
|
||||
String minuteStr = (minutes < 10) ? "0" + minutes : String.valueOf(minutes);
|
||||
return hours + ":" + minuteStr;
|
||||
}
|
||||
case "newline" -> {
|
||||
return "\n";
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -24,20 +24,32 @@ import net.momirealms.customnameplates.api.CNPlayer;
|
||||
import net.momirealms.customnameplates.api.feature.chat.emoji.EmojiProvider;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class OraxenEmojiProvider implements EmojiProvider {
|
||||
|
||||
private final FontManager fontManager;
|
||||
private final Function<Glyph, String> characterFunction;
|
||||
|
||||
public OraxenEmojiProvider(int version) {
|
||||
if (version == 1) {
|
||||
this.fontManager = OraxenPlugin.get().getFontManager();
|
||||
this.characterFunction = Glyph::getCharacter;
|
||||
} else {
|
||||
try {
|
||||
Method fm = OraxenPlugin.class.getMethod("fontManager");
|
||||
this.fontManager = (FontManager) fm.invoke(OraxenPlugin.get());
|
||||
Method cm = Glyph.class.getMethod("character");
|
||||
this.characterFunction = (glyph -> {
|
||||
try {
|
||||
return (String) cm.invoke(glyph);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -48,7 +60,7 @@ public class OraxenEmojiProvider implements EmojiProvider {
|
||||
public String replace(CNPlayer player, String text) {
|
||||
for (Map.Entry<String, Glyph> entry : this.fontManager.getGlyphByPlaceholderMap().entrySet()) {
|
||||
if (entry.getValue().hasPermission((Player) player.player())) {
|
||||
text = text.replace(entry.getKey(), "<white><font:default>" + entry.getValue().getCharacter() + "</font></white>");
|
||||
text = text.replace(entry.getKey(), "<white><font:default>" + characterFunction.apply(entry.getValue()) + "</font></white>");
|
||||
}
|
||||
}
|
||||
return text;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Project settings
|
||||
# Rule: [major update].[feature update].[bug fix]
|
||||
project_version=3.0.10
|
||||
project_version=3.0.12
|
||||
config_version=32
|
||||
project_group=net.momirealms
|
||||
|
||||
|
||||