mirror of
https://github.com/Xiao-MoMi/Custom-Nameplates.git
synced 2025-12-19 15:09:23 +00:00
optimize
This commit is contained in:
@@ -23,6 +23,8 @@ dependencies {
|
|||||||
compileOnly("io.netty:netty-all:4.1.113.Final")
|
compileOnly("io.netty:netty-all:4.1.113.Final")
|
||||||
// GSON
|
// GSON
|
||||||
compileOnly("com.google.code.gson:gson:${rootProject.properties["gson_version"]}")
|
compileOnly("com.google.code.gson:gson:${rootProject.properties["gson_version"]}")
|
||||||
|
// Fast util
|
||||||
|
compileOnly("it.unimi.dsi:fastutil:${rootProject.properties["fastutil_version"]}")
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
|
|||||||
@@ -18,6 +18,11 @@
|
|||||||
package net.momirealms.customnameplates.api;
|
package net.momirealms.customnameplates.api;
|
||||||
|
|
||||||
import io.netty.channel.Channel;
|
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;
|
||||||
import net.momirealms.customnameplates.api.feature.Feature;
|
import net.momirealms.customnameplates.api.feature.Feature;
|
||||||
import net.momirealms.customnameplates.api.feature.TimeStampData;
|
import net.momirealms.customnameplates.api.feature.TimeStampData;
|
||||||
import net.momirealms.customnameplates.api.feature.tag.TeamView;
|
import net.momirealms.customnameplates.api.feature.tag.TeamView;
|
||||||
@@ -51,11 +56,11 @@ public abstract class AbstractCNPlayer implements CNPlayer {
|
|||||||
|
|
||||||
private final TeamView teamView = new TeamView();
|
private final TeamView teamView = new TeamView();
|
||||||
|
|
||||||
private final Map<Integer, TimeStampData<String>> cachedValues = new ConcurrentHashMap<>();
|
private final Int2ObjectOpenHashMap<TimeStampData<String>> cachedValues = new Int2ObjectOpenHashMap<>(64);
|
||||||
private final Map<Integer, WeakHashMap<CNPlayer, TimeStampData<String>>> cachedRelationalValues = new ConcurrentHashMap<>();
|
private final Int2ObjectOpenHashMap<WeakHashMap<CNPlayer, TimeStampData<String>>> cachedRelationalValues = new Int2ObjectOpenHashMap<>(64);
|
||||||
|
|
||||||
private final Map<Requirement, TimeStampData<Boolean>> cachedRequirements = new ConcurrentHashMap<>();
|
private final Int2ObjectOpenHashMap<TimeStampData<Boolean>> cachedRequirements = new Int2ObjectOpenHashMap<>(128);
|
||||||
private final Map<Requirement, WeakHashMap<CNPlayer, TimeStampData<Boolean>>> cachedRelationalRequirements = new ConcurrentHashMap<>();
|
private final Int2ObjectOpenHashMap<WeakHashMap<CNPlayer, TimeStampData<Boolean>>> cachedRelationalRequirements = new Int2ObjectOpenHashMap<>(128);
|
||||||
|
|
||||||
private final Set<Feature> activeFeatures = new CopyOnWriteArraySet<>();
|
private final Set<Feature> activeFeatures = new CopyOnWriteArraySet<>();
|
||||||
private final Map<Placeholder, Set<Feature>> placeholder2Features = new ConcurrentHashMap<>();
|
private final Map<Placeholder, Set<Feature>> placeholder2Features = new ConcurrentHashMap<>();
|
||||||
@@ -71,7 +76,7 @@ public abstract class AbstractCNPlayer implements CNPlayer {
|
|||||||
@Override
|
@Override
|
||||||
public List<Placeholder> activePlaceholdersToRefresh() {
|
public List<Placeholder> activePlaceholdersToRefresh() {
|
||||||
Placeholder[] activePlaceholders = activePlaceholders();
|
Placeholder[] activePlaceholders = activePlaceholders();
|
||||||
List<Placeholder> placeholderWithChildren = new ArrayList<>();
|
List<Placeholder> placeholderWithChildren = new ObjectArrayList<>();
|
||||||
for (Placeholder placeholder : activePlaceholders) {
|
for (Placeholder placeholder : activePlaceholders) {
|
||||||
childrenFirstList(placeholder, placeholderWithChildren);
|
childrenFirstList(placeholder, placeholderWithChildren);
|
||||||
}
|
}
|
||||||
@@ -79,9 +84,9 @@ public abstract class AbstractCNPlayer implements CNPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void forceUpdatePlaceholders(Set<Placeholder> placeholders, Set<CNPlayer> others) {
|
public void forceUpdatePlaceholders(Set<Placeholder> placeholders, Collection<CNPlayer> others) {
|
||||||
if (placeholders.isEmpty()) return;
|
if (placeholders.isEmpty()) return;
|
||||||
List<Placeholder> placeholderWithChildren = new ArrayList<>();
|
List<Placeholder> placeholderWithChildren = new ObjectArrayList<>();
|
||||||
for (Placeholder placeholder : placeholders) {
|
for (Placeholder placeholder : placeholders) {
|
||||||
childrenFirstList(placeholder, placeholderWithChildren);
|
childrenFirstList(placeholder, placeholderWithChildren);
|
||||||
}
|
}
|
||||||
@@ -224,7 +229,7 @@ public abstract class AbstractCNPlayer implements CNPlayer {
|
|||||||
Set<Placeholder> allPlaceholders = feature.allPlaceholders();
|
Set<Placeholder> allPlaceholders = feature.allPlaceholders();
|
||||||
feature2Placeholders.put(feature, allPlaceholders);
|
feature2Placeholders.put(feature, allPlaceholders);
|
||||||
for (Placeholder placeholder : allPlaceholders) {
|
for (Placeholder placeholder : allPlaceholders) {
|
||||||
Set<Feature> featureSet = placeholder2Features.computeIfAbsent(placeholder, k -> new HashSet<>());
|
Set<Feature> featureSet = placeholder2Features.computeIfAbsent(placeholder, k -> new ObjectOpenHashSet<>());
|
||||||
featureSet.add(feature);
|
featureSet.add(feature);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -330,7 +335,7 @@ public abstract class AbstractCNPlayer implements CNPlayer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Placeholder[] activePlaceholders() {
|
public Placeholder[] activePlaceholders() {
|
||||||
HashSet<Placeholder> placeholders = new HashSet<>();
|
Set<Placeholder> placeholders = new ObjectOpenHashSet<>();
|
||||||
for (Feature feature : activeFeatures) {
|
for (Feature feature : activeFeatures) {
|
||||||
placeholders.addAll(feature.activePlaceholders());
|
placeholders.addAll(feature.activePlaceholders());
|
||||||
}
|
}
|
||||||
@@ -341,7 +346,7 @@ public abstract class AbstractCNPlayer implements CNPlayer {
|
|||||||
public boolean isMet(Requirement[] requirements) {
|
public boolean isMet(Requirement[] requirements) {
|
||||||
int currentTicks = MainTask.getTicks();
|
int currentTicks = MainTask.getTicks();
|
||||||
for (Requirement requirement : requirements) {
|
for (Requirement requirement : requirements) {
|
||||||
TimeStampData<Boolean> data = cachedRequirements.get(requirement);
|
TimeStampData<Boolean> data = cachedRequirements.get(requirement.countId());
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
if (data.ticks() + requirement.refreshInterval() > currentTicks) {
|
if (data.ticks() + requirement.refreshInterval() > currentTicks) {
|
||||||
if (!data.data()) {
|
if (!data.data()) {
|
||||||
@@ -358,7 +363,7 @@ public abstract class AbstractCNPlayer implements CNPlayer {
|
|||||||
} else {
|
} else {
|
||||||
boolean satisfied = requirement.isSatisfied(this, this);
|
boolean satisfied = requirement.isSatisfied(this, this);
|
||||||
data = new TimeStampData<>(satisfied, currentTicks, true);
|
data = new TimeStampData<>(satisfied, currentTicks, true);
|
||||||
cachedRequirements.put(requirement, data);
|
cachedRequirements.put(requirement.countId(), data);
|
||||||
if (!satisfied) {
|
if (!satisfied) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -371,7 +376,7 @@ public abstract class AbstractCNPlayer implements CNPlayer {
|
|||||||
public boolean isMet(CNPlayer another, Requirement[] requirements) {
|
public boolean isMet(CNPlayer another, Requirement[] requirements) {
|
||||||
int currentTicks = MainTask.getTicks();
|
int currentTicks = MainTask.getTicks();
|
||||||
for (Requirement requirement : requirements) {
|
for (Requirement requirement : requirements) {
|
||||||
WeakHashMap<CNPlayer, TimeStampData<Boolean>> innerMap = cachedRelationalRequirements.computeIfAbsent(requirement, k -> new WeakHashMap<>());
|
WeakHashMap<CNPlayer, TimeStampData<Boolean>> innerMap = cachedRelationalRequirements.computeIfAbsent(requirement.countId(), k -> new WeakHashMap<>());
|
||||||
TimeStampData<Boolean> data = innerMap.get(another);
|
TimeStampData<Boolean> data = innerMap.get(another);
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
if (data.ticks() + requirement.refreshInterval() > currentTicks) {
|
if (data.ticks() + requirement.refreshInterval() > currentTicks) {
|
||||||
@@ -421,8 +426,8 @@ public abstract class AbstractCNPlayer implements CNPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<CNPlayer> nearbyPlayers() {
|
public Collection<CNPlayer> nearbyPlayers() {
|
||||||
return new HashSet<>(trackers.keySet());
|
return new ObjectArrayList<>(trackers.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -446,7 +451,7 @@ public abstract class AbstractCNPlayer implements CNPlayer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Integer> getTrackedPassengerIds(CNPlayer another) {
|
public Set<Integer> getTrackedPassengerIds(CNPlayer another) {
|
||||||
return Optional.ofNullable(trackers.get(another)).map(Tracker::getPassengerIDs).orElse(new HashSet<>());
|
return Optional.ofNullable(trackers.get(another)).map(Tracker::getPassengerIDs).orElse(new ObjectOpenHashSet<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import net.momirealms.customnameplates.api.util.Vector3;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -190,7 +191,7 @@ public interface CNPlayer {
|
|||||||
* @param placeholders the placeholders to update
|
* @param placeholders the placeholders to update
|
||||||
* @param another the players related to the placeholders
|
* @param another the players related to the placeholders
|
||||||
*/
|
*/
|
||||||
void forceUpdatePlaceholders(Set<Placeholder> placeholders, Set<CNPlayer> another);
|
void forceUpdatePlaceholders(Set<Placeholder> placeholders, Collection<CNPlayer> another);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the cached data for a given placeholder.
|
* Retrieves the cached data for a given placeholder.
|
||||||
@@ -317,7 +318,7 @@ public interface CNPlayer {
|
|||||||
*
|
*
|
||||||
* @return the set of nearby players
|
* @return the set of nearby players
|
||||||
*/
|
*/
|
||||||
Set<CNPlayer> nearbyPlayers();
|
Collection<CNPlayer> nearbyPlayers();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds passenger entities to the tracker for another player.
|
* Adds passenger entities to the tracker for another player.
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
package net.momirealms.customnameplates.api;
|
package net.momirealms.customnameplates.api;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
import net.momirealms.customnameplates.api.feature.actionbar.ActionBarManager;
|
import net.momirealms.customnameplates.api.feature.actionbar.ActionBarManager;
|
||||||
import net.momirealms.customnameplates.api.feature.advance.AdvanceManager;
|
import net.momirealms.customnameplates.api.feature.advance.AdvanceManager;
|
||||||
import net.momirealms.customnameplates.api.feature.background.BackgroundManager;
|
import net.momirealms.customnameplates.api.feature.background.BackgroundManager;
|
||||||
@@ -38,10 +40,7 @@ import net.momirealms.customnameplates.common.locale.TranslationManager;
|
|||||||
import net.momirealms.customnameplates.common.plugin.NameplatesPlugin;
|
import net.momirealms.customnameplates.common.plugin.NameplatesPlugin;
|
||||||
import net.momirealms.customnameplates.common.plugin.scheduler.SchedulerTask;
|
import net.momirealms.customnameplates.common.plugin.scheduler.SchedulerTask;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
@@ -69,7 +68,7 @@ public abstract class CustomNameplates implements NameplatesPlugin {
|
|||||||
protected MainTask mainTask;
|
protected MainTask mainTask;
|
||||||
protected SchedulerTask scheduledMainTask;
|
protected SchedulerTask scheduledMainTask;
|
||||||
protected ConcurrentHashMap<UUID, CNPlayer> onlinePlayerMap = new ConcurrentHashMap<>();
|
protected ConcurrentHashMap<UUID, CNPlayer> onlinePlayerMap = new ConcurrentHashMap<>();
|
||||||
protected HashMap<Integer, CNPlayer> entityIDFastLookup = new HashMap<>();
|
protected Int2ObjectOpenHashMap<CNPlayer> entityIDFastLookup = new Int2ObjectOpenHashMap<>();
|
||||||
protected AdvanceManager advanceManager;
|
protected AdvanceManager advanceManager;
|
||||||
protected BackgroundManager backgroundManager;
|
protected BackgroundManager backgroundManager;
|
||||||
protected EventManager eventManager;
|
protected EventManager eventManager;
|
||||||
@@ -288,7 +287,7 @@ public abstract class CustomNameplates implements NameplatesPlugin {
|
|||||||
* @return a collection of {@link CNPlayer} instances
|
* @return a collection of {@link CNPlayer} instances
|
||||||
*/
|
*/
|
||||||
public Collection<CNPlayer> getOnlinePlayers() {
|
public Collection<CNPlayer> getOnlinePlayers() {
|
||||||
return new HashSet<>(onlinePlayerMap.values());
|
return new ObjectArrayList<>(onlinePlayerMap.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
package net.momirealms.customnameplates.api;
|
package net.momirealms.customnameplates.api;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -29,7 +31,7 @@ public class MainTask implements Runnable {
|
|||||||
|
|
||||||
private static final Map<Integer, Integer> TIME_1 = new ConcurrentHashMap<>(2048);
|
private static final Map<Integer, Integer> TIME_1 = new ConcurrentHashMap<>(2048);
|
||||||
private static final Map<Integer, Integer> TIME_2 = new ConcurrentHashMap<>(2048);
|
private static final Map<Integer, Integer> TIME_2 = new ConcurrentHashMap<>(2048);
|
||||||
private static final Set<Integer> requestedSharedPlaceholders = Collections.synchronizedSet(new HashSet<>());
|
private static final Set<Integer> requestedSharedPlaceholders = Collections.synchronizedSet(new ObjectOpenHashSet<>());
|
||||||
private int timer;
|
private int timer;
|
||||||
|
|
||||||
private final CustomNameplates plugin;
|
private final CustomNameplates plugin;
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
package net.momirealms.customnameplates.api.feature;
|
package net.momirealms.customnameplates.api.feature;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
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.placeholder.*;
|
import net.momirealms.customnameplates.api.placeholder.*;
|
||||||
@@ -27,8 +29,8 @@ import java.util.function.Function;
|
|||||||
public class PreParsedDynamicText {
|
public class PreParsedDynamicText {
|
||||||
|
|
||||||
private final String text;
|
private final String text;
|
||||||
private final List<Function<CNPlayer, Function<CNPlayer, String>>> textFunctions = new ArrayList<>();
|
private final List<Function<CNPlayer, Function<CNPlayer, String>>> textFunctions = new ObjectArrayList<>();
|
||||||
private final Set<Placeholder> set = new HashSet<>();
|
private final Set<Placeholder> set = new ObjectOpenHashSet<>();
|
||||||
private boolean init = false;
|
private boolean init = false;
|
||||||
|
|
||||||
public PreParsedDynamicText(String text) {
|
public PreParsedDynamicText(String text) {
|
||||||
@@ -86,12 +88,12 @@ public class PreParsedDynamicText {
|
|||||||
String remaining = original0.substring(lastIndex);
|
String remaining = original0.substring(lastIndex);
|
||||||
textFunctions.add((owner) -> (viewer) -> remaining);
|
textFunctions.add((owner) -> (viewer) -> remaining);
|
||||||
}
|
}
|
||||||
// To optimize the tree height, call new HashSet twice here
|
// To optimize the tree height
|
||||||
set.addAll(new HashSet<>(placeholders));
|
set.addAll(new ObjectArrayList<>(placeholders));
|
||||||
}
|
}
|
||||||
|
|
||||||
public DynamicText fastCreate(CNPlayer player) {
|
public DynamicText fastCreate(CNPlayer player) {
|
||||||
List<Function<CNPlayer, String>> functions = new ArrayList<>();
|
List<Function<CNPlayer, String>> functions = new ObjectArrayList<>();
|
||||||
for (Function<CNPlayer, Function<CNPlayer, String>> textFunction : textFunctions) {
|
for (Function<CNPlayer, Function<CNPlayer, String>> textFunction : textFunctions) {
|
||||||
functions.add(textFunction.apply(player));
|
functions.add(textFunction.apply(player));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
package net.momirealms.customnameplates.api.feature.advance;
|
package net.momirealms.customnameplates.api.feature.advance;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -28,11 +29,11 @@ import static java.util.Objects.requireNonNull;
|
|||||||
|
|
||||||
public class CharacterFontAdvanceDataImpl implements CharacterFontAdvanceData {
|
public class CharacterFontAdvanceDataImpl implements CharacterFontAdvanceData {
|
||||||
|
|
||||||
private final HashMap<Integer, Float> data;
|
private final Map<Integer, Float> data;
|
||||||
private final String id;
|
private final String id;
|
||||||
private final Function<Map<String, Object>, List<JsonObject>> fontProviderFunction;
|
private final Function<Map<String, Object>, List<JsonObject>> fontProviderFunction;
|
||||||
|
|
||||||
public CharacterFontAdvanceDataImpl(String id, HashMap<Integer, Float> data, Function<Map<String, Object>, List<JsonObject>> fontProviderFunction) {
|
public CharacterFontAdvanceDataImpl(String id, Map<Integer, Float> data, Function<Map<String, Object>, List<JsonObject>> fontProviderFunction) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.id = requireNonNull(id);
|
this.id = requireNonNull(id);
|
||||||
this.fontProviderFunction = requireNonNull(fontProviderFunction);
|
this.fontProviderFunction = requireNonNull(fontProviderFunction);
|
||||||
@@ -65,7 +66,7 @@ public class CharacterFontAdvanceDataImpl implements CharacterFontAdvanceData {
|
|||||||
|
|
||||||
public static class BuilderImpl implements Builder {
|
public static class BuilderImpl implements Builder {
|
||||||
|
|
||||||
private final HashMap<Integer, Float> data = new HashMap<>();
|
private final Int2FloatOpenHashMap data = new Int2FloatOpenHashMap();
|
||||||
private String id;
|
private String id;
|
||||||
private Function<Map<String, Object>, List<JsonObject>> fontProviderFunction = (stringObjectMap -> null);
|
private Function<Map<String, Object>, List<JsonObject>> fontProviderFunction = (stringObjectMap -> null);
|
||||||
|
|
||||||
|
|||||||
@@ -17,18 +17,18 @@
|
|||||||
|
|
||||||
package net.momirealms.customnameplates.api.feature.advance;
|
package net.momirealms.customnameplates.api.feature.advance;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;
|
||||||
import java.util.Collections;
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
|
|
||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
public class ConfigurableFontAdvanceDataImpl implements ConfigurableFontAdvanceData {
|
public class ConfigurableFontAdvanceDataImpl implements ConfigurableFontAdvanceData {
|
||||||
|
|
||||||
private final float defaultAdvance;
|
private final float defaultAdvance;
|
||||||
private final HashMap<Integer, Float> data = new HashMap<>();
|
private final Map<Integer, Float> data = new Int2FloatOpenHashMap();
|
||||||
private final List<CharacterFontAdvanceData> parents = new ArrayList<>();
|
private final List<CharacterFontAdvanceData> parents = new ObjectArrayList<>();
|
||||||
private final String id;
|
private final String id;
|
||||||
|
|
||||||
public ConfigurableFontAdvanceDataImpl(String id, float defaultAdvance, HashMap<Integer, Float> customData, List<CharacterFontAdvanceData> parentFonts) {
|
public ConfigurableFontAdvanceDataImpl(String id, float defaultAdvance, HashMap<Integer, Float> customData, List<CharacterFontAdvanceData> parentFonts) {
|
||||||
|
|||||||
@@ -17,16 +17,15 @@
|
|||||||
|
|
||||||
package net.momirealms.customnameplates.api.feature.tag;
|
package net.momirealms.customnameplates.api.feature.tag;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class TeamView {
|
public class TeamView {
|
||||||
|
|
||||||
private final HashMap<String, Set<String>> teamMembers = new HashMap<>();
|
private final Map<String, Set<String>> teamMembers = new Object2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Set<String> getTeamMembers(String team) {
|
public Set<String> getTeamMembers(String team) {
|
||||||
@@ -34,7 +33,7 @@ public class TeamView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addTeamMembers(String team, Collection<String> members) {
|
public void addTeamMembers(String team, Collection<String> members) {
|
||||||
teamMembers.computeIfAbsent(team, k -> new HashSet<>(members));
|
teamMembers.computeIfAbsent(team, k -> new ObjectOpenHashSet<>(members));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeTeamMembers(String team, Collection<String> members) {
|
public void removeTeamMembers(String team, Collection<String> members) {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package net.momirealms.customnameplates.api.network;
|
package net.momirealms.customnameplates.api.network;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
import net.momirealms.customnameplates.api.CNPlayer;
|
import net.momirealms.customnameplates.api.CNPlayer;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -80,7 +81,7 @@ public class Tracker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Set<Integer> getPassengerIDs() {
|
public Set<Integer> getPassengerIDs() {
|
||||||
return new HashSet<>(passengerIDs);
|
return new ObjectOpenHashSet<>(passengerIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package net.momirealms.customnameplates.api.placeholder;
|
package net.momirealms.customnameplates.api.placeholder;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
import net.momirealms.customnameplates.api.CustomNameplates;
|
import net.momirealms.customnameplates.api.CustomNameplates;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -29,8 +30,8 @@ public abstract class AbstractPlaceholder implements Placeholder {
|
|||||||
protected int countId = PlaceholderCounter.getAndIncrease();
|
protected int countId = PlaceholderCounter.getAndIncrease();
|
||||||
protected int refreshInterval;
|
protected int refreshInterval;
|
||||||
protected PlaceholderManager manager;
|
protected PlaceholderManager manager;
|
||||||
protected Set<Placeholder> children = new HashSet<>();
|
protected Set<Placeholder> children = new ObjectOpenHashSet<>();
|
||||||
protected Set<Placeholder> parents = new HashSet<>();
|
protected Set<Placeholder> parents = new ObjectOpenHashSet<>();
|
||||||
|
|
||||||
protected AbstractPlaceholder(PlaceholderManager manager, String id, int refreshInterval) {
|
protected AbstractPlaceholder(PlaceholderManager manager, String id, int refreshInterval) {
|
||||||
if (refreshInterval == 0) {
|
if (refreshInterval == 0) {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
package net.momirealms.customnameplates.api.requirement;
|
package net.momirealms.customnameplates.api.requirement;
|
||||||
|
|
||||||
import net.momirealms.customnameplates.api.CNPlayer;
|
import net.momirealms.customnameplates.api.CNPlayer;
|
||||||
|
import net.momirealms.customnameplates.api.CustomNameplates;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A requirement that is always satisfied, representing an "empty" or default requirement.
|
* A requirement that is always satisfied, representing an "empty" or default requirement.
|
||||||
@@ -57,6 +58,11 @@ public class EmptyRequirement implements Requirement {
|
|||||||
return "empty";
|
return "empty";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int countId() {
|
||||||
|
return CustomNameplates.getInstance().getRequirementManager().countId(this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns -1, indicating that this requirement does not have a refresh interval.
|
* Returns -1, indicating that this requirement does not have a refresh interval.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -40,6 +40,13 @@ public interface Requirement {
|
|||||||
*/
|
*/
|
||||||
String type();
|
String type();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the int id for faster lookup
|
||||||
|
*
|
||||||
|
* @return count id
|
||||||
|
*/
|
||||||
|
int countId();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the refresh interval of the requirement.
|
* Returns the refresh interval of the requirement.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -87,4 +87,12 @@ public interface RequirementManager extends Reloadable {
|
|||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
Requirement parseSimpleRequirement(@NotNull String type, @NotNull Object value);
|
Requirement parseSimpleRequirement(@NotNull String type, @NotNull Object value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the count id for the requirement for faster lookup
|
||||||
|
*
|
||||||
|
* @param requirement requirement
|
||||||
|
* @return the id
|
||||||
|
*/
|
||||||
|
int countId(Requirement requirement);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,4 +26,6 @@ dependencies {
|
|||||||
// TTF
|
// TTF
|
||||||
compileOnly("org.lwjgl:lwjgl-freetype:${rootProject.properties["lwjgl_version"]}")
|
compileOnly("org.lwjgl:lwjgl-freetype:${rootProject.properties["lwjgl_version"]}")
|
||||||
compileOnly("org.lwjgl:lwjgl:${rootProject.properties["lwjgl_version"]}")
|
compileOnly("org.lwjgl:lwjgl:${rootProject.properties["lwjgl_version"]}")
|
||||||
|
// Fast util
|
||||||
|
compileOnly("it.unimi.dsi:fastutil:${rootProject.properties["fastutil_version"]}")
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package net.momirealms.customnameplates.backend.feature.actionbar;
|
package net.momirealms.customnameplates.backend.feature.actionbar;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
import net.momirealms.customnameplates.api.CNPlayer;
|
import net.momirealms.customnameplates.api.CNPlayer;
|
||||||
import net.momirealms.customnameplates.api.ConfigManager;
|
import net.momirealms.customnameplates.api.ConfigManager;
|
||||||
import net.momirealms.customnameplates.api.CustomNameplates;
|
import net.momirealms.customnameplates.api.CustomNameplates;
|
||||||
@@ -177,7 +178,7 @@ public class ActionBarSender implements Feature {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Placeholder> allPlaceholders() {
|
public Set<Placeholder> allPlaceholders() {
|
||||||
HashSet<Placeholder> placeholders = new HashSet<>();
|
Set<Placeholder> placeholders = new ObjectOpenHashSet<>();
|
||||||
for (ActionBarConfig config : manager.actionBarConfigs()) {
|
for (ActionBarConfig config : manager.actionBarConfigs()) {
|
||||||
for (CarouselText text : config.carouselTexts()) {
|
for (CarouselText text : config.carouselTexts()) {
|
||||||
placeholders.addAll(text.preParsedDynamicText().placeholders());
|
placeholders.addAll(text.preParsedDynamicText().placeholders());
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import com.google.gson.JsonObject;
|
|||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import dev.dejvokep.boostedyaml.YamlDocument;
|
import dev.dejvokep.boostedyaml.YamlDocument;
|
||||||
import dev.dejvokep.boostedyaml.block.implementation.Section;
|
import dev.dejvokep.boostedyaml.block.implementation.Section;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
@@ -292,8 +294,8 @@ public class AdvanceManagerImpl implements AdvanceManager {
|
|||||||
private final HashMap<String, BiConsumer<String, Section>> templateConfigConsumersMap = new HashMap<>();
|
private final HashMap<String, BiConsumer<String, Section>> templateConfigConsumersMap = new HashMap<>();
|
||||||
|
|
||||||
private final CustomNameplates plugin;
|
private final CustomNameplates plugin;
|
||||||
private final HashMap<String, CharacterFontAdvanceData> charFontWidthDataMap = new HashMap<>();
|
private final Object2ObjectOpenHashMap<String, CharacterFontAdvanceData> charFontWidthDataMap = new Object2ObjectOpenHashMap<>();
|
||||||
private final HashMap<String, ConfigurableFontAdvanceData> configFontWidthDataMap = new HashMap<>();
|
private final Object2ObjectOpenHashMap<String, ConfigurableFontAdvanceData> configFontWidthDataMap = new Object2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
private final Cache<String, Float> textWidthCache;
|
private final Cache<String, Float> textWidthCache;
|
||||||
|
|
||||||
@@ -1220,7 +1222,7 @@ public class AdvanceManagerImpl implements AdvanceManager {
|
|||||||
public List<Tuple<String, Key, Boolean>> miniMessageToIterable(String text) {
|
public List<Tuple<String, Key, Boolean>> miniMessageToIterable(String text) {
|
||||||
if (AdventureHelper.legacySupport) text = AdventureHelper.legacyToMiniMessage(text);
|
if (AdventureHelper.legacySupport) text = AdventureHelper.legacyToMiniMessage(text);
|
||||||
ElementNode node = (ElementNode) AdventureHelper.miniMessage().deserializeToTree(text);
|
ElementNode node = (ElementNode) AdventureHelper.miniMessage().deserializeToTree(text);
|
||||||
ArrayList<Tuple<String, Key, Boolean>> iterableTexts = new ArrayList<>();
|
List<Tuple<String, Key, Boolean>> iterableTexts = new ObjectArrayList<>();
|
||||||
nodeToIterableTexts(node, iterableTexts, MINECRAFT_DEFAULT_FONT, false);
|
nodeToIterableTexts(node, iterableTexts, MINECRAFT_DEFAULT_FONT, false);
|
||||||
return iterableTexts;
|
return iterableTexts;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
package net.momirealms.customnameplates.backend.feature.background;
|
package net.momirealms.customnameplates.backend.feature.background;
|
||||||
|
|
||||||
import dev.dejvokep.boostedyaml.YamlDocument;
|
import dev.dejvokep.boostedyaml.YamlDocument;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
import net.momirealms.customnameplates.api.ConfigManager;
|
import net.momirealms.customnameplates.api.ConfigManager;
|
||||||
import net.momirealms.customnameplates.api.CustomNameplates;
|
import net.momirealms.customnameplates.api.CustomNameplates;
|
||||||
import net.momirealms.customnameplates.api.feature.ConfiguredCharacter;
|
import net.momirealms.customnameplates.api.feature.ConfiguredCharacter;
|
||||||
@@ -57,7 +58,7 @@ public class BackgroundManagerImpl implements BackgroundManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Background> getBackgrounds() {
|
public Collection<Background> getBackgrounds() {
|
||||||
return new HashSet<>(backgrounds.values());
|
return new ObjectArrayList<>(backgrounds.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadConfigs() {
|
private void loadConfigs() {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package net.momirealms.customnameplates.backend.feature.bossbar;
|
package net.momirealms.customnameplates.backend.feature.bossbar;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
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.CarouselText;
|
import net.momirealms.customnameplates.api.feature.CarouselText;
|
||||||
@@ -163,7 +164,7 @@ public class BossBarSender implements Feature, BossBar {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Placeholder> allPlaceholders() {
|
public Set<Placeholder> allPlaceholders() {
|
||||||
HashSet<Placeholder> placeholders = new HashSet<>();
|
Set<Placeholder> placeholders = new ObjectOpenHashSet<>();
|
||||||
for (CarouselText text : config.carouselTexts()) {
|
for (CarouselText text : config.carouselTexts()) {
|
||||||
placeholders.addAll(text.preParsedDynamicText().placeholders());
|
placeholders.addAll(text.preParsedDynamicText().placeholders());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ import dev.dejvokep.boostedyaml.settings.general.GeneralSettings;
|
|||||||
import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings;
|
import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings;
|
||||||
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
|
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
|
||||||
import dev.dejvokep.boostedyaml.utils.format.NodeRole;
|
import dev.dejvokep.boostedyaml.utils.format.NodeRole;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
import net.momirealms.customnameplates.api.CNPlayer;
|
import net.momirealms.customnameplates.api.CNPlayer;
|
||||||
import net.momirealms.customnameplates.api.ConfigManager;
|
import net.momirealms.customnameplates.api.ConfigManager;
|
||||||
import net.momirealms.customnameplates.api.CustomNameplates;
|
import net.momirealms.customnameplates.api.CustomNameplates;
|
||||||
@@ -51,7 +53,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
public class BubbleManagerImpl implements BubbleManager, ChatListener {
|
public class BubbleManagerImpl implements BubbleManager, ChatListener {
|
||||||
|
|
||||||
private final CustomNameplates plugin;
|
private final CustomNameplates plugin;
|
||||||
private final Map<String, Bubble> bubbles = new HashMap<>();
|
private final Map<String, Bubble> bubbles = new Object2ObjectOpenHashMap<>();
|
||||||
private Requirement[] sendBubbleRequirements;
|
private Requirement[] sendBubbleRequirements;
|
||||||
private Requirement[] viewBubbleRequirements;
|
private Requirement[] viewBubbleRequirements;
|
||||||
private String defaultBubbleId;
|
private String defaultBubbleId;
|
||||||
@@ -62,7 +64,7 @@ public class BubbleManagerImpl implements BubbleManager, ChatListener {
|
|||||||
private float viewRange;
|
private float viewRange;
|
||||||
private Set<String> blacklistChannels;
|
private Set<String> blacklistChannels;
|
||||||
private ChannelMode channelMode;
|
private ChannelMode channelMode;
|
||||||
private final HashMap<String, BubbleConfig> bubbleConfigs = new HashMap<>();
|
private final Map<String, BubbleConfig> bubbleConfigs = new Object2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
public BubbleManagerImpl(CustomNameplates plugin) {
|
public BubbleManagerImpl(CustomNameplates plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@@ -94,12 +96,12 @@ public class BubbleManagerImpl implements BubbleManager, ChatListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Bubble> bubbles() {
|
public Collection<Bubble> bubbles() {
|
||||||
return new HashSet<>(bubbles.values());
|
return new ObjectArrayList<>(bubbles.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<BubbleConfig> bubbleConfigs() {
|
public Collection<BubbleConfig> bubbleConfigs() {
|
||||||
return new HashSet<>(bubbleConfigs.values());
|
return new ObjectArrayList<>(bubbleConfigs.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
package net.momirealms.customnameplates.backend.feature.image;
|
package net.momirealms.customnameplates.backend.feature.image;
|
||||||
|
|
||||||
import dev.dejvokep.boostedyaml.YamlDocument;
|
import dev.dejvokep.boostedyaml.YamlDocument;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
import net.momirealms.customnameplates.api.ConfigManager;
|
import net.momirealms.customnameplates.api.ConfigManager;
|
||||||
import net.momirealms.customnameplates.api.CustomNameplates;
|
import net.momirealms.customnameplates.api.CustomNameplates;
|
||||||
import net.momirealms.customnameplates.api.feature.ConfiguredCharacter;
|
import net.momirealms.customnameplates.api.feature.ConfiguredCharacter;
|
||||||
@@ -60,7 +61,7 @@ public class ImageManagerImpl implements ImageManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Image> images() {
|
public Collection<Image> images() {
|
||||||
return new HashSet<>(images.values());
|
return new ObjectArrayList<>(images.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadConfigs() {
|
private void loadConfigs() {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
package net.momirealms.customnameplates.backend.feature.nameplate;
|
package net.momirealms.customnameplates.backend.feature.nameplate;
|
||||||
|
|
||||||
import dev.dejvokep.boostedyaml.YamlDocument;
|
import dev.dejvokep.boostedyaml.YamlDocument;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
import net.momirealms.customnameplates.api.CNPlayer;
|
import net.momirealms.customnameplates.api.CNPlayer;
|
||||||
import net.momirealms.customnameplates.api.ConfigManager;
|
import net.momirealms.customnameplates.api.ConfigManager;
|
||||||
import net.momirealms.customnameplates.api.CustomNameplates;
|
import net.momirealms.customnameplates.api.CustomNameplates;
|
||||||
@@ -61,7 +62,7 @@ public class NameplateManagerImpl implements NameplateManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Nameplate> nameplates() {
|
public Collection<Nameplate> nameplates() {
|
||||||
return new HashSet<>(nameplates.values());
|
return new ObjectArrayList<>(nameplates.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package net.momirealms.customnameplates.backend.feature.tag;
|
package net.momirealms.customnameplates.backend.feature.tag;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
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.CarouselText;
|
import net.momirealms.customnameplates.api.feature.CarouselText;
|
||||||
@@ -195,7 +196,7 @@ public class NameTag extends AbstractTag implements RelationalFeature {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Placeholder> allPlaceholders() {
|
public Set<Placeholder> allPlaceholders() {
|
||||||
HashSet<Placeholder> placeholders = new HashSet<>();
|
Set<Placeholder> placeholders = new ObjectOpenHashSet<>();
|
||||||
for (CarouselText text : config.carouselTexts()) {
|
for (CarouselText text : config.carouselTexts()) {
|
||||||
placeholders.addAll(text.preParsedDynamicText().placeholders());
|
placeholders.addAll(text.preParsedDynamicText().placeholders());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package net.momirealms.customnameplates.backend.feature.tag;
|
package net.momirealms.customnameplates.backend.feature.tag;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
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.Feature;
|
import net.momirealms.customnameplates.api.feature.Feature;
|
||||||
@@ -69,14 +70,15 @@ public class TagRendererImpl implements TagRenderer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTick() {
|
public void onTick() {
|
||||||
HashSet<CNPlayer> playersToUpdatePassengers = new HashSet<>();
|
Set<CNPlayer> playersToUpdatePassengers = new ObjectOpenHashSet<>();
|
||||||
HashSet<CNPlayer> tagTranslationUpdates = new HashSet<>();
|
Set<CNPlayer> tagTranslationUpdates = new ObjectOpenHashSet<>();
|
||||||
|
|
||||||
|
Collection<CNPlayer> nearbyPlayers = owner.nearbyPlayers();
|
||||||
for (Tag tag : tagArray) {
|
for (Tag tag : tagArray) {
|
||||||
boolean canShow = tag.canShow();
|
boolean canShow = tag.canShow();
|
||||||
if (canShow) {
|
if (canShow) {
|
||||||
if (tag.isShown()) {
|
if (tag.isShown()) {
|
||||||
for (CNPlayer nearby : owner.nearbyPlayers()) {
|
for (CNPlayer nearby : nearbyPlayers) {
|
||||||
if (tag.isShown(nearby)) {
|
if (tag.isShown(nearby)) {
|
||||||
if (!tag.canShow(nearby)) {
|
if (!tag.canShow(nearby)) {
|
||||||
tag.hide(nearby);
|
tag.hide(nearby);
|
||||||
@@ -97,7 +99,7 @@ public class TagRendererImpl implements TagRenderer {
|
|||||||
tag.init();
|
tag.init();
|
||||||
tag.tick();
|
tag.tick();
|
||||||
tag.show();
|
tag.show();
|
||||||
for (CNPlayer nearby : owner.nearbyPlayers()) {
|
for (CNPlayer nearby : nearbyPlayers) {
|
||||||
if (tag.canShow(nearby) && !tag.isShown(nearby)) {
|
if (tag.canShow(nearby) && !tag.isShown(nearby)) {
|
||||||
tag.show(nearby);
|
tag.show(nearby);
|
||||||
playersToUpdatePassengers.add(nearby);
|
playersToUpdatePassengers.add(nearby);
|
||||||
@@ -110,7 +112,7 @@ public class TagRendererImpl implements TagRenderer {
|
|||||||
if (tag.isShown()) {
|
if (tag.isShown()) {
|
||||||
tag.hide();
|
tag.hide();
|
||||||
if (!tag.relativeTranslation())
|
if (!tag.relativeTranslation())
|
||||||
tagTranslationUpdates.addAll(owner.nearbyPlayers());
|
tagTranslationUpdates.addAll(nearbyPlayers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ package net.momirealms.customnameplates.backend.placeholder;
|
|||||||
|
|
||||||
import dev.dejvokep.boostedyaml.YamlDocument;
|
import dev.dejvokep.boostedyaml.YamlDocument;
|
||||||
import dev.dejvokep.boostedyaml.block.implementation.Section;
|
import dev.dejvokep.boostedyaml.block.implementation.Section;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
import net.momirealms.customnameplates.api.CNPlayer;
|
import net.momirealms.customnameplates.api.CNPlayer;
|
||||||
import net.momirealms.customnameplates.api.ConfigManager;
|
import net.momirealms.customnameplates.api.ConfigManager;
|
||||||
import net.momirealms.customnameplates.api.CustomNameplates;
|
import net.momirealms.customnameplates.api.CustomNameplates;
|
||||||
@@ -51,7 +55,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
|
|||||||
|
|
||||||
private final CustomNameplates plugin;
|
private final CustomNameplates plugin;
|
||||||
private final HashMap<String, Integer> refreshIntervals = new HashMap<>();
|
private final HashMap<String, Integer> refreshIntervals = new HashMap<>();
|
||||||
private final HashMap<Integer, Integer> fasterRefreshIntervals = new HashMap<>();
|
private final Int2IntOpenHashMap fasterRefreshIntervals = new Int2IntOpenHashMap();
|
||||||
private final Map<String, Placeholder> registeredPlaceholders = new HashMap<>();
|
private final Map<String, Placeholder> registeredPlaceholders = new HashMap<>();
|
||||||
private final HashMap<Placeholder, List<PreParsedDynamicText>> childrenText = new HashMap<>();
|
private final HashMap<Placeholder, List<PreParsedDynamicText>> childrenText = new HashMap<>();
|
||||||
private final HashMap<String, Placeholder> nestedPlaceholders = new HashMap<>();
|
private final HashMap<String, Placeholder> nestedPlaceholders = new HashMap<>();
|
||||||
@@ -575,9 +579,9 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
|
|||||||
public void refreshPlaceholders() {
|
public void refreshPlaceholders() {
|
||||||
for (CNPlayer player : plugin.getOnlinePlayers()) {
|
for (CNPlayer player : plugin.getOnlinePlayers()) {
|
||||||
if (!player.isOnline()) continue;
|
if (!player.isOnline()) continue;
|
||||||
Set<Feature> featuresToNotifyUpdates = new HashSet<>();
|
Set<Feature> featuresToNotifyUpdates = new ObjectOpenHashSet<>();
|
||||||
Map<Feature, List<CNPlayer>> relationalFeaturesToNotifyUpdates = new HashMap<>();
|
Map<Feature, List<CNPlayer>> relationalFeaturesToNotifyUpdates = new Object2ObjectOpenHashMap<>();
|
||||||
List<RelationalPlaceholder> delayedPlaceholdersToUpdate = new ArrayList<>();
|
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.getValue(placeholder);
|
TimeStampData<String> previous = player.getValue(placeholder);
|
||||||
@@ -652,7 +656,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
|
|||||||
for (Feature feature : player.activeFeatures(placeholder)) {
|
for (Feature feature : player.activeFeatures(placeholder)) {
|
||||||
// Filter features that will not be updated for all players
|
// Filter features that will not be updated for all players
|
||||||
if (!featuresToNotifyUpdates.contains(feature)) {
|
if (!featuresToNotifyUpdates.contains(feature)) {
|
||||||
List<CNPlayer> players = relationalFeaturesToNotifyUpdates.computeIfAbsent(feature, k -> new ArrayList<>());
|
List<CNPlayer> players = relationalFeaturesToNotifyUpdates.computeIfAbsent(feature, k -> new ObjectArrayList<>());
|
||||||
players.add(nearby);
|
players.add(nearby);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -663,7 +667,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
|
|||||||
for (Feature feature : player.activeFeatures(placeholder)) {
|
for (Feature feature : player.activeFeatures(placeholder)) {
|
||||||
// Filter features that will not be updated for all players
|
// Filter features that will not be updated for all players
|
||||||
if (!featuresToNotifyUpdates.contains(feature)) {
|
if (!featuresToNotifyUpdates.contains(feature)) {
|
||||||
List<CNPlayer> players = relationalFeaturesToNotifyUpdates.computeIfAbsent(feature, k -> new ArrayList<>());
|
List<CNPlayer> players = relationalFeaturesToNotifyUpdates.computeIfAbsent(feature, k -> new ObjectArrayList<>());
|
||||||
players.add(nearby);
|
players.add(nearby);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -677,7 +681,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
|
|||||||
for (Feature feature : player.activeFeatures(placeholder)) {
|
for (Feature feature : player.activeFeatures(placeholder)) {
|
||||||
// Filter features that will not be updated for all players
|
// Filter features that will not be updated for all players
|
||||||
if (!featuresToNotifyUpdates.contains(feature)) {
|
if (!featuresToNotifyUpdates.contains(feature)) {
|
||||||
List<CNPlayer> players = relationalFeaturesToNotifyUpdates.computeIfAbsent(feature, k -> new ArrayList<>());
|
List<CNPlayer> players = relationalFeaturesToNotifyUpdates.computeIfAbsent(feature, k -> new ObjectArrayList<>());
|
||||||
players.add(nearby);
|
players.add(nearby);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -773,7 +777,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
|
|||||||
if (firstPercent == 0 && text.charAt(text.length() - 1) == '%' && text.indexOf('%', 1) == text.length() - 1) {
|
if (firstPercent == 0 && text.charAt(text.length() - 1) == '%' && text.indexOf('%', 1) == text.length() - 1) {
|
||||||
return Collections.singletonList(text);
|
return Collections.singletonList(text);
|
||||||
}
|
}
|
||||||
List<String> placeholders = new ArrayList<>();
|
List<String> placeholders = new ObjectArrayList<>();
|
||||||
Matcher m = PATTERN.matcher(text);
|
Matcher m = PATTERN.matcher(text);
|
||||||
while (m.find()) {
|
while (m.find()) {
|
||||||
placeholders.add(m.group());
|
placeholders.add(m.group());
|
||||||
|
|||||||
@@ -17,16 +17,29 @@
|
|||||||
|
|
||||||
package net.momirealms.customnameplates.backend.requirement;
|
package net.momirealms.customnameplates.backend.requirement;
|
||||||
|
|
||||||
|
import net.momirealms.customnameplates.api.CustomNameplates;
|
||||||
import net.momirealms.customnameplates.api.requirement.Requirement;
|
import net.momirealms.customnameplates.api.requirement.Requirement;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public abstract class AbstractRequirement implements Requirement {
|
public abstract class AbstractRequirement implements Requirement {
|
||||||
|
|
||||||
protected final int refreshInterval;
|
protected final int refreshInterval;
|
||||||
|
@Nullable
|
||||||
|
protected Integer countId;
|
||||||
|
|
||||||
public AbstractRequirement(int refreshInterval) {
|
public AbstractRequirement(int refreshInterval) {
|
||||||
this.refreshInterval = refreshInterval;
|
this.refreshInterval = refreshInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int countId() {
|
||||||
|
// lazy init
|
||||||
|
if (countId == null) {
|
||||||
|
countId = CustomNameplates.getInstance().getRequirementManager().countId(this);
|
||||||
|
}
|
||||||
|
return countId;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int refreshInterval() {
|
public int refreshInterval() {
|
||||||
return refreshInterval;
|
return refreshInterval;
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
package net.momirealms.customnameplates.backend.requirement;
|
package net.momirealms.customnameplates.backend.requirement;
|
||||||
|
|
||||||
import dev.dejvokep.boostedyaml.block.implementation.Section;
|
import dev.dejvokep.boostedyaml.block.implementation.Section;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
import net.momirealms.customnameplates.api.ConfigManager;
|
import net.momirealms.customnameplates.api.ConfigManager;
|
||||||
import net.momirealms.customnameplates.api.CustomNameplates;
|
import net.momirealms.customnameplates.api.CustomNameplates;
|
||||||
import net.momirealms.customnameplates.api.feature.PreParsedDynamicText;
|
import net.momirealms.customnameplates.api.feature.PreParsedDynamicText;
|
||||||
@@ -35,7 +37,9 @@ import java.util.*;
|
|||||||
public abstract class AbstractRequirementManager implements RequirementManager {
|
public abstract class AbstractRequirementManager implements RequirementManager {
|
||||||
|
|
||||||
protected final CustomNameplates plugin;
|
protected final CustomNameplates plugin;
|
||||||
private final HashMap<String, RequirementFactory> requirementFactoryMap = new HashMap<>();
|
private final Object2ObjectOpenHashMap<String, RequirementFactory> requirementFactoryMap = new Object2ObjectOpenHashMap<>(128);
|
||||||
|
private int countId = 0;
|
||||||
|
private final Map<Requirement, Integer> registeredRequirements = new Object2IntOpenHashMap<>(128);
|
||||||
|
|
||||||
public AbstractRequirementManager(CustomNameplates plugin) {
|
public AbstractRequirementManager(CustomNameplates plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@@ -43,6 +47,21 @@ public abstract class AbstractRequirementManager implements RequirementManager {
|
|||||||
this.registerPlatformRequirements();
|
this.registerPlatformRequirements();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload() {
|
||||||
|
this.countId = 0;
|
||||||
|
this.registeredRequirements.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int countId(Requirement requirement) {
|
||||||
|
if (requirement == null) return -1;
|
||||||
|
if (this.registeredRequirements.containsKey(requirement)) return this.registeredRequirements.get(requirement);
|
||||||
|
this.countId++;
|
||||||
|
this.registeredRequirements.put(requirement, countId);
|
||||||
|
return this.countId;
|
||||||
|
}
|
||||||
|
|
||||||
private void registerInternalRequirements() {
|
private void registerInternalRequirements() {
|
||||||
this.registerRequirement((args, interval) -> {
|
this.registerRequirement((args, interval) -> {
|
||||||
Section section = ConfigUtils.safeCast(args, Section.class);
|
Section section = ConfigUtils.safeCast(args, Section.class);
|
||||||
|
|||||||
@@ -37,8 +37,9 @@ public abstract class PlaceholdersRequirement extends AbstractRequirement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSatisfied(CNPlayer p1, CNPlayer p2) {
|
public boolean isSatisfied(CNPlayer p1, CNPlayer p2) {
|
||||||
p1.forceUpdatePlaceholders(t1.placeholders(), Set.of(p2));
|
Set<CNPlayer> set = Set.of(p2);
|
||||||
p1.forceUpdatePlaceholders(t2.placeholders(), Set.of(p2));
|
p1.forceUpdatePlaceholders(t1.placeholders(), set);
|
||||||
|
p1.forceUpdatePlaceholders(t2.placeholders(), set);
|
||||||
String a1 = t1.fastCreate(p1).render(p2);
|
String a1 = t1.fastCreate(p1).render(p2);
|
||||||
String a2 = t2.fastCreate(p1).render(p2);
|
String a2 = t2.fastCreate(p1).render(p2);
|
||||||
return checkArgument(a1, a2);
|
return checkArgument(a1, a2);
|
||||||
|
|||||||
@@ -309,6 +309,8 @@ public class BukkitCustomNameplates extends CustomNameplates implements Listener
|
|||||||
for (CNPlayer player : getOnlinePlayers()) {
|
for (CNPlayer player : getOnlinePlayers()) {
|
||||||
((AbstractCNPlayer) player).reload();
|
((AbstractCNPlayer) player).reload();
|
||||||
}
|
}
|
||||||
|
// clear requirement ids
|
||||||
|
this.requirementManager.reload();
|
||||||
// load basics
|
// load basics
|
||||||
this.configManager.reload();
|
this.configManager.reload();
|
||||||
this.storageManager.reload();
|
this.storageManager.reload();
|
||||||
@@ -321,8 +323,6 @@ public class BukkitCustomNameplates extends CustomNameplates implements Listener
|
|||||||
this.advanceManager.reload();
|
this.advanceManager.reload();
|
||||||
// set up placeholders
|
// set up placeholders
|
||||||
this.placeholderManager.reload();
|
this.placeholderManager.reload();
|
||||||
// set up requirements
|
|
||||||
this.requirementManager.reload();
|
|
||||||
// use the placeholders
|
// use the placeholders
|
||||||
this.actionBarManager.reload();
|
this.actionBarManager.reload();
|
||||||
this.bossBarManager.reload();
|
this.bossBarManager.reload();
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package net.momirealms.customnameplates.bukkit.compatibility.region;
|
package net.momirealms.customnameplates.bukkit.compatibility.region;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import com.sk89q.worldguard.WorldGuard;
|
import com.sk89q.worldguard.WorldGuard;
|
||||||
@@ -76,4 +77,16 @@ public class RegionRequirement extends AbstractRequirement {
|
|||||||
public String type() {
|
public String type() {
|
||||||
return "region";
|
return "region";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof RegionRequirement that)) return false;
|
||||||
|
return mode == that.mode && Objects.equal(regions, that.regions);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(regions, mode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Project settings
|
# Project settings
|
||||||
# Rule: [major update].[feature update].[bug fix]
|
# Rule: [major update].[feature update].[bug fix]
|
||||||
project_version=3.0.9
|
project_version=3.0.10
|
||||||
config_version=32
|
config_version=32
|
||||||
project_group=net.momirealms
|
project_group=net.momirealms
|
||||||
|
|
||||||
@@ -44,6 +44,7 @@ vault_version=1.7
|
|||||||
guava_version=33.3.1-jre
|
guava_version=33.3.1-jre
|
||||||
commons_io_version=2.17.0
|
commons_io_version=2.17.0
|
||||||
lwjgl_version=3.3.4
|
lwjgl_version=3.3.4
|
||||||
|
fastutil_version=8.5.15
|
||||||
|
|
||||||
# Proxy settings
|
# Proxy settings
|
||||||
#systemProp.socks.proxyHost=127.0.0.1
|
#systemProp.socks.proxyHost=127.0.0.1
|
||||||
|
|||||||
Reference in New Issue
Block a user