Skip to content

Commit

Permalink
Merge branch 'Xiao-MoMi:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaozhangup authored Oct 13, 2024
2 parents 58b72a6 + 8867b25 commit e627a2d
Show file tree
Hide file tree
Showing 39 changed files with 1,016 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package net.momirealms.customnameplates.api;

import io.netty.channel.Channel;
import net.momirealms.customnameplates.api.feature.Feature;
import net.momirealms.customnameplates.api.feature.TimeStampData;
import net.momirealms.customnameplates.api.network.Tracker;
Expand All @@ -35,7 +36,9 @@
public abstract class AbstractCNPlayer implements CNPlayer {

protected final CustomNameplates plugin;
protected final Object player;
protected final Channel channel;

protected Object player;

private boolean isLoaded = false;

Expand All @@ -57,9 +60,9 @@ public abstract class AbstractCNPlayer implements CNPlayer {

private final Map<CNPlayer, Tracker> trackers = Collections.synchronizedMap(new WeakHashMap<>());

protected AbstractCNPlayer(CustomNameplates plugin, Object player) {
protected AbstractCNPlayer(CustomNameplates plugin, Channel channel) {
this.plugin = plugin;
this.player = player;
this.channel = channel;
}

@Override
Expand Down Expand Up @@ -166,6 +169,15 @@ public void reload() {
feature2Placeholders.clear();
}

public void setPlayer(Object player) {
this.player = player;
}

@Override
public Channel channel() {
return channel;
}

@Override
public Set<Feature> activeFeatures(Placeholder placeholder) {
return placeholder2Features.getOrDefault(placeholder, Collections.emptySet());
Expand Down Expand Up @@ -206,13 +218,10 @@ public boolean isLoaded() {
@Override
public void addFeature(Feature feature) {
activeFeatures.add(feature);
Set<Placeholder> allPlaceholdersUsedInFeature = feature.allPlaceholders();
feature2Placeholders.put(feature, allPlaceholdersUsedInFeature);
for (Placeholder placeholder : allPlaceholdersUsedInFeature) {
Set<Feature> featureSet = placeholder2Features.computeIfAbsent(placeholder, k -> {
forceUpdatePlaceholders(Set.of(placeholder), nearbyPlayers());
return new HashSet<>();
});
Set<Placeholder> allPlaceholders = feature.allPlaceholders();
feature2Placeholders.put(feature, allPlaceholders);
for (Placeholder placeholder : allPlaceholders) {
Set<Feature> featureSet = placeholder2Features.computeIfAbsent(placeholder, k -> new HashSet<>());
featureSet.add(feature);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package net.momirealms.customnameplates.api;

import io.netty.channel.Channel;
import net.momirealms.customnameplates.api.feature.Feature;
import net.momirealms.customnameplates.api.feature.TimeStampData;
import net.momirealms.customnameplates.api.network.Tracker;
Expand Down Expand Up @@ -53,6 +54,13 @@ public interface CNPlayer {
*/
Object player();

/**
* Returns the channel of the player
*
* @return the channel
*/
Channel channel();

/**
* Returns the entity ID of the player.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,19 @@ public static YamlDocument getMainConfig() {
protected boolean debug;
protected boolean checkUpdate;
protected boolean metrics;
protected boolean nametagModule;
protected boolean actionbarModule;
protected boolean imageModule;
protected boolean bossBarModule;
protected boolean bubbleModule;
protected boolean nameplateModule;
protected boolean backgroundModule;
protected boolean hideTeamNames;
protected int defaultPlaceholderRefreshInterval;
protected int defaultConditionRefreshInterval;
protected int delaySend;
protected boolean catchOtherActionBar;
protected boolean displaySystemChat;
protected int otherActionBarStayTime;

protected String namespace;
Expand Down Expand Up @@ -163,6 +166,7 @@ private void loadSettings() {
checkUpdate = config.getBoolean("update-checker", false);

// Modules
nametagModule = config.getBoolean("modules.nametags", true);
actionbarModule = config.getBoolean("modules.actionbars", true);
imageModule = config.getBoolean("modules.images", true);
bossBarModule = config.getBoolean("modules.bossbars", true);
Expand Down Expand Up @@ -214,6 +218,8 @@ private void loadSettings() {
defaultConditionRefreshInterval = config.getInt("other-settings.ddefault-condition-refresh-interval", 1);
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);
hideTeamNames = config.getBoolean("other-settings.hide-team-names", true);
}

@Override
Expand Down Expand Up @@ -265,14 +271,26 @@ public static char initialChar() {
return instance.initialChar;
}

public static boolean hideTeamNames() {
return instance.hideTeamNames;
}

public static boolean actionbarModule() {
return instance.actionbarModule;
}

public static boolean nametagModule() {
return instance.nametagModule;
}

public static boolean catchOtherActionBar() {
return instance.catchOtherActionBar;
}

public static boolean displaySystemChat() {
return instance.displaySystemChat;
}

public static boolean packItemsAdder() {
return instance.packItemsAdder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,15 @@ List<Object> createTextDisplayPacket(
* @return the remove entity packet object
*/
Object removeEntityPacket(int... entityID);

/**
* Gets the biome based on location
*
* @param world world
* @param x x
* @param y y
* @param z z
* @return the biome key
*/
String getBiome(String world, int x, int y, int z);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,28 @@
import net.momirealms.customnameplates.api.CNPlayer;

/**
* Listener for handling player change worlds
* Listener for handling player actions
*/
public interface WorldChangeListener {
public interface PlayerListener {

/**
* Called when a player changes the world
*
* @param player the player who changes the world
*/
void onChangeWorld(CNPlayer player);

/**
* Called when a player respawns
*
* @param player the player who respawns
*/
void onRespawn(CNPlayer player);

/**
* Called when a player teleports
*
* @param player the player who respawns
*/
void onTeleport(CNPlayer player);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public class PreParsedDynamicText {
private boolean init = false;

public PreParsedDynamicText(String text) {
this.text = text;
this.text = Objects.requireNonNull(text);
}

public PreParsedDynamicText(String text, boolean init) {
this.text = Optional.ofNullable(text).orElse("");
this.text = Objects.requireNonNull(text);
if (init) init();
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -119,47 +119,48 @@ public ConfiguredCharacter right() {
}

@Override
public String createImagePrefix(float n, float leftMargin, float rightMargin) {
String offset1 = OffsetFont.shortestNegChars(n + rightMargin + right.advance());
n = leftMargin + n + rightMargin;
public String createImagePrefix(float advance, float leftMargin, float rightMargin) {
if (advance <= 0) return "";
String offset1 = OffsetFont.shortestNegChars(advance + rightMargin + right.advance());
advance = leftMargin + advance + rightMargin;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(left.character());
while (n >= 128) {
while (advance >= 128) {
stringBuilder.append(OffsetFont.NEG_1.character());
stringBuilder.append(width_128.character());
n -= 128;
advance -= 128;
}
if (n - 64 >= 0) {
if (advance - 64 >= 0) {
stringBuilder.append(OffsetFont.NEG_1.character());
stringBuilder.append(width_64.character());
n -= 64;
advance -= 64;
}
if (n - 32 >= 0) {
if (advance - 32 >= 0) {
stringBuilder.append(OffsetFont.NEG_1.character());
stringBuilder.append(width_32.character());
n -= 32;
advance -= 32;
}
if (n - 16 >= 0) {
if (advance - 16 >= 0) {
stringBuilder.append(OffsetFont.NEG_1.character());
stringBuilder.append(width_16.character());
n -= 16;
advance -= 16;
}
if (n - 8 >= 0) {
if (advance - 8 >= 0) {
stringBuilder.append(OffsetFont.NEG_1.character());
stringBuilder.append(width_8.character());
n -= 8;
advance -= 8;
}
if (n - 4 >= 0) {
if (advance - 4 >= 0) {
stringBuilder.append(OffsetFont.NEG_1.character());
stringBuilder.append(width_4.character());
n -= 4;
advance -= 4;
}
if (n - 2 >= 0) {
if (advance - 2 >= 0) {
stringBuilder.append(OffsetFont.NEG_1.character());
stringBuilder.append(width_2.character());
n -= 2;
advance -= 2;
}
if (n - 1 >= 0) {
if (advance - 1 >= 0) {
stringBuilder.append(OffsetFont.NEG_1.character());
stringBuilder.append(width_1.character());
}
Expand All @@ -171,50 +172,52 @@ public String createImagePrefix(float n, float leftMargin, float rightMargin) {

@Override
public String createImageSuffix(float advance, float leftMargin, float rightMargin) {
if (advance <= 0) return "";
return OffsetFont.shortestPosChars(rightMargin + right.advance());
}

@Override
public String createImage(float n, float leftMargin, float rightMargin) {
n = n + leftMargin + rightMargin + 2;
public String createImage(float advance, float leftMargin, float rightMargin) {
if (advance <= 0) return "";
advance = advance + leftMargin + rightMargin + 2;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(left.character());
while (n >= 128) {
while (advance >= 128) {
stringBuilder.append(OffsetFont.NEG_1.character());
stringBuilder.append(width_128.character());
n -= 128;
advance -= 128;
}
if (n - 64 >= 0) {
if (advance - 64 >= 0) {
stringBuilder.append(OffsetFont.NEG_1.character());
stringBuilder.append(width_64.character());
n -= 64;
advance -= 64;
}
if (n - 32 >= 0) {
if (advance - 32 >= 0) {
stringBuilder.append(OffsetFont.NEG_1.character());
stringBuilder.append(width_32.character());
n -= 32;
advance -= 32;
}
if (n - 16 >= 0) {
if (advance - 16 >= 0) {
stringBuilder.append(OffsetFont.NEG_1.character());
stringBuilder.append(width_16.character());
n -= 16;
advance -= 16;
}
if (n - 8 >= 0) {
if (advance - 8 >= 0) {
stringBuilder.append(OffsetFont.NEG_1.character());
stringBuilder.append(width_8.character());
n -= 8;
advance -= 8;
}
if (n - 4 >= 0) {
if (advance - 4 >= 0) {
stringBuilder.append(OffsetFont.NEG_1.character());
stringBuilder.append(width_4.character());
n -= 4;
advance -= 4;
}
if (n - 2 >= 0) {
if (advance - 2 >= 0) {
stringBuilder.append(OffsetFont.NEG_1.character());
stringBuilder.append(width_2.character());
n -= 2;
advance -= 2;
}
if (n - 1 >= 0) {
if (advance - 1 >= 0) {
stringBuilder.append(OffsetFont.NEG_1.character());
stringBuilder.append(width_1.character());
}
Expand Down
Loading

0 comments on commit e627a2d

Please sign in to comment.