Skip to content

Commit 4092d36

Browse files
committed
Added ProtocolLib Support + updated readme
1 parent dc4a92e commit 4092d36

16 files changed

Lines changed: 313 additions & 34 deletions

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
</div>
1313

1414
Mint ships **29** lightweight, vanilla-friendly gameplay modules. Each one can be toggled per-player, integrates with common protection plugins, supports multiple storage backends, and requires no client mods.
15+
We are talking Diamond Doors, Vertical Slabs, Mixed slabs and Colored ItemFrames. Make sure you checkout [Building Modules](docs/building.md)!
1516

1617
## Features
1718

@@ -32,10 +33,9 @@ Mint ships 29 lightweight modules grouped by category:
3233
2. Drop it into your `plugins/` folder and restart.
3334
3. Configure settings via `plugins/Mint/config.yml`.
3435

35-
**Requirements:** Paper 1.21.4+ Java 21+. (Folia support is currently **Experimental**)
36-
37-
**Optional integrations:** PlaceholderAPI, WorldGuard, GriefPrevention, Towny, and BentoBox (soft-dependencies).
36+
**Requirements:** Paper/Folia 1.21.4+ Java 21+.
3837

38+
**Soft Dependencies** PlaceholderAPI, WorldGuard, GriefPrevention, Towny, ProtocolLib and BentoBox
3939
## Commands & Permissions
4040

4141
| Command | Description | Permission |
@@ -73,7 +73,7 @@ mvn clean package
7373
```
7474
## License & Credits
7575

76-
Licensed under [AGPL-3.0](LICENSE). Inspired by the [Quark mod](https://quarkmod.net/) by Vazkii.
76+
Licensed under [AGPL-3.0](LICENSE). Inspired by the [Quark mod](https://quarkmod.net/) by Vazkii and [V-Tweaks](https://mods.oitsjustjose.com/V-Tweaks/) by oitsjustjose.
7777

7878
## Support & Contributions
7979

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@
116116
<version>2.11.5</version>
117117
<scope>provided</scope>
118118
</dependency>
119+
<dependency>
120+
<groupId>net.dmulloy2</groupId>
121+
<artifactId>ProtocolLib</artifactId>
122+
<version>5.4.0</version>
123+
<scope>provided</scope>
124+
</dependency>
119125
<dependency>
120126
<groupId>org.mariadb.jdbc</groupId>
121127
<artifactId>mariadb-java-client</artifactId>

src/main/java/ir/buddy/mint/MintPlugin.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import ir.buddy.mint.command.MintCommand;
44
import ir.buddy.mint.config.PluginConfigValidator;
55
import ir.buddy.mint.gui.ModuleToggleGui;
6+
import ir.buddy.mint.util.DisplayBackendManager;
67
import ir.buddy.mint.util.DisplayEntityController;
78
import ir.buddy.mint.util.MintJdbcLibraryLoader;
89
import ir.buddy.mint.util.MintLang;
@@ -37,6 +38,7 @@ public final class MintPlugin extends JavaPlugin {
3738
private FileConfiguration langConfig;
3839
private MintLang mintLang;
3940
private DisplayEntityController displayEntityController;
41+
private DisplayBackendManager displayBackendManager;
4042
private URLClassLoader runtimeLibrariesClassLoader;
4143
private final Object runtimeLibrariesLock = new Object();
4244
private volatile boolean bstatsHooked;
@@ -61,6 +63,8 @@ private void completeMintStartup() {
6163
this.protectionSupport = new ProtectionSupport();
6264
this.displayEntityController = new DisplayEntityController(this);
6365
this.displayEntityController.register();
66+
this.displayBackendManager = new DisplayBackendManager(this);
67+
this.displayBackendManager.initializeOrReload();
6468
this.moduleManager = new ModuleManager(this);
6569
this.moduleManager.registerModules();
6670
PluginConfigValidator.validateAndLog(this, moduleManager);
@@ -118,6 +122,7 @@ public void onDisable() {
118122
playerModulePreferences.close();
119123
playerModulePreferences = null;
120124
}
125+
displayBackendManager = null;
121126
displayEntityController = null;
122127
resetRuntimeLibrariesClassLoader();
123128
getLogger().info("Mint disabled.");
@@ -146,6 +151,10 @@ public void reloadPlugin() {
146151
} else {
147152
displayEntityController.reload();
148153
}
154+
if (displayBackendManager == null) {
155+
displayBackendManager = new DisplayBackendManager(this);
156+
}
157+
displayBackendManager.initializeOrReload();
149158
playerModulePreferences.preloadToggles(Bukkit.getOnlinePlayers(), moduleManager.getModules());
150159
PluginConfigValidator.validateAndLog(this, moduleManager);
151160
moduleManager.refreshActiveModules();
@@ -218,6 +227,10 @@ public DisplayEntityController getDisplayEntityController() {
218227
return displayEntityController;
219228
}
220229

230+
public DisplayBackendManager getDisplayBackendManager() {
231+
return displayBackendManager;
232+
}
233+
221234

222235

223236

src/main/java/ir/buddy/mint/module/impl/building/BlockDecorationModule.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -672,11 +672,8 @@ private void spawnPart(Block block, Material material, String locKey,
672672
float pad,
673673
@Nullable String decorationPart) {
674674
Location spawnLoc = block.getLocation();
675-
if (!plugin.getDisplayEntityController().canSpawn(spawnLoc, getConfigPath())) {
676-
return;
677-
}
678675
Display.Brightness brightness = sampleBrightness(block);
679-
block.getWorld().spawn(spawnLoc, BlockDisplay.class, display -> {
676+
plugin.getDisplayBackendManager().backend().spawnBlockDisplay(spawnLoc, getConfigPath(), display -> {
680677
display.setBlock(material.createBlockData());
681678
display.setTransformation(new Transformation(
682679
new Vector3f(tx - pad, ty - pad, tz - pad),
@@ -691,7 +688,6 @@ private void spawnPart(Block block, Material material, String locKey,
691688
if (decorationPart != null) {
692689
pdc.set(decorationPartKey, PersistentDataType.STRING, decorationPart);
693690
}
694-
plugin.getDisplayEntityController().markManaged(display, getConfigPath());
695691
display.setPersistent(true);
696692
display.setGravity(false);
697693
});

src/main/java/ir/buddy/mint/module/impl/building/CarpetGeometryModule.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ private void spawnPart(Block block, Material material, int variant, String locKe
378378
float transformedSz = sz * frame.xzScale();
379379
float transformedTy = frame.yTop() + (ty - DEFAULT_PATTERN_TOP);
380380

381-
block.getWorld().spawn(spawnLoc, BlockDisplay.class, display -> {
381+
plugin.getDisplayBackendManager().backend().spawnBlockDisplay(spawnLoc, getConfigPath(), display -> {
382382
display.setBlock(material.createBlockData());
383383
display.setTransformation(new Transformation(
384384
new Vector3f(transformedTx - HALF_PAD, transformedTy - HALF_PAD, transformedTz - HALF_PAD),
@@ -876,12 +876,11 @@ public void onBlockPlace(BlockPlaceEvent event) {
876876
public void onBlockBreak(BlockBreakEvent event) {
877877
if (!plugin.isEnabled()) return;
878878

879-
if (!ModuleAccess.isEnabledForPlayer(plugin, this, event.getPlayer())) {
880-
return;
881-
}
882-
883-
boolean shouldDrop = event.isDropItems() && event.getPlayer().getGameMode() != GameMode.CREATIVE;
884-
if (handlePatternBreak(event.getBlock(), shouldDrop)) {
879+
boolean moduleEnabledForPlayer = ModuleAccess.isEnabledForPlayer(plugin, this, event.getPlayer());
880+
boolean shouldDropCustomItem = moduleEnabledForPlayer
881+
&& event.isDropItems()
882+
&& event.getPlayer().getGameMode() != GameMode.CREATIVE;
883+
if (handlePatternBreak(event.getBlock(), shouldDropCustomItem) && shouldDropCustomItem) {
885884
event.setDropItems(false);
886885
}
887886
}

src/main/java/ir/buddy/mint/module/impl/building/DyeableItemFramesModule.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,7 @@ private ItemDisplay spawnDisplay(ItemFrame frame) {
213213
Vector facing = frame.getFacing().getDirection();
214214
Location displayLocation = location.clone().add(facing.clone().multiply(DISPLAY_OFFSET));
215215
displayLocation.setDirection(facing);
216-
if (!plugin.getDisplayEntityController().canSpawn(displayLocation, getConfigPath())) {
217-
return null;
218-
}
219-
220-
ItemDisplay display = frame.getWorld().spawn(displayLocation, ItemDisplay.class, d -> {
216+
ItemDisplay display = plugin.getDisplayBackendManager().backend().spawnItemDisplay(displayLocation, getConfigPath(), d -> {
221217
d.setPersistent(false);
222218
d.setInvulnerable(true);
223219
d.setGravity(false);
@@ -232,8 +228,10 @@ private ItemDisplay spawnDisplay(ItemFrame frame) {
232228
PersistentDataContainer displayPdc = d.getPersistentDataContainer();
233229
displayPdc.set(displayMarkerKey, PersistentDataType.BYTE, (byte) 1);
234230
displayPdc.set(displayFrameUuidKey, PersistentDataType.STRING, frame.getUniqueId().toString());
235-
plugin.getDisplayEntityController().markManaged(d, getConfigPath());
236231
});
232+
if (display == null) {
233+
return null;
234+
}
237235

238236
frame.getPersistentDataContainer().set(frameDisplayUuidKey, PersistentDataType.STRING, display.getUniqueId().toString());
239237
return display;

src/main/java/ir/buddy/mint/module/impl/building/MixedSlabModule.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,16 @@ public void onPlayerQuit(PlayerQuitEvent event) {
310310
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
311311
public void onBlockBreak(BlockBreakEvent event) {
312312
Player player = event.getPlayer();
313-
if (!ModuleAccess.isEnabledForPlayer(plugin, this, player)) return;
313+
boolean moduleEnabledForPlayer = ModuleAccess.isEnabledForPlayer(plugin, this, player);
314314
MiningContext ctx = activeMining.remove(player.getUniqueId());
315315

316316
Block block = event.getBlock();
317+
if (!moduleEnabledForPlayer) {
318+
if (block.getType() == Material.BARRIER && isMixedSlabAt(block)) {
319+
cleanupMixedSlab(block, false);
320+
}
321+
return;
322+
}
317323
if (!ModuleAccess.canBuild(plugin, player, block.getLocation())) return;
318324

319325

src/main/java/ir/buddy/mint/module/impl/building/ReacharoundPlacementModule.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,11 +551,23 @@ private boolean isValid(World world) {
551551

552552
private void remove() {
553553
for (BlockDisplay edge : edges) {
554-
if (edge != null && !edge.isDead()) {
554+
safeRemoveEdge(edge);
555+
}
556+
currentTarget = null;
557+
}
558+
559+
private void safeRemoveEdge(BlockDisplay edge) {
560+
if (edge == null || edge.isDead()) {
561+
return;
562+
}
563+
try {
564+
FoliaScheduler.runEntity(plugin, edge, edge::remove);
565+
} catch (Throwable ignored) {
566+
try {
555567
edge.remove();
568+
} catch (Throwable ignoredAgain) {
556569
}
557570
}
558-
currentTarget = null;
559571
}
560572

561573
private void hide() {

src/main/java/ir/buddy/mint/module/impl/building/SignItemsModule.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,7 @@ private boolean spawnDisplayOnSign(Block block, TileState tileState, PersistentD
139139
if (loc == null) {
140140
return false;
141141
}
142-
if (!plugin.getDisplayEntityController().canSpawn(loc, getConfigPath())) {
143-
return false;
144-
}
145-
146-
ItemDisplay display = block.getWorld().spawn(loc, ItemDisplay.class, d -> {
142+
ItemDisplay display = plugin.getDisplayBackendManager().backend().spawnItemDisplay(loc, getConfigPath(), d -> {
147143
d.setPersistent(true);
148144
d.setInvulnerable(true);
149145
d.setGravity(false);
@@ -158,8 +154,10 @@ private boolean spawnDisplayOnSign(Block block, TileState tileState, PersistentD
158154
));
159155

160156
d.getPersistentDataContainer().set(itemMarkerKey, PersistentDataType.BYTE, (byte) 1);
161-
plugin.getDisplayEntityController().markManaged(d, getConfigPath());
162157
});
158+
if (display == null) {
159+
return false;
160+
}
163161

164162
pdc.set(displayUuidKey, PersistentDataType.STRING, display.getUniqueId().toString());
165163
tileState.update();
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package ir.buddy.mint.util;
2+
3+
import ir.buddy.mint.MintPlugin;
4+
import org.bukkit.Location;
5+
import org.bukkit.entity.BlockDisplay;
6+
import org.bukkit.entity.ItemDisplay;
7+
8+
import java.util.function.Consumer;
9+
10+
public final class BukkitDisplayBackend implements DisplayBackend {
11+
12+
private final MintPlugin plugin;
13+
14+
public BukkitDisplayBackend(MintPlugin plugin) {
15+
this.plugin = plugin;
16+
}
17+
18+
@Override
19+
public String name() {
20+
return "bukkit";
21+
}
22+
23+
@Override
24+
public boolean isProtocolLibBacked() {
25+
return false;
26+
}
27+
28+
@Override
29+
public BlockDisplay spawnBlockDisplay(Location location, String source, Consumer<BlockDisplay> initializer) {
30+
if (!plugin.getDisplayEntityController().canSpawn(location, source)) {
31+
return null;
32+
}
33+
return location.getWorld().spawn(location, BlockDisplay.class, display -> {
34+
initializer.accept(display);
35+
plugin.getDisplayEntityController().markManaged(display, source);
36+
});
37+
}
38+
39+
@Override
40+
public ItemDisplay spawnItemDisplay(Location location, String source, Consumer<ItemDisplay> initializer) {
41+
if (!plugin.getDisplayEntityController().canSpawn(location, source)) {
42+
return null;
43+
}
44+
return location.getWorld().spawn(location, ItemDisplay.class, display -> {
45+
initializer.accept(display);
46+
plugin.getDisplayEntityController().markManaged(display, source);
47+
});
48+
}
49+
}

0 commit comments

Comments
 (0)