Add configurable blocked items list.
This commit is contained in:
@@ -27,6 +27,7 @@ import com.drtshock.playervaults.vaultmanagement.VaultViewInfo;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
@@ -38,6 +39,8 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class PlayerVaults extends JavaPlugin {
|
||||
@@ -55,21 +58,20 @@ public class PlayerVaults extends JavaPlugin {
|
||||
private YamlConfiguration signs;
|
||||
private File signsFile;
|
||||
private boolean saveQueued;
|
||||
private File configFile;
|
||||
private boolean backupsEnabled;
|
||||
private File backupsFolder = null;
|
||||
private File vaultData;
|
||||
private Set<Material> blockedMats = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
configFile = new File(getDataFolder(), "config.yml");
|
||||
loadConfig();
|
||||
vaultData = new File(this.getDataFolder(), "uuidvaults");
|
||||
getServer().getScheduler().runTask(this, new UUIDConversion()); // Convert to UUIDs first. Class checks if necessary.
|
||||
loadLang();
|
||||
new UUIDVaultManager();
|
||||
getServer().getPluginManager().registerEvents(new Listeners(this), this);
|
||||
loadConfig();
|
||||
this.backupsEnabled = this.getConfig().getBoolean("backups.enabled", true);
|
||||
loadSigns();
|
||||
checkUpdate();
|
||||
@@ -122,8 +124,9 @@ public class PlayerVaults extends JavaPlugin {
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String args[]) {
|
||||
if (cmd.getName().equals("pvreload")) {
|
||||
reloadConfig();
|
||||
loadConfig(); // To update blocked materials.
|
||||
loadLang();
|
||||
sender.sendMessage(ChatColor.GREEN + "Reloaded Playervaults confguration and lang files.");
|
||||
sender.sendMessage(ChatColor.GREEN + "Reloaded PlayerVaults' configuration and lang files.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -164,10 +167,18 @@ public class PlayerVaults extends JavaPlugin {
|
||||
}
|
||||
|
||||
private void loadConfig() {
|
||||
if (!configFile.exists()) {
|
||||
saveDefaultConfig();
|
||||
} else {
|
||||
updateConfig();
|
||||
saveDefaultConfig();
|
||||
|
||||
// Clear just in case this is a reload.
|
||||
blockedMats.clear();
|
||||
if (getConfig().getBoolean("blockitems", false) && getConfig().contains("blocked-items")) {
|
||||
for (String s : getConfig().getStringList("blocked-items")) {
|
||||
Material mat = Material.matchMaterial(s);
|
||||
if (mat != null) {
|
||||
blockedMats.add(mat);
|
||||
getLogger().log(Level.INFO, "Added {0} to list of blocked materials.", mat.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,32 +224,6 @@ public class PlayerVaults extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public void updateConfig() {
|
||||
boolean checkUpdate = getConfig().getBoolean("check-update", true);
|
||||
boolean ecoEnabled = getConfig().getBoolean("economy.enabled", false);
|
||||
int ecoCreate = getConfig().getInt("economy.cost-to-create", 100);
|
||||
int ecoOpen = getConfig().getInt("economy.cost-to-open", 10);
|
||||
int ecoDelete = getConfig().getInt("economy.refund-on-delete", 50);
|
||||
boolean dropEnabled = getConfig().getBoolean("drop-on-death.enabled", false);
|
||||
int dropInvs = getConfig().getInt("drop-on-death.inventories", 50);
|
||||
boolean backupsEnabled = getConfig().getBoolean("backups.enabled", true);
|
||||
configFile.delete();
|
||||
YamlConfiguration conf = YamlConfiguration.loadConfiguration(getResource("config.yml"));
|
||||
setInConfig("check-update", checkUpdate, conf);
|
||||
setInConfig("economy.enabled", ecoEnabled, conf);
|
||||
setInConfig("economy.cost-to-create", ecoCreate, conf);
|
||||
setInConfig("economy.cost-to-open", ecoOpen, conf);
|
||||
setInConfig("economy.refund-on-delete", ecoDelete, conf);
|
||||
setInConfig("drop-on-death.enabled", dropEnabled, conf);
|
||||
setInConfig("drop-on-death.inventories", dropInvs, conf);
|
||||
setInConfig("backups.enabled", backupsEnabled, conf);
|
||||
try {
|
||||
conf.save(configFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an object in the config.yml
|
||||
*
|
||||
@@ -357,6 +342,10 @@ public class PlayerVaults extends JavaPlugin {
|
||||
return this.backupsFolder;
|
||||
}
|
||||
|
||||
public boolean isBlockedMaterial(Material mat) {
|
||||
return blockedMats.contains(mat);
|
||||
}
|
||||
|
||||
public static PlayerVaults getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
@@ -227,4 +228,29 @@ public class Listeners implements Listener {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onClick(InventoryClickEvent event) {
|
||||
if (!(event.getWhoClicked() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (player.hasPermission("playervaults.bypassblockeditems")) {
|
||||
return;
|
||||
}
|
||||
|
||||
VaultViewInfo info = PlayerVaults.getInstance().getInVault().get(player.getUniqueId().toString());
|
||||
if (info != null) {
|
||||
int num = info.getNumber();
|
||||
String title = Lang.VAULT_TITLE.toString().replace("%number", String.valueOf(num)).replace("%p", info.getHolder());
|
||||
if ((event.getClickedInventory().getTitle().equalsIgnoreCase(title) || event.isShiftClick()) && event.getCurrentItem() != null) {
|
||||
if (PlayerVaults.getInstance().isBlockedMaterial(event.getCurrentItem().getType())) {
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.BLOCKED_ITEM.toString().replace("%m", event.getCurrentItem().getType().name()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,8 @@ public enum Lang {
|
||||
CONVERT_COMPLETE("conversion-complete", "&aConverted %converted players to PlayerVaults"),
|
||||
CONVERT_BACKGROUND("conversion-background", "&fConversion has been forked to the background. See console for updates."),
|
||||
LOCKED("vaults-locked", "&cVaults are currently locked while conversion occurs. Please try again in a moment!"),
|
||||
HELP("help", "/pv <number>");
|
||||
HELP("help", "/pv <number>"),
|
||||
BLOCKED_ITEM("blocked-item", "&6%m &cis blocked from vaults");
|
||||
|
||||
private String path;
|
||||
private String def;
|
||||
|
||||
Reference in New Issue
Block a user