Skip to content

Commit

Permalink
feat: allow Mimic custom items in allowedTools (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
knokko committed Jun 28, 2024
1 parent cc679d7 commit a0ebf4c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
6 changes: 6 additions & 0 deletions modules/SilkSpawners/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>ru.endlesscode.mimic</groupId>
<artifactId>mimic-bukkit-api</artifactId>
<version>0.8.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import lombok.Getter;
import lombok.Setter;
import me.confuser.barapi.BarAPI;
import ru.endlesscode.mimic.Mimic;

/**
* This is the util class where all the magic happens.
Expand Down Expand Up @@ -93,6 +94,11 @@ public class SilkUtil {
*/
private WorldGuardPlugin wg;

/**
* Mimic instance, may be null
*/
private Mimic mimic;

/**
* BarAPI usage toggle.
*/
Expand Down Expand Up @@ -130,6 +136,7 @@ public SilkUtil(final SilkSpawners instance) {
}

getWorldGuard();
getMimic();
final boolean nmsProviderFound = setupNMSProvider();

if (nmsProviderFound) {
Expand Down Expand Up @@ -837,6 +844,10 @@ public boolean isValidItemAndHasSilkTouch(final ItemStack tool) {
toolAllowed = true;
break;
}
if (mimic != null && mimic.getItemsRegistry().isSameItem(tool, allowedTool)) {
toolAllowed = true;
break;
}
}
if (!toolAllowed) {
plugin.getLogger().log(Level.FINE, "Tool not allowed: {0}", tool.getType());
Expand Down Expand Up @@ -910,6 +921,20 @@ private void getWorldGuard() {
wg = (WorldGuardPlugin) worldGuard;
}

private void getMimic() {
if (!plugin.getConfig().getBoolean("useMimic", true)) {
plugin.getLogger().info("Mimic support is disabled due to config setting");
return;
}
final Plugin mimicPlugin = plugin.getServer().getPluginManager().getPlugin("Mimic");
if (mimicPlugin == null) {
plugin.getLogger().info("Mimic was not found and support is disabled");
return;
}
mimic = Mimic.getInstance();
plugin.getLogger().info("Mimic was found and support is enabled");
}

/**
* Checks if a player can build here (WorldGuard).
*
Expand Down
3 changes: 3 additions & 0 deletions modules/SilkSpawners/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ permissionExplode: false
# Should be checked for WorldGuard build ability to change spawners
useWorldGuard: true

useMimic: true
# Allows you to use Mimic item IDs in allowedTools

# Percentage of dropping a spawner block when TNT or creepers explode
explosionDropChance: 30

Expand Down
2 changes: 1 addition & 1 deletion modules/SilkSpawners/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ permissions:
silkspawners.help:
description: Allows you to see the help menu
default: true
softdepend: [WorldGuard, BarAPI, Factions]
softdepend: [WorldGuard, BarAPI, Factions, Mimic]
loadbefore: [MergedSpawner, ShopGUIPlus]

0 comments on commit a0ebf4c

Please sign in to comment.