mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-31 04:46:37 +00:00
feat(bukkit): 添加配置文件
This commit is contained in:
@@ -183,6 +183,10 @@ furniture:
|
||||
# interaction (best performance)
|
||||
# boat (better compatibility with some anti-cheat plugin)
|
||||
collision-entity-type: interaction
|
||||
# Limit the maximum amount of furniture that players can see by default
|
||||
max-visible-furniture:
|
||||
enable: false
|
||||
amount: 100
|
||||
|
||||
emoji:
|
||||
chat: true
|
||||
|
||||
@@ -1601,25 +1601,29 @@ public class PacketConsumers {
|
||||
Player player = (Player) user.platformPlayer();
|
||||
List<Integer> fakeEntityIds = furniture.fakeEntityIds();
|
||||
user.entityPacketHandlers().computeIfAbsent(entityId, k -> new FurniturePacketHandler(fakeEntityIds));
|
||||
if (user.visualFurnitureView().getTotalMembers() <= 100) {
|
||||
if (Config.enableMaxVisibleFurniture()) {
|
||||
if (user.visualFurnitureView().getTotalMembers() <= Config.maxVisibleFurniture()) {
|
||||
user.sendPacket(furniture.spawnPacket(player), false);
|
||||
}
|
||||
int[] entityIdsArray = new int[fakeEntityIds.size() + 1];
|
||||
entityIdsArray[0] = entityId;
|
||||
for (int i = 0; i < fakeEntityIds.size(); i++) {
|
||||
entityIdsArray[i + 1] = fakeEntityIds.get(i);
|
||||
}
|
||||
double distance = player.getLocation().distance(furniture.location());
|
||||
Object removePacket = Reflections.constructor$ClientboundRemoveEntitiesPacket.newInstance(entityIdsArray);
|
||||
DynamicPriorityTracker.UpdateResult result = user.visualFurnitureView().addOrUpdateElement(new DynamicPriorityTracker.Element(entityId, distance, removePacket));
|
||||
for (DynamicPriorityTracker.Element element : result.getEntered()) {
|
||||
LoadedFurniture updateFurniture = BukkitFurnitureManager.instance().loadedFurnitureByRealEntityId(element.entityId());
|
||||
if (updateFurniture == null || !updateFurniture.isValid()) continue;
|
||||
user.sendPacket(updateFurniture.spawnPacket(player), false);
|
||||
}
|
||||
for (DynamicPriorityTracker.Element element : result.getExited()) {
|
||||
user.sendPacket(element.removePacket(), false);
|
||||
}
|
||||
} else {
|
||||
user.sendPacket(furniture.spawnPacket(player), false);
|
||||
}
|
||||
int[] entityIdsArray = new int[fakeEntityIds.size() + 1];
|
||||
entityIdsArray[0] = entityId;
|
||||
for (int i = 0; i < fakeEntityIds.size(); i++) {
|
||||
entityIdsArray[i + 1] = fakeEntityIds.get(i);
|
||||
}
|
||||
double distance = player.getLocation().distance(furniture.location());
|
||||
Object removePacket = Reflections.constructor$ClientboundRemoveEntitiesPacket.newInstance(entityIdsArray);
|
||||
DynamicPriorityTracker.UpdateResult result = user.visualFurnitureView().addOrUpdateElement(new DynamicPriorityTracker.Element(entityId, distance, removePacket));
|
||||
for (DynamicPriorityTracker.Element element : result.getEntered()) {
|
||||
LoadedFurniture updateFurniture = BukkitFurnitureManager.instance().loadedFurnitureByRealEntityId(element.entityId());
|
||||
if (updateFurniture == null || !updateFurniture.isValid()) continue;
|
||||
user.sendPacket(updateFurniture.spawnPacket(player), false);
|
||||
}
|
||||
for (DynamicPriorityTracker.Element element : result.getExited()) {
|
||||
user.sendPacket(element.removePacket(), false);
|
||||
}
|
||||
if (Config.hideBaseEntity() && !furniture.hasExternalModel()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ public class BukkitServerPlayer extends Player {
|
||||
private double cachedInteractionRange;
|
||||
|
||||
private final Map<Integer, EntityPacketHandler> entityTypeView = new ConcurrentHashMap<>();
|
||||
private final DynamicPriorityTracker visualFurnitureView = new DynamicPriorityTracker(100);
|
||||
private final DynamicPriorityTracker visualFurnitureView = new DynamicPriorityTracker();
|
||||
|
||||
public BukkitServerPlayer(BukkitCraftEngine plugin, Channel channel) {
|
||||
this.channel = channel;
|
||||
@@ -374,7 +374,8 @@ public class BukkitServerPlayer extends Player {
|
||||
}
|
||||
|
||||
private void updateVisualFurnitureView() {
|
||||
if (visualFurnitureView().getTotalMembers() <= 100) return;
|
||||
if (!Config.enableMaxVisibleFurniture()) return;
|
||||
if (visualFurnitureView().getTotalMembers() <= Config.maxVisibleFurniture()) return;
|
||||
for (DynamicPriorityTracker.Element element : visualFurnitureView().getAllElements()) {
|
||||
LoadedFurniture furniture = BukkitFurnitureManager.instance().loadedFurnitureByRealEntityId(element.entityId());
|
||||
if (furniture == null || !furniture.isValid()) continue;
|
||||
|
||||
@@ -110,6 +110,8 @@ public class Config {
|
||||
protected Map<String, String> furniture$handle_invalid_furniture_on_chunk_load$mapping;
|
||||
protected boolean furniture$hide_base_entity;
|
||||
protected ColliderType furniture$collision_entity_type;
|
||||
protected boolean furniture$max_visible_furniture_enable;
|
||||
protected int furniture$max_visible_furniture_amount;
|
||||
|
||||
protected boolean block$sound_system$enable;
|
||||
protected boolean block$simplify_adventure_break_check;
|
||||
@@ -300,6 +302,8 @@ public class Config {
|
||||
furniture$handle_invalid_furniture_on_chunk_load$mapping = builder.build();
|
||||
furniture$hide_base_entity = config.getBoolean("furniture.hide-base-entity", true);
|
||||
furniture$collision_entity_type = ColliderType.valueOf(config.getString("furniture.collision-entity-type", "interaction").toUpperCase(Locale.ENGLISH));
|
||||
furniture$max_visible_furniture_enable = config.getBoolean("furniture.max-visible-furniture.enable", false);
|
||||
furniture$max_visible_furniture_amount = config.getInt("furniture.max-visible-furniture.amount", 100);
|
||||
|
||||
// block
|
||||
block$sound_system$enable = config.getBoolean("block.sound-system.enable", true);
|
||||
@@ -417,6 +421,14 @@ public class Config {
|
||||
return instance.resource_pack$supported_version$min;
|
||||
}
|
||||
|
||||
public static boolean enableMaxVisibleFurniture() {
|
||||
return instance.furniture$max_visible_furniture_enable;
|
||||
}
|
||||
|
||||
public static int maxVisibleFurniture() {
|
||||
return instance.furniture$max_visible_furniture_amount;
|
||||
}
|
||||
|
||||
public static float packMaxVersion() {
|
||||
return instance.resource_pack$supported_version$max;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.momirealms.craftengine.core.util;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
@@ -50,14 +52,12 @@ public class DynamicPriorityTracker {
|
||||
}
|
||||
}
|
||||
|
||||
private final int capacity;
|
||||
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(int capacity) {
|
||||
this.capacity = capacity;
|
||||
public DynamicPriorityTracker() {
|
||||
this.maxHeap = new PriorityQueue<>((a, b) -> Double.compare(b.distance, a.distance));
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public class DynamicPriorityTracker {
|
||||
private UpdateResult handleNewElement(Element newElement, UpdateResult result) {
|
||||
elementMap.put(newElement.entityId, newElement);
|
||||
|
||||
if (maxHeap.size() < capacity) {
|
||||
if (maxHeap.size() < Config.maxVisibleFurniture()) {
|
||||
maxHeap.offer(newElement);
|
||||
inHeapSet.add(newElement.entityId);
|
||||
result.addEntered(newElement);
|
||||
@@ -106,7 +106,7 @@ public class DynamicPriorityTracker {
|
||||
maxHeap.remove(existing);
|
||||
maxHeap.offer(existing);
|
||||
} else if (nowInHeap) {
|
||||
if (maxHeap.size() < capacity) {
|
||||
if (maxHeap.size() < Config.maxVisibleFurniture()) {
|
||||
maxHeap.offer(existing);
|
||||
inHeapSet.add(existing.entityId);
|
||||
result.addEntered(existing);
|
||||
@@ -124,7 +124,7 @@ public class DynamicPriorityTracker {
|
||||
}
|
||||
|
||||
private boolean checkIfShouldBeInHeap(double distance) {
|
||||
if (maxHeap.size() < capacity) return true;
|
||||
if (maxHeap.size() < Config.maxVisibleFurniture()) return true;
|
||||
return maxHeap.peek() != null && distance < maxHeap.peek().distance;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G
|
||||
# Project settings
|
||||
# Rule: [major update].[feature update].[bug fix]
|
||||
project_version=0.0.54
|
||||
config_version=32
|
||||
config_version=33
|
||||
lang_version=12
|
||||
project_group=net.momirealms
|
||||
latest_supported_version=1.21.5
|
||||
|
||||
Reference in New Issue
Block a user