Custom model data allowing/denying

This commit is contained in:
mbax
2023-08-07 21:17:23 -04:00
parent 664dfd37a0
commit 3b91a09782
5 changed files with 56 additions and 6 deletions
+1 -1
View File
@@ -153,7 +153,7 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.13.1-R0.1-SNAPSHOT</version> <version>1.14.4-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
@@ -50,6 +50,7 @@ import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
@@ -94,6 +95,8 @@ public class PlayerVaults extends JavaPlugin {
// VaultViewInfo - Inventory // VaultViewInfo - Inventory
private final HashMap<String, Inventory> openInventories = new HashMap<>(); private final HashMap<String, Inventory> openInventories = new HashMap<>();
private final Set<Material> blockedMats = new HashSet<>(); private final Set<Material> blockedMats = new HashSet<>();
private boolean blockWithModelData = false;
private boolean blockWithoutModelData = false;
private boolean useVault; private boolean useVault;
private YamlConfiguration signs; private YamlConfiguration signs;
private File signsFile; private File signsFile;
@@ -393,8 +396,16 @@ public class PlayerVaults extends JavaPlugin {
// Clear just in case this is a reload. // Clear just in case this is a reload.
blockedMats.clear(); blockedMats.clear();
this.blockWithModelData = false;
this.blockWithoutModelData = false;
if (getConf().getItemBlocking().isEnabled()) { if (getConf().getItemBlocking().isEnabled()) {
for (String s : getConf().getItemBlocking().getList()) { for (String s : getConf().getItemBlocking().getList()) {
if (s.equalsIgnoreCase("BLOCK_ALL_WITH_CUSTOM_MODEL_DATA")) {
this.blockWithModelData = true;
}
if (s.equalsIgnoreCase("BLOCK_ALL_WITHOUT_CUSTOM_MODEL_DATA")) {
this.blockWithoutModelData = true;
}
Material mat = Material.matchMaterial(s); Material mat = Material.matchMaterial(s);
if (mat != null) { if (mat != null) {
blockedMats.add(mat); blockedMats.add(mat);
@@ -402,6 +413,12 @@ public class PlayerVaults extends JavaPlugin {
} }
} }
} }
try {
ItemMeta.class.getMethod("hasCustomModelData");
} catch (NoSuchMethodException e) {
this.blockWithModelData = false;
this.blockWithoutModelData = false;
}
File lang = new File(this.getDataFolder(), "lang"); File lang = new File(this.getDataFolder(), "lang");
if (lang.exists()) { if (lang.exists()) {
@@ -560,6 +577,14 @@ public class PlayerVaults extends JavaPlugin {
return blockedMats.contains(mat); return blockedMats.contains(mat);
} }
public boolean isBlockWithModelData() {
return this.blockWithModelData;
}
public boolean isBlockWithoutModelData() {
return this.blockWithoutModelData;
}
/** /**
* Tries to grab the server version as a string. * Tries to grab the server version as a string.
* *
@@ -30,7 +30,10 @@ public class Config {
public class Block { public class Block {
private boolean enabled = true; private boolean enabled = true;
@Comment("Material list for blocked items (does not support ID's), only effective if the feature is enabled.\n" + @Comment("Material list for blocked items (does not support ID's), only effective if the feature is enabled.\n" +
" If you don't know material names: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html") " If you don't know material names: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html\n" +
"\n" +
"Also, if you add \"BLOCK_ALL_WITH_CUSTOM_MODEL_DATA\" or \"BLOCK_ALL_WITHOUT_CUSTOM_MODEL_DATA\"\n" +
" then either all items with custom model data will be blocked, or all items without custom model data will be blocked.")
private List<String> list = new ArrayList<String>() { private List<String> list = new ArrayList<String>() {
{ {
this.add("PUMPKIN"); this.add("PUMPKIN");
@@ -174,6 +174,8 @@ public class Translation {
private TL locked = TL.of("<error>Vaults are currently locked while conversion occurs. Please try again in a moment!"); private TL locked = TL.of("<error>Vaults are currently locked while conversion occurs. Please try again in a moment!");
private TL help = TL.of("/pv <number>"); private TL help = TL.of("/pv <number>");
private TL blockedItem = TL.of("<gold><item></gold> <error>is blocked from vaults."); private TL blockedItem = TL.of("<gold><item></gold> <error>is blocked from vaults.");
private TL blockedItemWithModelData = TL.of("<error>This item is blocked from vaults.");
private TL blockedItemWithoutModelData = TL.of("<error>This item is blocked from vaults.");
private TL signsDisabled = TL.of("<error>Vault signs are currently disabled."); private TL signsDisabled = TL.of("<error>Vault signs are currently disabled.");
private TL blockedBadItem = TL.of("<error>This item is not allowed in a vault."); private TL blockedBadItem = TL.of("<error>This item is not allowed in a vault.");
} }
@@ -306,6 +308,14 @@ public class Translation {
return this.translations.blockedItem; return this.translations.blockedItem;
} }
public @NonNull TL blockedItemWithModelData() {
return this.translations.blockedItemWithModelData;
}
public @NonNull TL blockedItemWithoutModelData() {
return this.translations.blockedItemWithoutModelData;
}
public @NonNull TL signsDisabled() { public @NonNull TL signsDisabled() {
return this.translations.signsDisabled; return this.translations.signsDisabled;
} }
@@ -135,10 +135,22 @@ public class Listeners implements Listener {
if (item == null) { if (item == null) {
continue; continue;
} }
if (!player.hasPermission("playervaults.bypassblockeditems") && PlayerVaults.getInstance().isBlockedMaterial(item.getType())) { if (!player.hasPermission("playervaults.bypassblockeditems")) {
event.setCancelled(true); if (PlayerVaults.getInstance().isBlockWithModelData() && item.hasItemMeta() && item.getItemMeta().hasCustomModelData()) {
this.plugin.getTL().blockedItem().title().with("item", item.getType().name()).send(player); event.setCancelled(true);
return; this.plugin.getTL().blockedItemWithModelData().title().send(player);
return;
}
if (PlayerVaults.getInstance().isBlockWithoutModelData() && (!item.hasItemMeta() || !item.getItemMeta().hasCustomModelData())) {
event.setCancelled(true);
this.plugin.getTL().blockedItemWithoutModelData().title().send(player);
return;
}
if (PlayerVaults.getInstance().isBlockedMaterial(item.getType())) {
event.setCancelled(true);
this.plugin.getTL().blockedItem().title().with("item", item.getType().name()).send(player);
return;
}
} }
} }
} }