Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.lululombard.kingshop;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- import java.util.Enumeration;
- import java.util.Hashtable;
- import java.util.List;
- import java.util.Stack;
- import net.milkbowl.vault.economy.Economy;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.World;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Entity;
- import org.bukkit.entity.ItemFrame;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.EventPriority;
- import org.bukkit.event.Listener;
- import org.bukkit.event.entity.EntityDamageByEntityEvent;
- import org.bukkit.event.hanging.HangingBreakByEntityEvent;
- import org.bukkit.event.hanging.HangingBreakEvent;
- import org.bukkit.event.hanging.HangingPlaceEvent;
- import org.bukkit.event.inventory.InventoryClickEvent;
- import org.bukkit.event.player.PlayerInteractEntityEvent;
- import org.bukkit.inventory.Inventory;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.plugin.RegisteredServiceProvider;
- import org.bukkit.plugin.java.JavaPlugin;
- public class KingShop extends JavaPlugin implements Listener {
- private String url;
- private String user;
- private String passwd;
- private Connection sqlserver;
- String prefixchat = ChatColor.GOLD + "[KingShop] ";
- String shopname = ChatColor.DARK_RED + " ACHETER — KingShop — VENDRE";
- String prefixdiscount = ChatColor.AQUA + "" + ChatColor.ITALIC;
- String prefixprice = "" + ChatColor.GOLD;
- Material itemquit = Material.ANVIL;
- Material itemdisabled = Material.STICK;
- Stack<Location> ShopList = new Stack<Location>();
- Hashtable<UniqueItem, Prices> ItemPrices = new Hashtable<UniqueItem, Prices>();
- Hashtable<Player, Integer> Cooldown = new Hashtable<Player, Integer>();
- private String commandprefix = "ks";
- private boolean debug = false;
- public static Economy econ = null;
- public void onEnable() {
- if (!setupEconomy()) {
- getLogger().info("Vault not found. Disabling.");
- getServer().getPluginManager().disablePlugin(this);
- return;
- }
- this.getServer().getPluginManager().registerEvents(this, this);
- this.saveDefaultConfig();
- url = "jdbc:mysql://" + this.getConfig().getString("mysql-host") + ":" + this.getConfig().getString("mysql-port")+ "/" + this.getConfig().getString("mysql-db");
- user = this.getConfig().getString("mysql-user");
- passwd = this.getConfig().getString("mysql-password");
- if (!connect()) {
- getLogger().info("MySQL failed. Disabling.");
- getServer().getPluginManager().disablePlugin(this);
- return;
- }
- new Thread(new Runnable() {
- public void run() {
- try {
- Thread.sleep(5000);
- ActuPrice();
- ActuShop();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }).start();
- }
- private 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 boolean onCommand(final CommandSender sender, Command cmd, String label, String[] args) {
- if (cmd.getName().equalsIgnoreCase(commandprefix)) {
- Player player = null;
- if (sender instanceof Player) {
- player = (Player) sender;
- }
- String option = "null";
- if (args.length >= 1) option = args[0];
- if (option.equalsIgnoreCase("ramlist")) {
- if (!(sender instanceof Player) ||player.hasPermission("ks.ramlist")||player.hasPermission("ks.admin")||player.hasPermission("ks.*")||player.hasPermission("*")) {
- if (sender instanceof Player) player.sendMessage(ChatColor.GOLD + "Liste des shops : ");
- else getLogger().info("Liste des shops : ");
- for (Location frame : ShopList) {
- if (sender instanceof Player) player.sendMessage(ChatColor.GREEN + "World: " +frame.getWorld().getName() + " X: " + frame.getBlockX() + " Y: " + frame.getBlockY() + " Z: " + frame.getBlockZ() + " Yaw: " +frame.getYaw());
- else getLogger().info("World: " + frame.getWorld().getName() + " X: " +frame.getBlockX() + " Y: " + frame.getBlockY() + " Z: " + frame.getBlockZ() + " Yaw: " + frame.getYaw());
- }
- }
- else player.sendMessage(prefixchat + ChatColor.RED + "Vous n'avez pas la permission de faire cela.");
- }
- else if (option.equalsIgnoreCase("bddlist")) {
- if (!(sender instanceof Player) ||player.hasPermission("ks.bddlist")||player.hasPermission("ks.admin")||player.hasPermission("ks.*")||player.hasPermission("*")) {
- if (sender instanceof Player) player.sendMessage(ChatColor.GOLD + "Liste des shops : ");
- else getLogger().info("Liste des shops : ");
- final Player finalplayer = player;
- new Thread(new Runnable() {
- public void run() {
- try {
- Statement querry = sqlserver.createStatement();
- ResultSet result;
- result = querry.executeQuery("SELECT * FROM `kingshop_list`");
- ShopList.clear();
- while (result.next()) {
- if (sender instanceof Player)finalplayer.sendMessage(ChatColor.GREEN + "World: " + result.getString("world") + " X: " + result.getInt("x") + " Y: " +result.getInt("y") + " Z: " + result.getInt("z") + " Yaw: " + result.getInt("facing"));
- else getLogger().info("World: " +result.getString("world") + " X: " + result.getInt("x") + " Y: " + result.getInt("y") + " Z: " + result.getInt("z") + " Yaw: " +result.getInt("facing"));
- }
- querry.close();
- }
- catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }).start();
- }
- else player.sendMessage(prefixchat + ChatColor.RED + "Vous n'avez pas la permission de faire cela.");
- }
- else if (option.equalsIgnoreCase("syncshop")) {
- if (!(sender instanceof Player) ||player.hasPermission("ks.syncshop")||player.hasPermission("ks.admin")||player.hasPermission("ks.*")||player.hasPermission("*")) {
- final Player finalplayer = player;
- new Thread(new Runnable() {
- public void run() {
- if (sender instanceof Player) finalplayer.sendMessage(prefixchat +ChatColor.YELLOW + "Lancement de la synchro...");
- else getLogger().info("Lancement de la synchro...");
- ActuShop();
- if (sender instanceof Player) finalplayer.sendMessage(prefixchat +ChatColor.GREEN + "La liste des shops a été rechargée.");
- else getLogger().info("La liste des shops a été rechargée.");
- }
- }).start();
- }
- else player.sendMessage(prefixchat + ChatColor.RED + "Vous n'avez pas la permission de faire cela.");
- }
- else if (option.equalsIgnoreCase("syncprice")) {
- if (!(sender instanceof Player) ||player.hasPermission("ks.syncprice")||player.hasPermission("ks.admin")||player.hasPermission("ks.*")||player.hasPermission("*")) {
- final Player finalplayer = player;
- new Thread(new Runnable() {
- public void run() {
- if (sender instanceof Player) finalplayer.sendMessage(prefixchat +ChatColor.YELLOW + "Lancement de la synchro...");
- else getLogger().info("Lancement de la synchro...");
- ActuPrice();
- if (sender instanceof Player) finalplayer.sendMessage(prefixchat +ChatColor.GREEN + "La liste des prix a été rechargée.");
- else getLogger().info("La liste des prix a été rechargée.");
- }
- }).start();
- }
- else player.sendMessage(prefixchat + ChatColor.RED + "Vous n'avez pas la permission de faire cela.");
- }
- else {
- if (sender instanceof Player) {
- player.sendMessage(ChatColor.YELLOW + "-------" + ChatColor.WHITE + " KingShop " +ChatColor.YELLOW + "-------");
- player.sendMessage(ChatColor.GOLD + "/" + commandprefix + " ramlist" + ChatColor.YELLOW +" : " + ChatColor.WHITE + "Liste les shops chargés en RAM");
- player.sendMessage(ChatColor.GOLD + "/" + commandprefix + " bddlist" + ChatColor.YELLOW +" : " + ChatColor.WHITE + "Liste les shops depuis la base de données");
- player.sendMessage(ChatColor.GOLD + "/" + commandprefix + " syncshop" + ChatColor.YELLOW +" : " + ChatColor.WHITE + "Recharge les shops depuis la base de données");
- player.sendMessage(ChatColor.GOLD + "/" + commandprefix + " syncprice" + ChatColor.YELLOW+ " : " + ChatColor.WHITE + "Recharge les prix depuis la base de données");
- }
- else {
- getLogger().info(ChatColor.YELLOW + "------- KingShop -------");
- getLogger().info("/" + commandprefix + " ramlist : Liste les shops chargés en RAM");
- getLogger().info("/" + commandprefix + " bddlist : Liste les shops depuis la base de données");
- getLogger().info("/" + commandprefix + " syncshop : Recharge les shops depuis la base de données");
- getLogger().info("/" + commandprefix + " syncprice : Recharge les prix depuis la base de données");
- }
- }
- return true;
- }
- else return false;
- }
- @EventHandler (priority = EventPriority.MONITOR)
- public void onItemFramePlace(final HangingPlaceEvent e) {
- if (!e.isCancelled() && e.getEntity().getType().name().equals("ITEM_FRAME")) {
- final Player player = e.getPlayer();
- final int x = e.getEntity().getLocation().getBlockX();
- final int y = e.getEntity().getLocation().getBlockY();
- final int z = e.getEntity().getLocation().getBlockZ();
- final int face = e.getEntity().getFacing().ordinal();
- List<Entity> worldentities = e.getPlayer().getWorld().getEntities();
- int xlist;
- int ylist;
- int zlist;
- int facelist;
- Boolean framepresent = false;
- for (Entity entity: worldentities) {
- if (entity.getType().name().equals("ITEM_FRAME")) {
- xlist = entity.getLocation().getBlockX();
- ylist = entity.getLocation().getBlockY();
- zlist = entity.getLocation().getBlockZ();
- facelist = (int) entity.getLocation().getYaw();
- if (xlist==x&&ylist==y&&zlist==z&&facelist==face) framepresent = true;
- }
- }
- if (framepresent) {
- player.sendMessage(ChatColor.RED + "Il y a déjà une entité sur ce bloc.");
- e.setCancelled(true);
- }
- }
- }
- @EventHandler (priority = EventPriority.MONITOR)
- public void onItemFrameUse(final PlayerInteractEntityEvent e) {
- if (e.getRightClicked().getType().name().equals("ITEM_FRAME")) {
- final Player player = e.getPlayer();
- if (debug) getLogger().info(player.getName() + " used itemframe");
- World world = e.getRightClicked().getLocation().getWorld();
- int x = e.getRightClicked().getLocation().getBlockX();
- int y = e.getRightClicked().getLocation().getBlockY();
- int z = e.getRightClicked().getLocation().getBlockZ();
- int face = (int) e.getRightClicked().getLocation().getYaw();
- ItemFrame iframe = (ItemFrame) e.getRightClicked();
- if (player.isSneaking() && (player.hasPermission("ks.*") || player.hasPermission("ks.admin") ||player.hasPermission("ks.create"))) {
- if (!IsShop(world, x, y, z, face) && player.isSneaking()) {
- e.setCancelled(true);
- CreateShop(world, x, y, z, face, player);
- if (player.getItemInHand().getType()!=Material.AIR && iframe.isEmpty())iframe.setItem(player.getItemInHand());
- }
- }
- else if (IsShop(world, x, y, z, face)) {
- e.setCancelled(true);
- UseShop(world, x, y, z, face, player, iframe);
- }
- }
- }
- @EventHandler (priority = EventPriority.MONITOR)
- public void onItemFrameRemove(final EntityDamageByEntityEvent e) {
- final String entityname = e.getEntity().getType().name();
- if (!e.isCancelled() && entityname.equals("ITEM_FRAME")) {
- World world = e.getEntity().getWorld();
- int x = e.getEntity().getLocation().getBlockX();
- int y = e.getEntity().getLocation().getBlockY();
- int z = e.getEntity().getLocation().getBlockZ();
- int face = (int) e.getEntity().getLocation().getYaw();
- ItemFrame iframe = (ItemFrame) e.getEntity();
- if (IsShop(world, x, y, z, face)) {
- if (e.getCause().toString().equals("ENTITY_ATTACK")) {
- Player player = ((Player) e.getDamager());
- if (player.isSneaking() && (player.hasPermission("ks.*") ||player.hasPermission("ks.admin") || player.hasPermission("ks.delete"))) {
- DelShop(world, x, y, z, face, player);
- }
- else {
- e.setCancelled(true);
- UseShop(world, x, y, z, face, player, iframe);
- }
- }
- else e.setCancelled(true);
- }
- }
- }
- @EventHandler (priority = EventPriority.MONITOR)
- public void onItemFrameBreak(final HangingBreakEvent e) {
- final String entityname = e.getEntity().getType().name();
- if (!e.isCancelled() && entityname.equals("ITEM_FRAME")) {
- if (e instanceof HangingBreakByEntityEvent) {
- final HangingBreakByEntityEvent evt = (HangingBreakByEntityEvent) e;
- if (evt.getRemover() instanceof Player) {
- final Player player = ((Player) evt.getRemover());
- World world = e.getEntity().getWorld();
- int x = e.getEntity().getLocation().getBlockX();
- int y = e.getEntity().getLocation().getBlockY();
- int z = e.getEntity().getLocation().getBlockZ();
- int face = (int) e.getEntity().getLocation().getYaw();
- ItemFrame iframe = (ItemFrame) e.getEntity();
- if (player.isSneaking() && (player.hasPermission("ks.*") ||player.hasPermission("ks.admin") || player.hasPermission("ks.delete"))) DelShop(world, x, y, z, face, player);
- else if (IsShop(world, x, y, z, face)) {
- e.setCancelled(true);
- UseShop(world, x, y, z, face, player, iframe);
- }
- }
- }
- }
- }
- @EventHandler
- public void onInventoryClick(InventoryClickEvent e) {
- if (e.getCurrentItem() == null) return;
- String currency = econ.currencyNamePlural();
- Player player = (Player) e.getWhoClicked();
- Inventory inventory = e.getInventory();
- if (inventory.getName().equals(shopname)) {
- ItemStack clicked = e.getCurrentItem();
- if (clicked.getType() == itemquit) {
- e.setCancelled(true);
- player.closeInventory();
- }
- else if (clicked.getType() != Material.AIR) {
- e.setCancelled(true);
- player.closeInventory();
- ItemMeta clM = clicked.getItemMeta();
- Boolean isASell = false;
- if (clM.getDisplayName().substring(6, 7).equals("V")) isASell = true;
- List<String> lore = clM.getLore();
- String nom = "";
- for (String thislore : lore) if (thislore.contains("Nom : ")) nom = thislore.replace("Nom : ", "");
- clM.setLore(null);
- clM.setDisplayName(nom);
- clicked.setItemMeta(clM);
- int amount = clicked.getAmount();
- if (debug) getLogger().info(clicked.getData().toString() + " | " +clicked.getItemMeta().toString() + " * " + clicked.getAmount());
- String data = clicked.getData().toString();
- String meta = clicked.getItemMeta().toString();
- UniqueItem ItemofShop = new UniqueItem(data, meta);
- double unitSellPrice = 0;
- double stackDiscountSell = 0;
- double unitBuyPrice = Double.MAX_VALUE/64;
- double stackDiscountBuy = 0;
- boolean isConfigured = false;
- Enumeration<UniqueItem> allPrices = ItemPrices.keys();
- while(allPrices.hasMoreElements()) {
- UniqueItem key = allPrices.nextElement();
- if (key.GetData().equals(ItemofShop.GetData()) &&key.GetItemMeta().equals(ItemofShop.GetItemMeta())) {
- isConfigured = true;
- unitSellPrice = ItemPrices.get(key).GetUnitSellPrice();
- stackDiscountSell = ItemPrices.get(key).GetDiscountSell();
- unitBuyPrice = ItemPrices.get(key).GetUnitBuyPrice();
- stackDiscountBuy = ItemPrices.get(key).GetDiscountBuy();
- break;
- }
- }
- if (!isConfigured) return;
- clM.setDisplayName("");
- clicked.setItemMeta(clM);
- if (isASell) {
- data = clicked.getData().toString();
- meta = clicked.getItemMeta().toString();
- double price = unitSellPrice;
- if (amount == 32 && stackDiscountSell < 50 && clicked.getMaxStackSize()*64>36) price +=price * stackDiscountSell / 100;
- if (amount == 64 && stackDiscountSell < 50) price += price * stackDiscountSell / 100;
- if (!player.getInventory().contains(clicked.getType())) player.sendMessage(prefixchat +ChatColor.RED + "Il semble que vous n'ayez pas l'item demandé.");
- else {
- int quantityininv = 0;
- for (ItemStack invItem : player.getInventory()) if (invItem != null) {
- getLogger().info("clicked = " + clicked.getData().toString() + " | " +clicked.getItemMeta().toString() + " * " + clicked.getAmount());
- if (invItem.getData().toString().equals(data) &&invItem.getItemMeta().toString().equals(meta)) {
- getLogger().info("found = " + invItem.getData().toString() + " | "+ invItem.getItemMeta().toString() + " * " + invItem.getAmount());
- quantityininv += invItem.getAmount();
- }
- }
- if (quantityininv >= amount) {
- ItemStack soldItem = clicked;
- soldItem.setAmount(amount);
- player.getInventory().removeItem(soldItem);
- econ.depositPlayer(player, price*amount);
- double displayAmount = (double)Math.round(price*amount * 100) / 100;
- player.sendMessage(prefixchat + ChatColor.GREEN + "Merci de votre vente ! " + displayAmount + " " + currency + " ont été ajoutés à votre compte. Au plaisir de vous revoir chez KingShop !");
- getLogger().info(player.getName() + " sold " + amount + " " +soldItem.toString() + " for " + (price*amount));
- }
- else player.sendMessage(prefixchat + ChatColor.RED + "Vous n'avez pas l'item demandé en quantité suffisante ou les enchantements/durabilités ne sont pas identiques.");
- }
- }
- else {
- double price = unitBuyPrice;
- if (amount == 64 && stackDiscountBuy < 50) price -= price * stackDiscountBuy / 100;
- if (player.getInventory().firstEmpty()==-1) player.sendMessage(prefixchat + ChatColor.RED+ "Votre inventaire est plein, veuillez le vider et revenir pour faire la transaction ;)");
- else {
- if (econ.has(player, price*amount)) {
- econ.withdrawPlayer(player, price*amount);
- double displayAmount = (double)Math.round(price*amount * 100) / 100;
- player.getInventory().addItem(clicked);
- player.sendMessage(prefixchat + ChatColor.GREEN + "Merci de votre achat ! " + displayAmount + " " + currency + " ont été débités de votre compte. Au plaisir de vous revoir chez KingShop !");
- getLogger().info(player.getName() + " buyed " + amount + " " +clicked.toString() + " for " + (price*amount));
- }
- else player.sendMessage(prefixchat + ChatColor.RED + "Vous n'avez pas l'argent necessaire pour vous payer cela :(");
- }
- }
- }
- }
- }
- public void UseShop(World world, int x, int y, int z, int face, Player player, ItemFrame iframe) {
- int ActualTime = (int) (System.currentTimeMillis() / 1000);
- if (debug) getLogger().info("Cd " + player.getName() + " Cooldown : " + Cooldown.get(player) + " Actu: " +ActualTime);
- if (Cooldown.containsKey(player) && Cooldown.get(player)>=(ActualTime)) {
- return;
- }
- else {
- Cooldown.remove(player);
- Cooldown.put(player, ActualTime);
- }
- String currency = econ.currencyNamePlural();
- if (debug) getLogger().info(player.getName() + " open shop at X" + x + " Y" + y + " Z" + z + " facing " + face + " at " + world.getName());
- if (iframe.getItem().getType()==Material.AIR) {
- player.sendMessage(prefixchat + ChatColor.RED + "Ce shop est vide, veuillez contacter un opérateur ou un administrateur.");
- }
- else if (iframe.getItem().getType()==itemquit) {
- player.sendMessage(prefixchat + ChatColor.RED + "Les " + itemquit.toString().toLowerCase() + " ne sont pas disponibles à la vente.");
- }
- else {
- final String data = iframe.getItem().getData().toString();
- final String meta = iframe.getItem().getItemMeta().toString();
- UniqueItem ItemofShop = new UniqueItem(data, meta);
- double unitSellPrice = 0;
- double stackDiscountSell = 0;
- double unitBuyPrice = Double.MAX_VALUE/64;
- double stackDiscountBuy = 0;
- boolean isConfigured = false;
- Enumeration<UniqueItem> allPrices = ItemPrices.keys();
- while(allPrices.hasMoreElements()) {
- UniqueItem key = allPrices.nextElement();
- if (key.GetData().equals(ItemofShop.GetData()) &&key.GetItemMeta().equals(ItemofShop.GetItemMeta())) {
- isConfigured = true;
- unitSellPrice = ItemPrices.get(key).GetUnitSellPrice();
- stackDiscountSell = ItemPrices.get(key).GetDiscountSell();
- unitBuyPrice = ItemPrices.get(key).GetUnitBuyPrice();
- stackDiscountBuy = ItemPrices.get(key).GetDiscountBuy();
- break;
- }
- }
- if (isConfigured) {
- boolean isMaxSell = false;
- Inventory inventory = Bukkit.getServer().createInventory(null, 9, shopname);
- List<String> Lore = new ArrayList<String>();
- ItemStack quit = new ItemStack(itemquit, 1);
- ItemMeta isM = quit.getItemMeta();
- isM.setDisplayName("" + ChatColor.RESET + ChatColor.DARK_RED + ChatColor.ITALIC + "Quitter le shop");
- quit.setItemMeta(isM);
- ItemStack disabled = new ItemStack(itemdisabled, 1);
- isM = disabled.getItemMeta();
- isM.setDisplayName("" + ChatColor.RESET + ChatColor.DARK_RED + ChatColor.BOLD + "Non disponible");
- disabled.setItemMeta(isM);
- ItemStack buy1 = iframe.getItem();
- buy1.setAmount(1);
- isM = buy1.getItemMeta();
- Lore.clear();
- Lore.add(prefixprice + (double)Math.round(unitBuyPrice * 1 * 100) / 100 + " " + currency);
- if (buy1.getItemMeta().hasDisplayName()) Lore.add("Nom : " + buy1.getItemMeta().getDisplayName());
- isM.setLore(Lore);
- isM.setDisplayName("" + ChatColor.RESET + ChatColor.GREEN + ChatColor.BOLD + "Acheter à l'unité");
- buy1.setItemMeta(isM);
- ItemStack buy16 = iframe.getItem();
- buy16.setAmount(16);
- isM = buy16.getItemMeta();
- Lore.clear();
- Lore.add(prefixprice + (double)Math.round(unitBuyPrice * 16 * 100) / 100 + " " + currency);
- isM.setLore(Lore);
- isM.setDisplayName("" + ChatColor.RESET + ChatColor.GREEN + ChatColor.BOLD + "Acheter 16 unités");
- if (buy16.getItemMeta().hasDisplayName()) Lore.add("Nom : " +buy16.getItemMeta().getDisplayName());
- buy16.setItemMeta(isM);
- ItemStack buy32 = iframe.getItem();
- buy32.setAmount(32);
- isM = buy32.getItemMeta();
- Lore.clear();
- Lore.add(prefixprice + (double)Math.round(unitBuyPrice * 32 * 100) / 100 + " " + currency);
- isM.setLore(Lore);
- isM.setDisplayName("" + ChatColor.RESET + ChatColor.GREEN + ChatColor.BOLD + "Acheter un demi stack");
- if (buy32.getItemMeta().hasDisplayName()) Lore.add("Nom : " +buy32.getItemMeta().getDisplayName());
- buy32.setItemMeta(isM);
- ItemStack buy64 = iframe.getItem();
- buy64.setAmount(64);
- isM = buy64.getItemMeta();
- Lore.clear();
- double priceStackBuy = unitBuyPrice*64;
- if (stackDiscountBuy > 0 && stackDiscountBuy < 50) priceStackBuy -= priceStackBuy *stackDiscountBuy / 100;
- priceStackBuy = (double)Math.round(priceStackBuy * 100) / 100;
- Lore.add(prefixprice + priceStackBuy + " " + currency);
- if (buy64.getItemMeta().hasDisplayName()) Lore.add("Nom : " +buy64.getItemMeta().getDisplayName());
- if (stackDiscountBuy > 0 && stackDiscountBuy < 50) {
- Lore.add(prefixdiscount + "Réduction de " + stackDiscountBuy + "% pour le stack");
- Lore.add(prefixdiscount + "(Prix initial : " + (double)Math.round(unitBuyPrice * 64 * 100)/ 100 + " " + currency + ")");
- }
- isM.setLore(Lore);
- isM.setDisplayName("" + ChatColor.RESET + ChatColor.GREEN + ChatColor.BOLD + "Acheter un stack");
- buy64.setItemMeta(isM);
- ItemStack sell1 = iframe.getItem();
- sell1.setAmount(1);
- isM = sell1.getItemMeta();
- Lore.clear();
- Lore.add(prefixprice + (double)Math.round(unitSellPrice * 1 * 100) / 100 + " " + currency);
- if (sell1.getItemMeta().hasDisplayName()) Lore.add("Nom : " +sell1.getItemMeta().getDisplayName());
- isM.setLore(Lore);
- isM.setDisplayName("" + ChatColor.RESET + ChatColor.GREEN + ChatColor.BOLD + "Vendre à l'unité");
- sell1.setItemMeta(isM);
- ItemStack sell16 = iframe.getItem();
- sell16.setAmount(16);
- isM = sell16.getItemMeta();
- Lore.clear();
- Lore.add(prefixprice + (double)Math.round(unitSellPrice * 16 * 100) / 100 + " " + currency);
- if (sell16.getItemMeta().hasDisplayName()) Lore.add("Nom : " +sell16.getItemMeta().getDisplayName());
- isM.setLore(Lore);
- isM.setDisplayName("" + ChatColor.RESET + ChatColor.GREEN + ChatColor.BOLD + "Vendre 16 unités");
- sell16.setItemMeta(isM);
- ItemStack sell32 = iframe.getItem();
- sell32.setAmount(32);
- isM = sell32.getItemMeta();
- Lore.clear();
- Lore.add(prefixprice + (double)Math.round(unitSellPrice * 32 * 100) / 100 + " " + currency);
- if (sell32.getItemMeta().hasDisplayName()) Lore.add("Nom : " +sell32.getItemMeta().getDisplayName());
- if (!isMaxSell && iframe.getItem().getMaxStackSize()<2 && stackDiscountSell > 0 &&stackDiscountSell < 50) {
- double priceHalfStackSell = unitSellPrice*32;
- if (stackDiscountSell > 0 && stackDiscountSell < 50) priceHalfStackSell +=priceHalfStackSell * stackDiscountSell / 100;
- Lore.clear();
- Lore.add(prefixprice + (double)Math.round(priceHalfStackSell * 100) / 100 + " " +currency);
- isMaxSell = true;
- Lore.add(prefixdiscount + "Rajout de " + stackDiscountSell + "% pour le demi-stack");
- Lore.add(prefixdiscount + "(Prix initial : " + (double)Math.round(unitSellPrice * 32 *100) / 100 + " " + currency + ")");
- }
- isM.setLore(Lore);
- isM.setDisplayName("" + ChatColor.RESET + ChatColor.GREEN + ChatColor.BOLD + "Vendre un demi-stack");
- sell32.setItemMeta(isM);
- ItemStack sell64 = iframe.getItem();
- sell64.setAmount(64);
- isM = sell64.getItemMeta();
- isM.setDisplayName("" + ChatColor.RESET + ChatColor.GREEN + ChatColor.BOLD + "Vendre un stack");
- Lore.clear();
- double priceStackSell = unitSellPrice*64;
- if (stackDiscountSell > 0 && stackDiscountSell < 50) priceStackSell += priceStackSell *stackDiscountSell / 100;
- priceStackSell = (double)Math.round(priceStackSell * 100) / 100;
- Lore.add(prefixprice + priceStackSell + " " + currency);
- if (sell64.getItemMeta().hasDisplayName()) Lore.add("Nom : " +sell64.getItemMeta().getDisplayName());
- if (!isMaxSell && stackDiscountSell > 0 && stackDiscountSell < 50) {
- Lore.add(prefixdiscount + "Rajout de " + stackDiscountSell + "% pour le stack");
- Lore.add(prefixdiscount + "(Prix initial : " + (double)Math.round(unitSellPrice * 64 *100) / 100 + " " + currency + ")");
- }
- isM.setLore(Lore);
- sell64.setItemMeta(isM);
- if (iframe.getItem().getMaxStackSize()<16) buy16 = disabled;
- if (iframe.getItem().getMaxStackSize()<32) buy32 = disabled;
- if (iframe.getItem().getMaxStackSize()<64) buy64 = disabled;
- if (iframe.getItem().getMaxStackSize()<2) {
- if (iframe.getItem().getMaxStackSize()*16>36) sell16 = disabled;
- if (iframe.getItem().getMaxStackSize()*32>36) sell32 = disabled;
- if (iframe.getItem().getMaxStackSize()*64>36) sell64 = disabled;
- }
- inventory.setItem(0, buy1);
- inventory.setItem(1, buy16);
- inventory.setItem(2, buy32);
- inventory.setItem(3, buy64);
- inventory.setItem(4, quit);
- inventory.setItem(5, sell1);
- inventory.setItem(6, sell16);
- inventory.setItem(7, sell32);
- inventory.setItem(8, sell64);
- player.openInventory(inventory);
- }
- else {
- if (player.hasPermission("ks.*") || player.hasPermission("ks.admin") ||player.hasPermission("ks.create")) {
- player.sendMessage(prefixchat + ChatColor.YELLOW + "Informations pour configurer le shop : ");
- player.sendMessage(ChatColor.GOLD + "Data : " + ChatColor.GREEN + data);
- player.sendMessage(ChatColor.GOLD + "Meta : " + ChatColor.GREEN + meta);
- }
- player.sendMessage(prefixchat + ChatColor.RED + "Les prix de ce shop n'ont pas été fixés. Contactez un opérateur ou un administrateur pour qu'il le fasse.");
- new Thread(new Runnable() {
- public void run() {
- try {
- Statement querry = sqlserver.createStatement();
- querry.executeUpdate("INSERT INTO `kingshop_prices` (`data`, `meta`) VALUES ('" + data + "', '" + meta + "') ON DUPLICATE KEY UPDATE data=data;");
- querry.close();
- }
- catch (SQLException e1) {
- e1.printStackTrace();
- }
- }
- }).start();
- }
- }
- }
- public void DelShop(final World world, final int x, final int y, final int z, final int face, final Player player) {
- if (debug) getLogger().info(player.getName() + " deleted shop at X" + x + " Y" + y + " Z" + z + " facing " + face + " at " + world.getName());
- new Thread(new Runnable() {
- public void run() {
- try {
- Statement querry = sqlserver.createStatement();
- querry.executeUpdate("DELETE FROM `kingshop_list` WHERE `world` = '" + world.getName() +"' AND `x` = '" + x + "' AND `y` = '" + y + "' AND `z` = '" + z + "' AND `facing` ='" + face + "';");
- ShopList.remove(new Location(world, x, y, z, face, 0));
- player.sendMessage(prefixchat + ChatColor.GREEN + "Le shop a bien été supprimé.");
- querry.close();
- } catch (SQLException e1) {
- e1.printStackTrace();
- connect();
- }
- }
- }).start();
- }
- public void CreateShop(final World world, final int x, final int y, final int z, final int face, final Player player) {
- if (debug) getLogger().info(player.getName() + " created shop at X" + x + " Y" + y + " Z" + z + " facing " + face + " at " + world.getName());
- new Thread(new Runnable() {
- public void run() {
- try {
- Statement querry = sqlserver.createStatement();
- querry.executeUpdate("INSERT INTO `kingshop_list` (`world`, `x`, `y`, `z`, `facing`) VALUES ('" + world.getName() + "', '" + x + "', '" + y + "', '" + z + "', '" + face + "');");
- ShopList.add(new Location(world, x, y, z, face, 0));
- player.sendMessage(prefixchat + ChatColor.GREEN + "Le shop a bien été créé.");
- querry.close();
- } catch (SQLException e1) {
- }
- }
- }).start();
- }
- public boolean IsShop(World world, int x, int y, int z, int face) {
- if (debug) getLogger().info("Someone asked if shop at X" + x + " Y" + y + " Z" + z + " facing " + face + " at " +world.getName());
- if (ShopList.contains(new Location(world, x, y, z, face, 0))) return true;
- else return false;
- }
- public void ActuShop() {
- try {
- Statement querry = sqlserver.createStatement();
- ResultSet result;
- result = querry.executeQuery("SELECT * FROM `kingshop_list`");
- ShopList.clear();
- while (result.next()) {
- World world = Bukkit.getServer().getWorld(result.getString("world"));
- int x = result.getInt("x");
- int y = result.getInt("y");
- int z = result.getInt("z");
- int facing = result.getInt("facing");
- ShopList.add(new Location(world, x, y, z, facing, 0));
- }
- querry.close();
- }
- catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public void ActuPrice() {
- try {
- Statement querry = sqlserver.createStatement();
- ResultSet result;
- result = querry.executeQuery("SELECT * FROM `kingshop_prices` WHERE `buy_unit` IS NOT NULL AND `buy_percent` IS NOT NULL AND `sell_unit` IS NOT NULL AND `sell_percent` IS NOT NULL");
- ItemPrices.clear();
- while (result.next()) ItemPrices.put(new UniqueItem(result.getString("data"), result.getString("meta")), new Prices(result.getDouble("sell_unit"), result.getDouble("sell_percent"), result.getDouble("buy_unit"), result.getDouble("buy_percent")));
- querry.close();
- }
- catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public boolean connect() {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- }
- catch (ClassNotFoundException e1) {
- e1.printStackTrace();
- }
- try {
- sqlserver = DriverManager.getConnection(url, user, passwd);
- getLogger().info("MySQL connexion okay !");
- try {
- Statement querry = sqlserver.createStatement();
- querry.executeUpdate("CREATE TABLE IF NOT EXISTS `kingshop_list` (`world` VARCHAR(250) NOT NULL, `x` INT(17) NOT NULL, `y` INT(17) NOT NULL, `z` INT(17) NOT NULL, `facing` INT(9) UNSIGNED NOT NULL, UNIQUE INDEX `coords` (`world`, `x`, `y`, `z`, `facing`));");
- querry.executeUpdate("CREATE TABLE IF NOT EXISTS `kingshop_prices` (`data` VARCHAR(100) NOT NULL, `meta` VARCHAR(250) NOT NULL, `buy_unit` DOUBLE UNSIGNED NULL DEFAULT NULL, `buy_percent` DOUBLE UNSIGNED NULL DEFAULT NULL, `sell_unit` DOUBLE UNSIGNED NULL DEFAULT NULL, `sell_percent` DOUBLE UNSIGNED NULL DEFAULT NULL, UNIQUE INDEX `material_data` (`data`, `meta`));");
- querry.close();
- return true;
- }
- catch(SQLException e){
- e.printStackTrace();
- }
- }
- catch (SQLException e) {
- getLogger().info("MySQL failed, please check config.yml");
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement