mirror of
https://github.com/Xiao-MoMi/Custom-Nameplates.git
synced 2026-01-04 15:31:47 +00:00
Fix concurrent modification
This commit is contained in:
@@ -26,6 +26,8 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Pose;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Vector;
|
||||
|
||||
public class UnlimitedEntity implements EntityTagEntity {
|
||||
@@ -33,7 +35,9 @@ public class UnlimitedEntity implements EntityTagEntity {
|
||||
protected final UnlimitedTagManagerImpl manager;
|
||||
protected final Entity entity;
|
||||
protected final Vector<Player> nearbyPlayers;
|
||||
protected Player[] nearbyPlayerArray;
|
||||
protected final Vector<StaticTextEntity> staticTags;
|
||||
protected StaticTextEntity[] staticTagArray;
|
||||
|
||||
public UnlimitedEntity(UnlimitedTagManagerImpl manager, Entity entity) {
|
||||
this.manager = manager;
|
||||
@@ -46,8 +50,8 @@ public class UnlimitedEntity implements EntityTagEntity {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public Vector<Player> getNearbyPlayers() {
|
||||
return nearbyPlayers;
|
||||
public Player[] getNearbyPlayers() {
|
||||
return nearbyPlayerArray;
|
||||
}
|
||||
|
||||
public void addNearbyPlayerNaturally(Player player) {
|
||||
@@ -55,7 +59,8 @@ public class UnlimitedEntity implements EntityTagEntity {
|
||||
return;
|
||||
}
|
||||
nearbyPlayers.add(player);
|
||||
for (StaticTextEntity tag : staticTags) {
|
||||
playerVectorToArray();
|
||||
for (StaticTextEntity tag : staticTagArray) {
|
||||
if (tag.getComeRule().isPassed(player, entity)) {
|
||||
tag.addPlayerToViewers(player);
|
||||
}
|
||||
@@ -67,7 +72,8 @@ public class UnlimitedEntity implements EntityTagEntity {
|
||||
return;
|
||||
}
|
||||
nearbyPlayers.remove(player);
|
||||
for (StaticTextEntity tag : staticTags) {
|
||||
playerVectorToArray();
|
||||
for (StaticTextEntity tag : staticTagArray) {
|
||||
if (tag.getLeaveRule().isPassed(player, entity)) {
|
||||
tag.removePlayerFromViewers(player);
|
||||
}
|
||||
@@ -91,6 +97,7 @@ public class UnlimitedEntity implements EntityTagEntity {
|
||||
return;
|
||||
}
|
||||
staticTags.add(tag);
|
||||
staticTagVectorToArray();
|
||||
for (Player all : nearbyPlayers) {
|
||||
if (tag.getComeRule().isPassed(all, entity)) {
|
||||
tag.addPlayerToViewers(all);
|
||||
@@ -109,12 +116,13 @@ public class UnlimitedEntity implements EntityTagEntity {
|
||||
public void removeTag(StaticTextEntity tag) {
|
||||
if (staticTags.remove(tag)) {
|
||||
tag.destroy();
|
||||
staticTagVectorToArray();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector<StaticTextEntity> getStaticTags() {
|
||||
return staticTags;
|
||||
public Collection<StaticTextEntity> getStaticTags() {
|
||||
return new ArrayList<>(staticTags);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -123,7 +131,8 @@ public class UnlimitedEntity implements EntityTagEntity {
|
||||
return;
|
||||
}
|
||||
nearbyPlayers.add(player);
|
||||
for (StaticTextEntity tag : staticTags) {
|
||||
playerVectorToArray();
|
||||
for (StaticTextEntity tag : staticTagArray) {
|
||||
tag.addPlayerToViewers(player);
|
||||
}
|
||||
}
|
||||
@@ -134,31 +143,32 @@ public class UnlimitedEntity implements EntityTagEntity {
|
||||
return;
|
||||
}
|
||||
nearbyPlayers.remove(player);
|
||||
for (StaticTextEntity tag : staticTags) {
|
||||
playerVectorToArray();
|
||||
for (StaticTextEntity tag : staticTagArray) {
|
||||
tag.removePlayerFromViewers(player);
|
||||
}
|
||||
}
|
||||
|
||||
public void move(Player receiver, short x, short y, short z, boolean onGround) {
|
||||
for (StaticTextEntity tag : staticTags) {
|
||||
for (StaticTextEntity tag : staticTagArray) {
|
||||
tag.move(receiver, x, y, z, onGround);
|
||||
}
|
||||
}
|
||||
|
||||
public void teleport(Player receiver, double x, double y, double z, boolean onGround) {
|
||||
for (StaticTextEntity tag : staticTags) {
|
||||
for (StaticTextEntity tag : staticTagArray) {
|
||||
tag.teleport(receiver, x, y, z, onGround);
|
||||
}
|
||||
}
|
||||
|
||||
public void teleport() {
|
||||
for (StaticTextEntity tag : staticTags) {
|
||||
for (StaticTextEntity tag : staticTagArray) {
|
||||
tag.teleport();
|
||||
}
|
||||
}
|
||||
|
||||
public void handlePose(Pose previous, Pose pose) {
|
||||
for (StaticTextEntity tag : staticTags) {
|
||||
for (StaticTextEntity tag : staticTagArray) {
|
||||
tag.handlePose(previous, pose);
|
||||
}
|
||||
}
|
||||
@@ -166,16 +176,26 @@ public class UnlimitedEntity implements EntityTagEntity {
|
||||
@Override
|
||||
public void destroy() {
|
||||
manager.removeUnlimitedEntityFromMap(entity.getUniqueId());
|
||||
for (StaticTextEntity tag : staticTags) {
|
||||
for (StaticTextEntity tag : staticTagArray) {
|
||||
tag.destroy();
|
||||
}
|
||||
nearbyPlayers.clear();
|
||||
staticTags.clear();
|
||||
staticTagArray = null;
|
||||
nearbyPlayerArray = null;
|
||||
}
|
||||
|
||||
public void respawn() {
|
||||
for (StaticTextEntity tag : staticTags) {
|
||||
for (StaticTextEntity tag : staticTagArray) {
|
||||
tag.respawn(entity.getPose());
|
||||
}
|
||||
}
|
||||
|
||||
protected void staticTagVectorToArray() {
|
||||
staticTagArray = staticTags.toArray(new StaticTextEntity[0]);
|
||||
}
|
||||
|
||||
protected void playerVectorToArray() {
|
||||
nearbyPlayerArray = nearbyPlayers.toArray(new Player[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,12 +26,15 @@ import net.momirealms.customnameplates.paper.setting.CNConfig;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Pose;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Vector;
|
||||
|
||||
public class UnlimitedPlayer extends UnlimitedEntity implements EntityTagPlayer {
|
||||
|
||||
private final Player owner;
|
||||
private final Vector<DynamicTextEntity> dynamicTags;
|
||||
private DynamicTextEntity[] dynamicTagArray;
|
||||
private double hatOffset;
|
||||
private boolean isPreviewing;
|
||||
|
||||
@@ -39,6 +42,7 @@ public class UnlimitedPlayer extends UnlimitedEntity implements EntityTagPlayer
|
||||
super(manager, player);
|
||||
this.owner = player;
|
||||
this.dynamicTags = new Vector<>();
|
||||
this.dynamicTagVectorToArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,7 +51,8 @@ public class UnlimitedPlayer extends UnlimitedEntity implements EntityTagPlayer
|
||||
return;
|
||||
}
|
||||
dynamicTags.add(tag);
|
||||
for (Player all : nearbyPlayers) {
|
||||
dynamicTagVectorToArray();
|
||||
for (Player all : getNearbyPlayers()) {
|
||||
if (tag.canShow() && tag.canSee(all)) {
|
||||
tag.addPlayerToViewers(all);
|
||||
}
|
||||
@@ -60,7 +65,8 @@ public class UnlimitedPlayer extends UnlimitedEntity implements EntityTagPlayer
|
||||
return;
|
||||
}
|
||||
staticTags.add(tag);
|
||||
for (Player all : nearbyPlayers) {
|
||||
dynamicTagVectorToArray();
|
||||
for (Player all : getNearbyPlayers()) {
|
||||
if (tag.getComeRule().isPassed(all, owner)) {
|
||||
tag.addPlayerToViewers(all);
|
||||
}
|
||||
@@ -85,19 +91,13 @@ public class UnlimitedPlayer extends UnlimitedEntity implements EntityTagPlayer
|
||||
public void removeTag(DynamicTextEntity tag) {
|
||||
if (dynamicTags.remove(tag)) {
|
||||
tag.destroy();
|
||||
dynamicTagVectorToArray();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeTag(StaticTextEntity tag) {
|
||||
if (staticTags.remove(tag)) {
|
||||
tag.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector<DynamicTextEntity> getDynamicTags() {
|
||||
return dynamicTags;
|
||||
public Collection<DynamicTextEntity> getDynamicTags() {
|
||||
return new ArrayList<>(dynamicTags);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -130,7 +130,7 @@ public class UnlimitedPlayer extends UnlimitedEntity implements EntityTagPlayer
|
||||
|
||||
@Override
|
||||
public void updateText() {
|
||||
for (DynamicTextEntity tag : dynamicTags) {
|
||||
for (DynamicTextEntity tag : dynamicTagArray) {
|
||||
tag.updateText();
|
||||
}
|
||||
}
|
||||
@@ -146,13 +146,14 @@ public class UnlimitedPlayer extends UnlimitedEntity implements EntityTagPlayer
|
||||
return;
|
||||
}
|
||||
nearbyPlayers.add(player);
|
||||
playerVectorToArray();
|
||||
setNameInvisibleFor(player);
|
||||
for (StaticTextEntity tag : staticTags) {
|
||||
for (StaticTextEntity tag : staticTagArray) {
|
||||
if (tag.getComeRule().isPassed(player, entity)) {
|
||||
tag.addPlayerToViewers(player);
|
||||
}
|
||||
}
|
||||
for (DynamicTextEntity tag : dynamicTags) {
|
||||
for (DynamicTextEntity tag : dynamicTagArray) {
|
||||
if (tag.canShow() && tag.canSee(player)) {
|
||||
tag.addPlayerToViewers(player);
|
||||
}
|
||||
@@ -164,14 +165,15 @@ public class UnlimitedPlayer extends UnlimitedEntity implements EntityTagPlayer
|
||||
if (!nearbyPlayers.contains(player)) {
|
||||
return;
|
||||
}
|
||||
super.nearbyPlayers.remove(player);
|
||||
nearbyPlayers.remove(player);
|
||||
playerVectorToArray();
|
||||
setNameVisibleFor(player);
|
||||
for (StaticTextEntity tag : staticTags) {
|
||||
for (StaticTextEntity tag : staticTagArray) {
|
||||
if (tag.getLeaveRule().isPassed(player, entity)) {
|
||||
tag.removePlayerFromViewers(player);
|
||||
}
|
||||
}
|
||||
for (DynamicTextEntity tag : dynamicTags) {
|
||||
for (DynamicTextEntity tag : dynamicTagArray) {
|
||||
tag.removePlayerFromViewers(player);
|
||||
}
|
||||
}
|
||||
@@ -179,22 +181,23 @@ public class UnlimitedPlayer extends UnlimitedEntity implements EntityTagPlayer
|
||||
@Override
|
||||
public void destroy() {
|
||||
manager.removeUnlimitedEntityFromMap(entity.getUniqueId());
|
||||
for (Player viewer : nearbyPlayers) {
|
||||
for (Player viewer : getNearbyPlayers()) {
|
||||
setNameVisibleFor(viewer);
|
||||
}
|
||||
for (DynamicTextEntity tag : dynamicTags) {
|
||||
for (DynamicTextEntity tag : dynamicTagArray) {
|
||||
tag.destroy();
|
||||
}
|
||||
for (StaticTextEntity tag : staticTags) {
|
||||
for (StaticTextEntity tag : staticTagArray) {
|
||||
tag.destroy();
|
||||
}
|
||||
nearbyPlayers.clear();
|
||||
dynamicTags.clear();
|
||||
staticTags.clear();
|
||||
staticTagArray = null;
|
||||
}
|
||||
|
||||
public void sneak(boolean sneaking, boolean flying) {
|
||||
for (DynamicTextEntity tag : dynamicTags) {
|
||||
for (DynamicTextEntity tag : dynamicTagArray) {
|
||||
tag.setSneak(sneaking, !flying);
|
||||
}
|
||||
}
|
||||
@@ -202,7 +205,7 @@ public class UnlimitedPlayer extends UnlimitedEntity implements EntityTagPlayer
|
||||
@Override
|
||||
public void respawn() {
|
||||
super.respawn();
|
||||
for (DynamicTextEntity tag : dynamicTags) {
|
||||
for (DynamicTextEntity tag : dynamicTagArray) {
|
||||
tag.respawn(owner.getPose());
|
||||
}
|
||||
}
|
||||
@@ -210,7 +213,7 @@ public class UnlimitedPlayer extends UnlimitedEntity implements EntityTagPlayer
|
||||
@Override
|
||||
public void move(Player receiver, short x, short y, short z, boolean onGround) {
|
||||
super.move(receiver, x, y, z, onGround);
|
||||
for (DynamicTextEntity tag : dynamicTags) {
|
||||
for (DynamicTextEntity tag : dynamicTagArray) {
|
||||
tag.move(receiver, x, y, z, onGround);
|
||||
}
|
||||
}
|
||||
@@ -218,7 +221,7 @@ public class UnlimitedPlayer extends UnlimitedEntity implements EntityTagPlayer
|
||||
@Override
|
||||
public void teleport(Player receiver, double x, double y, double z, boolean onGround) {
|
||||
super.teleport(receiver, x, y, z, onGround);
|
||||
for (DynamicTextEntity tag : dynamicTags) {
|
||||
for (DynamicTextEntity tag : dynamicTagArray) {
|
||||
tag.teleport(receiver, x, y, z, onGround);
|
||||
}
|
||||
}
|
||||
@@ -226,7 +229,7 @@ public class UnlimitedPlayer extends UnlimitedEntity implements EntityTagPlayer
|
||||
@Override
|
||||
public void teleport() {
|
||||
super.teleport();
|
||||
for (DynamicTextEntity tag : dynamicTags) {
|
||||
for (DynamicTextEntity tag : dynamicTagArray) {
|
||||
tag.teleport();
|
||||
}
|
||||
}
|
||||
@@ -234,7 +237,7 @@ public class UnlimitedPlayer extends UnlimitedEntity implements EntityTagPlayer
|
||||
@Override
|
||||
public void handlePose(Pose previous, Pose pose) {
|
||||
super.handlePose(previous, pose);
|
||||
for (DynamicTextEntity tag : dynamicTags) {
|
||||
for (DynamicTextEntity tag : dynamicTagArray) {
|
||||
tag.handlePose(previous, pose);
|
||||
}
|
||||
}
|
||||
@@ -266,8 +269,12 @@ public class UnlimitedPlayer extends UnlimitedEntity implements EntityTagPlayer
|
||||
}
|
||||
|
||||
public void timer() {
|
||||
for (DynamicTextEntity tag : dynamicTags) {
|
||||
for (DynamicTextEntity tag : dynamicTagArray) {
|
||||
tag.timer();
|
||||
}
|
||||
}
|
||||
|
||||
private void dynamicTagVectorToArray() {
|
||||
dynamicTagArray = dynamicTags.toArray(new DynamicTextEntity[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,8 @@ other-settings:
|
||||
create-real-teams: false
|
||||
|
||||
# It's recommended to use MiniMessage format. If you insist on using legacy color code "&", enable the support below.
|
||||
legacy-color-code-support: false
|
||||
# Disabling this option would make color formatting faster
|
||||
legacy-color-code-support: true
|
||||
|
||||
# Thread pool settings
|
||||
thread-pool-settings:
|
||||
@@ -103,7 +104,7 @@ other-settings:
|
||||
# If a thread is idle for more than this attribute value, it will exit due to timeout
|
||||
keepAliveTime: 30
|
||||
|
||||
# delay x ticks before actionbar/bossbar is sent to players
|
||||
# delay x ticks before actionbar/bossbar sent to players
|
||||
send-delay: 0
|
||||
|
||||
# Set the size for the cache system. This is useful and would bring huge performance improvement if you keep it to a reasonable value
|
||||
|
||||
Reference in New Issue
Block a user