Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.core.mayodwarf.pokeballers.shop;
- import net.milkbowl.vault.economy.Economy;
- import org.bukkit.ChatColor;
- import org.bukkit.block.Sign;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.inventory.InventoryAction;
- import org.bukkit.event.inventory.InventoryClickEvent;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.plugin.RegisteredServiceProvider;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.entity.Player;
- import java.util.List;
- /**
- * Created with IntelliJ IDEA.
- * User: MayoDwarf
- * Date: 1/31/14
- * Time: 5:27 PM
- * To change this template use File | Settings | File Templates.
- */
- @SuppressWarnings("unchecked")
- public class Main extends JavaPlugin implements Listener {
- public FileConfiguration config;
- public static Economy economy= null;
- private Shop shop;
- public void onEnable() {
- this.saveDefaultConfig();
- shop = new Shop(this);
- getServer().getPluginManager().registerEvents(this, this);
- setupEconomy();
- }
- public void onDisable() {}
- /* [1/31/14, 7:43:44 PM] [Developer] Jared: You type /shop and it opens up a gui with different shops you guys can make with commands. To add the items you do
- * "/shop <name> add <price> <buy or sell>" and that will add the item in your hand with right amount and enchantments and stuff and
- * if it is buy or sell with the price you specify.
- *
- * [1/31/14, 7:44:56 PM] [Developer] Jared: Add a new shop "/shop new <name>".
- * They wouldn't be able to use a shop without the permission "Shop.use.<name of shop>"
- */
- public boolean setupEconomy()
- {
- RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
- if (economyProvider != null) {
- economy = economyProvider.getProvider();
- }
- return (economy != null);
- }
- public boolean onCommand (CommandSender sender, Command cmd, String commandLabel, String[] args) {
- Player p = (Player) sender;
- if(cmd.getName().equalsIgnoreCase("setLore")) {
- if(p.hasPermission("Shops.setlore")) {
- StringBuilder sb = new StringBuilder("");
- for(String strings : args) {
- sb.append(strings).append(" ");
- }
- String words = sb.toString();
- shop.setLore(p.getItemInHand(), words, p);
- }
- }
- if (cmd.getName().equalsIgnoreCase("shop")) {
- if (args.length == 0) {
- if (p.hasPermission("Shops.Admin")) {
- shop.openShopMenu(p);
- }
- }
- if (args.length == 1) {
- //If the args is a shop name
- List<String> list = (List<String>) getConfig().getList("Shops");
- for (String strings : list) {
- if (args[0].equals(strings)) {
- //Open up the args[0] shop
- if (p.hasPermission("Shops.use."+strings)) {
- shop.openShop(args[0], (Player)sender);
- }
- }
- }
- if (args[0].equalsIgnoreCase("reload")) {
- if (p.hasPermission("Shops.Admin")) {
- shop.reloadCfg();
- p.sendMessage(ChatColor.RED+"The config has been reloaded for "+ChatColor.GOLD+"PokeballersShop"+ChatColor.RED+"!");
- }
- }
- if (args[0].equalsIgnoreCase("output")) {
- shop.outPut(p.getItemInHand());
- p.sendMessage(ChatColor.RED+"The output for "+ChatColor.GOLD+""+p.getItemInHand().getType().toString()+ChatColor.RED+" has been added!");
- }
- }
- if (args.length == 3) {
- if (args[0].equalsIgnoreCase("new")) {
- shop.newShop(args[1], p, args[2], p.getItemInHand());
- }
- }
- if (args.length == 3 || args.length == 4) {
- if (args[0].equalsIgnoreCase("add")) {
- if (p.hasPermission("Shops.Admin")) {
- p.sendMessage(ChatColor.RED+"Invalid arguments! Correct: ./shop add <shop> <buy/sell> <price> <spot>");
- }
- }
- }
- if (args.length == 5) {
- if (p.hasPermission("Shops.Admin")) {
- if (args[0].equalsIgnoreCase("add")) {
- if (args[2].equalsIgnoreCase("buy") || args[2].equalsIgnoreCase("sell")) {
- if (getConfig().getList("Shops").contains(args[1])) {
- shop.add(p.getItemInHand(), p, args[3], args[1], args[2], args[4]);
- //shop add <shop> <buy/sell> <price> <spot>
- // 0 1 2 3 4
- }
- }
- }
- }
- }
- }
- return true;
- }
- @EventHandler
- public void onInteract(PlayerInteractEvent evt) {
- if (evt.getClickedBlock().getState() instanceof Sign) {
- Sign sign = (Sign) evt.getClickedBlock().getState();
- if (ChatColor.stripColor(sign.getLine(0)).equals("PokeShop")) {
- List<String> list = (List<String>) getConfig().get("Shops");
- for (String strings : list) {
- if (ChatColor.stripColor(sign.getLine(1)).equalsIgnoreCase(strings)) {
- if (evt.getPlayer().hasPermission("Shops.use."+ChatColor.stripColor(sign.getLine(1)))) {
- evt.getPlayer().performCommand("shop "+ChatColor.stripColor(sign.getLine(1)));
- }
- }
- }
- }
- }
- }
- @EventHandler
- public void onClick(InventoryClickEvent evt) {
- Player p = (Player) evt.getWhoClicked();
- if (evt.getInventory().getTitle().toString().equalsIgnoreCase(ChatColor.AQUA+"Shops")) {
- //Shop gui
- evt.setCancelled(true);
- p.closeInventory();
- evt.setCancelled(true);
- shop.openShop(evt.getCurrentItem().getItemMeta().getDisplayName().toString(), p);
- }
- List<String> shops = (List<String>) getConfig().get("Shops");
- for(String strings : shops) {
- if (ChatColor.stripColor(evt.getInventory().getTitle().toString()).equalsIgnoreCase(strings)) {
- ItemStack item = evt.getCurrentItem();
- ItemMeta im = item.getItemMeta(); evt.setCancelled(true);
- if(im !=null) {
- String priceC = ChatColor.stripColor(im.getDisplayName());
- String priceD = priceC.replace("$", "");
- Integer price = Integer.parseInt(priceD);
- if(im.getLore().get(0) !=null) {
- String typeC = ChatColor.stripColor(im.getLore().get(0).toString());
- evt.setCancelled(true);
- if (typeC.equalsIgnoreCase("buy")) {
- ItemStack returnItem = null;
- for(ItemStack items: (List<ItemStack>) this.getConfig().getList("Outputs")){
- if(items.getType()==item.getType() && items.getDurability()==item.getDurability()){
- returnItem = items.clone();
- break;
- }
- }
- if(returnItem==null){ //No item found
- return;
- }
- int amount;
- switch(evt.getAction()){
- case PICKUP_ALL: amount = 1;
- case PICKUP_HALF: amount = 16;
- default:
- amount = 1;
- }
- if(!economy.has(p.getName(), price*amount)){
- p.sendMessage("You are a broke man nigga");
- return;
- }
- returnItem.setAmount(amount);
- p.getInventory().addItem(returnItem);
- /*if(economy.getBalance(p.getName()) >= price) {
- if(evt.getAction() == InventoryAction.PICKUP_ALL) {
- //Give them 1 of item
- for(ItemStack items : (List<ItemStack>) getConfig().getList("Outputs")) {
- if(!(items.getType() == item.getType()) && !(items.getDurability() == item.getDurability())) {
- p.getInventory().addItem(new ItemStack(item.getType(), 1, item.getDurability()));
- economy.withdrawPlayer(p.getName(), price);
- evt.setCancelled(true);
- break;
- } else if(items.getType() == item.getType() && items.getDurability() == item.getDurability()) {
- //Output adding 1
- List<ItemStack> outputs = (List<ItemStack>) getConfig().get("Outputs");
- for(ItemStack itemss : outputs) {
- if(itemss.getType() == item.getType() && itemss.getDurability() == item.getDurability()) {
- //Do stuff
- p.getInventory().addItem(itemss);
- evt.setCancelled(true);
- economy.withdrawPlayer(p.getName(), price);
- }
- }
- }
- }
- } else if(evt.getAction() == InventoryAction.PICKUP_HALF) {
- //Give them 16 of item
- for(ItemStack items : (List<ItemStack>) getConfig().getList("Outputs")) {
- if(!(items.getType() == item.getType()) && !(items.getDurability() == item.getDurability())) {
- for(int j=0;j<16;j++) {
- p.getInventory().addItem(item);
- }
- economy.withdrawPlayer(p.getName(), price*16);
- evt.setCancelled(true);
- break;
- } else if(item.getType() == items.getType() && item.getDurability() == items.getDurability()) {
- //Output adding 16
- List<ItemStack> outputs = (List<ItemStack>) getConfig().get("Outputs");
- for(ItemStack itemss : outputs) {
- if(itemss.getType() == item.getType() && itemss.getDurability() == item.getDurability()) {
- //Do stuff
- for(int i=0;i<16;i++) {
- p.getInventory().addItem(itemss);
- }
- evt.setCancelled(true);
- economy.withdrawPlayer(p.getName(), price*16);
- }
- }
- }
- }
- }
- } else {
- p.sendMessage(ChatColor.RED+"You do not have enough cash for this item!"); p.closeInventory(); evt.setCancelled(true);
- }*/
- } else
- if (typeC.equalsIgnoreCase("sell")) {
- if (p.getInventory().contains(new ItemStack(item.getType(), item.getDurability()))) {
- if(evt.getAction() == InventoryAction.PICKUP_ALL) {
- //Take 1
- p.getInventory().removeItem(item);
- evt.setCancelled(true);
- economy.depositPlayer(p.getName(), price);
- } else if(evt.getAction() == InventoryAction.PICKUP_HALF) {
- //Take 16 of them
- for(int d=0;d<16;d++) {
- p.getInventory().removeItem(item);
- }
- evt.setCancelled(true);
- economy.depositPlayer(p.getName(), price*16);
- }
- } else {
- p.sendMessage(ChatColor.RED+"You do not have enough of this item to sell!"); p.closeInventory();
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment