Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dark.net;
- import java.io.File;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.Random;
- import java.util.UUID;
- import net.milkbowl.vault.economy.Economy;
- import net.minecraft.server.v1_8_R1.ChatSerializer;
- import net.minecraft.server.v1_8_R1.Enchantment;
- import net.minecraft.server.v1_8_R1.IChatBaseComponent;
- import net.minecraft.server.v1_8_R1.PacketPlayOutChat;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Material;
- import org.bukkit.SkullType;
- import org.bukkit.Sound;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.conversations.Conversable;
- import org.bukkit.conversations.ConversationAbandonedEvent;
- import org.bukkit.conversations.ConversationAbandonedListener;
- import org.bukkit.conversations.ConversationContext;
- import org.bukkit.conversations.ConversationFactory;
- import org.bukkit.conversations.NumericPrompt;
- import org.bukkit.conversations.Prompt;
- import org.bukkit.conversations.StringPrompt;
- import org.bukkit.craftbukkit.libs.jline.internal.Log;
- import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.EventPriority;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.inventory.ClickType;
- import org.bukkit.event.inventory.InventoryAction;
- import org.bukkit.event.inventory.InventoryClickEvent;
- import org.bukkit.event.inventory.InventoryCloseEvent;
- import org.bukkit.event.player.AsyncPlayerChatEvent;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.event.player.PlayerJoinEvent;
- import org.bukkit.inventory.Inventory;
- import org.bukkit.inventory.InventoryHolder;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.plugin.RegisteredServiceProvider;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Main extends JavaPlugin implements Listener, ConversationAbandonedListener{
- static HashMap<String, Integer> ids = new HashMap<String, Integer>();
- private static Plugin plugin;
- private static File playerbank;
- private static Player p;
- public static Economy econ = null;
- public static int GetRandom;
- private ConversationFactory upgradeBank;
- public static Random random = new Random();
- public static int code;
- static HashMap<UUID, String> amountOperation = new HashMap();
- public boolean setupEconomy() {
- if (getServer().getPluginManager().getPlugin("Vault") == null) {
- return false;
- }
- RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
- if (rsp == null) {
- return false;
- }
- econ = rsp.getProvider();
- return econ != null;
- }
- public void onEnable(){
- plugin=this;
- Bukkit.getServer().getPluginManager().registerEvents(this, this);
- getDataFolder().mkdir();
- playerbank = new File(getDataFolder(), "userbanks");
- playerbank.mkdir();
- }
- public void onDisable(){
- plugin=null;
- }
- public Main() {
- upgradeBank = new ConversationFactory(this)
- .withModality(true)
- .withLocalEcho(false)
- .withFirstPrompt(new upgradebank())
- .thatExcludesNonPlayersWithMessage("Go away evil console!")
- .addConversationAbandonedListener(this);
- }
- @EventHandler
- public void upgradebankclick(InventoryClickEvent e){
- File invFile = new File(playerbank, p.getName() + ".bankshard");
- FileConfiguration invConfig = YamlConfiguration.loadConfiguration(invFile);
- try{
- Player p = (Player) e.getWhoClicked();
- Inventory inv = e.getInventory();
- ItemStack item = e.getCurrentItem();
- ItemMeta itemM = item.getItemMeta();
- String amountInOperation = getAmountInOperation(p.getUniqueId());
- if(inv.getTitle().contains(ChatColor.BLACK + "Bank")){
- e.setCancelled(true);
- if(e.getCurrentItem().getItemMeta().getDisplayName().contains("§b§lShard(s)")){
- if(e.getClick().equals(ClickType.MIDDLE)){
- if(!(invConfig.getInt("Size") == 63)){
- e.setCancelled(true);
- p.closeInventory();
- code = random.nextInt(99999);
- int newslots = invConfig.getInt("Size") + 9;
- int cost = (int) (invConfig.getInt("Size") * 18 / 2);
- p.sendMessage("");
- p.sendMessage("§8 *** §b§lBank Upgrade Confirmation §8***");
- p.sendMessage("§8 CURRENT Slots: §b" + invConfig.getInt("Size") + " §8NEW Slots: §b" + newslots);
- p.sendMessage(" §8Upgrade Cost: §b" + cost + " Shard(s)");
- p.sendMessage("");
- p.sendMessage("§bEnter the code '§b§l" + code + "§b' to confirm your upgrade.");
- p.sendMessage("");
- p.sendMessage("§c§lWARNING: §cBank upgrades are NOT reversible or refundable.\nType 'cancel' to void this upgrade request.");
- upgradeBank.buildConversation((Conversable)p).begin();
- }else{
- p.sendMessage("§c§lERROR: §cYou have already upgraded your bank to its maximum potential");
- p.closeInventory();
- }
- }else if(e.getClick().equals(ClickType.RIGHT)){
- initialiseInventoryKeyPad("§0Withdrawl - Banknote", p.getUniqueId(), p);
- e.setCancelled(true);
- }else if(e.getClick().equals(ClickType.LEFT)){
- e.setCancelled(true);
- initialiseInventoryKeyPad("§0Withdrawl - Shards", p.getUniqueId(), p);
- }
- }
- else if(item.getType()==Material.STAINED_GLASS_PANE && item.getDurability()==(short)7 && itemM.getDisplayName()==" "){
- }
- }if(inv.getTitle().contains("§0Withdrawl - Banknote")){
- if(e.getCurrentItem().getItemMeta().getDisplayName().contains("§b§lShard(s)")){
- }
- else if(e.getCurrentItem().getItemMeta().getDisplayName().contains("§aConfirm")){
- if (amountInOperation != null){
- if(econ.getBalance(p) >= Integer.parseInt(amountInOperation)){
- ItemStack items = new ItemStack(Material.PAPER);
- ItemMeta meta = items.getItemMeta();
- meta.setDisplayName("§bBank Note");
- meta.setLore(Arrays.asList(new String[] { "§f§lValue: §f" + amountInOperation + " Shards","§fExchange at any bank for SHARD(s)"}));
- items.setItemMeta(meta);
- p.getInventory().addItem(items);
- econ.withdrawPlayer(p, Integer.parseInt(amountInOperation));
- try {
- invConfig.save(invFile);
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- clearAmountInOperation(p.getUniqueId());
- p.closeInventory();
- }else{
- p.sendMessage("§c§lERROR: §cYou have insufficient funds to preform this action.");
- p.closeInventory();
- clearAmountInOperation(p.getUniqueId());
- }
- }
- }else if(item.getType()==Material.STAINED_GLASS_PANE && item.getDurability()==(short)7 && itemM.getDisplayName()==" "){
- }
- else if (itemM.getDisplayName().equalsIgnoreCase("§b0"))
- {
- if (getAmountInOperation(p.getUniqueId()) != null)
- {
- changeAmountOperation(p.getUniqueId(), "0", inv);
- }
- else
- {
- p.sendMessage(ChatColor.RED + "You can't begin with 0.");
- }
- }
- else if (itemM.getDisplayName().equalsIgnoreCase("§b1"))
- {
- changeAmountOperation(p.getUniqueId(), "1", inv);
- }
- else if (itemM.getDisplayName().equalsIgnoreCase("§b2"))
- {
- changeAmountOperation(p.getUniqueId(), "2", inv);
- }
- else if (itemM.getDisplayName().equalsIgnoreCase("§b3"))
- {
- changeAmountOperation(p.getUniqueId(), "3", inv);
- ;
- }
- else if (itemM.getDisplayName().equalsIgnoreCase("§b4"))
- {
- changeAmountOperation(p.getUniqueId(), "4", inv);
- ;
- }
- else if (itemM.getDisplayName().equalsIgnoreCase("§b5"))
- {
- changeAmountOperation(p.getUniqueId(), "5", inv);
- ;
- }
- else if (itemM.getDisplayName().equalsIgnoreCase("§b6"))
- {
- changeAmountOperation(p.getUniqueId(), "6", inv);
- ;
- }
- else if (itemM.getDisplayName().equalsIgnoreCase("§b7"))
- {
- changeAmountOperation(p.getUniqueId(), "7", inv);
- ;
- }
- else if (itemM.getDisplayName().equalsIgnoreCase("§b8"))
- {
- changeAmountOperation(p.getUniqueId(), "8", inv);
- ;
- }
- else if (itemM.getDisplayName().equalsIgnoreCase("§b9"))
- {
- changeAmountOperation(p.getUniqueId(), "9", inv);
- ;
- }
- else if(itemM.getDisplayName().contains("§eCorrection")){
- ;
- clearAmountInOperation(p.getUniqueId());
- changeAmountOperation(p.getUniqueId(), "", inv);
- p.sendMessage(ChatColor.GREEN + "Clears the current amount that was previous selected!");
- }
- else if(itemM.getDisplayName().contains("§cCancel")){
- Inventory playerInventory = getInventoryFromFile(new File(playerbank, p.getName() + ".bankshard"));
- ;
- clearAmountInOperation(p.getUniqueId());
- p.openInventory(playerInventory);
- }else{
- }
- }if(inv.getTitle().contains("§0Withdrawl - Shards")){
- if(e.getCurrentItem().getItemMeta().getDisplayName().contains("§b§lShard(s)")){
- ;
- }
- else if(e.getCurrentItem().getItemMeta().getDisplayName().contains("§aConfirm")){
- ;
- if (amountInOperation != null){
- if(econ.getBalance(p) >= Integer.parseInt(amountInOperation)){
- ;
- ItemStack items = new ItemStack(Material.PRISMARINE_SHARD);
- ItemMeta meta = items.getItemMeta();
- meta.setDisplayName("§fShard");
- items.setAmount(Integer.parseInt(amountInOperation));
- items.setItemMeta(meta);
- p.getInventory().addItem(items);
- econ.withdrawPlayer(p, Integer.parseInt(amountInOperation));
- try {
- invConfig.save(invFile);
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- clearAmountInOperation(p.getUniqueId());
- p.closeInventory();
- }else{
- p.sendMessage("§c§lERROR: §cYou have insufficient funds to preform this action.");
- p.closeInventory();
- clearAmountInOperation(p.getUniqueId());
- }
- }
- }else if(item.getType()==Material.STAINED_GLASS_PANE && item.getDurability()==(short)7 && itemM.getDisplayName()==" "){
- ;
- }
- else if (itemM.getDisplayName().equalsIgnoreCase("§b0"))
- {
- if (getAmountInOperation(p.getUniqueId()) != null)
- {
- changeAmountOperation(p.getUniqueId(), "0", inv);
- ;
- }
- else
- {
- p.sendMessage(ChatColor.RED + "You can't begin with 0.");
- ;
- }
- }
- else if (itemM.getDisplayName().equalsIgnoreCase("§b1"))
- {
- changeAmountOperation(p.getUniqueId(), "1", inv);
- ;
- }
- else if (itemM.getDisplayName().equalsIgnoreCase("§b2"))
- {
- changeAmountOperation(p.getUniqueId(), "2", inv);
- ;
- }
- else if (itemM.getDisplayName().equalsIgnoreCase("§b3"))
- {
- changeAmountOperation(p.getUniqueId(), "3", inv);
- ;
- }
- else if (itemM.getDisplayName().equalsIgnoreCase("§b4"))
- {
- changeAmountOperation(p.getUniqueId(), "4", inv);
- ;
- }
- else if (itemM.getDisplayName().equalsIgnoreCase("§b5"))
- {
- changeAmountOperation(p.getUniqueId(), "5", inv);
- ;
- }
- else if (itemM.getDisplayName().equalsIgnoreCase("§b6"))
- {
- changeAmountOperation(p.getUniqueId(), "6", inv);
- ;
- }
- else if (itemM.getDisplayName().equalsIgnoreCase("§b7"))
- {
- changeAmountOperation(p.getUniqueId(), "7", inv);
- ;
- }
- else if (itemM.getDisplayName().equalsIgnoreCase("§b8"))
- {
- changeAmountOperation(p.getUniqueId(), "8", inv);
- ;
- }
- else if (itemM.getDisplayName().equalsIgnoreCase("§b9"))
- {
- changeAmountOperation(p.getUniqueId(), "9", inv);
- ;
- }
- else if(itemM.getDisplayName().contains("§eCorrection")){
- ;
- clearAmountInOperation(p.getUniqueId());
- changeAmountOperation(p.getUniqueId(), "", inv);
- p.sendMessage(ChatColor.GREEN + "Clears the current amount that was previous selected!");
- }
- else if(itemM.getDisplayName().contains("§cCancel")){
- Inventory playerInventory = getInventoryFromFile( new File(playerbank, p.getName() + ".bankshard"));
- ;
- clearAmountInOperation(p.getUniqueId());
- p.openInventory(playerInventory);
- }else{
- }
- }
- }catch(Exception ex){
- }
- }
- @EventHandler
- public void PlayerOpen(PlayerInteractEvent event){
- Player player = event.getPlayer();
- Inventory playerInventory = getInventoryFromFile( new File(playerbank, event.getPlayer().getName() + ".bankshard"));
- if(event.getClickedBlock().getType()==Material.ENDER_CHEST && event.getAction()==Action.RIGHT_CLICK_BLOCK){
- event.setCancelled(true);
- if(playerInventory != null)
- {
- player.openInventory(playerInventory);
- }else{
- sendAnnouncement(player, "§c§lLEVEL I BANK GENERATED COMPLETE");
- player.sendMessage("§a§l*** LEVEL I BANK GENERATION COMPLETE ***");
- player.sendMessage("§7You now have 9 bank slots available.");
- Inventory inv = Bukkit.createInventory(null, 18, ChatColor.BLACK + "Bank Shard [" + ChatColor.YELLOW + "I" + ChatColor.BLACK + "/" + ChatColor.YELLOW + "VI" + ChatColor.BLACK + "]");
- player.openInventory(inv);
- }
- }
- }
- @EventHandler
- public void PlayerClose(InventoryCloseEvent event){
- if(event.getInventory().getTitle().contains(ChatColor.BLACK + "Bank Shard")){
- saveInventoryToFile(event.getInventory(), playerbank, event.getPlayer().getName());
- sendAnnouncement((Player) event.getPlayer(), "§0§oSynchronizing bank data to Hive");
- }else{
- }
- }
- public static void sendAnnouncement(Player p, String msg)
- {
- String s = ChatColor.translateAlternateColorCodes('&', msg);
- IChatBaseComponent icbc = ChatSerializer.a("{\"text\": \"" + s +
- "\"}");
- PacketPlayOutChat bar = new PacketPlayOutChat(icbc, (byte)2);
- ((CraftPlayer) p).getHandle().playerConnection.sendPacket(bar);
- }
- public static void sendmsg(Player p, String msg){
- p.sendMessage(msg);
- }
- public static boolean saveInventoryToFile(Inventory inventory, File path, String fileName)
- {
- File invFile = new File(path, fileName + ".bankshard");
- FileConfiguration invConfig = YamlConfiguration.loadConfiguration(invFile);
- if ((inventory == null) || (path == null) || (fileName == null)) {
- return false;
- }
- try
- {
- if (invFile.exists()) invFile.delete();
- invConfig.set("Title", inventory.getTitle());
- invConfig.set("Size", inventory.getSize());
- invConfig.set("Max stack size", inventory.getMaxStackSize());
- if ((inventory.getHolder() instanceof Player)) {
- invConfig.set("Holder", ((Player)inventory.getHolder()).getName());
- }
- ItemStack[] invContents = inventory.getContents();
- for (int i = 0; i < invContents.length; i++)
- {
- ItemStack itemInInv = invContents[i];
- if ((itemInInv != null) && (itemInInv.getType() != Material.AIR)) {
- invConfig.set("Slot " + i, itemInInv);
- }else{
- invConfig.set("Slot " + i, null);
- }
- }
- invConfig.save(invFile);
- return true;
- }
- catch (Exception ex) {
- }
- return false;
- }
- public static Inventory getInventoryFromFile(File file)
- {
- if (file == null) {
- return null;
- }
- if ((!file.exists()) || (file.isDirectory()) || (!file.getAbsolutePath().endsWith(".bankshard"))) {
- return null;
- }
- try
- {
- FileConfiguration invConfig = YamlConfiguration.loadConfiguration(file);
- String invTitle = invConfig.getString("Title", "Inventory");
- int invSize = invConfig.getInt("Size");
- int invMaxStackSize = invConfig.getInt("Max stack size", 64);
- InventoryHolder invHolder = null;
- if (invConfig.contains("Holder")) {
- invHolder = Bukkit.getPlayer(invConfig.getString("Holder"));
- }
- Inventory inventory = Bukkit.createInventory(invHolder, invSize, ChatColor.translateAlternateColorCodes('&', invTitle));
- inventory.setMaxStackSize(invMaxStackSize);
- try
- {
- ItemStack[] invContents = new ItemStack[invSize];
- for (int i = 0; i < invSize; i++) {
- if (invConfig.contains("Slot " + i)) {
- invContents[i] = invConfig.getItemStack("Slot " + i);
- } else {
- invContents[i] = new ItemStack(Material.AIR);
- }
- }
- inventory.setContents(invContents);
- }
- catch (Exception settingcontents) {
- }
- return inventory;
- }
- catch (Exception ex) {}
- return null;
- }
- @EventHandler
- public void itemshow(AsyncPlayerChatEvent e){
- if(e.getMessage().contains("@i@")){
- //TODO
- e.setMessage(e.getMessage().replace("@i@", "§f§l§nSHOW§r"));
- }
- }
- public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
- Player p = (Player) commandSender;
- File invFile = new File(playerbank, p.getName() + ".bankshard");
- FileConfiguration invConfig = YamlConfiguration.loadConfiguration(invFile);
- if (commandSender instanceof Conversable) {
- if(command.getName().equalsIgnoreCase("addshard")){
- if (args.length == 2) {
- Player t = Bukkit.getPlayer(args[0]);
- if (t == null) {
- p.sendMessage("please select an onine player");
- } else {
- try {
- int amount = Integer.parseInt(args[1]);
- econ.depositPlayer(t, amount);
- t.sendMessage("§7You have recieved §b" + amount + " Shard(s) §7by §c§o" + p.getName());
- p.sendMessage("§7You have given §c§o" + t.getName() + "§b " + amount + " Shard(s)");
- try {
- invConfig.save(invFile);
- } catch (IOException e) {
- e.printStackTrace();
- }
- } catch (NumberFormatException e) {
- p.sendMessage("§c\"" + args[1] + "\" is not a valid amount");
- return true;
- }
- }
- }
- }
- else if(command.getName().equalsIgnoreCase("removeshard")){
- if (args.length == 2) {
- Player t = Bukkit.getPlayer(args[0]);
- if (t == null) {
- p.sendMessage("please select an onine player");
- } else {
- try {
- int amount = Integer.parseInt(args[1]);
- econ.withdrawPlayer(t, amount);
- t.sendMessage("§c§o" + p.getName() + " §7has removed §b" + amount + " Shard(s) §7from your bank");
- p.sendMessage("§7You have removed §b" + amount + " Shard(s) §7from §c§o" + t.getName());
- try {
- invConfig.save(invFile);
- } catch (IOException e) {
- e.printStackTrace();
- }
- } catch (NumberFormatException e) {
- p.sendMessage("§c\"" + args[1] + "\" is not a valid amount");
- return true;
- }
- }
- }
- }
- else if(command.getName().equalsIgnoreCase("giveshardnote")){
- if(args.length == 1){
- int amount = Integer.parseInt(args[0]);
- ItemStack item = new ItemStack(Material.PAPER);
- ItemMeta meta = item.getItemMeta();
- meta.setDisplayName("§bBank Note");
- meta.setLore(Arrays.asList(new String[] {"§f§lValue: §f" + amount + " Shards","§fExchange at any bank for SHARD(s)"}));
- item.setItemMeta(meta);
- p.getInventory().addItem(item);
- }
- }
- return true;
- } else {
- return false;
- }
- }
- private class upgradebank extends StringPrompt {
- @Override
- public Prompt acceptInput(ConversationContext context, String s) {
- Player p = (Player) context.getForWhom();
- File invFile = new File(playerbank, p.getName() + ".bankshard");
- FileConfiguration invConfig = YamlConfiguration.loadConfiguration(invFile);
- int cost = (int) (invConfig.getInt("Size") * 18 / 2);
- if (s.equalsIgnoreCase("cancel")) {
- context.getForWhom().sendRawMessage("§cBank upgrade operation cancelled.");
- return END_OF_CONVERSATION;
- }else if(s.equalsIgnoreCase("" + code)){
- if(cost <= invConfig.getInt("Shards")){
- if(invConfig.getInt("Size") == 18){
- invConfig.set("Size", invConfig.getInt("Size") + 9);
- int upgradedsize = invConfig.getInt("Size");
- context.getForWhom().sendRawMessage("");
- context.getForWhom().sendRawMessage("§a§l*** BANK UPGRADE TO LEVEL II COMPLETE ***");
- context.getForWhom().sendRawMessage("§7You now have "+ upgradedsize + " bank slots available.");
- context.getForWhom().sendRawMessage("");
- econ.withdrawPlayer(p, cost);
- invConfig.set("Title", ChatColor.BLACK + "Bank Shard [" + ChatColor.YELLOW + "II" + ChatColor.BLACK + "/" + ChatColor.YELLOW + "VI" + ChatColor.BLACK + "]");
- invConfig.set("Slot 17", "");
- invConfig.set("Slot 16", "");
- invConfig.set("Slot 15", "");
- invConfig.set("Slot 14", "");
- invConfig.set("Slot 13", "");
- invConfig.set("Slot 12", "");
- invConfig.set("Slot 11", "");
- invConfig.set("Slot 10", "");
- invConfig.set("Slot 9", "");
- p.playSound(p.getLocation(), Sound.LEVEL_UP, 0, 0);
- try {
- invConfig.save(invFile);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }else if(invConfig.getInt("Size") == 27){
- invConfig.set("Size", invConfig.getInt("Size") + 9);
- int upgradedsize = invConfig.getInt("Size");
- context.getForWhom().sendRawMessage("");
- context.getForWhom().sendRawMessage("§a§l*** BANK UPGRADE TO LEVEL III COMPLETE ***");
- context.getForWhom().sendRawMessage("§7You now have "+ upgradedsize + " bank slots available.");
- context.getForWhom().sendRawMessage("");
- econ.withdrawPlayer(p, cost);
- invConfig.set("Title", ChatColor.BLACK + "Bank Shard [" + ChatColor.YELLOW + "III" + ChatColor.BLACK + "/" + ChatColor.YELLOW + "VI" + ChatColor.BLACK + "]");
- invConfig.set("Slot 26", "");
- invConfig.set("Slot 25", "");
- invConfig.set("Slot 24", "");
- invConfig.set("Slot 23", "");
- invConfig.set("Slot 22", "");
- invConfig.set("Slot 21", "");
- invConfig.set("Slot 20", "");
- invConfig.set("Slot 19", "");
- invConfig.set("Slot 18", "");
- p.playSound(p.getLocation(), Sound.LEVEL_UP, 0, 0);
- try {
- invConfig.save(invFile);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }else if(invConfig.getInt("Size") == 36){
- invConfig.set("Size", invConfig.getInt("Size") + 9);
- int upgradedsize = invConfig.getInt("Size");
- context.getForWhom().sendRawMessage("");
- context.getForWhom().sendRawMessage("§a§l*** BANK UPGRADE TO LEVEL IV COMPLETE ***");
- context.getForWhom().sendRawMessage("§7You now have "+ upgradedsize + " bank slots available.");
- context.getForWhom().sendRawMessage("");
- econ.withdrawPlayer(p, cost);
- invConfig.set("Title", ChatColor.BLACK + "Bank Shard [" + ChatColor.YELLOW + "IV" + ChatColor.BLACK + "/" + ChatColor.YELLOW + "VI" + ChatColor.BLACK + "]");
- invConfig.set("Slot 35", "");
- invConfig.set("Slot 34", "");
- invConfig.set("Slot 33", "");
- invConfig.set("Slot 32", "");
- invConfig.set("Slot 31", "");
- invConfig.set("Slot 30", "");
- invConfig.set("Slot 29", "");
- invConfig.set("Slot 28", "");
- invConfig.set("Slot 27", "");
- p.playSound(p.getLocation(), Sound.LEVEL_UP, 0, 0);
- try {
- invConfig.save(invFile);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }else if(invConfig.getInt("Size") == 45){
- invConfig.set("Size", invConfig.getInt("Size") + 9);
- int upgradedsize = invConfig.getInt("Size");
- context.getForWhom().sendRawMessage("");
- context.getForWhom().sendRawMessage("§a§l*** BANK UPGRADE TO LEVEL V COMPLETE ***");
- context.getForWhom().sendRawMessage("§7You now have "+ upgradedsize + " bank slots available.");
- context.getForWhom().sendRawMessage("");
- econ.withdrawPlayer(p, cost);
- invConfig.set("Title", ChatColor.BLACK + "Bank Shard [" + ChatColor.YELLOW + "V" + ChatColor.BLACK + "/" + ChatColor.YELLOW + "VI" + ChatColor.BLACK + "]");
- invConfig.set("Slot 44", "");
- invConfig.set("Slot 43", "");
- invConfig.set("Slot 42", "");
- invConfig.set("Slot 41", "");
- invConfig.set("Slot 40", "");
- invConfig.set("Slot 39", "");
- invConfig.set("Slot 38", "");
- invConfig.set("Slot 37", "");
- invConfig.set("Slot 36", "");
- p.playSound(p.getLocation(), Sound.LEVEL_UP, 0, 0);
- try {
- invConfig.save(invFile);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }else if(invConfig.getInt("Size") == 54){
- invConfig.set("Size", invConfig.getInt("Size") + 9);
- int upgradedsize = invConfig.getInt("Size");
- context.getForWhom().sendRawMessage("");
- context.getForWhom().sendRawMessage("§a§l*** BANK UPGRADE TO LEVEL VI COMPLETE ***");
- context.getForWhom().sendRawMessage("§7You now have "+ upgradedsize + " bank slots available.");
- invConfig.set("Title", ChatColor.BLACK + "Bank Shard [" + ChatColor.YELLOW + "VI" + ChatColor.BLACK + "/" + ChatColor.YELLOW + "VI" + ChatColor.BLACK + "]");
- context.getForWhom().sendRawMessage("");
- econ.withdrawPlayer(p, cost);
- invConfig.set("Slot 53", "");
- invConfig.set("Slot 52", "");
- invConfig.set("Slot 51", "");
- invConfig.set("Slot 50", "");
- invConfig.set("Slot 49", "");
- invConfig.set("Slot 48", "");
- invConfig.set("Slot 47", "");
- invConfig.set("Slot 46", "");
- invConfig.set("Slot 45", "");
- p.playSound(p.getLocation(), Sound.LEVEL_UP, 0, 0);
- try {
- invConfig.save(invFile);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }else{
- context.getForWhom().sendRawMessage("§cYou do not have enough shards to purchase this upgrade.\n Upgrade cancelled.");
- context.getForWhom().sendRawMessage("§c§lCOST: §c" + cost + " Shard(s)");
- return END_OF_CONVERSATION;
- }
- }else{
- context.getForWhom().sendRawMessage("§cInvalid authentication code entered. Bank upgrade cancelled.");
- return END_OF_CONVERSATION;
- }
- return END_OF_CONVERSATION;
- }
- @Override
- public String getPromptText(ConversationContext c) {
- return "";
- }
- }
- @Override
- public void conversationAbandoned(ConversationAbandonedEvent e) {
- }
- private void changeAmountOperation(UUID playerUUID, String amount, Inventory inv)
- {
- ItemStack item36 = inv.getItem(36);
- ItemStack item37 = inv.getItem(37);
- ItemStack item38 = inv.getItem(38);
- ItemStack item45 = inv.getItem(45);
- ItemStack item46 = inv.getItem(46);
- ItemStack item47 = inv.getItem(47);
- if (item36 != null || item37 != null || item38 != null || item45 != null || item46 != null || item47 != null)
- {
- ItemMeta meta36 = item36.getItemMeta();
- ItemMeta meta37 = item37.getItemMeta();
- ItemMeta meta38 = item38.getItemMeta();
- ItemMeta meta45 = item45.getItemMeta();
- ItemMeta meta46 = item46.getItemMeta();
- ItemMeta meta47 = item47.getItemMeta();
- if (meta36.getDisplayName().contains("§aConfirm") || meta37.getDisplayName().contains("§aConfirm") || meta38.getDisplayName().contains("§aConfirm") || meta45.getDisplayName().contains("§aConfirm") || meta46.getDisplayName().contains("§aConfirm") || meta47.getDisplayName().contains("§aConfirm"))
- {
- addAmountInOperation(playerUUID, amount);
- String newDisplay36 = meta36.getDisplayName().substring(0, 9);
- String newDisplay37 = meta37.getDisplayName().substring(0, 9);
- String newDisplay38 = meta38.getDisplayName().substring(0, 9);
- String newDisplay45 = meta45.getDisplayName().substring(0, 9);
- String newDisplay46 = meta46.getDisplayName().substring(0, 9);
- String newDisplay47 = meta47.getDisplayName().substring(0, 9);
- String amountInOperationa = getAmountInOperation(playerUUID);
- if (amountInOperationa != null) {
- newDisplay36 = newDisplay36 + " - " + amountInOperationa + " ";
- newDisplay37 = newDisplay37 + " - " + amountInOperationa + " ";
- newDisplay38 = newDisplay38 + " - " + amountInOperationa + " ";
- newDisplay45 = newDisplay45 + " - " + amountInOperationa + " ";
- newDisplay46 = newDisplay46 + " - " + amountInOperationa + " ";
- newDisplay47 = newDisplay47 + " - " + amountInOperationa + " ";
- }
- meta36.setDisplayName(newDisplay36);
- meta37.setDisplayName(newDisplay37);
- meta38.setDisplayName(newDisplay38);
- meta45.setDisplayName(newDisplay45);
- meta46.setDisplayName(newDisplay46);
- meta47.setDisplayName(newDisplay47);
- item36.setItemMeta(meta36);
- item37.setItemMeta(meta37);
- item38.setItemMeta(meta38);
- item45.setItemMeta(meta45);
- item46.setItemMeta(meta46);
- item47.setItemMeta(meta47);
- inv.setItem(36, item36);
- inv.setItem(37, item37);
- inv.setItem(38, item38);
- inv.setItem(45, item45);
- inv.setItem(46, item46);
- inv.setItem(47, item47);
- }
- }
- }
- public void addAmountInOperation(UUID playerUUID, String amount)
- {
- if ((amount == null) || (amount.isEmpty())) {
- return;
- }
- if (amountOperation.get(playerUUID) != null) {
- amountOperation.put(playerUUID,
- (String)amountOperation.get(playerUUID) + amount);
- } else {
- amountOperation.put(playerUUID, amount);
- }
- }
- public static String getAmountInOperation(UUID playerUUID)
- {
- return (String)amountOperation.get(playerUUID);
- }
- public void clearAmountInOperation(UUID playerUUID)
- {
- amountOperation.remove(playerUUID);
- }
- private void initialiseInventoryKeyPad(String string, UUID playerUUID, Player p)
- {
- File invFile = new File(playerbank, p.getName() + ".bankshard");
- FileConfiguration invConfig = YamlConfiguration.loadConfiguration(invFile);
- Inventory inv = Bukkit.createInventory(null, 63, string);
- int shards = invConfig.getInt("Shards");
- ItemStack indexbaritem = new ItemStack(Material.STAINED_GLASS_PANE, 1);
- ItemMeta indexbaritemim = indexbaritem.getItemMeta();
- indexbaritem.setDurability((short)7);
- indexbaritemim.setDisplayName(" ");
- indexbaritem.setItemMeta(indexbaritemim);
- ItemStack sharditem = new ItemStack(Material.PRISMARINE_SHARD);
- ItemMeta shardsmeta = sharditem.getItemMeta();
- shardsmeta.setDisplayName("§b" + shards + " §b§lShard(s)");
- shardsmeta.setLore(Arrays.asList(new String[] {"§bLeft Click §7to withdraw §b§lRAW SHARDS","§bRight Click §7to create §b§lA SHARD NOTE","§bMiddle Click §7to upgrade your bank size."}));
- sharditem.setItemMeta(shardsmeta);
- ItemStack ok = new ItemStack(Material.EMERALD_BLOCK, 1);
- ItemMeta okim = ok.getItemMeta();
- okim.setDisplayName(ChatColor.GREEN + "Confirm");
- ok.setItemMeta(okim);
- ItemStack correction = new ItemStack(Material.GOLD_BLOCK, 1);
- ItemMeta correctionim = correction.getItemMeta();
- correctionim.setDisplayName(ChatColor.YELLOW + "Correction");
- correction.setItemMeta(correctionim);
- ItemStack cancel = new ItemStack(Material.REDSTONE_BLOCK, 1);
- ItemMeta cancelim = cancel.getItemMeta();
- cancelim.setDisplayName(ChatColor.RED + "Cancel");
- cancel.setItemMeta(cancelim);
- ItemStack[] numbpad = new ItemStack[9];
- ItemStack numpad0 = new ItemStack(Material.IRON_BLOCK, 1);
- for (int i = 0; i < numbpad.length; i++)
- {
- numbpad[i] = new ItemStack(Material.IRON_BLOCK, i + 1);
- ItemMeta im = numbpad[i].getItemMeta();
- im.setDisplayName(ChatColor.AQUA + "" + (i + 1));
- numbpad[i].setItemMeta(im);
- }
- ItemMeta numpad0im = numpad0.getItemMeta();
- numpad0im.setDisplayName("§b0");
- numpad0.setItemMeta(numpad0im);
- inv.setItem(0, indexbaritem);
- inv.setItem(1, indexbaritem);
- inv.setItem(2, indexbaritem);
- inv.setItem(3, numbpad[0]);
- inv.setItem(4, numbpad[1]);
- inv.setItem(5, numbpad[2]);
- inv.setItem(6, indexbaritem);
- inv.setItem(7, indexbaritem);
- inv.setItem(8, indexbaritem);
- inv.setItem(9, indexbaritem);
- inv.setItem(10, indexbaritem);
- inv.setItem(11, indexbaritem);
- inv.setItem(12, numbpad[3]);
- inv.setItem(13, numbpad[4]);
- inv.setItem(14, numbpad[5]);
- inv.setItem(15, indexbaritem);
- inv.setItem(16, indexbaritem);
- inv.setItem(17, indexbaritem);
- inv.setItem(18, indexbaritem);
- inv.setItem(19, indexbaritem);
- inv.setItem(20, indexbaritem);
- inv.setItem(21, numbpad[6]);
- inv.setItem(22, numbpad[7]);
- inv.setItem(23, numbpad[8]);
- inv.setItem(24, indexbaritem);
- inv.setItem(25, indexbaritem);
- inv.setItem(26, indexbaritem);
- inv.setItem(27, indexbaritem);
- inv.setItem(28, indexbaritem);
- inv.setItem(29, indexbaritem);
- inv.setItem(30, numpad0);
- inv.setItem(31, numpad0);
- inv.setItem(32, numpad0);
- inv.setItem(33, indexbaritem);
- inv.setItem(34, indexbaritem);
- inv.setItem(35, indexbaritem);
- inv.setItem(36, ok);
- inv.setItem(37, ok);
- inv.setItem(38, ok);
- inv.setItem(39, correction);
- inv.setItem(40, correction);
- inv.setItem(41, correction);
- inv.setItem(42, cancel);
- inv.setItem(43, cancel);
- inv.setItem(44, cancel);
- inv.setItem(45, ok);
- inv.setItem(46, ok);
- inv.setItem(47, ok);
- inv.setItem(48, correction);
- inv.setItem(49, correction);
- inv.setItem(50, correction);
- inv.setItem(51, cancel);
- inv.setItem(52, cancel);
- inv.setItem(53, cancel);
- inv.setItem(54, indexbaritem);
- inv.setItem(55, indexbaritem);
- inv.setItem(56, indexbaritem);
- inv.setItem(57, indexbaritem);
- inv.setItem(58, sharditem);
- inv.setItem(59, indexbaritem);
- inv.setItem(60, indexbaritem);
- inv.setItem(61, indexbaritem);
- inv.setItem(62, indexbaritem);
- p.openInventory(inv);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement