mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-30 04:19:27 +00:00
fix(bukkit): 修复一些问题
This commit is contained in:
@@ -3,6 +3,7 @@ package net.momirealms.craftengine.core.plugin;
|
||||
import net.momirealms.craftengine.core.advancement.AdvancementManager;
|
||||
import net.momirealms.craftengine.core.block.BlockManager;
|
||||
import net.momirealms.craftengine.core.entity.furniture.FurnitureManager;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.entity.projectile.ProjectileManager;
|
||||
import net.momirealms.craftengine.core.font.FontManager;
|
||||
import net.momirealms.craftengine.core.item.ItemManager;
|
||||
@@ -131,6 +132,9 @@ public abstract class CraftEngine implements Plugin {
|
||||
long time1 = System.currentTimeMillis();
|
||||
// firstly reload main config
|
||||
this.config.load();
|
||||
for (Player player : this.networkManager().onlineUsers()) {
|
||||
player.setMaxVisibleFurniture(Config.maxVisibleFurniture(), false);
|
||||
}
|
||||
// reset debugger
|
||||
this.debugger = Config.debug() ? (s) -> logger.info("[Debug] " + s.get()) : (s) -> {};
|
||||
// now we reload the translations
|
||||
|
||||
@@ -46,6 +46,8 @@ public interface NetWorkUser {
|
||||
|
||||
DynamicPriorityTracker visualFurnitureView();
|
||||
|
||||
void setMaxVisibleFurniture(int maxVisibleFurniture, boolean fromCommand);
|
||||
|
||||
boolean clientModEnabled();
|
||||
|
||||
void setClientModState(boolean enable);
|
||||
|
||||
@@ -31,6 +31,15 @@ public class DynamicPriorityTracker {
|
||||
public Object removePacket() {
|
||||
return removePacket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Element{" +
|
||||
"entityId=" + entityId +
|
||||
", distance=" + distance +
|
||||
", removePacket=" + removePacket +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
public static class UpdateResult {
|
||||
@@ -50,17 +59,31 @@ public class DynamicPriorityTracker {
|
||||
void addExited(Element e) {
|
||||
exited.add(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UpdateResult{" +
|
||||
"entered=" + entered +
|
||||
", exited=" + exited +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
private Integer maxVisibleFurniture;
|
||||
private final PriorityQueue<Element> maxHeap;
|
||||
private final Map<Integer, Element> elementMap = new ConcurrentHashMap<>();
|
||||
private final Set<Integer> inHeapSet = ConcurrentHashMap.newKeySet();
|
||||
private final ReentrantLock heapLock = new ReentrantLock();
|
||||
|
||||
public DynamicPriorityTracker() {
|
||||
this.maxVisibleFurniture = Config.maxVisibleFurniture();
|
||||
this.maxHeap = new PriorityQueue<>((a, b) -> Double.compare(b.distance, a.distance));
|
||||
}
|
||||
|
||||
public void setMaxVisibleFurniture(int maxVisibleFurniture) {
|
||||
this.maxVisibleFurniture = maxVisibleFurniture;
|
||||
}
|
||||
|
||||
public UpdateResult addOrUpdateElement(Element newElement) {
|
||||
UpdateResult result = new UpdateResult();
|
||||
heapLock.lock();
|
||||
@@ -80,7 +103,7 @@ public class DynamicPriorityTracker {
|
||||
private UpdateResult handleNewElement(Element newElement, UpdateResult result) {
|
||||
elementMap.put(newElement.entityId, newElement);
|
||||
|
||||
if (maxHeap.size() < Config.maxVisibleFurniture()) {
|
||||
if (maxHeap.size() < maxVisibleFurniture) {
|
||||
maxHeap.offer(newElement);
|
||||
inHeapSet.add(newElement.entityId);
|
||||
result.addEntered(newElement);
|
||||
@@ -106,7 +129,7 @@ public class DynamicPriorityTracker {
|
||||
maxHeap.remove(existing);
|
||||
maxHeap.offer(existing);
|
||||
} else if (nowInHeap) {
|
||||
if (maxHeap.size() < Config.maxVisibleFurniture()) {
|
||||
if (maxHeap.size() < maxVisibleFurniture) {
|
||||
maxHeap.offer(existing);
|
||||
inHeapSet.add(existing.entityId);
|
||||
result.addEntered(existing);
|
||||
@@ -124,7 +147,7 @@ public class DynamicPriorityTracker {
|
||||
}
|
||||
|
||||
private boolean checkIfShouldBeInHeap(double distance) {
|
||||
if (maxHeap.size() < Config.maxVisibleFurniture()) return true;
|
||||
if (maxHeap.size() < maxVisibleFurniture) return true;
|
||||
return maxHeap.peek() != null && distance < maxHeap.peek().distance;
|
||||
}
|
||||
|
||||
@@ -146,16 +169,26 @@ public class DynamicPriorityTracker {
|
||||
}
|
||||
}
|
||||
|
||||
public Element removeByEntityId(int entityId) {
|
||||
public void removeByEntityId(int entityId) {
|
||||
heapLock.lock();
|
||||
try {
|
||||
Element removed = elementMap.remove(entityId);
|
||||
if (removed != null) {
|
||||
maxHeap.remove(removed);
|
||||
inHeapSet.remove(entityId);
|
||||
}
|
||||
return removed;
|
||||
} finally {
|
||||
heapLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DynamicPriorityTracker{" +
|
||||
"maxHeap=" + maxHeap +
|
||||
", elementMap=" + elementMap +
|
||||
", inHeapSet=" + inHeapSet +
|
||||
", heapLock=" + heapLock +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user