Skip to content

Commit 668bbec

Browse files
committed
Config, enhancements
1 parent 465ebea commit 668bbec

15 files changed

Lines changed: 370 additions & 192 deletions

pom.xml

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@
1515
</properties>
1616

1717
<repositories>
18+
<repository>
19+
<id>spigot-repo</id>
20+
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
21+
</repository>
22+
<!--
1823
<repository>
1924
<id>papermc</id>
2025
<url>https://papermc.io/repo/repository/maven-public/</url>
2126
</repository>
27+
-->
2228
<repository>
2329
<id>codemc-nms</id>
2430
<url>https://repo.codemc.io/repository/nms/</url>
@@ -30,6 +36,19 @@
3036
</repositories>
3137

3238
<dependencies>
39+
<dependency>
40+
<groupId>org.spigotmc</groupId>
41+
<artifactId>spigot-api</artifactId>
42+
<version>1.16.5-R0.1-SNAPSHOT</version>
43+
<scope>provided</scope>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.spigotmc</groupId>
47+
<artifactId>spigot</artifactId>
48+
<version>1.16.5-R0.1-SNAPSHOT</version>
49+
<scope>provided</scope>
50+
</dependency>
51+
<!--
3352
<dependency>
3453
<groupId>com.destroystokyo.paper</groupId>
3554
<artifactId>paper-api</artifactId>
@@ -42,6 +61,7 @@
4261
<version>1.16.5-R0.1-SNAPSHOT</version>
4362
<scope>provided</scope>
4463
</dependency>
64+
-->
4565
<dependency>
4666
<groupId>io.netty</groupId>
4767
<artifactId>netty-all</artifactId>
@@ -85,41 +105,6 @@
85105
<target>${jdk.version}</target>
86106
</configuration>
87107
</plugin>
88-
<!--
89-
<plugin>
90-
<groupId>org.apache.maven.plugins</groupId>
91-
<artifactId>maven-shade-plugin</artifactId>
92-
<version>3.2.4</version>
93-
<executions>
94-
<execution>
95-
<phase>package</phase>
96-
<goals>
97-
<goal>shade</goal>
98-
</goals>
99-
</execution>
100-
</executions>
101-
<configuration>
102-
<createDependencyReducedPom>false</createDependencyReducedPom>
103-
<relocations>
104-
<relocation>
105-
<pattern>it.unimi.dsi.fastutil</pattern>
106-
<shadedPattern>it.feargames.tileculling.libs.it.unimi.dsi.fastutil</shadedPattern>
107-
</relocation>
108-
</relocations>
109-
110-
<filters>
111-
<filter>
112-
<artifact>*:*</artifact>
113-
<excludes>
114-
<exclude>META-INF/*.SF</exclude>
115-
<exclude>META-INF/*.DSA</exclude>
116-
<exclude>META-INF/*.RSA</exclude>
117-
</excludes>
118-
</filter>
119-
</filters>
120-
</configuration>
121-
</plugin>
122-
-->
123108
</plugins>
124109
</build>
125110

src/main/java/it/feargames/tileculling/ChunkCache.java

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package it.feargames.tileculling;
22

3+
import it.feargames.tileculling.util.LocationUtilities;
34
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
45
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
56
import org.bukkit.Chunk;
@@ -26,17 +27,19 @@
2627
public class ChunkCache implements Listener {
2728

2829
private final CullingPlugin plugin;
30+
private final HiddenTileRegistry hiddenTileRegistry;
2931

3032
private final Map<World, Long2ObjectMap<ChunkEntry>> cachedChunks = new HashMap<>();
3133
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
3234
private final ReentrantReadWriteLock.WriteLock writeLock = lock.writeLock();
3335
private final ReentrantReadWriteLock.ReadLock readLock = lock.readLock();
3436

35-
public ChunkCache(CullingPlugin plugin) {
37+
public ChunkCache(CullingPlugin plugin, HiddenTileRegistry hiddenTileRegistry) {
3638
this.plugin = plugin;
39+
this.hiddenTileRegistry = hiddenTileRegistry;
3740
for (World world : plugin.getServer().getWorlds()) {
3841
for (Chunk chunk : world.getLoadedChunks()) {
39-
updateCachedChunkSync(chunk.getWorld(), chunk.getChunkKey(), chunk);
42+
updateCachedChunkSync(chunk.getWorld(), LocationUtilities.getChunkKey(chunk), chunk);
4043
}
4144
}
4245
}
@@ -58,7 +61,7 @@ public void onBlockPlace(BlockPlaceEvent e) {
5861
new BukkitRunnable() {
5962
@Override
6063
public void run() {
61-
updateCachedChunkSync(chunk.getWorld(), chunk.getChunkKey(), chunk);
64+
updateCachedChunkSync(chunk.getWorld(), LocationUtilities.getChunkKey(chunk), chunk);
6265
}
6366
}.runTask(plugin);
6467
}
@@ -70,7 +73,7 @@ public void onBlockBreak(BlockBreakEvent e) {
7073
new BukkitRunnable() {
7174
@Override
7275
public void run() {
73-
updateCachedChunkSync(chunk.getWorld(), chunk.getChunkKey(), chunk);
76+
updateCachedChunkSync(chunk.getWorld(), LocationUtilities.getChunkKey(chunk), chunk);
7477
}
7578
}.runTask(plugin);
7679
}
@@ -82,21 +85,21 @@ public void onSignUpdate(SignChangeEvent e) {
8285
new BukkitRunnable() {
8386
@Override
8487
public void run() {
85-
updateCachedChunkSync(chunk.getWorld(), chunk.getChunkKey(), chunk);
88+
updateCachedChunkSync(chunk.getWorld(), LocationUtilities.getChunkKey(chunk), chunk);
8689
}
8790
}.runTask(plugin);
8891
}
8992

9093
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
9194
public void onChunkLoad(ChunkLoadEvent e) {
9295
Chunk chunk = e.getChunk();
93-
updateCachedChunkSync(chunk.getWorld(), chunk.getChunkKey(), chunk);
96+
updateCachedChunkSync(chunk.getWorld(), LocationUtilities.getChunkKey(chunk), chunk);
9497
}
9598

9699
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
97100
public void onChunkUnload(ChunkUnloadEvent e) {
98101
Chunk chunk = e.getChunk();
99-
updateCachedChunkSync(chunk.getWorld(), chunk.getChunkKey(), null);
102+
updateCachedChunkSync(chunk.getWorld(), LocationUtilities.getChunkKey(chunk), null);
100103
}
101104

102105
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@@ -115,7 +118,7 @@ private void handleExplosionSync(List<Block> blockList) {
115118
chunks.add(block.getChunk());
116119
}
117120
for (Chunk chunk : chunks) {
118-
updateCachedChunkSync(chunk.getWorld(), chunk.getChunkKey(), chunk);
121+
updateCachedChunkSync(chunk.getWorld(), LocationUtilities.getChunkKey(chunk), chunk);
119122
}
120123
}
121124

@@ -153,26 +156,13 @@ private List<BlockState> filterTiles(BlockState[] tiles) {
153156

154157
List<BlockState> result = new LinkedList<>();
155158
for (BlockState state : tiles) {
156-
if (CullingPlugin.shouldHide(state)) {
159+
if (hiddenTileRegistry.shouldHide(state)) {
157160
result.add(state);
158161
}
159162
}
160163
return result;
161164
}
162165

163-
public boolean isInLoadedChunk(World world, long chunkKey) {
164-
try {
165-
readLock.lock();
166-
Long2ObjectMap<ChunkEntry> entries = cachedChunks.get(world);
167-
return entries != null && entries.containsKey(chunkKey);
168-
} catch (Throwable t) {
169-
t.printStackTrace();
170-
} finally {
171-
readLock.unlock();
172-
}
173-
return false;
174-
}
175-
176166
public ChunkSnapshot getChunk(World world, long chunkKey) {
177167
try {
178168
readLock.lock();

src/main/java/it/feargames/tileculling/ChunkTileVisibilityManager.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
import it.feargames.tileculling.adapter.IAdapter;
44
import it.feargames.tileculling.occlusionculling.AxisAlignedBB;
55
import it.feargames.tileculling.occlusionculling.OcclusionCulling;
6-
import org.bukkit.Chunk;
76
import org.bukkit.Location;
8-
import org.bukkit.Material;
97
import org.bukkit.World;
108
import org.bukkit.block.BlockState;
9+
import org.bukkit.block.TileState;
1110
import org.bukkit.entity.Player;
1211
import org.bukkit.util.Vector;
1312

@@ -24,13 +23,13 @@ public class ChunkTileVisibilityManager {
2423

2524
private final OcclusionCulling culling;
2625

27-
public ChunkTileVisibilityManager(IAdapter adapter, PlayerChunkTracker playerTracker, VisibilityCache visibilityCache, ChunkCache chunkCache) {
26+
public ChunkTileVisibilityManager(SettingsHolder settings, IAdapter adapter, PlayerChunkTracker playerTracker, VisibilityCache visibilityCache, ChunkCache chunkCache) {
2827
this.adapter = adapter;
2928
this.playerTracker = playerTracker;
3029
this.visibilityCache = visibilityCache;
3130
this.chunkCache = chunkCache;
3231

33-
this.culling = new OcclusionCulling(chunkCache);
32+
this.culling = new OcclusionCulling(chunkCache, settings.getTileRange());
3433
}
3534

3635
public void updateVisibility(Player player) {
@@ -55,10 +54,13 @@ public void updateVisibility(Player player) {
5554
if (hidden && canSee) {
5655
visibilityCache.setHidden(player, bloc, false);
5756
adapter.updateBlockState(player, bloc, block.getBlockData());
58-
adapter.updateBlockData(player, bloc, block);
57+
if (block instanceof TileState) {
58+
adapter.updateBlockData(player, bloc, block);
59+
60+
}
5961
} else if (!hidden && !canSee) {
6062
visibilityCache.setHidden(player, bloc, true);
61-
adapter.updateBlockState(player, bloc, Material.AIR, (byte) 0);
63+
adapter.updateBlockState(player, bloc, null);
6264
}
6365
}
6466
}
Lines changed: 17 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,48 @@
11
package it.feargames.tileculling;
22

33
import com.comphenix.protocol.ProtocolLibrary;
4-
import com.destroystokyo.paper.MaterialTags;
54
import it.feargames.tileculling.adapter.Adapter_1_16_R3;
65
import it.feargames.tileculling.adapter.IAdapter;
7-
import it.feargames.tileculling.protocol.MapChunkPacketListener;
6+
import it.feargames.tileculling.protocol.ChunkPacketListener;
87
import org.bukkit.Material;
9-
import org.bukkit.block.BlockState;
108
import org.bukkit.entity.Player;
119
import org.bukkit.plugin.java.JavaPlugin;
1210

13-
import java.util.ArrayList;
14-
import java.util.Arrays;
15-
import java.util.List;
16-
1711
public class CullingPlugin extends JavaPlugin {
1812

19-
private IAdapter adapter;
13+
private SettingsHolder settings;
14+
private HiddenTileRegistry hiddenTileRegistry;
2015

16+
private IAdapter adapter;
2117
private ChunkTileVisibilityManager chunkTileVisibilityManager;
2218
private PlayerChunkTracker playerChunkTracker;
2319
private ChunkCache chunkCache;
2420
private VisibilityCache visibilityCache;
25-
private MapChunkPacketListener mapChunkPacketListener;
21+
private ChunkPacketListener chunkPacketListener;
2622

2723
private VisibilityUpdateThread visibilityUpdateThread;
2824

2925
@Override
3026
public void onEnable() {
27+
saveDefaultConfig();
28+
29+
settings = new SettingsHolder();
30+
settings.load(getConfig().getConfigurationSection("settings"));
31+
hiddenTileRegistry = new HiddenTileRegistry(getLogger());
32+
hiddenTileRegistry.load(getConfig().getConfigurationSection("hiddenTiles"));
33+
3134
adapter = new Adapter_1_16_R3();
3235
playerChunkTracker = new PlayerChunkTracker(this);
3336
visibilityCache = new VisibilityCache();
34-
chunkCache = new ChunkCache(this);
35-
chunkTileVisibilityManager = new ChunkTileVisibilityManager(adapter, playerChunkTracker, visibilityCache, chunkCache);
37+
chunkCache = new ChunkCache(this, hiddenTileRegistry);
38+
chunkTileVisibilityManager = new ChunkTileVisibilityManager(settings, adapter, playerChunkTracker, visibilityCache, chunkCache);
3639

3740
getServer().getPluginManager().registerEvents(playerChunkTracker, this);
3841
getServer().getPluginManager().registerEvents(chunkCache, this);
3942
getServer().getPluginManager().registerEvents(visibilityCache, this);
4043

41-
mapChunkPacketListener = new MapChunkPacketListener(this, adapter, playerChunkTracker);
42-
ProtocolLibrary.getProtocolManager().addPacketListener(mapChunkPacketListener);
44+
chunkPacketListener = new ChunkPacketListener(this, hiddenTileRegistry, adapter, playerChunkTracker);
45+
ProtocolLibrary.getProtocolManager().addPacketListener(chunkPacketListener);
4346

4447
visibilityUpdateThread = new VisibilityUpdateThread(chunkTileVisibilityManager);
4548
visibilityUpdateThread.start();
@@ -63,63 +66,13 @@ public void onDisable() {
6366
}
6467
}
6568

66-
// TODO: create a registry
67-
68-
private static final Material[] hiddenMaterials;
69-
private static final String[] hiddenNamespaces;
70-
71-
static {
72-
List<Material> materials = new ArrayList<>(Arrays.asList(
73-
Material.CHEST,
74-
Material.TRAPPED_CHEST,
75-
Material.ENDER_CHEST,
76-
Material.FURNACE,
77-
Material.DISPENSER,
78-
Material.DROPPER,
79-
Material.HOPPER,
80-
Material.BREWING_STAND,
81-
Material.BARREL,
82-
Material.SPAWNER,
83-
Material.ENCHANTING_TABLE
84-
85-
));
86-
materials.addAll(MaterialTags.SHULKER_BOXES.getValues());
87-
materials.addAll(MaterialTags.SKULLS.getValues());
88-
materials.addAll(MaterialTags.SIGNS.getValues());
89-
// Cache values
90-
hiddenMaterials = materials.toArray(new Material[0]);
91-
hiddenNamespaces = materials.stream().map(material -> material.getKey().toString()).toArray(String[]::new);
92-
}
93-
94-
public static boolean shouldHide(String namespacedKey) {
95-
for (String current : hiddenNamespaces) {
96-
if (current.equals(namespacedKey)) {
97-
return true;
98-
}
99-
}
100-
return true;
101-
}
102-
103-
public static boolean shouldHide(Material material) {
104-
for (Material current : hiddenMaterials) {
105-
if (current == material) {
106-
return true;
107-
}
108-
}
109-
return true;
110-
}
111-
112-
public static boolean shouldHide(BlockState state) {
113-
return shouldHide(state.getType());
114-
}
115-
69+
// TODO: registry
11670
public static boolean isOccluding(Material material) {
11771
switch (material) {
11872
case BARRIER:
11973
case SPAWNER:
12074
return false;
12175
}
122-
// TODO: are we sure we want to use this?
12376
return material.isOccluding();
12477
}
12578
}

0 commit comments

Comments
 (0)