9
0
mirror of https://github.com/Xiao-MoMi/Custom-Nameplates.git synced 2025-12-19 15:09:23 +00:00
This commit is contained in:
XiaoMoMi
2024-11-09 02:22:37 +08:00
parent ca70dfb2b4
commit 366cda6bef
11 changed files with 303 additions and 20 deletions

View File

@@ -57,6 +57,13 @@ public interface Nameplate extends AdaptiveImage {
*/
ConfiguredCharacter right();
/**
* Gets the min width of the nameplate
*
* @return the min width of the nameplate
*/
int minWidth();
/**
* Creates a new builder for constructing a Nameplate configuration.
*
@@ -87,6 +94,14 @@ public interface Nameplate extends AdaptiveImage {
*/
Builder displayName(String displayName);
/**
* Sets the min width for the nameplate
*
* @param minWidth min width
* @return the builder instance
*/
Builder minWidth(int minWidth);
/**
* Sets the configured character for the left side of the nameplate.
*

View File

@@ -29,10 +29,12 @@ public class NameplateImpl implements Nameplate {
private final ConfiguredCharacter left;
private final ConfiguredCharacter middle;
private final ConfiguredCharacter right;
private final int minWidth;
public NameplateImpl(String id, String displayName, ConfiguredCharacter left, ConfiguredCharacter middle, ConfiguredCharacter right) {
public NameplateImpl(String id, String displayName, int minWidth, ConfiguredCharacter left, ConfiguredCharacter middle, ConfiguredCharacter right) {
this.id = id;
this.displayName = displayName;
this.minWidth = minWidth;
this.left = left;
this.middle = middle;
this.right = right;
@@ -63,6 +65,11 @@ public class NameplateImpl implements Nameplate {
return right;
}
@Override
public int minWidth() {
return minWidth;
}
@Override
public boolean equals(Object object) {
if (this == object) return true;
@@ -80,6 +87,7 @@ public class NameplateImpl implements Nameplate {
@Override
public String createImagePrefix(float advance, float leftMargin, float rightMargin) {
if (advance <= 0) return "";
advance = Math.max(minWidth, advance);
StringBuilder sb = new StringBuilder();
sb.append(left.character());
sb.append(OffsetFont.NEG_1.character());
@@ -99,6 +107,7 @@ public class NameplateImpl implements Nameplate {
@Override
public String createImageSuffix(float advance, float leftMargin, float rightMargin) {
if (advance <= 0) return "";
advance = Math.max(minWidth, advance);
int mid_amount = (int) Math.ceil((advance + leftMargin + rightMargin) / (middle.advance() - 1));
float exceed = mid_amount * (middle.advance() - 1) - advance - leftMargin - rightMargin;
return OffsetFont.shortestPosChars((float) Math.ceil(exceed / 2) + rightMargin + right.advance());
@@ -108,6 +117,7 @@ public class NameplateImpl implements Nameplate {
@Override
public String createImage(float advance, float leftMargin, float rightMargin) {
if (advance <= 0) return "";
advance = Math.max(minWidth, advance);
StringBuilder sb = new StringBuilder();
sb.append(left.character());
sb.append(OffsetFont.NEG_1.character());
@@ -131,6 +141,7 @@ public class NameplateImpl implements Nameplate {
private ConfiguredCharacter left;
private ConfiguredCharacter middle;
private ConfiguredCharacter right;
private int minWidth;
@Override
public Builder id(String id) {
@@ -144,6 +155,12 @@ public class NameplateImpl implements Nameplate {
return this;
}
@Override
public Builder minWidth(int minWidth) {
this.minWidth = minWidth;
return this;
}
@Override
public Builder left(ConfiguredCharacter left) {
this.left = left;
@@ -164,7 +181,7 @@ public class NameplateImpl implements Nameplate {
@Override
public Nameplate build() {
return new NameplateImpl(id, displayName, left, middle, right);
return new NameplateImpl(id, displayName, minWidth, left, middle, right);
}
}
}

View File

@@ -231,7 +231,7 @@ public class BubbleManagerImpl implements BubbleManager, ChatListener {
.displayName(inner.getString("display-name", key))
.lineWidth(inner.getInt("line-width", 100))
.backgroundColor(ConfigUtils.argb(inner.getString("background-color", "0,0,0,0")))
.textPrefix(inner.getString("text-prefix", ""))
.textPrefix(inner.getString("text-prefix", "").replace("{namespace}", ConfigManager.namespace()))
.textSuffix(inner.getString("text-suffix", ""))
.scale(ConfigUtils.vector3(inner.getString("scale", "1,1,1")))
.build());
@@ -305,6 +305,7 @@ public class BubbleManagerImpl implements BubbleManager, ChatListener {
String fullText = config.textPrefix() + AdventureHelper.stripTags(message.replace("\\", "\\\\")) + config.textSuffix();
int lines = plugin.getAdvanceManager().getLines(fullText, config.lineWidth());
if (lines > config.maxLines()) return;
if (lines <= 0) return;
int space = (int) plugin.getAdvanceManager().getLineAdvance(" ");
String fakeSpace = AdventureHelper.surroundWithNameplatesFont(OffsetFont.createOffsets(space));
fullText = fullText.replace(" ", fakeSpace);

View File

@@ -115,6 +115,7 @@ public class NameplateManagerImpl implements NameplateManager {
Nameplate nameplate = Nameplate.builder()
.id(id)
.displayName(config.getString("display-name", id))
.minWidth(config.getInt("min-width", 0))
.left(ConfiguredCharacter.create(
ConfigUtils.getFileInTheSameFolder(configFile, config.getString("left.image") + ".png"),
config.getInt("left.ascent", 12),

View File

@@ -26,6 +26,7 @@ import net.momirealms.customnameplates.api.requirement.RequirementFactory;
import net.momirealms.customnameplates.api.requirement.RequirementManager;
import net.momirealms.customnameplates.api.util.ConfigUtils;
import net.momirealms.customnameplates.backend.requirement.builtin.*;
import net.momirealms.customnameplates.common.util.ListUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -178,6 +179,10 @@ public abstract class AbstractRequirementManager implements RequirementManager {
boolean has = (boolean) args;
return new HasBubbleRequirement(interval, has);
}, "has-bubble");
this.registerRequirement((args, interval) -> new NameplateRequirement(interval, new HashSet<>(ListUtils.toList(args))), "nameplate");
this.registerRequirement((args, interval) -> new NotNameplateRequirement(interval, new HashSet<>(ListUtils.toList(args))), "!nameplate");
this.registerRequirement((args, interval) -> new BubbleRequirement(interval, new HashSet<>(ListUtils.toList(args))), "bubble");
this.registerRequirement((args, interval) -> new NotBubbleRequirement(interval, new HashSet<>(ListUtils.toList(args))), "!bubble");
}
protected abstract void registerPlatformRequirements();

View File

@@ -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.api.CustomNameplates;
import net.momirealms.customnameplates.backend.requirement.AbstractRequirement;
import java.util.Objects;
import java.util.Set;
public class BubbleRequirement extends AbstractRequirement {
private final Set<String> bubbles;
public BubbleRequirement(int refreshInterval, Set<String> bubbles) {
super(refreshInterval);
this.bubbles = bubbles;
}
@Override
public boolean isSatisfied(CNPlayer p1, CNPlayer p2) {
if (!ConfigManager.bubbleModule()) return false;
String bubble = p1.equippedBubble();
if (bubble.equals("none")) bubble = CustomNameplates.getInstance().getBubbleManager().defaultBubbleId();
return bubbles.contains(bubble);
}
@Override
public String type() {
return "bubble";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof BubbleRequirement that)) return false;
return bubbles.equals(that.bubbles);
}
@Override
public int hashCode() {
return Objects.hashCode(bubbles);
}
}

View File

@@ -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.api.CustomNameplates;
import net.momirealms.customnameplates.backend.requirement.AbstractRequirement;
import java.util.Objects;
import java.util.Set;
public class NameplateRequirement extends AbstractRequirement {
private final Set<String> nameplates;
public NameplateRequirement(int refreshInterval, Set<String> nameplates) {
super(refreshInterval);
this.nameplates = nameplates;
}
@Override
public boolean isSatisfied(CNPlayer p1, CNPlayer p2) {
if (!ConfigManager.nameplateModule()) return false;
String nameplate = p1.equippedNameplate();
if (nameplate.equals("none")) nameplate = CustomNameplates.getInstance().getNameplateManager().defaultNameplateId();
return nameplates.contains(nameplate);
}
@Override
public String type() {
return "nameplate";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof NameplateRequirement that)) return false;
return nameplates.equals(that.nameplates);
}
@Override
public int hashCode() {
return Objects.hashCode(nameplates);
}
}

View File

@@ -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.api.CustomNameplates;
import net.momirealms.customnameplates.backend.requirement.AbstractRequirement;
import java.util.Objects;
import java.util.Set;
public class NotBubbleRequirement extends AbstractRequirement {
private final Set<String> bubbles;
public NotBubbleRequirement(int refreshInterval, Set<String> bubbles) {
super(refreshInterval);
this.bubbles = bubbles;
}
@Override
public boolean isSatisfied(CNPlayer p1, CNPlayer p2) {
if (!ConfigManager.bubbleModule()) return false;
String bubble = p1.equippedBubble();
if (bubble.equals("none")) bubble = CustomNameplates.getInstance().getBubbleManager().defaultBubbleId();
return !bubbles.contains(bubble);
}
@Override
public String type() {
return "!bubble";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof NotBubbleRequirement that)) return false;
return bubbles.equals(that.bubbles);
}
@Override
public int hashCode() {
return Objects.hashCode(bubbles);
}
}

View File

@@ -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.api.CustomNameplates;
import net.momirealms.customnameplates.backend.requirement.AbstractRequirement;
import java.util.Objects;
import java.util.Set;
public class NotNameplateRequirement extends AbstractRequirement {
private final Set<String> nameplates;
public NotNameplateRequirement(int refreshInterval, Set<String> nameplates) {
super(refreshInterval);
this.nameplates = nameplates;
}
@Override
public boolean isSatisfied(CNPlayer p1, CNPlayer p2) {
if (!ConfigManager.nameplateModule()) return false;
String nameplate = p1.equippedNameplate();
if (nameplate.equals("none")) nameplate = CustomNameplates.getInstance().getNameplateManager().defaultNameplateId();
return !nameplates.contains(nameplate);
}
@Override
public String type() {
return "!nameplate";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof NotNameplateRequirement that)) return false;
return nameplates.equals(that.nameplates);
}
@Override
public int hashCode() {
return Objects.hashCode(nameplates);
}
}

View File

@@ -26,5 +26,5 @@ bubble-settings:
3: chat_3
line-width: 150
background-color: 0,0,0,0
text-prefix: "<black><font:nameplates:shift_0>"
text-prefix: "<black><font:{namespace}:shift_0>" # {namespace} would be replaced by the namespace set in config.yml
text-suffix: "</font></black>"

View File

@@ -9,7 +9,20 @@ nameplate:
player-name: '%np_shift_player_name%'
suffix: '%np_switch_nameplate_color_suffix%'
unlimited:
tag_1:
tag_normal:
text: '%np_tag-text%'
translation: 0,0.2,0
viewer-conditions: { }
owner-conditions:
has-nameplate: false
potion-effect: "INVISIBILITY<0"
self-disguised: false
affected-by-crouching: true
affected-by-scale-attribute: true
affected-by-spectator: true
line-width: 1024
background-color: 64,0,0,0
tag_image_part:
text: '%np_tag-image%'
translation: 0,0.2,0
viewer-conditions: { }
@@ -22,7 +35,7 @@ unlimited:
affected-by-spectator: true
line-width: 1024
background-color: 0,0,0,0
tag_2:
tag_text_part:
text: '%np_tag-text%'
translation: 0.01,0.2,0.01
viewer-conditions: { }
@@ -34,17 +47,4 @@ unlimited:
affected-by-scale-attribute: true
affected-by-spectator: true
line-width: 1024
background-color: 0,0,0,0
tag_3:
text: '%np_tag-text%'
translation: 0,0.2,0
viewer-conditions: { }
owner-conditions:
has-nameplate: false
potion-effect: "INVISIBILITY<0"
self-disguised: false
affected-by-crouching: true
affected-by-scale-attribute: true
affected-by-spectator: true
line-width: 1024
background-color: 64,0,0,0
background-color: 0,0,0,0