Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.38 KB | None | 0 0
  1. package de.lightShop.gui;
  2.  
  3. import java.sql.SQLException;
  4. import java.util.ArrayList;
  5. import java.util.Arrays;
  6. import java.util.List;
  7.  
  8. import org.bukkit.Material;
  9. import org.bukkit.configuration.file.FileConfiguration;
  10. import org.bukkit.entity.Player;
  11. import org.bukkit.event.Listener;
  12. import org.bukkit.inventory.ItemStack;
  13. import org.bukkit.inventory.meta.ItemMeta;
  14. import org.bukkit.scheduler.BukkitRunnable;
  15.  
  16. import de.lightShop.asyncMysql.AsyncMySQL;
  17. import de.lightShop.main.Main;
  18. import de.lightShop.mysql.sqlmanager;
  19. import de.lightShop.utils.serialize;
  20. import de.lightShop.utils.sounds;
  21.  
  22.  
  23. public class GuiAllItems implements Listener {
  24.    
  25.    
  26.     public static void createItemList(Player p) {
  27.        
  28.         List<String> ID = new ArrayList<String>();
  29.        
  30.         FileConfiguration c = Main.plugin.getConfig();
  31.        
  32.         String prefix = c.getString("messages.prefix").replace("&", "§");
  33.        
  34.         List<ClickItem> ciList = new ArrayList<ClickItem>();
  35.        
  36.         AsyncMySQL sqlID = new AsyncMySQL("localhost", 3306, "root", "******", "lightShop");
  37.        
  38.         sqlID.query("SELECT ID FROM shops", test ->  {
  39.            
  40.             try {
  41.                 while(test.next()) {
  42.                     ID.add(test.getString("ID"));
  43.                    
  44.                 }
  45.  
  46.                         for(String allItems : ID) {
  47.                             if(sqlmanager.isBought(allItems) == false) {
  48.                                 if(sqlmanager.isExpired(allItems) == false) {
  49.                            
  50.                                    
  51.                    
  52.                                 ItemStack Deserialize = serialize.deserialize(sqlmanager.getItemStack(allItems));
  53.                                 ItemMeta DeserializeMeta = Deserialize.getItemMeta();
  54.                                
  55.                            
  56.                                
  57.                                 ClickItem ci = new ClickItem(Deserialize, DeserializeMeta.getDisplayName(), new ArrayList<String>(Arrays.asList("§7ID: §6" + allItems)));
  58.                                 ci.addClickAction((y) -> {
  59.                                    
  60.                                    
  61.                                     ItemStack giveItem = serialize.deserialize(sqlmanager.getItemStack(allItems));
  62.                                    
  63.                                    
  64.                                    
  65.                                     if(sqlmanager.isBought(allItems) == true) {
  66.                                         y.sendMessage("Das Item ist bereits verkauft");
  67.                                        
  68.                                     } else {
  69.                                         sqlmanager.setBought(true, allItems);
  70.                                         y.getInventory().addItem(giveItem);
  71.                                         y.sendMessage("Gekauft!");
  72.                                     }
  73.                                    
  74.                                     //y.closeInventory();
  75.                                    
  76.                                     GuiAllItems.createItemList(p);
  77.                                    
  78.                                 });
  79.                                
  80.                                 ciList.add(ci);
  81.                                
  82.                                
  83.                                 new BukkitRunnable() {
  84.                                    
  85.                                     @Override
  86.                                     public void run() {
  87.                                         GuiInfinite.openInfiniteGuiList(p, ciList, 0, "Get poor!", (y) -> {
  88.                                            
  89.                                             GuiMain.openMainInv(p);
  90.                                         }, (z) -> {
  91.                                            
  92.                                                 GuiAllItems.createItemList(p);
  93.                                            
  94.                                            
  95.                                         });
  96.                                        
  97.                                     }
  98.                                 }.runTask(Main.plugin);
  99.                                
  100.                                
  101.                             }  
  102.                         }  
  103.                     }
  104.                        
  105.                         if(ciList.size() == 0) {
  106.                            
  107.                             p.sendMessage(prefix + c.getString("messages.noItemsOnMarket").replace("&", "§"));
  108.                             sounds.sendFailSound(p);
  109.                             p.closeInventory();
  110.                            
  111.                         } else {
  112.                             sounds.sendSuccessSound(p);
  113.                         }
  114.                        
  115.                        
  116.             } catch (SQLException e) {
  117.                 // TODO Auto-generated catch block
  118.                 e.printStackTrace();
  119.             }
  120.            
  121.         });
  122.     }
  123.    
  124.    
  125.     public static ItemStack decoStack() {
  126.        
  127.         ItemStack deco = new ItemStack(Material.BLACK_STAINED_GLASS_PANE, 1);
  128.         ItemMeta decoMeta = deco.getItemMeta();
  129.         decoMeta.setDisplayName(" ");
  130.        
  131.         deco.setItemMeta(decoMeta);
  132.        
  133.         return deco;
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement