Advertisement
Dark_FX

backup of "gemEconomoyuuu"

Jan 26th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.37 KB | None | 0 0
  1. package dark.net;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6. import java.util.Arrays;
  7. import java.util.HashMap;
  8. import java.util.Random;
  9. import java.util.UUID;
  10.  
  11. import net.milkbowl.vault.economy.Economy;
  12. import net.minecraft.server.v1_8_R1.ChatSerializer;
  13. import net.minecraft.server.v1_8_R1.Enchantment;
  14. import net.minecraft.server.v1_8_R1.IChatBaseComponent;
  15. import net.minecraft.server.v1_8_R1.PacketPlayOutChat;
  16.  
  17. import org.bukkit.Bukkit;
  18. import org.bukkit.ChatColor;
  19. import org.bukkit.Material;
  20. import org.bukkit.SkullType;
  21. import org.bukkit.Sound;
  22. import org.bukkit.command.Command;
  23. import org.bukkit.command.CommandSender;
  24. import org.bukkit.configuration.file.FileConfiguration;
  25. import org.bukkit.configuration.file.YamlConfiguration;
  26. import org.bukkit.conversations.Conversable;
  27. import org.bukkit.conversations.ConversationAbandonedEvent;
  28. import org.bukkit.conversations.ConversationAbandonedListener;
  29. import org.bukkit.conversations.ConversationContext;
  30. import org.bukkit.conversations.ConversationFactory;
  31. import org.bukkit.conversations.NumericPrompt;
  32. import org.bukkit.conversations.Prompt;
  33. import org.bukkit.conversations.StringPrompt;
  34. import org.bukkit.craftbukkit.libs.jline.internal.Log;
  35. import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
  36. import org.bukkit.entity.Player;
  37. import org.bukkit.event.EventHandler;
  38. import org.bukkit.event.EventPriority;
  39. import org.bukkit.event.Listener;
  40. import org.bukkit.event.block.Action;
  41. import org.bukkit.event.inventory.ClickType;
  42. import org.bukkit.event.inventory.InventoryAction;
  43. import org.bukkit.event.inventory.InventoryClickEvent;
  44. import org.bukkit.event.inventory.InventoryCloseEvent;
  45. import org.bukkit.event.player.AsyncPlayerChatEvent;
  46. import org.bukkit.event.player.PlayerInteractEvent;
  47. import org.bukkit.event.player.PlayerJoinEvent;
  48. import org.bukkit.inventory.Inventory;
  49. import org.bukkit.inventory.InventoryHolder;
  50. import org.bukkit.inventory.ItemStack;
  51. import org.bukkit.inventory.meta.ItemMeta;
  52. import org.bukkit.plugin.Plugin;
  53. import org.bukkit.plugin.RegisteredServiceProvider;
  54. import org.bukkit.plugin.java.JavaPlugin;
  55.  
  56.  
  57.  
  58. public class Main extends JavaPlugin implements Listener, ConversationAbandonedListener{
  59.  
  60. static HashMap<String, Integer> ids = new HashMap<String, Integer>();
  61. private static Plugin plugin;
  62. private static File playerbank;
  63. private static Player p;
  64. public static Economy econ = null;
  65. public static int GetRandom;
  66. private ConversationFactory upgradeBank;
  67. public static Random random = new Random();
  68. public static int code;
  69. static HashMap<UUID, String> amountOperation = new HashMap();
  70.  
  71. public boolean setupEconomy() {
  72. if (getServer().getPluginManager().getPlugin("Vault") == null) {
  73. return false;
  74. }
  75. RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
  76. if (rsp == null) {
  77. return false;
  78. }
  79. econ = rsp.getProvider();
  80. return econ != null;
  81. }
  82.  
  83. public void onEnable(){
  84. plugin=this;
  85. Bukkit.getServer().getPluginManager().registerEvents(this, this);
  86. getDataFolder().mkdir();
  87. playerbank = new File(getDataFolder(), "userbanks");
  88. playerbank.mkdir();
  89. }
  90. public void onDisable(){
  91. plugin=null;
  92. }
  93.  
  94. public Main() {
  95. upgradeBank = new ConversationFactory(this)
  96. .withModality(true)
  97. .withLocalEcho(false)
  98. .withFirstPrompt(new upgradebank())
  99. .thatExcludesNonPlayersWithMessage("Go away evil console!")
  100. .addConversationAbandonedListener(this);
  101. }
  102.  
  103. @EventHandler
  104. public void upgradebankclick(InventoryClickEvent e){
  105. File invFile = new File(playerbank, p.getName() + ".bankshard");
  106. FileConfiguration invConfig = YamlConfiguration.loadConfiguration(invFile);
  107. try{
  108. Player p = (Player) e.getWhoClicked();
  109. Inventory inv = e.getInventory();
  110. ItemStack item = e.getCurrentItem();
  111. ItemMeta itemM = item.getItemMeta();
  112. String amountInOperation = getAmountInOperation(p.getUniqueId());
  113.  
  114. if(inv.getTitle().contains(ChatColor.BLACK + "Bank")){
  115. e.setCancelled(true);
  116. if(e.getCurrentItem().getItemMeta().getDisplayName().contains("§b§lShard(s)")){
  117. if(e.getClick().equals(ClickType.MIDDLE)){
  118. if(!(invConfig.getInt("Size") == 63)){
  119. e.setCancelled(true);
  120. p.closeInventory();
  121. code = random.nextInt(99999);
  122. int newslots = invConfig.getInt("Size") + 9;
  123. int cost = (int) (invConfig.getInt("Size") * 18 / 2);
  124. p.sendMessage("");
  125. p.sendMessage("§8 *** §b§lBank Upgrade Confirmation §8***");
  126. p.sendMessage("§8 CURRENT Slots: §b" + invConfig.getInt("Size") + " §8NEW Slots: §b" + newslots);
  127. p.sendMessage(" §8Upgrade Cost: §b" + cost + " Shard(s)");
  128. p.sendMessage("");
  129. p.sendMessage("§bEnter the code '§b§l" + code + "§b' to confirm your upgrade.");
  130. p.sendMessage("");
  131. p.sendMessage("§c§lWARNING: §cBank upgrades are NOT reversible or refundable.\nType 'cancel' to void this upgrade request.");
  132. upgradeBank.buildConversation((Conversable)p).begin();
  133. }else{
  134. p.sendMessage("§c§lERROR: §cYou have already upgraded your bank to its maximum potential");
  135. p.closeInventory();
  136. }
  137. }else if(e.getClick().equals(ClickType.RIGHT)){
  138. initialiseInventoryKeyPad("§0Withdrawl - Banknote", p.getUniqueId(), p);
  139. e.setCancelled(true);
  140. }else if(e.getClick().equals(ClickType.LEFT)){
  141. e.setCancelled(true);
  142. initialiseInventoryKeyPad("§0Withdrawl - Shards", p.getUniqueId(), p);
  143. }
  144. }
  145. else if(item.getType()==Material.STAINED_GLASS_PANE && item.getDurability()==(short)7 && itemM.getDisplayName()==" "){
  146. }
  147. }if(inv.getTitle().contains("§0Withdrawl - Banknote")){
  148. if(e.getCurrentItem().getItemMeta().getDisplayName().contains("§b§lShard(s)")){
  149. }
  150. else if(e.getCurrentItem().getItemMeta().getDisplayName().contains("§aConfirm")){
  151. if (amountInOperation != null){
  152. if(econ.getBalance(p) >= Integer.parseInt(amountInOperation)){
  153. ItemStack items = new ItemStack(Material.PAPER);
  154. ItemMeta meta = items.getItemMeta();
  155. meta.setDisplayName("§bBank Note");
  156. meta.setLore(Arrays.asList(new String[] { "§f§lValue: §f" + amountInOperation + " Shards","§fExchange at any bank for SHARD(s)"}));
  157. items.setItemMeta(meta);
  158. p.getInventory().addItem(items);
  159. econ.withdrawPlayer(p, Integer.parseInt(amountInOperation));
  160. try {
  161. invConfig.save(invFile);
  162. } catch (IOException e1) {
  163. // TODO Auto-generated catch block
  164. e1.printStackTrace();
  165. }
  166. clearAmountInOperation(p.getUniqueId());
  167. p.closeInventory();
  168.  
  169.  
  170. }else{
  171. p.sendMessage("§c§lERROR: §cYou have insufficient funds to preform this action.");
  172. p.closeInventory();
  173. clearAmountInOperation(p.getUniqueId());
  174. }
  175. }
  176. }else if(item.getType()==Material.STAINED_GLASS_PANE && item.getDurability()==(short)7 && itemM.getDisplayName()==" "){
  177. }
  178. else if (itemM.getDisplayName().equalsIgnoreCase("§b0"))
  179. {
  180. if (getAmountInOperation(p.getUniqueId()) != null)
  181. {
  182. changeAmountOperation(p.getUniqueId(), "0", inv);
  183. }
  184. else
  185. {
  186. p.sendMessage(ChatColor.RED + "You can't begin with 0.");
  187. }
  188. }
  189. else if (itemM.getDisplayName().equalsIgnoreCase("§b1"))
  190. {
  191. changeAmountOperation(p.getUniqueId(), "1", inv);
  192. }
  193. else if (itemM.getDisplayName().equalsIgnoreCase("§b2"))
  194. {
  195. changeAmountOperation(p.getUniqueId(), "2", inv);
  196. }
  197. else if (itemM.getDisplayName().equalsIgnoreCase("§b3"))
  198. {
  199. changeAmountOperation(p.getUniqueId(), "3", inv);
  200. ;
  201. }
  202. else if (itemM.getDisplayName().equalsIgnoreCase("§b4"))
  203. {
  204. changeAmountOperation(p.getUniqueId(), "4", inv);
  205. ;
  206. }
  207. else if (itemM.getDisplayName().equalsIgnoreCase("§b5"))
  208. {
  209. changeAmountOperation(p.getUniqueId(), "5", inv);
  210. ;
  211. }
  212. else if (itemM.getDisplayName().equalsIgnoreCase("§b6"))
  213. {
  214. changeAmountOperation(p.getUniqueId(), "6", inv);
  215. ;
  216. }
  217. else if (itemM.getDisplayName().equalsIgnoreCase("§b7"))
  218. {
  219. changeAmountOperation(p.getUniqueId(), "7", inv);
  220. ;
  221. }
  222. else if (itemM.getDisplayName().equalsIgnoreCase("§b8"))
  223. {
  224. changeAmountOperation(p.getUniqueId(), "8", inv);
  225. ;
  226. }
  227. else if (itemM.getDisplayName().equalsIgnoreCase("§b9"))
  228. {
  229. changeAmountOperation(p.getUniqueId(), "9", inv);
  230. ;
  231. }
  232. else if(itemM.getDisplayName().contains("§eCorrection")){
  233. ;
  234. clearAmountInOperation(p.getUniqueId());
  235. changeAmountOperation(p.getUniqueId(), "", inv);
  236. p.sendMessage(ChatColor.GREEN + "Clears the current amount that was previous selected!");
  237. }
  238. else if(itemM.getDisplayName().contains("§cCancel")){
  239. Inventory playerInventory = getInventoryFromFile(new File(playerbank, p.getName() + ".bankshard"));
  240. ;
  241. clearAmountInOperation(p.getUniqueId());
  242. p.openInventory(playerInventory);
  243. }else{
  244.  
  245. }
  246. }if(inv.getTitle().contains("§0Withdrawl - Shards")){
  247. if(e.getCurrentItem().getItemMeta().getDisplayName().contains("§b§lShard(s)")){
  248. ;
  249. }
  250. else if(e.getCurrentItem().getItemMeta().getDisplayName().contains("§aConfirm")){
  251. ;
  252. if (amountInOperation != null){
  253. if(econ.getBalance(p) >= Integer.parseInt(amountInOperation)){
  254. ;
  255. ItemStack items = new ItemStack(Material.PRISMARINE_SHARD);
  256. ItemMeta meta = items.getItemMeta();
  257. meta.setDisplayName("§fShard");
  258. items.setAmount(Integer.parseInt(amountInOperation));
  259. items.setItemMeta(meta);
  260. p.getInventory().addItem(items);
  261. econ.withdrawPlayer(p, Integer.parseInt(amountInOperation));
  262. try {
  263. invConfig.save(invFile);
  264. } catch (IOException e1) {
  265. // TODO Auto-generated catch block
  266. e1.printStackTrace();
  267. }
  268. clearAmountInOperation(p.getUniqueId());
  269. p.closeInventory();
  270.  
  271.  
  272. }else{
  273. p.sendMessage("§c§lERROR: §cYou have insufficient funds to preform this action.");
  274. p.closeInventory();
  275. clearAmountInOperation(p.getUniqueId());
  276. }
  277. }
  278. }else if(item.getType()==Material.STAINED_GLASS_PANE && item.getDurability()==(short)7 && itemM.getDisplayName()==" "){
  279. ;
  280. }
  281. else if (itemM.getDisplayName().equalsIgnoreCase("§b0"))
  282. {
  283. if (getAmountInOperation(p.getUniqueId()) != null)
  284. {
  285. changeAmountOperation(p.getUniqueId(), "0", inv);
  286. ;
  287. }
  288. else
  289. {
  290. p.sendMessage(ChatColor.RED + "You can't begin with 0.");
  291. ;
  292. }
  293. }
  294. else if (itemM.getDisplayName().equalsIgnoreCase("§b1"))
  295. {
  296. changeAmountOperation(p.getUniqueId(), "1", inv);
  297. ;
  298. }
  299. else if (itemM.getDisplayName().equalsIgnoreCase("§b2"))
  300. {
  301. changeAmountOperation(p.getUniqueId(), "2", inv);
  302. ;
  303. }
  304. else if (itemM.getDisplayName().equalsIgnoreCase("§b3"))
  305. {
  306. changeAmountOperation(p.getUniqueId(), "3", inv);
  307. ;
  308. }
  309. else if (itemM.getDisplayName().equalsIgnoreCase("§b4"))
  310. {
  311. changeAmountOperation(p.getUniqueId(), "4", inv);
  312. ;
  313. }
  314. else if (itemM.getDisplayName().equalsIgnoreCase("§b5"))
  315. {
  316. changeAmountOperation(p.getUniqueId(), "5", inv);
  317. ;
  318. }
  319. else if (itemM.getDisplayName().equalsIgnoreCase("§b6"))
  320. {
  321. changeAmountOperation(p.getUniqueId(), "6", inv);
  322. ;
  323. }
  324. else if (itemM.getDisplayName().equalsIgnoreCase("§b7"))
  325. {
  326. changeAmountOperation(p.getUniqueId(), "7", inv);
  327. ;
  328. }
  329. else if (itemM.getDisplayName().equalsIgnoreCase("§b8"))
  330. {
  331. changeAmountOperation(p.getUniqueId(), "8", inv);
  332. ;
  333. }
  334. else if (itemM.getDisplayName().equalsIgnoreCase("§b9"))
  335. {
  336. changeAmountOperation(p.getUniqueId(), "9", inv);
  337. ;
  338. }
  339. else if(itemM.getDisplayName().contains("§eCorrection")){
  340. ;
  341. clearAmountInOperation(p.getUniqueId());
  342. changeAmountOperation(p.getUniqueId(), "", inv);
  343. p.sendMessage(ChatColor.GREEN + "Clears the current amount that was previous selected!");
  344. }
  345. else if(itemM.getDisplayName().contains("§cCancel")){
  346. Inventory playerInventory = getInventoryFromFile( new File(playerbank, p.getName() + ".bankshard"));
  347. ;
  348. clearAmountInOperation(p.getUniqueId());
  349. p.openInventory(playerInventory);
  350. }else{
  351.  
  352. }
  353. }
  354. }catch(Exception ex){
  355.  
  356. }
  357.  
  358. }
  359.  
  360.  
  361. @EventHandler
  362. public void PlayerOpen(PlayerInteractEvent event){
  363. Player player = event.getPlayer();
  364. Inventory playerInventory = getInventoryFromFile( new File(playerbank, event.getPlayer().getName() + ".bankshard"));
  365. if(event.getClickedBlock().getType()==Material.ENDER_CHEST && event.getAction()==Action.RIGHT_CLICK_BLOCK){
  366. event.setCancelled(true);
  367. if(playerInventory != null)
  368. {
  369. player.openInventory(playerInventory);
  370. }else{
  371. sendAnnouncement(player, "§c§lLEVEL I BANK GENERATED COMPLETE");
  372. player.sendMessage("§a§l*** LEVEL I BANK GENERATION COMPLETE ***");
  373. player.sendMessage("§7You now have 9 bank slots available.");
  374. Inventory inv = Bukkit.createInventory(null, 18, ChatColor.BLACK + "Bank Shard [" + ChatColor.YELLOW + "I" + ChatColor.BLACK + "/" + ChatColor.YELLOW + "VI" + ChatColor.BLACK + "]");
  375. player.openInventory(inv);
  376.  
  377. }
  378.  
  379. }
  380.  
  381. }
  382.  
  383.  
  384. @EventHandler
  385. public void PlayerClose(InventoryCloseEvent event){
  386. if(event.getInventory().getTitle().contains(ChatColor.BLACK + "Bank Shard")){
  387. saveInventoryToFile(event.getInventory(), playerbank, event.getPlayer().getName());
  388. sendAnnouncement((Player) event.getPlayer(), "§0§oSynchronizing bank data to Hive");
  389.  
  390. }else{
  391. }
  392. }
  393.  
  394. public static void sendAnnouncement(Player p, String msg)
  395. {
  396. String s = ChatColor.translateAlternateColorCodes('&', msg);
  397. IChatBaseComponent icbc = ChatSerializer.a("{\"text\": \"" + s +
  398. "\"}");
  399. PacketPlayOutChat bar = new PacketPlayOutChat(icbc, (byte)2);
  400. ((CraftPlayer) p).getHandle().playerConnection.sendPacket(bar);
  401. }
  402.  
  403. public static void sendmsg(Player p, String msg){
  404. p.sendMessage(msg);
  405. }
  406.  
  407. public static boolean saveInventoryToFile(Inventory inventory, File path, String fileName)
  408. {
  409. File invFile = new File(path, fileName + ".bankshard");
  410. FileConfiguration invConfig = YamlConfiguration.loadConfiguration(invFile);
  411. if ((inventory == null) || (path == null) || (fileName == null)) {
  412. return false;
  413. }
  414. try
  415. {
  416. if (invFile.exists()) invFile.delete();
  417. invConfig.set("Title", inventory.getTitle());
  418. invConfig.set("Size", inventory.getSize());
  419. invConfig.set("Max stack size", inventory.getMaxStackSize());
  420. if ((inventory.getHolder() instanceof Player)) {
  421. invConfig.set("Holder", ((Player)inventory.getHolder()).getName());
  422. }
  423. ItemStack[] invContents = inventory.getContents();
  424. for (int i = 0; i < invContents.length; i++)
  425. {
  426. ItemStack itemInInv = invContents[i];
  427. if ((itemInInv != null) && (itemInInv.getType() != Material.AIR)) {
  428. invConfig.set("Slot " + i, itemInInv);
  429. }else{
  430. invConfig.set("Slot " + i, null);
  431. }
  432. }
  433. invConfig.save(invFile);
  434. return true;
  435. }
  436. catch (Exception ex) {
  437. }
  438. return false;
  439. }
  440.  
  441. public static Inventory getInventoryFromFile(File file)
  442. {
  443. if (file == null) {
  444. return null;
  445. }
  446. if ((!file.exists()) || (file.isDirectory()) || (!file.getAbsolutePath().endsWith(".bankshard"))) {
  447. return null;
  448. }
  449. try
  450. {
  451. FileConfiguration invConfig = YamlConfiguration.loadConfiguration(file);
  452. String invTitle = invConfig.getString("Title", "Inventory");
  453. int invSize = invConfig.getInt("Size");
  454. int invMaxStackSize = invConfig.getInt("Max stack size", 64);
  455. InventoryHolder invHolder = null;
  456. if (invConfig.contains("Holder")) {
  457. invHolder = Bukkit.getPlayer(invConfig.getString("Holder"));
  458. }
  459. Inventory inventory = Bukkit.createInventory(invHolder, invSize, ChatColor.translateAlternateColorCodes('&', invTitle));
  460. inventory.setMaxStackSize(invMaxStackSize);
  461. try
  462. {
  463. ItemStack[] invContents = new ItemStack[invSize];
  464. for (int i = 0; i < invSize; i++) {
  465. if (invConfig.contains("Slot " + i)) {
  466. invContents[i] = invConfig.getItemStack("Slot " + i);
  467. } else {
  468. invContents[i] = new ItemStack(Material.AIR);
  469. }
  470. }
  471. inventory.setContents(invContents);
  472. }
  473. catch (Exception settingcontents) {
  474. }
  475. return inventory;
  476. }
  477. catch (Exception ex) {}
  478. return null;
  479. }
  480.  
  481. @EventHandler
  482. public void itemshow(AsyncPlayerChatEvent e){
  483. if(e.getMessage().contains("@i@")){
  484. //TODO
  485. e.setMessage(e.getMessage().replace("@i@", "§f§l§nSHOW§r"));
  486. }
  487. }
  488.  
  489. public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
  490. Player p = (Player) commandSender;
  491. File invFile = new File(playerbank, p.getName() + ".bankshard");
  492. FileConfiguration invConfig = YamlConfiguration.loadConfiguration(invFile);
  493. if (commandSender instanceof Conversable) {
  494. if(command.getName().equalsIgnoreCase("addshard")){
  495. if (args.length == 2) {
  496. Player t = Bukkit.getPlayer(args[0]);
  497. if (t == null) {
  498. p.sendMessage("please select an onine player");
  499. } else {
  500. try {
  501. int amount = Integer.parseInt(args[1]);
  502. econ.depositPlayer(t, amount);
  503. t.sendMessage("§7You have recieved §b" + amount + " Shard(s) §7by §c§o" + p.getName());
  504. p.sendMessage("§7You have given §c§o" + t.getName() + "§b " + amount + " Shard(s)");
  505. try {
  506. invConfig.save(invFile);
  507. } catch (IOException e) {
  508. e.printStackTrace();
  509. }
  510. } catch (NumberFormatException e) {
  511. p.sendMessage("§c\"" + args[1] + "\" is not a valid amount");
  512. return true;
  513. }
  514. }
  515. }
  516. }
  517. else if(command.getName().equalsIgnoreCase("removeshard")){
  518. if (args.length == 2) {
  519. Player t = Bukkit.getPlayer(args[0]);
  520. if (t == null) {
  521. p.sendMessage("please select an onine player");
  522. } else {
  523. try {
  524. int amount = Integer.parseInt(args[1]);
  525. econ.withdrawPlayer(t, amount);
  526. t.sendMessage("§c§o" + p.getName() + " §7has removed §b" + amount + " Shard(s) §7from your bank");
  527. p.sendMessage("§7You have removed §b" + amount + " Shard(s) §7from §c§o" + t.getName());
  528. try {
  529. invConfig.save(invFile);
  530. } catch (IOException e) {
  531. e.printStackTrace();
  532. }
  533. } catch (NumberFormatException e) {
  534. p.sendMessage("§c\"" + args[1] + "\" is not a valid amount");
  535. return true;
  536. }
  537. }
  538. }
  539. }
  540. else if(command.getName().equalsIgnoreCase("giveshardnote")){
  541. if(args.length == 1){
  542. int amount = Integer.parseInt(args[0]);
  543. ItemStack item = new ItemStack(Material.PAPER);
  544. ItemMeta meta = item.getItemMeta();
  545. meta.setDisplayName("§bBank Note");
  546. meta.setLore(Arrays.asList(new String[] {"§f§lValue: §f" + amount + " Shards","§fExchange at any bank for SHARD(s)"}));
  547. item.setItemMeta(meta);
  548. p.getInventory().addItem(item);
  549. }
  550. }
  551. return true;
  552.  
  553. } else {
  554. return false;
  555. }
  556. }
  557.  
  558. private class upgradebank extends StringPrompt {
  559.  
  560. @Override
  561. public Prompt acceptInput(ConversationContext context, String s) {
  562. Player p = (Player) context.getForWhom();
  563. File invFile = new File(playerbank, p.getName() + ".bankshard");
  564. FileConfiguration invConfig = YamlConfiguration.loadConfiguration(invFile);
  565. int cost = (int) (invConfig.getInt("Size") * 18 / 2);
  566. if (s.equalsIgnoreCase("cancel")) {
  567. context.getForWhom().sendRawMessage("§cBank upgrade operation cancelled.");
  568. return END_OF_CONVERSATION;
  569. }else if(s.equalsIgnoreCase("" + code)){
  570. if(cost <= invConfig.getInt("Shards")){
  571. if(invConfig.getInt("Size") == 18){
  572. invConfig.set("Size", invConfig.getInt("Size") + 9);
  573. int upgradedsize = invConfig.getInt("Size");
  574. context.getForWhom().sendRawMessage("");
  575. context.getForWhom().sendRawMessage("§a§l*** BANK UPGRADE TO LEVEL II COMPLETE ***");
  576. context.getForWhom().sendRawMessage("§7You now have "+ upgradedsize + " bank slots available.");
  577. context.getForWhom().sendRawMessage("");
  578. econ.withdrawPlayer(p, cost);
  579. invConfig.set("Title", ChatColor.BLACK + "Bank Shard [" + ChatColor.YELLOW + "II" + ChatColor.BLACK + "/" + ChatColor.YELLOW + "VI" + ChatColor.BLACK + "]");
  580. invConfig.set("Slot 17", "");
  581. invConfig.set("Slot 16", "");
  582. invConfig.set("Slot 15", "");
  583. invConfig.set("Slot 14", "");
  584. invConfig.set("Slot 13", "");
  585. invConfig.set("Slot 12", "");
  586. invConfig.set("Slot 11", "");
  587. invConfig.set("Slot 10", "");
  588. invConfig.set("Slot 9", "");
  589. p.playSound(p.getLocation(), Sound.LEVEL_UP, 0, 0);
  590. try {
  591. invConfig.save(invFile);
  592. } catch (IOException e) {
  593. e.printStackTrace();
  594. }
  595. }else if(invConfig.getInt("Size") == 27){
  596. invConfig.set("Size", invConfig.getInt("Size") + 9);
  597. int upgradedsize = invConfig.getInt("Size");
  598. context.getForWhom().sendRawMessage("");
  599. context.getForWhom().sendRawMessage("§a§l*** BANK UPGRADE TO LEVEL III COMPLETE ***");
  600. context.getForWhom().sendRawMessage("§7You now have "+ upgradedsize + " bank slots available.");
  601. context.getForWhom().sendRawMessage("");
  602. econ.withdrawPlayer(p, cost);
  603. invConfig.set("Title", ChatColor.BLACK + "Bank Shard [" + ChatColor.YELLOW + "III" + ChatColor.BLACK + "/" + ChatColor.YELLOW + "VI" + ChatColor.BLACK + "]");
  604. invConfig.set("Slot 26", "");
  605. invConfig.set("Slot 25", "");
  606. invConfig.set("Slot 24", "");
  607. invConfig.set("Slot 23", "");
  608. invConfig.set("Slot 22", "");
  609. invConfig.set("Slot 21", "");
  610. invConfig.set("Slot 20", "");
  611. invConfig.set("Slot 19", "");
  612. invConfig.set("Slot 18", "");
  613. p.playSound(p.getLocation(), Sound.LEVEL_UP, 0, 0);
  614. try {
  615. invConfig.save(invFile);
  616. } catch (IOException e) {
  617. e.printStackTrace();
  618. }
  619. }else if(invConfig.getInt("Size") == 36){
  620. invConfig.set("Size", invConfig.getInt("Size") + 9);
  621. int upgradedsize = invConfig.getInt("Size");
  622. context.getForWhom().sendRawMessage("");
  623. context.getForWhom().sendRawMessage("§a§l*** BANK UPGRADE TO LEVEL IV COMPLETE ***");
  624. context.getForWhom().sendRawMessage("§7You now have "+ upgradedsize + " bank slots available.");
  625. context.getForWhom().sendRawMessage("");
  626. econ.withdrawPlayer(p, cost);
  627. invConfig.set("Title", ChatColor.BLACK + "Bank Shard [" + ChatColor.YELLOW + "IV" + ChatColor.BLACK + "/" + ChatColor.YELLOW + "VI" + ChatColor.BLACK + "]");
  628. invConfig.set("Slot 35", "");
  629. invConfig.set("Slot 34", "");
  630. invConfig.set("Slot 33", "");
  631. invConfig.set("Slot 32", "");
  632. invConfig.set("Slot 31", "");
  633. invConfig.set("Slot 30", "");
  634. invConfig.set("Slot 29", "");
  635. invConfig.set("Slot 28", "");
  636. invConfig.set("Slot 27", "");
  637. p.playSound(p.getLocation(), Sound.LEVEL_UP, 0, 0);
  638. try {
  639. invConfig.save(invFile);
  640. } catch (IOException e) {
  641. e.printStackTrace();
  642. }
  643. }else if(invConfig.getInt("Size") == 45){
  644. invConfig.set("Size", invConfig.getInt("Size") + 9);
  645. int upgradedsize = invConfig.getInt("Size");
  646. context.getForWhom().sendRawMessage("");
  647. context.getForWhom().sendRawMessage("§a§l*** BANK UPGRADE TO LEVEL V COMPLETE ***");
  648. context.getForWhom().sendRawMessage("§7You now have "+ upgradedsize + " bank slots available.");
  649. context.getForWhom().sendRawMessage("");
  650. econ.withdrawPlayer(p, cost);
  651. invConfig.set("Title", ChatColor.BLACK + "Bank Shard [" + ChatColor.YELLOW + "V" + ChatColor.BLACK + "/" + ChatColor.YELLOW + "VI" + ChatColor.BLACK + "]");
  652. invConfig.set("Slot 44", "");
  653. invConfig.set("Slot 43", "");
  654. invConfig.set("Slot 42", "");
  655. invConfig.set("Slot 41", "");
  656. invConfig.set("Slot 40", "");
  657. invConfig.set("Slot 39", "");
  658. invConfig.set("Slot 38", "");
  659. invConfig.set("Slot 37", "");
  660. invConfig.set("Slot 36", "");
  661. p.playSound(p.getLocation(), Sound.LEVEL_UP, 0, 0);
  662. try {
  663. invConfig.save(invFile);
  664. } catch (IOException e) {
  665. e.printStackTrace();
  666. }
  667. }else if(invConfig.getInt("Size") == 54){
  668. invConfig.set("Size", invConfig.getInt("Size") + 9);
  669. int upgradedsize = invConfig.getInt("Size");
  670. context.getForWhom().sendRawMessage("");
  671. context.getForWhom().sendRawMessage("§a§l*** BANK UPGRADE TO LEVEL VI COMPLETE ***");
  672. context.getForWhom().sendRawMessage("§7You now have "+ upgradedsize + " bank slots available.");
  673. invConfig.set("Title", ChatColor.BLACK + "Bank Shard [" + ChatColor.YELLOW + "VI" + ChatColor.BLACK + "/" + ChatColor.YELLOW + "VI" + ChatColor.BLACK + "]");
  674. context.getForWhom().sendRawMessage("");
  675. econ.withdrawPlayer(p, cost);
  676. invConfig.set("Slot 53", "");
  677. invConfig.set("Slot 52", "");
  678. invConfig.set("Slot 51", "");
  679. invConfig.set("Slot 50", "");
  680. invConfig.set("Slot 49", "");
  681. invConfig.set("Slot 48", "");
  682. invConfig.set("Slot 47", "");
  683. invConfig.set("Slot 46", "");
  684. invConfig.set("Slot 45", "");
  685. p.playSound(p.getLocation(), Sound.LEVEL_UP, 0, 0);
  686. try {
  687. invConfig.save(invFile);
  688. } catch (IOException e) {
  689. e.printStackTrace();
  690. }
  691. }
  692. }else{
  693. context.getForWhom().sendRawMessage("§cYou do not have enough shards to purchase this upgrade.\n Upgrade cancelled.");
  694. context.getForWhom().sendRawMessage("§c§lCOST: §c" + cost + " Shard(s)");
  695. return END_OF_CONVERSATION;
  696. }
  697.  
  698. }else{
  699. context.getForWhom().sendRawMessage("§cInvalid authentication code entered. Bank upgrade cancelled.");
  700. return END_OF_CONVERSATION;
  701. }
  702. return END_OF_CONVERSATION;
  703. }
  704.  
  705. @Override
  706. public String getPromptText(ConversationContext c) {
  707. return "";
  708. }
  709.  
  710. }
  711.  
  712. @Override
  713. public void conversationAbandoned(ConversationAbandonedEvent e) {
  714. }
  715.  
  716. private void changeAmountOperation(UUID playerUUID, String amount, Inventory inv)
  717. {
  718. ItemStack item36 = inv.getItem(36);
  719. ItemStack item37 = inv.getItem(37);
  720. ItemStack item38 = inv.getItem(38);
  721. ItemStack item45 = inv.getItem(45);
  722. ItemStack item46 = inv.getItem(46);
  723. ItemStack item47 = inv.getItem(47);
  724. if (item36 != null || item37 != null || item38 != null || item45 != null || item46 != null || item47 != null)
  725. {
  726. ItemMeta meta36 = item36.getItemMeta();
  727. ItemMeta meta37 = item37.getItemMeta();
  728. ItemMeta meta38 = item38.getItemMeta();
  729. ItemMeta meta45 = item45.getItemMeta();
  730. ItemMeta meta46 = item46.getItemMeta();
  731. ItemMeta meta47 = item47.getItemMeta();
  732.  
  733. 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"))
  734. {
  735. addAmountInOperation(playerUUID, amount);
  736. String newDisplay36 = meta36.getDisplayName().substring(0, 9);
  737. String newDisplay37 = meta37.getDisplayName().substring(0, 9);
  738. String newDisplay38 = meta38.getDisplayName().substring(0, 9);
  739. String newDisplay45 = meta45.getDisplayName().substring(0, 9);
  740. String newDisplay46 = meta46.getDisplayName().substring(0, 9);
  741. String newDisplay47 = meta47.getDisplayName().substring(0, 9);
  742. String amountInOperationa = getAmountInOperation(playerUUID);
  743. if (amountInOperationa != null) {
  744.  
  745. newDisplay36 = newDisplay36 + " - " + amountInOperationa + " ";
  746. newDisplay37 = newDisplay37 + " - " + amountInOperationa + " ";
  747. newDisplay38 = newDisplay38 + " - " + amountInOperationa + " ";
  748. newDisplay45 = newDisplay45 + " - " + amountInOperationa + " ";
  749. newDisplay46 = newDisplay46 + " - " + amountInOperationa + " ";
  750. newDisplay47 = newDisplay47 + " - " + amountInOperationa + " ";
  751. }
  752. meta36.setDisplayName(newDisplay36);
  753. meta37.setDisplayName(newDisplay37);
  754. meta38.setDisplayName(newDisplay38);
  755. meta45.setDisplayName(newDisplay45);
  756. meta46.setDisplayName(newDisplay46);
  757. meta47.setDisplayName(newDisplay47);
  758. item36.setItemMeta(meta36);
  759. item37.setItemMeta(meta37);
  760. item38.setItemMeta(meta38);
  761. item45.setItemMeta(meta45);
  762. item46.setItemMeta(meta46);
  763. item47.setItemMeta(meta47);
  764. inv.setItem(36, item36);
  765. inv.setItem(37, item37);
  766. inv.setItem(38, item38);
  767. inv.setItem(45, item45);
  768. inv.setItem(46, item46);
  769. inv.setItem(47, item47);
  770.  
  771. }
  772. }
  773. }
  774.  
  775. public void addAmountInOperation(UUID playerUUID, String amount)
  776. {
  777. if ((amount == null) || (amount.isEmpty())) {
  778. return;
  779. }
  780. if (amountOperation.get(playerUUID) != null) {
  781. amountOperation.put(playerUUID,
  782. (String)amountOperation.get(playerUUID) + amount);
  783. } else {
  784. amountOperation.put(playerUUID, amount);
  785. }
  786. }
  787.  
  788. public static String getAmountInOperation(UUID playerUUID)
  789. {
  790. return (String)amountOperation.get(playerUUID);
  791. }
  792.  
  793. public void clearAmountInOperation(UUID playerUUID)
  794. {
  795. amountOperation.remove(playerUUID);
  796. }
  797.  
  798. private void initialiseInventoryKeyPad(String string, UUID playerUUID, Player p)
  799. {
  800. File invFile = new File(playerbank, p.getName() + ".bankshard");
  801. FileConfiguration invConfig = YamlConfiguration.loadConfiguration(invFile);
  802. Inventory inv = Bukkit.createInventory(null, 63, string);
  803. int shards = invConfig.getInt("Shards");
  804.  
  805.  
  806. ItemStack indexbaritem = new ItemStack(Material.STAINED_GLASS_PANE, 1);
  807. ItemMeta indexbaritemim = indexbaritem.getItemMeta();
  808. indexbaritem.setDurability((short)7);
  809. indexbaritemim.setDisplayName(" ");
  810. indexbaritem.setItemMeta(indexbaritemim);
  811.  
  812. ItemStack sharditem = new ItemStack(Material.PRISMARINE_SHARD);
  813. ItemMeta shardsmeta = sharditem.getItemMeta();
  814. shardsmeta.setDisplayName("§b" + shards + " §b§lShard(s)");
  815. 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."}));
  816. sharditem.setItemMeta(shardsmeta);
  817.  
  818.  
  819. ItemStack ok = new ItemStack(Material.EMERALD_BLOCK, 1);
  820. ItemMeta okim = ok.getItemMeta();
  821. okim.setDisplayName(ChatColor.GREEN + "Confirm");
  822. ok.setItemMeta(okim);
  823.  
  824. ItemStack correction = new ItemStack(Material.GOLD_BLOCK, 1);
  825. ItemMeta correctionim = correction.getItemMeta();
  826. correctionim.setDisplayName(ChatColor.YELLOW + "Correction");
  827. correction.setItemMeta(correctionim);
  828.  
  829. ItemStack cancel = new ItemStack(Material.REDSTONE_BLOCK, 1);
  830. ItemMeta cancelim = cancel.getItemMeta();
  831. cancelim.setDisplayName(ChatColor.RED + "Cancel");
  832. cancel.setItemMeta(cancelim);
  833.  
  834.  
  835. ItemStack[] numbpad = new ItemStack[9];
  836. ItemStack numpad0 = new ItemStack(Material.IRON_BLOCK, 1);
  837. for (int i = 0; i < numbpad.length; i++)
  838. {
  839. numbpad[i] = new ItemStack(Material.IRON_BLOCK, i + 1);
  840. ItemMeta im = numbpad[i].getItemMeta();
  841. im.setDisplayName(ChatColor.AQUA + "" + (i + 1));
  842. numbpad[i].setItemMeta(im);
  843. }
  844.  
  845. ItemMeta numpad0im = numpad0.getItemMeta();
  846. numpad0im.setDisplayName("§b0");
  847. numpad0.setItemMeta(numpad0im);
  848. inv.setItem(0, indexbaritem);
  849. inv.setItem(1, indexbaritem);
  850. inv.setItem(2, indexbaritem);
  851. inv.setItem(3, numbpad[0]);
  852. inv.setItem(4, numbpad[1]);
  853. inv.setItem(5, numbpad[2]);
  854. inv.setItem(6, indexbaritem);
  855. inv.setItem(7, indexbaritem);
  856. inv.setItem(8, indexbaritem);
  857. inv.setItem(9, indexbaritem);
  858. inv.setItem(10, indexbaritem);
  859. inv.setItem(11, indexbaritem);
  860. inv.setItem(12, numbpad[3]);
  861. inv.setItem(13, numbpad[4]);
  862. inv.setItem(14, numbpad[5]);
  863. inv.setItem(15, indexbaritem);
  864. inv.setItem(16, indexbaritem);
  865. inv.setItem(17, indexbaritem);
  866. inv.setItem(18, indexbaritem);
  867. inv.setItem(19, indexbaritem);
  868. inv.setItem(20, indexbaritem);
  869. inv.setItem(21, numbpad[6]);
  870. inv.setItem(22, numbpad[7]);
  871. inv.setItem(23, numbpad[8]);
  872. inv.setItem(24, indexbaritem);
  873. inv.setItem(25, indexbaritem);
  874. inv.setItem(26, indexbaritem);
  875. inv.setItem(27, indexbaritem);
  876. inv.setItem(28, indexbaritem);
  877. inv.setItem(29, indexbaritem);
  878. inv.setItem(30, numpad0);
  879. inv.setItem(31, numpad0);
  880. inv.setItem(32, numpad0);
  881. inv.setItem(33, indexbaritem);
  882. inv.setItem(34, indexbaritem);
  883. inv.setItem(35, indexbaritem);
  884. inv.setItem(36, ok);
  885. inv.setItem(37, ok);
  886. inv.setItem(38, ok);
  887. inv.setItem(39, correction);
  888. inv.setItem(40, correction);
  889. inv.setItem(41, correction);
  890. inv.setItem(42, cancel);
  891. inv.setItem(43, cancel);
  892. inv.setItem(44, cancel);
  893. inv.setItem(45, ok);
  894. inv.setItem(46, ok);
  895. inv.setItem(47, ok);
  896. inv.setItem(48, correction);
  897. inv.setItem(49, correction);
  898. inv.setItem(50, correction);
  899. inv.setItem(51, cancel);
  900. inv.setItem(52, cancel);
  901. inv.setItem(53, cancel);
  902. inv.setItem(54, indexbaritem);
  903. inv.setItem(55, indexbaritem);
  904. inv.setItem(56, indexbaritem);
  905. inv.setItem(57, indexbaritem);
  906. inv.setItem(58, sharditem);
  907. inv.setItem(59, indexbaritem);
  908. inv.setItem(60, indexbaritem);
  909. inv.setItem(61, indexbaritem);
  910. inv.setItem(62, indexbaritem);
  911. p.openInventory(inv);
  912.  
  913. }
  914.  
  915. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement