Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.46 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", "KING1500", "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.  
  47.                         for(String allItems : ID) {
  48.                             if(sqlmanager.isBought(allItems) == false) {
  49.                                 if(sqlmanager.isExpired(allItems) == false) {
  50.                            
  51.                                    
  52.                    
  53.                                 ItemStack Deserialize = serialize.deserialize(sqlmanager.getItemStack(allItems));
  54.                                 ItemMeta DeserializeMeta = Deserialize.getItemMeta();
  55.                                
  56.                            
  57.                                
  58.                                 ClickItem ci = new ClickItem(Deserialize, DeserializeMeta.getDisplayName(), new ArrayList<String>(Arrays.asList("§7ID: §6" + allItems)));
  59.                                 ci.addClickAction((y) -> {
  60.                                    
  61.                                    
  62.                                     ItemStack giveItem = serialize.deserialize(sqlmanager.getItemStack(allItems));
  63.                                    
  64.                                    
  65.                                    
  66.                                     if(sqlmanager.isBought(allItems) == true) {
  67.                                         y.sendMessage("Das Item ist bereits verkauft");
  68.                                        
  69.                                     } else {
  70.                                         sqlmanager.setBought(true, allItems);
  71.                                         y.getInventory().addItem(giveItem);
  72.                                         y.sendMessage("Gekauft!");
  73.                                     }
  74.                                    
  75.                                     //y.closeInventory();
  76.                                    
  77.                                     GuiAllItems.createItemList(p);
  78.                                    
  79.                                 });
  80.                                
  81.                                
  82.                                
  83.                                 ciList.add(ci);
  84.                                
  85.                                
  86.                                 new BukkitRunnable() {
  87.                                    
  88.                                     @Override
  89.                                     public void run() {
  90.                                         GuiInfinite.openInfiniteGuiList(p, ciList, 0, "Get poor!", (y) -> {
  91.                                            
  92.                                             GuiMain.openMainInv(p);
  93.                                         }, (z) -> {
  94.                                            
  95.                                                 GuiAllItems.createItemList(p);
  96.                                            
  97.                                            
  98.                                         });
  99.                                        
  100.                                     }
  101.                                 }.runTask(Main.plugin);
  102.                                
  103.                                
  104.                             }  
  105.                         }  
  106.                     }
  107.                        
  108.                         if(ciList.size() == 0) {
  109.                            
  110.                             p.sendMessage(prefix + c.getString("messages.noItemsOnMarket").replace("&", "§"));
  111.                             sounds.sendFailSound(p);
  112.                             p.closeInventory();
  113.                            
  114.                         } else {
  115.                             sounds.sendSuccessSound(p);
  116.                         }
  117.                        
  118.                        
  119.             } catch (SQLException e) {
  120.                 // TODO Auto-generated catch block
  121.                 e.printStackTrace();
  122.             }
  123.            
  124.         });
  125.                
  126.                
  127.                
  128.                
  129.            
  130.        
  131.        
  132.     }
  133.    
  134.    
  135.     public static ItemStack decoStack() {
  136.        
  137.         ItemStack deco = new ItemStack(Material.BLACK_STAINED_GLASS_PANE, 1);
  138.         ItemMeta decoMeta = deco.getItemMeta();
  139.         decoMeta.setDisplayName(" ");
  140.        
  141.         deco.setItemMeta(decoMeta);
  142.        
  143.        
  144.         return deco;
  145.        
  146.        
  147.        
  148.     }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement