Last active
April 30, 2017 20:39
-
-
Save TheMasteredPanda/0549d9ad66058e901f0772952150f606 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##DEconomy 1.0 made for Dungeons owned by Harry created by TheMasteredPanda. | |
DEconomy: | |
#If you don't know what this is. then it would be wise not to touch it. | |
ThreadPoolSize: 40 | |
#Allow normal players to view other players bank balances. | |
BalanceViewing: false | |
#Prefix for all the plugin to player messages. | |
Prefix: '&aDEconomy &8»&7' | |
#Line header and footer used for all box messages. | |
Line: '&7&m-------------------------------' | |
#Information line. | |
PageInfoLine: '&8(&7{currentpage}&8/&7{maxpages}&8) &7{command} {nextpage}' | |
#Default lore and name for the page directors in the villager shops. | |
GUI: | |
PageDirector: | |
Lore: | |
- '&7» &7Click to go to next page. :)' | |
Name: '&7» &aClick to go to the next page.' | |
#Limit - Amount of banks any user can own at one time. | |
#Enabled - If the bank feature is enabled on this server. | |
Banks: | |
#If the feature is enabled. | |
Enabled: true | |
#Default amount of banks any user without op or admin perms can own. If a player has deconomy.banks.<number of bank> it will override the default limit. | |
Limit: 5 | |
#For /deconomy banks | |
BankEntryTemplate: '&aBank: &7{bank} &8- &aAccessibility: &7{accesstype}' | |
SQL: | |
UsingSQLite: true | |
#If UsingSQLite is true, don't bother with filling this out. | |
MySQL: | |
Address: | |
Port: | |
Database: | |
Username: | |
Password: | |
MaximumPoolSize: 10 | |
Shop: | |
#This value corresponds to the multiplier in the shop. When a person shift + left/right click | |
Multipler: 8 | |
#All messages | |
Messages: | |
NoPermission: | |
Shop: '{prefix} &cYou do not have permission to use shop {shopname}.' | |
Sign: '{prefix} &cYou do not have permission to use the sign.' | |
OpeningShop: '{prefix} &aOpening shop {shopname}.' | |
CannotBuyItem: '{prefix} &cYou cannot buy item {item}.' | |
NotEnoughMoney: | |
Shop: '{prefix} &cYou do not have enough money to {tradetype} {item} for {price}.' | |
Bank: '{prefix} &c{bank} does not have enough money for a withdrawal of {amount}.' | |
Player: '{prefix} &cYou do not have enough money to {action}.' | |
SuccessfullyBrought: '{prefix} &aYou successfully brought {item} for {price}.' | |
CannotSellItem: '{prefix} &cYou cannot sell item {item}.' | |
SuccessfullySold: '{prefix} &cYou successfully sold item {item} for {price}.' | |
ClosingShop: '{prefix} &Closing shop {shopname}.' | |
CannotViewOtherBalances: '{prefix} &cYou do not have permission to view other peoples balances.' | |
PlayerNotFound: '{prefix} &cCould not find player {player}.' | |
PlayerBalanceInfo: '{prefix} {player}s balance is: {balance}.' | |
DEconomyHelpList: | |
- '{line}' | |
- '&a /deconomy bal | /deconomy bal <player name>' | |
- '&a /deconomy bank' | |
- '{line}' | |
BankHelpList: | |
- '{line}' | |
- '&a /deconomy bank create <bank name>' | |
- '&a /deconomy bank deposit <bank name> <amount>' | |
- '&a /deconomy bank withdraw <bank name> <amount>' | |
- '&a /deconomy bank leave <bank name>' | |
- '&a /deconomy bank delete <bank name>' | |
- '&a /deconomy bank info <bank name>' | |
- '{line}' | |
NotEnoughArguments: '{prefix} &cNot enough arguments given to successfully execute command {commandusage}.' | |
BankNotFound: '{prefix} &cCould not find bank {bank}.' | |
ArgumentsNotANumber: 'Arguments specified does not include a number. {commandusage}.' | |
SuccessfullyDeposited: '{prefix} &aSuccessfully deposited {amount} into {bank}.' | |
NotEnoughMoney: '{prefix} &cYou do not have enough money to do this.' | |
SuccessfullyWithdrew: '{prefix} &aSuccessfully withdrew {amount} from {bank}.' | |
NotTheBankOwner: '{prefix} &cYou do not own this bank so you cannot do this.' | |
RemovedFromBank: '{prefix} &aYou are no longer a member of {bank}.' | |
Sudo: | |
Successfully: | |
RemovedItems: '{prefix} &aSuccessfully removed item {item} from shop {shop}.' | |
Changed: | |
BothPrices: '{prefix} &aSuccessfully changed both buy and sell prices for {item}.' | |
BuyPrice: '{prefix} &aSuccessfully changed buy price for {item}.' | |
SellPrice: '{prefix} &aSuccessfully changed sell price for {item}.' | |
Disable: '{prefix} &cSudo disabled for {name}.' | |
Enable: '{prefix} &aSudo Enabled for {name}.' | |
AdminHelpList: | |
- '{line}' | |
- '&a /adeconomy create <permission> <name> <profession> &8- &7Create a villager shop.' | |
- '&a /adeconomy remove <shopid> &8- &7Remove a shop.' | |
- '&a /adeconomy bank info <bank name> &8- &7Get a players bank information.' | |
- '&a /adeconomy bank remove <bank name> &8- &7Forcibly remove a bank.' | |
- '&a /adeconomy withdraw <bank name> <amount> &8- &7Withdraw money from any bank.' | |
- '&a /adeconomy bank deposit <bank name> <amount> &8- &7Deposit money into any bank.' | |
- '&a /adeconomy bank transfer <bank name> <new owner> <remove old owner to member (yes|no) &8- &7Change the ownership of a bank.' | |
- '&a /adeconomy member add <bank name> <player name> &8- &7Add a member to any bank.' | |
- '&a /adeconomy member remove <bank name> <player name> &8- &7Remove a member of any bank.' | |
- '{line}' | |
ItemNotFound: '{prefix} &cItem advertised in the sign is not found.' | |
SuccessfullyCreatedShop: '{prefix} &aSuccessfully created shop {shopName}.' | |
SuccessfullyRemovedShop: '{prefix} &aSuccessfully removed shop {shopName}.' | |
CantFindShop: '{prefix} &cCannot find shop {shopName}.' | |
BankInfoList: | |
- '{line}' | |
- '&aOwner: &7{owner}' | |
- '&aMembers: &7{members}' | |
- '&aBank Balance: &7{balance}' | |
- '{line}' | |
SuccessfullyCreatedBank: '{prefix} Successfully created bank {bank}.' | |
UnsuccessfullyCreatedShop: '{prefix} &cFailed to create bank. Seek further assistance from a Developer if need be.' | |
TransferredOwnership: '{prefix} &aBank {bank}s ownership has been transferred to {bankowner}.' | |
PlayerAlreadyABankMember: '{prefix} &cPlayer {player} is already a member of {bank}.' | |
PlayerIsNotABankMember: '{prefix} &cPlayer {player} is not a member of {bank}.' | |
RemovedBankMember: '{prefix} Player {player} has been removed from bank membership {bank}.' | |
NoAccess: '{prefix} &cYou do not have access to bank {bank}.' | |
NotAMember: '{prefix} &cYou are not a member of bank {bank}.' | |
CannotLeaveBank: '{prefix} You cannot leave this bank, you are the owner of it! If you want to remove it either transfer the ownership over to another player or remove it altogether.' | |
ContainsBannedWord: '{prefix} {name} contains a banned word, please choose another name that does not contain a banned word.' | |
NoAccessibleBanksFound: '{prefix} &cWe could not find any banks that you had access to.' | |
PageDoesNotExist: '{prefix} &cPage {pagenumber} does not exist.' | |
AlreadyOwnsBankNamed: '{prefix} &cYou already own a bank named {bank}.' | |
MaximumBanksMet: '{prefix} &cYou have hit or exceeded the limit of banks you are allowed to own.' | |
BankDeleted: '{prefix} {bank} successfully deleted.' | |
OwnershipTransferred: '{prefix} Ownership of {bank} has now been transferred to {newowner} from {oldowner}.' | |
LeftBank: '{prefix} Left bank {bank}.' | |
ContainsBannedWord: '{prefix} {name} contains a banned word, please choose another name that does not contain a banned word.' | |
CannotPlaceTwoShopsInOneBlock: '{prefix} &cYou cannot place two shops in one block!' | |
NameAlreadyUsed: '{prefix} &cThat name has already been used for a shop.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ackage net.dungeons.config; | |
import com.google.common.collect.Lists; | |
import net.dungeons.DEconomy; | |
import net.dungeons.utils.Pair; | |
import org.bukkit.ChatColor; | |
import org.bukkit.command.CommandSender; | |
import org.bukkit.entity.Player; | |
import java.util.List; | |
/** | |
* Created by TheMasteredPanda on 23/02/2017. | |
*/ | |
public class MainConfig extends BaseConfig | |
{ | |
private DEconomy instance = DEconomy.getInstance(); | |
public MainConfig() | |
{ | |
super("config.yml"); | |
} | |
public void sendMessage(CommandSender sender, String messageNode, boolean color) | |
{ | |
String message = this.config.getString(messageNode).replace("{prefix}", this.getPrefix().replace("{line}", this.getDEconomyContainerLine())); | |
if (color) { | |
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); | |
} else { | |
sender.sendMessage(message); | |
} | |
} | |
public void sendMessage(CommandSender sender, String messageNode, boolean color, Pair... pairs) | |
{ | |
String message = this.config.getString(messageNode).replace("{prefix}", this.getPrefix().replace("{line}", this.getDEconomyContainerLine())); | |
for (int i = 0; i < pairs.length; i++) { | |
Pair pair = pairs[i]; | |
message = message.replace((String) pair.getLeft(), (String) pair.getRight()); | |
} | |
if (color) { | |
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); | |
} else { | |
sender.sendMessage(this.config.getString(message)); | |
} | |
} | |
public void sendMessage(Player player, String messageNode, boolean color) | |
{ | |
String message = this.config.getString(messageNode).replace("{prefix}", this.getPrefix().replace("{line}", this.getDEconomyContainerLine())); | |
if (color) { | |
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); | |
} else { | |
player.sendMessage(message); | |
} | |
} | |
public void sendMessage(Player player, String messageNode, boolean color, Pair... pairs) | |
{ | |
String message = this.config.getString(messageNode).replace("{prefix}", this.getPrefix()).replace("{line}", this.getDEconomyContainerLine()); | |
for (int i = 0; i < pairs.length; i++) { | |
Pair pair = pairs[i]; | |
message = message.replace((String) pair.getLeft(), (String) pair.getRight()); | |
} | |
if (color) { | |
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); | |
} else { | |
player.sendMessage(this.config.getString(message)); | |
} | |
} | |
public void sendMessages(CommandSender sender, String messageNode, boolean color) | |
{ | |
if (color) { | |
this.config.getStringList(messageNode).forEach(line -> sender.sendMessage(ChatColor.translateAlternateColorCodes('&', line.replace("{prefix}", this.getPrefix()).replace("{line}", this.getDEconomyContainerLine())))); | |
} else { | |
this.config.getStringList(messageNode).forEach(line -> sender.sendMessage(line.replace("{prefix}", this.getPrefix()).replace("{line}", this.getDEconomyContainerLine()))); | |
} | |
} | |
public void sendMessages(CommandSender sender, String messageNode, boolean color, Pair... pairs) | |
{ | |
List<String> content = Lists.newArrayList(); | |
this.config.getStringList(messageNode).forEach(line -> { | |
String message = line.replace("{prefix}", this.getPrefix()).replace("{line}", this.getDEconomyContainerLine()); | |
for (Pair pair : pairs) { | |
message = message.replace((String) pair.getLeft(), (String) pair.getRight()); | |
} | |
if (color) { | |
message = ChatColor.translateAlternateColorCodes('&', message); | |
} | |
content.add(message); | |
}); | |
content.forEach(sender::sendMessage); | |
} | |
public void sendMessages(Player player, String messageNode, boolean color) | |
{ | |
if (color) { | |
this.config.getStringList(messageNode).forEach(line -> player.sendMessage(ChatColor.translateAlternateColorCodes('&', line.replace("{prefix}", this.getPrefix()).replace("{line}", this.getDEconomyContainerLine())))); | |
} else { | |
this.config.getStringList(messageNode).forEach(line -> player.sendMessage(line.replace("{prefix}", this.getPrefix()).replace("{line}", this.getDEconomyContainerLine()))); | |
} | |
} | |
public void sendMessages(Player player, String messageNode, boolean color, Pair... pairs) | |
{ | |
System.out.println(messageNode + "\n" + pairs); | |
List<String> content = Lists.newArrayList(); | |
this.config.getStringList(messageNode).forEach((String line) -> { | |
String message = line.replace("{prefix}", this.getPrefix()).replace("{line}", this.getDEconomyContainerLine()); | |
for (Pair pair : pairs) { | |
message = message.replace((String) pair.getLeft(), (String) pair.getRight()); | |
} | |
if (color) { | |
message = ChatColor.translateAlternateColorCodes('&', message); | |
} | |
content.add(message); | |
}); | |
System.out.println(content); | |
content.forEach(player::sendMessage); | |
} | |
public List<String> getDefaultPageDirectorLore() | |
{ | |
return this.config.getStringList("DEconomy.GUI.PageDirector.Lore"); | |
} | |
public String getDefaultPageDirectorName() | |
{ | |
return this.config.getString("DEconomy.GUI.PageDirector.Name"); | |
} | |
public List<String> getShopEntryLore() | |
{ | |
List<String> lore = this.config.getStringList("Shop.Entry.Lore"); | |
lore.forEach(line -> line = ChatColor.translateAlternateColorCodes('&', line)); | |
return lore; | |
} | |
public String getPrefix() | |
{ | |
return ChatColor.translateAlternateColorCodes('&', this.config.getString("DEconomy.Prefix")); | |
} | |
public boolean getBankSupport() | |
{ | |
return this.config.getBoolean("DEconomy.Banks.Enabled"); | |
} | |
public boolean getUsingSQLite() | |
{ | |
return this.config.getBoolean("DEconomy.SQL.UsingSQLite"); | |
} | |
public String getMySQLAddress() | |
{ | |
return this.config.getString("DEconomy.SQL.MySQL.Address"); | |
} | |
public int getMySQLPort() | |
{ | |
return this.config.getInt("DEconomy.SQL.MySQL.Port"); | |
} | |
public String getMySQLDatabase() | |
{ | |
return this.config.getString("DEconomy.SQL.MySQL.Database"); | |
} | |
public String getMySQLUsername() | |
{ | |
return this.config.getString("DEconomy.SQL.MySQL.Username"); | |
} | |
public String getMySQLPassword() | |
{ | |
return this.config.getString("DEconomy.SQL.MySQL.Password"); | |
} | |
public int getMySQLPoolSize() | |
{ | |
return this.config.getInt("DEconomy.SQL.MySQL.MaximumPoolSize"); | |
} | |
public int getDEconomyThreadPool() | |
{ | |
return this.config.getInt("DEconomy.ThreadPoolSize"); | |
} | |
public boolean getViewingOtherBalances() | |
{ | |
return this.config.getBoolean("DEconomy.BalanceViewing"); | |
} | |
public String getBankEntryTemplate() | |
{ | |
return this.config.getString("DEconomy.Banks.BankEntryTemplate"); | |
} | |
public String getDEconomyContainerLine() | |
{ | |
return this.config.getString("DEconomy.Line"); | |
} | |
public String getDEconomyContainerInfoPage() | |
{ | |
return this.config.getString("DEconomy.PageInfoLine"); | |
} | |
public int getMaximumAllowedBanksOwned() | |
{ | |
return this.config.getInt("DEconomy.Banks.Limit"); | |
} | |
public int getShopMultiplier() | |
{ | |
return this.config.getInt("DEconomy.Shop.Multiplier"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.dungeons.shop.villager; | |
import lombok.Getter; | |
import net.dungeons.DEconomy; | |
import net.dungeons.config.MainConfig; | |
import net.dungeons.config.ShopTemplateConfig; | |
import net.dungeons.shop.villager.page.DEconomyGUI; | |
import net.dungeons.shop.villager.page.GUIListeners; | |
import net.dungeons.shop.villager.page.GUIPage; | |
import net.dungeons.utils.InventoryUtils; | |
import net.dungeons.utils.Pair; | |
import net.dungeons.utils.ShopUtils; | |
import net.milkbowl.vault.economy.Economy; | |
import org.bukkit.entity.Entity; | |
import org.bukkit.entity.Player; | |
import org.bukkit.entity.Villager; | |
import org.bukkit.event.EventHandler; | |
import org.bukkit.event.Listener; | |
import org.bukkit.event.entity.EntityDamageByEntityEvent; | |
import org.bukkit.event.inventory.InventoryClickEvent; | |
import org.bukkit.event.inventory.InventoryCloseEvent; | |
import org.bukkit.event.inventory.InventoryOpenEvent; | |
import org.bukkit.event.inventory.InventoryType; | |
import org.bukkit.event.player.PlayerInteractEntityEvent; | |
import org.bukkit.inventory.ItemStack; | |
import java.util.stream.Stream; | |
/** | |
* Created by TheMasteredPanda on 02/02/2017. | |
*/ | |
public class Shop implements GUIListeners, Listener | |
{ | |
private @Getter String shopName; | |
private @Getter String permission; | |
private @Getter DEconomyGUI gui; | |
private @Getter String id; | |
private @Getter Villager shopKeeper; | |
private MainConfig config; | |
private DEconomy instance; | |
private Economy economy; | |
private @Getter ShopTemplateConfig shopConfig; | |
public Shop(DEconomy instance, ShopKeeperMeta shopKeeperMeta, DEconomyGUI gui, ShopTemplateConfig shopConfig, boolean newShop) | |
{ | |
this(instance, shopKeeperMeta, gui, newShop); | |
this.shopConfig = shopConfig; | |
} | |
public Shop(DEconomy instance, ShopKeeperMeta shopKeeperMeta, DEconomyGUI gui, boolean newShop) | |
{ | |
this.instance = instance; | |
this.economy = instance.getEconomy(); | |
this.gui = gui; | |
this.gui.addGUIListeners(this); | |
instance.debug("ShopKeeperMeta: " + shopKeeperMeta + ", DEconomy: " + gui + ", newShop: " + newShop); | |
instance.debug(shopKeeperMeta.toString()); | |
this.shopName = shopKeeperMeta.getName(); | |
this.permission = shopKeeperMeta.getPermission(); | |
if (newShop) { | |
instance.debug("Shop is a new shop."); | |
if (this.shopKeeper == null) { | |
this.shopKeeper = ShopUtils.spawnVillager(shopKeeperMeta); | |
this.shopConfig = new ShopTemplateConfig(shopKeeperMeta); | |
} | |
this.reload(); | |
return; | |
} else { | |
instance.debug("Shop is not a new shop."); | |
Entity[] entities = shopKeeperMeta.getLocation().getChunk().getEntities(); | |
System.out.println("Shop Keeper UUID is: " + shopKeeperMeta.getVillagerUniqueID()); | |
Stream.of(entities).forEach(entity -> { | |
instance.debug("Currently iterating though entity: " + entity.getName() + " with uuid " + entity.getUniqueId()); | |
if (entity.getUniqueId().equals(shopKeeperMeta.getVillagerUniqueID())) { | |
instance.debug("Entity " + entity.getName() + " has the same unique id as " + shopKeeperMeta.getVillagerUniqueID()); | |
this.shopKeeper = (Villager) entity; | |
} | |
}); | |
if (this.shopKeeper == null) { | |
this.shopKeeper = ShopUtils.spawnVillager(shopKeeperMeta); | |
} | |
} | |
this.id = shopKeeperMeta.getId(); | |
this.config = instance.getConfigManager().getMainConfig(); | |
instance.getServer().getPluginManager().registerEvents(this, instance); | |
} | |
public void reload() | |
{ | |
this.shopConfig.loadShop(); | |
this.instance.getShopManager().getShops().remove(this); | |
} | |
@EventHandler | |
public void onInteract(PlayerInteractEntityEvent e) | |
{ | |
if (!(e.getRightClicked() instanceof Villager)) { | |
return; | |
} | |
Villager villager = (Villager) e.getRightClicked(); | |
if (!villager.getUniqueId().equals(this.shopKeeper.getUniqueId())) { | |
return; | |
} | |
e.setCancelled(true); | |
Player p = e.getPlayer(); | |
if (!p.hasPermission(this.permission)) { | |
this.config.sendMessage(p, "Messages.NoPermission.Shop", true, new Pair("{shop}", this.shopName)); | |
return; | |
} | |
if (this.gui.getFirstPage() == null) { | |
this.config.sendMessage(p, "Messages.NoPagesInShop", true, new Pair("{shop}", this.shopName)); | |
return; | |
} | |
p.openInventory(this.gui.getFirstPage().getInventory()); | |
} | |
@EventHandler | |
public void onDamage(EntityDamageByEntityEvent e) | |
{ | |
if (!(e.getEntity() instanceof Villager)) { | |
return; | |
} | |
Villager villager = (Villager) e.getEntity(); | |
if (!villager.getUniqueId().equals(this.shopKeeper.getUniqueId())) { | |
return; | |
} | |
e.setCancelled(true); | |
} | |
public void onOpen(InventoryOpenEvent e, GUIPage page) | |
{ | |
if (e.getInventory().getType() == InventoryType.MERCHANT) { | |
e.setCancelled(true); | |
} | |
} | |
public void onClick(InventoryClickEvent e, GUIPage page, boolean isPageDirector, ShopEntry shopEntry) | |
{ | |
Player p = (Player) e.getWhoClicked(); | |
double balance = this.instance.getEconomy().getBalance(p); | |
if (shopEntry == null) { | |
return; | |
} | |
String name = shopEntry.getItem().getItemMeta().getDisplayName(); | |
//Single - buy/sell one item per click | |
if (e.getClick() == shopEntry.getType().getSingle() || shopEntry.getType() == ShopEntry.Type.BUY_AND_SELL) { | |
if (shopEntry.getType() == ShopEntry.Type.BUY || (shopEntry.getType() == ShopEntry.Type.BUY_AND_SELL && e.getClick() == ShopEntry.Type.BUY.getSingle())) { | |
double price = shopEntry.getBuyPrice(); | |
if (balance < price) { | |
this.config.sendMessage(p, "Messages.NotEnoughMoney.Shop", true); /*new Pair("{tradetype}", "buy"), new Pair("{item}", name), new Pair("{price}", price)*/ | |
return; | |
} | |
if (this.economy.withdrawPlayer(p, shopEntry.getBuyPrice()).transactionSuccess()) { | |
this.config.sendMessage(p, "Messages.SuccessfullyBrought", true, new Pair("{item}", name)); | |
InventoryUtils.addItems(p.getInventory(), new ItemStack[] {shopEntry.getItem()}, p.getLocation()); | |
} | |
} | |
if (shopEntry.getType() == ShopEntry.Type.SELL || (shopEntry.getType() == ShopEntry.Type.BUY_AND_SELL && e.getClick() == ShopEntry.Type.SELL.getSingle())) { | |
double price = shopEntry.getSellPrice(); | |
if (!p.getInventory().contains(shopEntry.getItem())) { | |
this.config.sendMessage(p, "Messages.ItemNotFound", true); | |
return; | |
} | |
boolean removedItem = false; | |
for (ItemStack item : p.getInventory().getContents()) { | |
if (!item.getType().equals(shopEntry.getItem().getType())) { | |
continue; | |
} | |
if (item.getAmount() > 1) { | |
int amount =- item.getAmount(); | |
item.setAmount(amount); | |
removedItem = true; | |
break; | |
} else { | |
p.getInventory().remove(item); | |
removedItem = true; | |
} | |
} | |
if (removedItem) { | |
if (this.economy.depositPlayer(p, price).transactionSuccess()) { | |
this.config.sendMessage(p, "Messages.SuccessfullySold", true, new Pair("{item}", name)); | |
return; | |
} | |
} else { | |
throw new IllegalArgumentException("Didn't remove item " + name + "."); | |
} | |
} | |
} | |
//Multiple - buy/sell a bulk amount that is set in the config | |
if (e.getClick() == shopEntry.getType().getMultiple() || shopEntry.getType() == ShopEntry.Type.BUY_AND_SELL) { | |
String multiplierName = name + " x" + this.config.getShopMultiplier(); | |
if (shopEntry.getType() == ShopEntry.Type.BUY || (shopEntry.getType() == ShopEntry.Type.BUY_AND_SELL && e.getClick() == ShopEntry.Type.BUY.getMultiple())) { | |
double price = this.config.getShopMultiplier() * shopEntry.getBuyPrice(); | |
if (balance < price) { | |
this.config.sendMessage(p, "Messages.NotEnoughMoney.Shop", true, new Pair("{tradetype}", "buy"), new Pair("{item}", multiplierName), new Pair("{price}", this.economy.format(price))); | |
return; | |
} | |
if (this.economy.withdrawPlayer(p, price).transactionSuccess()) { | |
ItemStack itemStack = shopEntry.getItem().clone(); | |
itemStack.setAmount(this.config.getShopMultiplier()); | |
InventoryUtils.addItems(p.getInventory(), new ItemStack[] {itemStack}, p.getLocation()); | |
this.config.sendMessage(p, "Messages.SuccessfullyBrought", true, new Pair("{item}", multiplierName)); | |
} | |
return; | |
} | |
if (shopEntry.getType() == ShopEntry.Type.SELL || shopEntry.getType() == ShopEntry.Type.BUY_AND_SELL) { | |
double price = this.config.getShopMultiplier() * shopEntry.getSellPrice(); | |
if (!p.getInventory().contains(shopEntry.getItem().getType())) { | |
this.config.sendMessage(p, "Message.ItemNotFound", true, new Pair("{item}", shopEntry.getItem().getType().name().toLowerCase())); | |
return; | |
} | |
boolean removedItems = false; | |
int itemsToRemove = this.config.getShopMultiplier(); | |
for (ItemStack item : p.getInventory().getContents()) { | |
if (!item.getType().equals(shopEntry.getItem().getType())) { | |
continue; | |
} | |
if (item.getAmount() >= this.config.getShopMultiplier()) { | |
int amount = item.getAmount() - this.config.getShopMultiplier(); | |
item.setAmount(amount); | |
removedItems = true; | |
break; | |
} else { | |
itemsToRemove = itemsToRemove - item.getAmount(); | |
p.getInventory().remove(item); | |
} | |
if (itemsToRemove == 0) { | |
removedItems = true; | |
break; | |
} | |
} | |
if (removedItems) { | |
if (this.economy.depositPlayer(p, price).transactionSuccess()) { | |
this.config.sendMessage(p, "Messages.SuccessfullySold", true, new Pair("{item}", multiplierName)); | |
return; | |
} | |
} else { | |
throw new IllegalArgumentException("Didn't remove item " + multiplierName + "."); | |
} | |
} | |
} | |
} | |
public void onClose(InventoryCloseEvent e, GUIPage page) {} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
org.bukkit.event.EventException | |
at org.bukkit.plugin.EventExecutor$1.execute(EventExecutor.java:46) ~[patched_1.11.2.jar:git-Paper-1081] | |
at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:78) ~[patched_1.11.2.jar:git-Paper-1081] | |
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[patched_1.11.2.jar:git-Paper-1081] | |
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:517) ~[patched_1.11.2.jar:git-Paper-1081] | |
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:502) ~[patched_1.11.2.jar:git-Paper-1081] | |
at net.minecraft.server.v1_11_R1.PlayerConnection.a(PlayerConnection.java:1897) ~[patched_1.11.2.jar:git-Paper-1081] | |
at net.minecraft.server.v1_11_R1.PacketPlayInWindowClick.a(SourceFile:33) ~[patched_1.11.2.jar:git-Paper-1081] | |
at net.minecraft.server.v1_11_R1.PacketPlayInWindowClick.a(SourceFile:10) ~[patched_1.11.2.jar:git-Paper-1081] | |
at net.minecraft.server.v1_11_R1.PlayerConnectionUtils.lambda$ensureMainThread$0(PlayerConnectionUtils.java:14) ~[patched_1.11.2.jar:git-Paper-1081] | |
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_121] | |
at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_121] | |
at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:46) [patched_1.11.2.jar:git-Paper-1081] | |
at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:830) [patched_1.11.2.jar:git-Paper-1081] | |
at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:403) [patched_1.11.2.jar:git-Paper-1081] | |
at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:754) [patched_1.11.2.jar:git-Paper-1081] | |
at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:652) [patched_1.11.2.jar:git-Paper-1081] | |
at java.lang.Thread.run(Unknown Source) [?:1.8.0_121] | |
Caused by: java.lang.NullPointerException | |
at net.dungeons.config.MainConfig.sendMessage(MainConfig.java:55) ~[?:?] | |
at net.dungeons.shop.villager.Shop.onClick(Shop.java:176) ~[?:?] | |
at net.dungeons.shop.villager.page.DEconomyGUI.onInventoryClick(DEconomyGUI.java:117) ~[?:?] | |
at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor25.execute(Unknown Source) ~[?:?] | |
at org.bukkit.plugin.EventExecutor$1.execute(EventExecutor.java:44) ~[patched_1.11.2.jar:git-Paper-1081] | |
... 16 more | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment