Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/java/com/drtshock/playervaults/PlayerVaults.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class PlayerVaults extends JavaPlugin {
// VaultViewInfo - Inventory
private final HashMap<String, Inventory> openInventories = new HashMap<>();
private final Set<Material> blockedMats = new HashSet<>();
private final Set<String> blockedNames = new HashSet<>();
private boolean useVault;
private YamlConfiguration signs;
private File signsFile;
Expand Down Expand Up @@ -345,6 +346,17 @@ private void loadConfig() {
}
}

// Clear just in case this is a reload.
blockedNames.clear();
if (getConf().getItemBlocking().isEnabled()) {
for (String s : getConf().getItemBlocking().getNames()) {
if (s != null && !s.isEmpty()) {
blockedNames.add(s);
getLogger().log(Level.INFO, "Added {0} to list of blocked names.", s);
}
}
}

File lang = new File(this.getDataFolder(), "lang");
if (lang.exists()) {
this.getLogger().warning("There is no clean way for us to migrate your old lang data.");
Expand Down Expand Up @@ -494,6 +506,9 @@ public String getNameIfPlayer(String potentialUUID) {
public boolean isBlockedMaterial(Material mat) {
return blockedMats.contains(mat);
}
public boolean isBlockedName(String name) {
return blockedNames.contains(name);
}

/**
* Tries to grab the server version as a string.
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/drtshock/playervaults/config/file/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ public List<String> getList() {
}
return Collections.unmodifiableList(list);
}

@Comment("Exact item names for blocked items, only effective if the feature is enabled.\n" +
" Useful for blocking custom items based on item name.")
private List<String> names = new ArrayList<String>() {
{
this.add("Named item to be blocked");
}
};

public List<String> getNames() {
if (this.names == null) {
this.names = new ArrayList<>();
}
return Collections.unmodifiableList(names);
}
}

public class Economy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ private static class Translations {
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 blockedItemName = TL.of("<gold>{name}</gold> <error>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.");
}
Expand Down Expand Up @@ -350,6 +351,10 @@ public Translation(@NonNull PlayerVaults plugin) {
return this.translations.blockedItem;
}

public @NonNull TL blockedItemName() {
return this.translations.blockedItemName;
}

public @NonNull TL signsDisabled() {
return this.translations.signsDisabled;
}
Expand Down
30 changes: 22 additions & 8 deletions src/main/java/com/drtshock/playervaults/listeners/Listeners.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,17 @@ public void onClick(InventoryClickEvent event) {
if (item == null) {
continue;
}
if (!player.hasPermission("playervaults.bypassblockeditems") && PlayerVaults.getInstance().isBlockedMaterial(item.getType())) {
event.setCancelled(true);
this.plugin.getTL().blockedItem().title().with("item", item.getType().name()).send(player);
return;
if (!player.hasPermission("playervaults.bypassblockeditems")) {
if (PlayerVaults.getInstance().isBlockedMaterial(item.getType())) {
event.setCancelled(true);
this.plugin.getTL().blockedItem().title().with("item", item.getType().name()).send(player);
return;
}
else if (PlayerVaults.getInstance().isBlockedName(item.getItemMeta().getDisplayName())) {
event.setCancelled(true);
this.plugin.getTL().blockedItemName().title().with("name", item.getItemMeta().getDisplayName()).send(player);
return;
}
}
}
}
Expand All @@ -160,10 +167,17 @@ public void onDrag(InventoryDragEvent event) {
String title = this.plugin.getVaultTitle(String.valueOf(num));
if ((inventoryTitle != null && inventoryTitle.equalsIgnoreCase(title)) && event.getNewItems() != null) {
for (ItemStack item : event.getNewItems().values()) {
if (!player.hasPermission("playervaults.bypassblockeditems") && PlayerVaults.getInstance().isBlockedMaterial(item.getType())) {
event.setCancelled(true);
this.plugin.getTL().blockedItem().title().with("item", item.getType().name()).send(player);
return;
if (!player.hasPermission("playervaults.bypassblockeditems")) {
if (PlayerVaults.getInstance().isBlockedMaterial(item.getType())) {
event.setCancelled(true);
this.plugin.getTL().blockedItem().title().with("item", item.getType().name()).send(player);
return;
}
else if (PlayerVaults.getInstance().isBlockedName(item.getItemMeta().getDisplayName())) {
event.setCancelled(true);
this.plugin.getTL().blockedItemName().title().with("name", item.getItemMeta().getDisplayName()).send(player);
return;
}
}
}
}
Expand Down