[1.15.2.b.3] - Skull Value, Item Cost, & more

This commit is contained in:
TheTealViper 2020-05-22 14:18:11 -07:00
parent df24c692d2
commit f4d723fd46
7 changed files with 494 additions and 54 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<projectDescription> <projectDescription>
<name>Spigot_EnderBank2</name> <name>Spigot_EnderBank</name>
<comment></comment> <comment></comment>
<projects> <projects>
</projects> </projects>

View File

@ -4,15 +4,34 @@
Default_Page_Price: 10 Default_Page_Price: 10
#This is how much the first bank page will cost #This is how much the first bank page will cost
Page_Price_Multiplier: 1 Page_Price_Multiplier: 1
#This is how much the bank page cost will be multiplied #This is how much the bank page cost will be multiplied
#by for every additional page. #by for every additional page.
Page_Price_Addition: 0 Page_Price_Addition: 0
#This is how much the bank page cost will be increased #This is how much the bank page cost will be increased
#by for every additional page. #by for every additional page.
Use_Item_For_Page_Price: false
#Enable this if you wish to use an item to purchase new pages.
#This does NOT replace cash but works WITH cash. Set cash to 0
#if you only want items for purchase
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.
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.
Must_Look_At_Chest_To_Search: true Must_Look_At_Chest_To_Search: true
#This makes it so players must be looking at an EnderChest #This makes it so players must be looking at an EnderChest
#to utilize the search feature, resulting in a "never left #to utilize the search feature, resulting in a "never left
@ -42,12 +61,65 @@ Open_Bank_Noise_Global: true
#This is a list of worlds that the plugin is disabled in. #This is a list of worlds that the plugin is disabled in.
#To enable this feature, simply uncomment it. #To enable this feature, simply uncomment it.
Disable_Dump_Into_Inventory: false
#Setting this to true disables use of the dump buttons.
Dump_Into_Inventory_Blacklist:
item1randomidentifier:
id: "COMPASS"
name: "&cServer Changer"
lore:
- "&rRight click to change servers!"
item2randomidentifier:
id: "STICK"
#Items on this blacklist will not automatically be carried over into EnderBanks upon clicking the
#dump into inventory buttons. Add server switching compasses, tutorial books, or anything else like that
#you see fit. PROBABLY REMOVE THE VANILLA STICK FROM IT.
##########################
###Syntax for each item###
##########################
#id: DIRT (Required)
#amount: 1 (Optional)
#name: "Dirt" (Optional)
#enchantments: (Optional)
# - "arrowdamage:1" (Optional)
# - "arrowfire:1" (Optional)
# - "arrowinfinite:1" (Optional)
# - "arrowknockback:1" (Optional)
# - "damage:1" (Optional)
# - "digspeed:1" (Optional)
# - "durability:1" (Optional)
# - "fireaspect:1" (Optional)
# - "knockback:1" (Optional)
# - "lootbonusblock:1" (Optional)
# - "lootbonusmob:1" (Optional)
# - "luck:1" (Optional)
# - "protectionfall:1" (Optional)
# - "protectionfire:1" (Optional)
# - "silktouch:1" (Optional)
#tags: (Optional)
# - "playerskullskin:SKINVALUE" (Optional)
# - "vanilladurability:256" (Optional)
# - "unbreakable:true" (Optional)
# - "custommodeldata:1234567" (Optional)
#flags: (Optional)
# - "HIDE_ATTRIBUTES" (Optional)
# - "HIDE_DESTROYS" (Optional)
# - "HIDE_ENCHANTS" (Optional)
# - "HIDE_PLACED_ON" (Optional)
# - "HIDE_POTION_EFFECTS" (Optional)
# - "HIDE_UNBREAKABLE" (Optional)
########################################################## ##########################################################
# GUI Items # # GUI Items #
########################################################## ##########################################################
#Syntax: #Syntax:
#%eb_pagecost% -> Cost of next page #%eb_pagecost% -> Cost of next page
#%eb_pagecostitemname% -> Name of item required for next page purchase
#%eb_pagecostitemamount% -> Amount of item required for next page purchase
GUI: GUI:
Next_Page: Next_Page:
@ -91,5 +163,5 @@ GUI:
# Version # # Version #
########################################################## ##########################################################
VERSION: 4 VERSION: 7
#Do not touch this. No touchy. #Do not touch this. No touchy.

View File

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

View File

@ -15,13 +15,17 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import me.TheTealViper.enderbank.utils.LoadItemstackFromConfig;
import me.TheTealViper.enderbank.utils.PluginFile; import me.TheTealViper.enderbank.utils.PluginFile;
import net.milkbowl.vault.economy.Economy;
public class BankStorage { public class BankStorage {
public static Map<UUID, BankStorage> bankDatabase = new HashMap<UUID, BankStorage>(); // This links players to THEIR own bank public static Map<UUID, BankStorage> bankDatabase = new HashMap<UUID, BankStorage>(); // This links players to THEIR own bank
public static Map<Player, BankStorage> openBankDatabase = new HashMap<Player, BankStorage>(); // This links players to the bank they are viewing public static Map<Player, BankStorage> openBankDatabase = new HashMap<Player, BankStorage>(); // This links players to the bank they are viewing
public static Map<Player, BankStorage> searchDatabase = new HashMap<Player, BankStorage>(); // This links players to the last bank they tried to search public static Map<Player, BankStorage> searchDatabase = new HashMap<Player, BankStorage>(); // This links players to the last bank they tried to search
public static EnderBank plugin; public static EnderBank plugin;
public static List<ItemStack> dumpBlacklistedItems = new ArrayList<ItemStack>();
public static Map<Integer, ItemStack> pagePriceItems = new HashMap<Integer, ItemStack>();
public List<ItemStack> items; public List<ItemStack> items;
public int unlockedPages; public int unlockedPages;
@ -31,6 +35,11 @@ public class BankStorage {
public List<Integer> itemIdentifiers; public List<Integer> itemIdentifiers;
public UUID bankOwnerUUID; public UUID bankOwnerUUID;
//Multiple people editing the same EnderBank at the same time should 100% corrupt the saves and lead to potential duplication methods.
//Don't do that.
//If you're reading this and not TheTealViper, now you know the secret.
//Staff are the only ones who could open an enderbank at the same time though so there would have to be a rat who helps players dupe.
public static void setup(EnderBank plugin) { public static void setup(EnderBank plugin) {
BankStorage.plugin = plugin; BankStorage.plugin = plugin;
} }
@ -191,7 +200,14 @@ public class BankStorage {
if(replaced) if(replaced)
continue; continue;
//First check for same items //First check for blacklist
for(ItemStack blacklistedItem : dumpBlacklistedItems) {
if(blacklistedItem.isSimilar(pItem)) {
return;
}
}
//Second check for same items
if(items.get(i).isSimilar(pItem)) { //If there is empty space in the bank if(items.get(i).isSimilar(pItem)) { //If there is empty space in the bank
ItemStack bItem = items.get(i); ItemStack bItem = items.get(i);
int bAmount = bItem.getAmount(); int bAmount = bItem.getAmount();
@ -223,6 +239,70 @@ public class BankStorage {
if(playerInvSlotNumber == 40 && pAmount == 0) if(playerInvSlotNumber == 40 && pAmount == 0)
opener.getInventory().setItemInOffHand(new ItemStack(Material.AIR)); opener.getInventory().setItemInOffHand(new ItemStack(Material.AIR));
} }
@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");
ItemStack itemRequiredForPay = new LoadItemstackFromConfig().getItem(sec);
int amountRequiredForPayment = itemRequiredForPay.getAmount();
int amountPlayerHas = 0;
//Check if player has enough of item
for(ItemStack i : opener.getInventory().getContents()) {
if(i != null && LoadItemstackFromConfig.isSimilar(i, itemRequiredForPay))
amountPlayerHas += i.getAmount();
}
if(amountPlayerHas < amountRequiredForPayment) {
opener.sendMessage(EnderBank.notificationString + " You don't have required items!");
return;
}
//Check balance of player if funds also involved
if(!econ.has(opener.getName(), BankStorage.getPageCost(unlockedPages + 1))) {
opener.sendMessage(EnderBank.notificationString + " You don't have enough money!");
return;
}
//Remove items from player
int amountToRemove = amountRequiredForPayment;
for(ItemStack i : opener.getInventory().getContents()) {
if(i != null && LoadItemstackFromConfig.isSimilar(i, itemRequiredForPay)){
if(amountToRemove > i.getAmount()) {
amountToRemove -= i.getAmount();
i.setAmount(0);
}else {
i.setAmount(i.getAmount() - amountToRemove);
amountToRemove = 0;
}
}
}
//Remove cash from player
econ.withdrawPlayer(opener.getName(), BankStorage.getPageCost(unlockedPages + 1));
//Close out of purchase state
EnderBank.pendingResponseDatabase.remove(opener);
unlockedPages = pf.getInt("unlockedPages") + 1;
savePage(lastOpenedPage, inv);
openPage(lastOpenedPage + 1, opener);
}else {
//Check balance of player if funds also involved
if(!econ.has(opener.getName(), BankStorage.getPageCost(unlockedPages + 1))) {
opener.sendMessage(EnderBank.notificationString + " You don't have enough money!");
return;
}
//Remove cash from player
econ.withdrawPlayer(opener.getName(), BankStorage.getPageCost(unlockedPages + 1));
//Close out of purchase state
EnderBank.pendingResponseDatabase.remove(opener);
unlockedPages = pf.getInt("unlockedPages") + 1;
savePage(lastOpenedPage, inv);
openPage(lastOpenedPage + 1, opener);
}
}
public void openSearch(String search, Player opener) { public void openSearch(String search, Player opener) {
//Load up inventory //Load up inventory

View File

@ -10,7 +10,7 @@ import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import me.TheTealViper.enderbank.utils.ItemCreator; import me.TheTealViper.enderbank.utils.LoadItemstackFromConfig;
public class CustomItemHandler implements Listener{ public class CustomItemHandler implements Listener{
@ -37,7 +37,7 @@ public class CustomItemHandler implements Listener{
static ItemStack NextPage = null; static ItemStack NextPage = null;
public static ItemStack GetNextPage(){ public static ItemStack GetNextPage(){
if(NextPage == null) { if(NextPage == null) {
NextPage = ItemCreator.createItemFromConfiguration(EnderBank.plugin.getConfig().getConfigurationSection("GUI.Next_Page")); NextPage = new LoadItemstackFromConfig().getItem(EnderBank.plugin.getConfig().getConfigurationSection("GUI.Next_Page"));
} }
return NextPage.clone(); return NextPage.clone();
} }
@ -45,7 +45,7 @@ public class CustomItemHandler implements Listener{
static ItemStack BuyNextPage = null; static ItemStack BuyNextPage = null;
public static ItemStack GetBuyNextPage(){ public static ItemStack GetBuyNextPage(){
if(BuyNextPage == null) { if(BuyNextPage == null) {
BuyNextPage = ItemCreator.createItemFromConfiguration(EnderBank.plugin.getConfig().getConfigurationSection("GUI.Buy_Next_Page")); BuyNextPage = new LoadItemstackFromConfig().getItem(EnderBank.plugin.getConfig().getConfigurationSection("GUI.Buy_Next_Page"));
} }
return BuyNextPage.clone(); return BuyNextPage.clone();
} }
@ -53,7 +53,7 @@ public class CustomItemHandler implements Listener{
static ItemStack ConfirmBuyNextPage = null; static ItemStack ConfirmBuyNextPage = null;
public static ItemStack GetConfirmBuyNextPage(){ public static ItemStack GetConfirmBuyNextPage(){
if(ConfirmBuyNextPage == null) { if(ConfirmBuyNextPage == null) {
ConfirmBuyNextPage = ItemCreator.createItemFromConfiguration(EnderBank.plugin.getConfig().getConfigurationSection("GUI.Confirm_Buy_Next_Page")); ConfirmBuyNextPage = new LoadItemstackFromConfig().getItem(EnderBank.plugin.getConfig().getConfigurationSection("GUI.Confirm_Buy_Next_Page"));
} }
return ConfirmBuyNextPage.clone(); return ConfirmBuyNextPage.clone();
} }
@ -61,7 +61,7 @@ public class CustomItemHandler implements Listener{
static ItemStack PreviousPage = null; static ItemStack PreviousPage = null;
public static ItemStack GetPreviousPage(){ public static ItemStack GetPreviousPage(){
if(PreviousPage == null) { if(PreviousPage == null) {
PreviousPage = ItemCreator.createItemFromConfiguration(EnderBank.plugin.getConfig().getConfigurationSection("GUI.Previous_Page")); PreviousPage = new LoadItemstackFromConfig().getItem(EnderBank.plugin.getConfig().getConfigurationSection("GUI.Previous_Page"));
} }
return PreviousPage.clone(); return PreviousPage.clone();
} }
@ -69,7 +69,7 @@ public class CustomItemHandler implements Listener{
static ItemStack DumpEquipment = null; static ItemStack DumpEquipment = null;
public static ItemStack GetDumpEquipment(){ public static ItemStack GetDumpEquipment(){
if(DumpEquipment == null) { if(DumpEquipment == null) {
DumpEquipment = ItemCreator.createItemFromConfiguration(EnderBank.plugin.getConfig().getConfigurationSection("GUI.Dump_Equipment")); DumpEquipment = new LoadItemstackFromConfig().getItem(EnderBank.plugin.getConfig().getConfigurationSection("GUI.Dump_Equipment"));
} }
return DumpEquipment.clone(); return DumpEquipment.clone();
} }
@ -77,7 +77,7 @@ public class CustomItemHandler implements Listener{
static ItemStack DumpItems = null; static ItemStack DumpItems = null;
public static ItemStack GetDumpItems(){ public static ItemStack GetDumpItems(){
if(DumpItems == null) { if(DumpItems == null) {
DumpItems = ItemCreator.createItemFromConfiguration(EnderBank.plugin.getConfig().getConfigurationSection("GUI.Dump_Items")); DumpItems = new LoadItemstackFromConfig().getItem(EnderBank.plugin.getConfig().getConfigurationSection("GUI.Dump_Items"));
} }
return DumpItems.clone(); return DumpItems.clone();
} }
@ -85,7 +85,7 @@ public class CustomItemHandler implements Listener{
static ItemStack Search = null; static ItemStack Search = null;
public static ItemStack GetSearch(){ public static ItemStack GetSearch(){
if(Search == null) { if(Search == null) {
Search = ItemCreator.createItemFromConfiguration(EnderBank.plugin.getConfig().getConfigurationSection("GUI.Search")); Search = new LoadItemstackFromConfig().getItem(EnderBank.plugin.getConfig().getConfigurationSection("GUI.Search"));
} }
return Search.clone(); return Search.clone();
} }
@ -93,7 +93,7 @@ public class CustomItemHandler implements Listener{
static ItemStack Separator = null; static ItemStack Separator = null;
public static ItemStack GetSeparator(){ public static ItemStack GetSeparator(){
if(Separator == null) { if(Separator == null) {
Separator = ItemCreator.createItemFromConfiguration(EnderBank.plugin.getConfig().getConfigurationSection("GUI.Separator")); Separator = new LoadItemstackFromConfig().getItem(EnderBank.plugin.getConfig().getConfigurationSection("GUI.Separator"));
} }
return Separator.clone(); return Separator.clone();
} }
@ -102,8 +102,38 @@ public class CustomItemHandler implements Listener{
List<String> lore = item.hasItemMeta() && item.getItemMeta().hasLore() ? item.getItemMeta().getLore() : new ArrayList<String>(); List<String> lore = item.hasItemMeta() && item.getItemMeta().hasLore() ? item.getItemMeta().getLore() : new ArrayList<String>();
List<String> dummy = new ArrayList<String> (lore); List<String> dummy = new ArrayList<String> (lore);
BankStorage bank = BankStorage.getBank(uuid); BankStorage bank = BankStorage.getBank(uuid);
ItemStack pageCostItem = null;
for(int i = 0;i < dummy.size();i++) { for(int i = 0;i < dummy.size();i++) {
lore.set(i, dummy.get(i).replace("%eb_pagecost%", BankStorage.getPageCost(bank.unlockedPages + 1) + "")); String s = dummy.get(i);
while(s.contains("%eb_pagecost%"))
s = s.replace("%eb_pagecost%", BankStorage.getPageCost(bank.unlockedPages + 1) + "");
while(s.contains("%eb_pagecostitemname%")) {
if(pageCostItem == null) {
if(BankStorage.pagePriceItems.containsKey(bank.unlockedPages + 1)) {
pageCostItem = BankStorage.pagePriceItems.get(bank.unlockedPages + 1);
} else {
pageCostItem = BankStorage.pagePriceItems.get(0);
}
}
if(pageCostItem.hasItemMeta() && pageCostItem.getItemMeta().hasDisplayName())
s = s.replace("%eb_pagecostitemname%", pageCostItem.getItemMeta().getDisplayName());
else {
String type = pageCostItem.getType().toString();
type = type.replaceAll("_", " ");
type = type.substring(0, 1) + type.substring(1).toLowerCase();
s = s.replace("%eb_pagecostitemname%", type);
}
}
while(s.contains("%eb_pagecostitemamount%")) {
if(pageCostItem == null) {
if(BankStorage.pagePriceItems.containsKey(bank.unlockedPages + 1))
pageCostItem = BankStorage.pagePriceItems.get(bank.unlockedPages + 1);
else
pageCostItem = BankStorage.pagePriceItems.get(0);
}
s = s.replace("%eb_pagecostitemamount%", BankStorage.pagePriceItems.get(bank.unlockedPages + 1).getAmount() + "");
}
lore.set(i, s);
} }
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
meta.setLore(lore); meta.setLore(lore);

View File

@ -13,6 +13,7 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -25,10 +26,12 @@ import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import me.TheTealViper.enderbank.utils.EnableShit; import me.TheTealViper.enderbank.utils.EnableShit;
import me.TheTealViper.enderbank.utils.LoadItemstackFromConfig;
import me.TheTealViper.enderbank.utils.VersionType; import me.TheTealViper.enderbank.utils.VersionType;
import me.TheTealViper.enderbank.utils.ViperStringUtils; import me.TheTealViper.enderbank.utils.ViperStringUtils;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
@ -90,6 +93,23 @@ public class EnderBank extends JavaPlugin implements Listener {
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class); RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
if (rsp != null) if (rsp != null)
econ = rsp.getProvider(); econ = rsp.getProvider();
ConfigurationSection mainSec = getConfig().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(pageIdentifier.equalsIgnoreCase("default")) {
BankStorage.pagePriceItems.put(0, item);
}else {
BankStorage.pagePriceItems.put(Integer.valueOf(pageIdentifier), item);
}
}
}
} }
public void onDisable() { public void onDisable() {
@ -159,7 +179,6 @@ public class EnderBank extends JavaPlugin implements Listener {
getServer().getConsoleSender().sendMessage(ViperStringUtils.makeColors(s)); getServer().getConsoleSender().sendMessage(ViperStringUtils.makeColors(s));
} }
@SuppressWarnings("deprecation")
@EventHandler @EventHandler
public void onInventoryClick(InventoryClickEvent e) { public void onInventoryClick(InventoryClickEvent e) {
Player opener = (Player) e.getWhoClicked(); Player opener = (Player) e.getWhoClicked();
@ -177,16 +196,7 @@ public class EnderBank extends JavaPlugin implements Listener {
}else if(e.getSlot() == 8) { //next page }else if(e.getSlot() == 8) { //next page
e.setCancelled(true); e.setCancelled(true);
if(pendingResponseDatabase.containsKey(opener) && pendingResponseDatabase.get(opener).equals("buypage")) { //If responding to confirm purchase if(pendingResponseDatabase.containsKey(opener) && pendingResponseDatabase.get(opener).equals("buypage")) { //If responding to confirm purchase
//Confirm if have the funds bank.attemptToPurchasePage(econ, opener, e.getInventory());
if(econ.has(opener.getName(), BankStorage.getPageCost(bank.unlockedPages + 1))) {
econ.withdrawPlayer(opener.getName(), BankStorage.getPageCost(bank.unlockedPages + 1));
pendingResponseDatabase.remove(opener);
bank.unlockedPages = bank.pf.getInt("unlockedPages") + 1;
bank.savePage(bank.lastOpenedPage, e.getInventory());
bank.openPage(bank.lastOpenedPage + 1, opener);
}else {
opener.sendMessage(EnderBank.notificationString + " You don't have enough money!");
}
}else if(bank.lastOpenedPage == bank.unlockedPages) { //If clicking buy ask to confirm }else if(bank.lastOpenedPage == bank.unlockedPages) { //If clicking buy ask to confirm
e.getInventory().setItem(8, CustomItemHandler.GetConfirmBuyNextPage().clone()); e.getInventory().setItem(8, CustomItemHandler.GetConfirmBuyNextPage().clone());
pendingResponseDatabase.put(opener, "buypage"); pendingResponseDatabase.put(opener, "buypage");
@ -205,35 +215,15 @@ public class EnderBank extends JavaPlugin implements Listener {
} }
}else if(e.getSlot() == 26) { }else if(e.getSlot() == 26) {
e.setCancelled(true); e.setCancelled(true);
}else if(e.getSlot() == 35) { }else if(e.getSlot() == 35) { //Dump equipment
e.setCancelled(true); e.setCancelled(true);
bank.savePage(bank.lastOpenedPage, e.getInventory());
for(int j = 9;j < 13;j++) { if(getConfig().getBoolean("Disable_Dump_Into_Inventory")) {
if(opener.getInventory().getItem(j) != null) { e.getWhoClicked().sendMessage(EnderBank.notificationString + " The server has disabled this feature!");
//Check if rune filler return;
// boolean currentIsTome = false;
// if(!p.getInventory().getItem(j).getType().toString().equals("AIR")) {
// if(p.getInventory().getItem(j).hasItemMeta()) {
// if(p.getInventory().getItem(j).getItemMeta().hasDisplayName()) {
// if(p.getInventory().getItem(j).getItemMeta().getDisplayName().contains("Tome")) {
// currentIsTome = true;
// }else {
//
// }
// }else {
//
// }
// }else {
//
// }
// }
//
// if(currentIsTome) {
// bank.attemptToAddToBank(j);
// p.getInventory().setItem(j, CustomItemHandler.GetRelicFiller());
// }
}
} }
bank.savePage(bank.lastOpenedPage, e.getInventory());
for(int j = 36;j < 40;j++) { for(int j = 36;j < 40;j++) {
if(opener.getInventory().getItem(j) != null) { if(opener.getInventory().getItem(j) != null) {
bank.attemptToAddToBank(j, opener); bank.attemptToAddToBank(j, opener);
@ -242,6 +232,12 @@ public class EnderBank extends JavaPlugin implements Listener {
bank.openPage(bank.lastOpenedPage, opener); bank.openPage(bank.lastOpenedPage, opener);
}else if(e.getSlot() == 44) { //Dump all items }else if(e.getSlot() == 44) { //Dump all items
e.setCancelled(true); e.setCancelled(true);
if(getConfig().getBoolean("Disable_Dump_Into_Inventory")) {
e.getWhoClicked().sendMessage(EnderBank.notificationString + " The server has disabled this feature!");
return;
}
bank.savePage(bank.lastOpenedPage, e.getInventory()); bank.savePage(bank.lastOpenedPage, e.getInventory());
if(e.getAction().equals(InventoryAction.PICKUP_ALL)) { //Encluding hotbar if(e.getAction().equals(InventoryAction.PICKUP_ALL)) { //Encluding hotbar
for(int j = 9;j < 36;j++) { for(int j = 9;j < 36;j++) {

View File

@ -0,0 +1,262 @@
package me.TheTealViper.enderbank.utils;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.craftbukkit.libs.org.apache.commons.codec.binary.Base64;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
public class LoadItemstackFromConfig {
/**
* id: DIRT
* amount: 1
* name: "Dirt"
* enchantments:
* - "arrowdamage:1"
* - "arrowfire:1"
* - "arrowinfinite:1"
* - "arrowknockback:1"
* - "damage:1"
* - "digspeed:1"
* - "durability:1"
* - "fireaspect:1"
* - "knockback:1"
* - "lootbonusblock:1"
* - "lootbonusmob:1"
* - "luck:1"
* - "protectionfall:1"
* - "protectionfire:1"
* - "silktouch:1"
* tags:
* - "playerskullskin:SKINVALUE" //Do note that skulls will NOT stack properly or be considered "similar" because different UUID. Use Enhanced for UUID tracking.
* - "vanilladurability:256"
* - "unbreakable:true"
* - "custommodeldata:1234567"
* flags:
* - "HIDE_ATTRIBUTES"
* - "HIDE_DESTROYS"
* - "HIDE_ENCHANTS"
* - "HIDE_PLACED_ON"
* - "HIDE_POTION_EFFECTS"
* - "HIDE_UNBREAKABLE"
*/
public LoadItemstackFromConfig(){
}
public ItemStack getItem(ConfigurationSection sec) {
//Null check
if(sec == null)
return null;
ItemStack item = null;
boolean modifiedMetaSoApply = false;
//Handle ID
item = (sec == null || !sec.contains("id")) ? null : new ItemStack(Material.getMaterial(sec.getString("id")));
//Initiate Meta
ItemMeta meta = item.getItemMeta();
//Handle amount
if(sec.contains("amount")) item.setAmount(sec.getInt("amount"));
//Handle name
if(sec.contains("name")) {meta.setDisplayName(ViperStringUtils.makeColors(sec.getString("name"))); modifiedMetaSoApply = true;}
//Handle lore
if(sec.contains("lore")) {
List<String> dummy = sec.getStringList("lore");
List<String> lore = new ArrayList<String>();
for(String s : dummy) {
lore.add(ViperStringUtils.makeColors(s));
}
meta.setLore(lore);
modifiedMetaSoApply = true;
}
//Handle enchantments
if(sec.contains("enchantments")) {
List<String> enchantmentStrings = sec.getStringList("enchantments");
for(String enchantmentString : enchantmentStrings) {
String enchantmentName = enchantmentString.split(":")[0];
int enchantmentLevel = Integer.valueOf(enchantmentString.split(":")[1]);
switch(enchantmentName) {
case "arrowdamage":
meta.addEnchant(Enchantment.ARROW_DAMAGE, enchantmentLevel, true);
break;
case "arrowfire":
meta.addEnchant(Enchantment.ARROW_FIRE, enchantmentLevel, true);
break;
case "arrowinfinite":
meta.addEnchant(Enchantment.ARROW_INFINITE, enchantmentLevel, true);
break;
case "arrowknockback":
meta.addEnchant(Enchantment.ARROW_KNOCKBACK, enchantmentLevel, true);
break;
case "damage":
meta.addEnchant(Enchantment.DAMAGE_ALL, enchantmentLevel, true);
break;
case "digspeed":
meta.addEnchant(Enchantment.DIG_SPEED, enchantmentLevel, true);
break;
case "durability":
meta.addEnchant(Enchantment.DURABILITY, enchantmentLevel, true);
break;
case "fireaspect":
meta.addEnchant(Enchantment.FIRE_ASPECT, enchantmentLevel, true);
break;
case "knockback":
meta.addEnchant(Enchantment.KNOCKBACK, enchantmentLevel, true);
break;
case "lootbonusblock":
meta.addEnchant(Enchantment.LOOT_BONUS_BLOCKS, enchantmentLevel, true);
break;
case "lootbonusmob":
meta.addEnchant(Enchantment.LOOT_BONUS_MOBS, enchantmentLevel, true);
break;
case "luck":
meta.addEnchant(Enchantment.LUCK, enchantmentLevel, true);
break;
case "protectionfall":
meta.addEnchant(Enchantment.PROTECTION_FALL, enchantmentLevel, true);
break;
case "protectionfire":
meta.addEnchant(Enchantment.PROTECTION_FALL, enchantmentLevel, true);
break;
case "silktouch":
meta.addEnchant(Enchantment.SILK_TOUCH, enchantmentLevel, true);
break;
}
}
modifiedMetaSoApply = true;
}
//Handle vanilla tags
if(sec.contains("tags")) {
for(String tagString : sec.getStringList("tags")) {
String[] tagStringProcessed = tagString.split(":");
String tag = tagStringProcessed[0];
String value = tagStringProcessed[1];
switch(tag) {
case "playerskullskin":
JsonParser parser = new JsonParser();
JsonObject o = parser.parse(new String(Base64.decodeBase64(value))).getAsJsonObject();
String skinUrl = o.get("textures").getAsJsonObject().get("SKIN").getAsJsonObject().get("url").getAsString();
SkullMeta skullMeta = (SkullMeta) meta;
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
byte[] encodedData = Base64.encodeBase64(("{textures:{SKIN:{url:\"" + skinUrl + "\"}}}").getBytes());
profile.getProperties().put("textures", new Property("textures", new String(encodedData)));
Field profileField = null;
try {
profileField = skullMeta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(skullMeta, profile);
} catch (Exception e) {
e.printStackTrace();
}
meta = skullMeta;
break;
case "vanilladurability":
Bukkit.broadcastMessage("changing durability: " + value);
Damageable dam = (Damageable) meta;
dam.setDamage(Integer.valueOf(value));
meta = (ItemMeta) dam;
break;
case "unbreakable":
meta.setUnbreakable(Boolean.valueOf(value));
break;
case "custommodeldata":
meta.setCustomModelData(Integer.valueOf(value));
break;
}
}
modifiedMetaSoApply = true;
}
//Handle vanilla flags
if(sec.contains("flags")){
for(String s : sec.getStringList("flags")){
meta.addItemFlags(ItemFlag.valueOf(s));
}
modifiedMetaSoApply = true;
}
if(modifiedMetaSoApply) item.setItemMeta(meta);
return item;
}
public static boolean isSimilar(ItemStack item1, ItemStack item2) {
if(item2.getType() != item1.getType())
return false;
if(item2.hasItemMeta() != item1.hasItemMeta())
return false;
if(item2.hasItemMeta()) {
ItemMeta item1Meta = item1.getItemMeta();
ItemMeta item2Meta = item2.getItemMeta();
if (item2Meta.hasDisplayName() != item1Meta.hasDisplayName())
return false;
if(item2Meta.hasDisplayName()) {
if(!item2Meta.getDisplayName().equals(item1Meta.getDisplayName()))
return false;
}
if (item2Meta.hasLore() != item1Meta.hasLore())
return false;
if (item2Meta.hasLore()) {
for(int i = 0;i < item2Meta.getLore().size();i++) {
if(!item2Meta.getLore().get(i).equals(item1Meta.getLore().get(i)))
return false;
}
}
if (item2Meta.hasEnchants() != item1Meta.hasEnchants())
return false;
if (item2Meta.hasEnchants()) {
if (item2Meta.getEnchants().size() != item1Meta.getEnchants().size()) {
return false;
}
for (Entry<Enchantment, Integer> enchantInfo : item1Meta.getEnchants().entrySet()) {
if (item2Meta.getEnchantLevel(enchantInfo.getKey()) != item1Meta.getEnchantLevel(enchantInfo.getKey())) {
return false;
}
}
}
if (item2Meta.getItemFlags().size() != item1Meta.getItemFlags().size())
return false;
for (ItemFlag flag : item2Meta.getItemFlags()) { //We can do this because we already know the itemflag list size is the same
if (!item1Meta.hasItemFlag(flag)) {
return false;
}
}
if((item2Meta instanceof Damageable) != (item1Meta instanceof Damageable))
return false;
if(item2Meta instanceof Damageable) {
Damageable dam1 = (Damageable) item1Meta;
Damageable dam2 = (Damageable) item2Meta;
if(dam1.hasDamage() != dam2.hasDamage())
return false;
if(dam2.hasDamage()) {
if(dam2.getDamage() != dam1.getDamage())
return false;
}
}
}
return true;
}
}