[1.15.2.b.4] Override default config.yml values + bug fix

This commit is contained in:
TheTealViper 2020-05-24 12:34:08 -07:00
parent f4d723fd46
commit 3604393208
8 changed files with 61 additions and 103 deletions

View File

@ -20,17 +20,17 @@ Page_Price_Items:
2:
id: "STICK"
amount: 2
#This item "2" is the item required for the second page (first unlocked). Same goes for other pages.
#This item "2" is the item required for the second page (first unlocked). Same goes for other pages.
Default:
id: "EMERALD"
name: "&r&cEnderBank Storage Upgrade"
amount: 1
lore:
- "&r&7Use me to upgrade your EnderBank page count!"
#This default item is the one that will be looked for if a specific page doesn't
#have an item like how page 1 does above.
#If you wish to cap the EnderBank page counts, simply put specific items for all
#the pages you wish to include, and then make the default item something unobtainable.
#This default item is the one that will be looked for if a specific page doesn't
#have an item like how page 1 does above.
#If you wish to cap the EnderBank page counts, simply put specific items for all
#the pages you wish to include, and then make the default item something unobtainable.
Must_Look_At_Chest_To_Search: true
#This makes it so players must be looking at an EnderChest
@ -77,7 +77,7 @@ Dump_Into_Inventory_Blacklist:
#you see fit. PROBABLY REMOVE THE VANILLA STICK FROM IT.
##########################
###Syntax for each item###
###Item Building Syntax###
##########################
#id: DIRT (Required)

View File

@ -1,6 +1,6 @@
name: "EnderBank"
author: TheTealViper
version: "1.15.2.b.3"
version: "1.15.2.b.4"
api-version: 1.13
description: "Bank system from popular RPG's."
main: me.TheTealViper.enderbank.EnderBank

View File

@ -52,7 +52,7 @@ public class BankStorage {
}
public static boolean hasBank(UUID bankOwner) {
PluginFile pf = new PluginFile(plugin, "banks/banks." + bankOwner.toString() + ".yml");
PluginFile pf = new PluginFile(plugin, "banks/banks." + bankOwner.toString() + ".yml", true);
if(pf.contains("unlockedPages"))
return true;
else
@ -63,7 +63,7 @@ public class BankStorage {
//This should be run the first time the player tries opening their ender inv
//and the enderbank is created.
public static void initiateBank(Player p) {
PluginFile pf = new PluginFile(plugin, "banks/banks." + p.getUniqueId().toString() + ".yml");
PluginFile pf = new PluginFile(plugin, "banks/banks." + p.getUniqueId().toString() + ".yml", true);
//Set default items
for(int i = 0;i < 42;i++) {
@ -87,7 +87,7 @@ public class BankStorage {
public BankStorage(UUID bankOwnerUUID) {
bankDatabase.put(bankOwnerUUID, this);
this.bankOwnerUUID = bankOwnerUUID;
pf = new PluginFile(plugin, "banks/banks." + bankOwnerUUID.toString() + ".yml");
pf = new PluginFile(plugin, "banks/banks." + bankOwnerUUID.toString() + ".yml", true);
//Load in items
items = new ArrayList<ItemStack>();
@ -101,11 +101,11 @@ public class BankStorage {
}
public void openPage(int page, Player opener) {
if(page == 1 && EnderBank.plugin.getConfig().getBoolean("Enable_Open_Bank_Noise")) {
if(EnderBank.plugin.getConfig().getBoolean("Open_Bank_Noise_Global")) {
opener.getWorld().playSound(opener.getLocation(), Sound.valueOf(EnderBank.plugin.getConfig().getString("Open_Bank_Noise")), 1, 1);
if(page == 1 && EnderBank.pf.getBoolean("Enable_Open_Bank_Noise")) {
if(EnderBank.pf.getBoolean("Open_Bank_Noise_Global")) {
opener.getWorld().playSound(opener.getLocation(), Sound.valueOf(EnderBank.pf.getString("Open_Bank_Noise")), 1, 1);
}else {
opener.playSound(opener.getLocation(), Sound.valueOf(EnderBank.plugin.getConfig().getString("Open_Bank_Noise")), 1, 1);
opener.playSound(opener.getLocation(), Sound.valueOf(EnderBank.pf.getString("Open_Bank_Noise")), 1, 1);
}
}
@ -183,9 +183,9 @@ public class BankStorage {
}
public static int getPageCost(int page) {
int starter = plugin.getConfig().getInt("Default_Page_Price");
double multiplier = plugin.getConfig().getDouble("Page_Price_Multiplier");
int addition = plugin.getConfig().getInt("Page_Price_Addition");
int starter = EnderBank.pf.getInt("Default_Page_Price");
double multiplier = EnderBank.pf.getDouble("Page_Price_Multiplier");
int addition = EnderBank.pf.getInt("Page_Price_Addition");
int partOne = (int) (starter * Math.pow(multiplier, page - 2));
int price = partOne + (addition * (page - 2));
return price;
@ -242,8 +242,8 @@ public class BankStorage {
@SuppressWarnings("deprecation")
public void attemptToPurchasePage(Economy econ, Player opener, Inventory inv) {
if(plugin.getConfig().getBoolean("Use_Item_For_Page_Price")) {
ConfigurationSection sec = plugin.getConfig().contains("Page_Price_Items." + (lastOpenedPage+1)) ? plugin.getConfig().getConfigurationSection("Page_Price_Items." + (lastOpenedPage+1)) : plugin.getConfig().getConfigurationSection("Page_Price_Items.Default");
if(EnderBank.pf.getBoolean("Use_Item_For_Page_Price")) {
ConfigurationSection sec = EnderBank.pf.contains("Page_Price_Items." + (lastOpenedPage+1)) ? EnderBank.pf.getConfigurationSection("Page_Price_Items." + (lastOpenedPage+1)) : EnderBank.pf.getConfigurationSection("Page_Price_Items.Default");
ItemStack itemRequiredForPay = new LoadItemstackFromConfig().getItem(sec);
int amountRequiredForPayment = itemRequiredForPay.getAmount();
int amountPlayerHas = 0;

View File

@ -37,7 +37,7 @@ public class CustomItemHandler implements Listener{
static ItemStack NextPage = null;
public static ItemStack GetNextPage(){
if(NextPage == null) {
NextPage = new LoadItemstackFromConfig().getItem(EnderBank.plugin.getConfig().getConfigurationSection("GUI.Next_Page"));
NextPage = new LoadItemstackFromConfig().getItem(EnderBank.pf.getConfigurationSection("GUI.Next_Page"));
}
return NextPage.clone();
}
@ -45,7 +45,7 @@ public class CustomItemHandler implements Listener{
static ItemStack BuyNextPage = null;
public static ItemStack GetBuyNextPage(){
if(BuyNextPage == null) {
BuyNextPage = new LoadItemstackFromConfig().getItem(EnderBank.plugin.getConfig().getConfigurationSection("GUI.Buy_Next_Page"));
BuyNextPage = new LoadItemstackFromConfig().getItem(EnderBank.pf.getConfigurationSection("GUI.Buy_Next_Page"));
}
return BuyNextPage.clone();
}
@ -53,7 +53,7 @@ public class CustomItemHandler implements Listener{
static ItemStack ConfirmBuyNextPage = null;
public static ItemStack GetConfirmBuyNextPage(){
if(ConfirmBuyNextPage == null) {
ConfirmBuyNextPage = new LoadItemstackFromConfig().getItem(EnderBank.plugin.getConfig().getConfigurationSection("GUI.Confirm_Buy_Next_Page"));
ConfirmBuyNextPage = new LoadItemstackFromConfig().getItem(EnderBank.pf.getConfigurationSection("GUI.Confirm_Buy_Next_Page"));
}
return ConfirmBuyNextPage.clone();
}
@ -61,7 +61,7 @@ public class CustomItemHandler implements Listener{
static ItemStack PreviousPage = null;
public static ItemStack GetPreviousPage(){
if(PreviousPage == null) {
PreviousPage = new LoadItemstackFromConfig().getItem(EnderBank.plugin.getConfig().getConfigurationSection("GUI.Previous_Page"));
PreviousPage = new LoadItemstackFromConfig().getItem(EnderBank.pf.getConfigurationSection("GUI.Previous_Page"));
}
return PreviousPage.clone();
}
@ -69,7 +69,7 @@ public class CustomItemHandler implements Listener{
static ItemStack DumpEquipment = null;
public static ItemStack GetDumpEquipment(){
if(DumpEquipment == null) {
DumpEquipment = new LoadItemstackFromConfig().getItem(EnderBank.plugin.getConfig().getConfigurationSection("GUI.Dump_Equipment"));
DumpEquipment = new LoadItemstackFromConfig().getItem(EnderBank.pf.getConfigurationSection("GUI.Dump_Equipment"));
}
return DumpEquipment.clone();
}
@ -77,7 +77,7 @@ public class CustomItemHandler implements Listener{
static ItemStack DumpItems = null;
public static ItemStack GetDumpItems(){
if(DumpItems == null) {
DumpItems = new LoadItemstackFromConfig().getItem(EnderBank.plugin.getConfig().getConfigurationSection("GUI.Dump_Items"));
DumpItems = new LoadItemstackFromConfig().getItem(EnderBank.pf.getConfigurationSection("GUI.Dump_Items"));
}
return DumpItems.clone();
}
@ -85,7 +85,7 @@ public class CustomItemHandler implements Listener{
static ItemStack Search = null;
public static ItemStack GetSearch(){
if(Search == null) {
Search = new LoadItemstackFromConfig().getItem(EnderBank.plugin.getConfig().getConfigurationSection("GUI.Search"));
Search = new LoadItemstackFromConfig().getItem(EnderBank.pf.getConfigurationSection("GUI.Search"));
}
return Search.clone();
}
@ -93,7 +93,7 @@ public class CustomItemHandler implements Listener{
static ItemStack Separator = null;
public static ItemStack GetSeparator(){
if(Separator == null) {
Separator = new LoadItemstackFromConfig().getItem(EnderBank.plugin.getConfig().getConfigurationSection("GUI.Separator"));
Separator = new LoadItemstackFromConfig().getItem(EnderBank.pf.getConfigurationSection("GUI.Separator"));
}
return Separator.clone();
}
@ -115,8 +115,9 @@ public class CustomItemHandler implements Listener{
pageCostItem = BankStorage.pagePriceItems.get(0);
}
}
if(pageCostItem.hasItemMeta() && pageCostItem.getItemMeta().hasDisplayName())
if(pageCostItem.hasItemMeta() && pageCostItem.getItemMeta().hasDisplayName()) {
s = s.replace("%eb_pagecostitemname%", pageCostItem.getItemMeta().getDisplayName());
}
else {
String type = pageCostItem.getType().toString();
type = type.replaceAll("_", " ");
@ -126,12 +127,13 @@ public class CustomItemHandler implements Listener{
}
while(s.contains("%eb_pagecostitemamount%")) {
if(pageCostItem == null) {
if(BankStorage.pagePriceItems.containsKey(bank.unlockedPages + 1))
if(BankStorage.pagePriceItems.containsKey(bank.unlockedPages + 1)) {
pageCostItem = BankStorage.pagePriceItems.get(bank.unlockedPages + 1);
else
} else {
pageCostItem = BankStorage.pagePriceItems.get(0);
}
}
s = s.replace("%eb_pagecostitemamount%", BankStorage.pagePriceItems.get(bank.unlockedPages + 1).getAmount() + "");
s = s.replace("%eb_pagecostitemamount%", pageCostItem.getAmount() + "");
}
lore.set(i, s);
}

View File

@ -32,6 +32,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import me.TheTealViper.enderbank.utils.EnableShit;
import me.TheTealViper.enderbank.utils.LoadItemstackFromConfig;
import me.TheTealViper.enderbank.utils.PluginFile;
import me.TheTealViper.enderbank.utils.VersionType;
import me.TheTealViper.enderbank.utils.ViperStringUtils;
import net.milkbowl.vault.economy.Economy;
@ -43,6 +44,7 @@ public class EnderBank extends JavaPlugin implements Listener {
public static String notificationString = ChatColor.BOLD + "[" + ChatColor.AQUA + ChatColor.BOLD + "!" + ChatColor.WHITE + ChatColor.BOLD + "]" + ChatColor.RESET
, questionString = ChatColor.BOLD + "[" + ChatColor.AQUA + ChatColor.BOLD + "?" + ChatColor.WHITE + ChatColor.BOLD + "]" + ChatColor.RESET;
private List<String> disabledWorlds;
public static PluginFile pf;
//Chat Queue (for asking which tracker you'd like to add)
public static Map<Player, List<String>> chatHandlerQueue = new HashMap<Player, List<String>>();
@ -66,6 +68,7 @@ public class EnderBank extends JavaPlugin implements Listener {
//Load values from config
saveDefaultConfig();
pf = new PluginFile(this, "config.yml", "f.yml", false);
//Set initial values
equipmentTypes.add(Material.CHAINMAIL_BOOTS);
@ -88,21 +91,21 @@ public class EnderBank extends JavaPlugin implements Listener {
equipmentTypes.add(Material.DIAMOND_CHESTPLATE);
equipmentTypes.add(Material.DIAMOND_HELMET);
equipmentTypes.add(Material.DIAMOND_LEGGINGS);
disabledWorlds = getConfig().contains("Disabled_Worlds") ? getConfig().getStringList("Disabled_Worlds") : new ArrayList<String>();
disabledWorlds = pf.contains("Disabled_Worlds") ? pf.getStringList("Disabled_Worlds") : new ArrayList<String>();
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
if (rsp != null)
econ = rsp.getProvider();
ConfigurationSection mainSec = getConfig().getConfigurationSection("Dump_Into_Inventory_Blacklist");
ConfigurationSection mainSec = pf.getConfigurationSection("Dump_Into_Inventory_Blacklist");
for(String itemIdentifier : mainSec.getKeys(false)) {
ItemStack item = new LoadItemstackFromConfig().getItem(mainSec.getConfigurationSection(itemIdentifier));
BankStorage.dumpBlacklistedItems.add(item);
}
if(getConfig().getBoolean("Use_Item_For_Page_Price")) {
for(String pageIdentifier : getConfig().getConfigurationSection("Page_Price_Items").getKeys(false)) {
ItemStack item = new LoadItemstackFromConfig().getItem(getConfig().getConfigurationSection("Page_Price_Items." + pageIdentifier));
if(pf.getBoolean("Use_Item_For_Page_Price")) {
for(String pageIdentifier : pf.getConfigurationSection("Page_Price_Items").getKeys(false)) {
ItemStack item = new LoadItemstackFromConfig().getItem(pf.getConfigurationSection("Page_Price_Items." + pageIdentifier));
if(pageIdentifier.equalsIgnoreCase("default")) {
BankStorage.pagePriceItems.put(0, item);
}else {
@ -218,7 +221,7 @@ public class EnderBank extends JavaPlugin implements Listener {
}else if(e.getSlot() == 35) { //Dump equipment
e.setCancelled(true);
if(getConfig().getBoolean("Disable_Dump_Into_Inventory")) {
if(pf.getBoolean("Disable_Dump_Into_Inventory")) {
e.getWhoClicked().sendMessage(EnderBank.notificationString + " The server has disabled this feature!");
return;
}
@ -233,7 +236,7 @@ public class EnderBank extends JavaPlugin implements Listener {
}else if(e.getSlot() == 44) { //Dump all items
e.setCancelled(true);
if(getConfig().getBoolean("Disable_Dump_Into_Inventory")) {
if(pf.getBoolean("Disable_Dump_Into_Inventory")) {
e.getWhoClicked().sendMessage(EnderBank.notificationString + " The server has disabled this feature!");
return;
}
@ -334,6 +337,16 @@ public class EnderBank extends JavaPlugin implements Listener {
@EventHandler
public void onChat(AsyncPlayerChatEvent e) {
Player p = e.getPlayer();
//DEBUG
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {public void run() {
Map<Integer, ItemStack> dummy = new HashMap<Integer, ItemStack>(BankStorage.pagePriceItems);
for(int pageID : dummy.keySet()) {
Bukkit.broadcastMessage(pageID + " : " + BankStorage.pagePriceItems.get(pageID));
}
p.getWorld().dropItem(p.getLocation(), BankStorage.pagePriceItems.get(2));
Bukkit.broadcastMessage(pf.getStringList("Page_Price_Items.Default.lore").get(0));
}}, 1);
//
if(!chatHandlerQueue.containsKey(p))
return;
List<String> queue = chatHandlerQueue.get(p);
@ -350,7 +363,7 @@ public class EnderBank extends JavaPlugin implements Listener {
queue.remove(queue.size() - 1);
e.setCancelled(true);
Block b = p.getTargetBlock(null, 10);
if(!getConfig().getBoolean("Must_Look_At_Chest_To_Search") || b.getType().equals(Material.ENDER_CHEST)) {
if(!pf.getBoolean("Must_Look_At_Chest_To_Search") || b.getType().equals(Material.ENDER_CHEST)) {
String search = e.getMessage();
BankStorage bank = BankStorage.searchDatabase.get(p);
bank.openSearch(search, p);

View File

@ -1,54 +0,0 @@
package me.TheTealViper.enderbank.utils;
import java.lang.reflect.Field;
import java.util.UUID;
import org.bukkit.craftbukkit.libs.org.apache.commons.codec.binary.Base64;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
public class Base64Skull {
// public static ItemStack getSkull(String base64) {
// ItemStack item = new ItemStack(Material.PLAYER_HEAD);
// SkullMeta meta = (SkullMeta) item.getItemMeta();
//
// GameProfile profile = new GameProfile(UUID.randomUUID(), "");
// profile.getProperties().put("textures", new Property("textures", base64));
// Field profileField = null;
// try {
// profileField = meta.getClass().getDeclaredField("profile");
// profileField.setAccessible(true);
// profileField.set(meta, profile);
// } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
// e.printStackTrace();
// }
//
// item.setItemMeta(meta);
// return item;
// }
public static ItemStack getSkull(ItemStack head, String uuid, String url) {
if(url == null)return head;
if(url.isEmpty())return head;
SkullMeta headMeta = (SkullMeta) head.getItemMeta();
GameProfile profile = new GameProfile(UUID.fromString(uuid), null);
byte[] encodedData = Base64.encodeBase64(String.format("{textures:{SKIN:{url:\"%s\"}}}", url).getBytes());
profile.getProperties().put("textures", new Property("textures", new String(encodedData)));
Field profileField = null;
try {
profileField = headMeta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(headMeta, profile);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e1) {
e1.printStackTrace();
}
head.setItemMeta(headMeta);
return head;
}
}

View File

@ -11,17 +11,18 @@ import org.bukkit.plugin.java.JavaPlugin;
public class PluginFile extends YamlConfiguration {
private File file;
private File file;
private String defaults;
private JavaPlugin plugin;
private boolean saveDefaults;
/**
* Creates new PluginFile, without defaults
* @param plugin - Your plugin
* @param fileName - Name of the file
*/
public PluginFile(JavaPlugin plugin, String fileName) {
this(plugin, fileName, null);
public PluginFile(JavaPlugin plugin, String fileName, boolean saveDefaults) {
this(plugin, fileName, null, saveDefaults);
}
/**
@ -30,10 +31,11 @@ public class PluginFile extends YamlConfiguration {
* @param fileName - Name of the file
* @param defaultsName - Name of the defaults
*/
public PluginFile(JavaPlugin plugin, String fileName, String defaultsName) {
public PluginFile(JavaPlugin plugin, String fileName, String defaultsName, boolean saveDefaults) {
this.plugin = plugin;
this.defaults = defaultsName;
this.file = new File(plugin.getDataFolder(), fileName);
this.saveDefaults = saveDefaults;
reload();
}
@ -58,7 +60,7 @@ public class PluginFile extends YamlConfiguration {
try {
load(file);
if (defaults != null) {
if (defaults != null && saveDefaults) {
InputStreamReader reader = new InputStreamReader(plugin.getResource(defaults));
FileConfiguration defaultsConfig = YamlConfiguration.loadConfiguration(reader);

View File

@ -1,5 +0,0 @@
module Spigot_Trackers {
requires spigot;
requires HolographicDisplaysAPI;
requires Vault;
}