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-18 02:51:49 +08:00
parent 5c2411e420
commit 8d63ad9c74
9 changed files with 104 additions and 12 deletions

View File

@@ -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);

View File

@@ -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();

View File

@@ -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.
*/

View File

@@ -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,6 +69,11 @@ public class TagRendererImpl implements TagRenderer {
}
}
@Override
public boolean isValid() {
return valid;
}
@Override
public void onTick() {
Set<CNPlayer> playersToUpdatePassengers = new ObjectOpenHashSet<>();
@@ -135,6 +141,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) {

View File

@@ -142,7 +142,6 @@ public class UnlimitedTagManagerImpl implements UnlimitedTagManager, JoinQuitLis
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();

View File

@@ -66,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();

View File

@@ -0,0 +1,62 @@
/*
* 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.requirement.Requirement;
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;
}
}

View File

@@ -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

View File

@@ -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: