Custom model data allowing/denying
This commit is contained in:
@@ -153,7 +153,7 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.13.1-R0.1-SNAPSHOT</version>
|
||||
<version>1.14.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -50,6 +50,7 @@ import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
@@ -94,6 +95,8 @@ public class PlayerVaults extends JavaPlugin {
|
||||
// VaultViewInfo - Inventory
|
||||
private final HashMap<String, Inventory> openInventories = new HashMap<>();
|
||||
private final Set<Material> blockedMats = new HashSet<>();
|
||||
private boolean blockWithModelData = false;
|
||||
private boolean blockWithoutModelData = false;
|
||||
private boolean useVault;
|
||||
private YamlConfiguration signs;
|
||||
private File signsFile;
|
||||
@@ -393,8 +396,16 @@ public class PlayerVaults extends JavaPlugin {
|
||||
|
||||
// Clear just in case this is a reload.
|
||||
blockedMats.clear();
|
||||
this.blockWithModelData = false;
|
||||
this.blockWithoutModelData = false;
|
||||
if (getConf().getItemBlocking().isEnabled()) {
|
||||
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);
|
||||
if (mat != null) {
|
||||
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");
|
||||
if (lang.exists()) {
|
||||
@@ -560,6 +577,14 @@ public class PlayerVaults extends JavaPlugin {
|
||||
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.
|
||||
*
|
||||
|
||||
@@ -30,7 +30,10 @@ public class Config {
|
||||
public class Block {
|
||||
private boolean enabled = true;
|
||||
@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>() {
|
||||
{
|
||||
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 help = TL.of("/pv <number>");
|
||||
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 blockedBadItem = TL.of("<error>This item is not allowed in a vault.");
|
||||
}
|
||||
@@ -306,6 +308,14 @@ public class Translation {
|
||||
return this.translations.blockedItem;
|
||||
}
|
||||
|
||||
public @NonNull TL blockedItemWithModelData() {
|
||||
return this.translations.blockedItemWithModelData;
|
||||
}
|
||||
|
||||
public @NonNull TL blockedItemWithoutModelData() {
|
||||
return this.translations.blockedItemWithoutModelData;
|
||||
}
|
||||
|
||||
public @NonNull TL signsDisabled() {
|
||||
return this.translations.signsDisabled;
|
||||
}
|
||||
|
||||
@@ -135,7 +135,18 @@ public class Listeners implements Listener {
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
if (!player.hasPermission("playervaults.bypassblockeditems") && PlayerVaults.getInstance().isBlockedMaterial(item.getType())) {
|
||||
if (!player.hasPermission("playervaults.bypassblockeditems")) {
|
||||
if (PlayerVaults.getInstance().isBlockWithModelData() && item.hasItemMeta() && item.getItemMeta().hasCustomModelData()) {
|
||||
event.setCancelled(true);
|
||||
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;
|
||||
@@ -145,6 +156,7 @@ public class Listeners implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onDrag(InventoryDragEvent event) {
|
||||
|
||||
Reference in New Issue
Block a user