Guest User

Untitled

a guest
Jan 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.96 KB | None | 0 0
  1. package net.rothcraft.npcevents;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Iterator;
  5. import net.rothcraft.Inv;
  6.  
  7. import net.rothcraft.Rothcraft;
  8. import net.rothcraft.gui.GenericWindow;
  9. import net.rothcraft.gui.ItemButton;
  10. import org.bukkit.ChatColor;
  11. import org.bukkit.inventory.ItemStack;
  12. import org.getspout.spoutapi.gui.Button;
  13. import org.getspout.spoutapi.gui.GenericButton;
  14. import org.getspout.spoutapi.gui.GenericLabel;
  15. import org.getspout.spoutapi.gui.Label;
  16. import org.getspout.spoutapi.gui.RenderPriority;
  17. import org.getspout.spoutapi.gui.Widget;
  18. import org.getspout.spoutapi.player.SpoutPlayer;
  19.  
  20. /**
  21.  *
  22.  * @author Rothens
  23.  */
  24. public class Butcher extends GenericWindow {
  25.  
  26.     private SpoutPlayer player;
  27.     private Button closeWindowButton;
  28.     private Label sellLabel;
  29.     private HashMap<GridLocation, ItemButton> buttons = new HashMap<GridLocation, ItemButton>();
  30.  
  31.     public class GridLocation {
  32.  
  33.         int x;
  34.  
  35.         public GridLocation(int x) {
  36.             this.x = x;
  37.         }
  38.  
  39.         @Override
  40.         public int hashCode() {
  41.             return x * 10000;
  42.         }
  43.     }
  44.    
  45.     public class Food{
  46.         int price;
  47.         String name;
  48.         public Food(int price, String name){
  49.             this.price = price;
  50.             this.name = name;
  51.         }
  52.     }
  53.  
  54.     private HashMap<ItemStack, Food> foods = new HashMap<ItemStack, Food>();
  55.  
  56.     public Butcher(SpoutPlayer player) {
  57.         super("Hentes", player, ChatColor.GOLD + "Üdvözöllek a hentesüzletemben vándor!");
  58.         this.player = player;
  59.         initButcher();
  60.     }
  61.  
  62.     private void initButcher() {
  63.         foods.put(new ItemStack(319), new Food(20, "disznóhús"));//disznohus
  64.         foods.put(new ItemStack(320), new Food(50, "sült disznóhús"));//sult d.hus
  65.         foods.put(new ItemStack(363), new Food(20, "marhahús"));//marhahus
  66.         foods.put(new ItemStack(364), new Food(50, "sült marhahús"));//sult m.hus
  67.         foods.put(new ItemStack(365), new Food(10, "csirkehús"));//csirek
  68.         foods.put(new ItemStack(366), new Food(40, "sült csirkehús"));//sult csirek
  69.         foods.put(new ItemStack(367), new Food(5, "rothadt hús"));//rotten chunk
  70.         Rothcraft plg = Rothcraft.getInstance();
  71.         closeWindowButton = new GenericButton(ChatColor.RED + "X");
  72.         closeWindowButton.setTooltip("Ablak bezárása");
  73.         closeWindowButton.setWidth(20).setHeight(20).setX(getMarginRight() - 26).setY(getMarginTop() - 2);
  74.         closeWindowButton.setPriority(RenderPriority.Low);
  75.         sellLabel = new GenericLabel(ChatColor.GOLD + "Ezeket adom el:");
  76.         sellLabel.setWidth(380).setHeight(20).setX(getMarginLeft() + 4).setY(getMarginTop() + 34);
  77.         sellLabel.setPriority(RenderPriority.Low);
  78.         this.attachWidget(plg, sellLabel);
  79.        
  80.         attachWidget(plg, closeWindowButton);
  81.         int x = 0;
  82.         Iterator<ItemStack> it = foods.keySet().iterator();
  83.         while (it.hasNext()) {
  84.             GridLocation loc = new GridLocation(x);
  85.             ItemStack l = it.next();
  86.             ItemButton current = new ItemButton(l, this, foods.get(l).price);
  87.             current.setX(x * ((getMarginRight() - getMarginLeft()-20) / foods.size()) + getMarginLeft());
  88.             current.setY(getMarginTop() + 50);
  89.             current.attachToScreen();
  90.             current.setVisible(true);
  91.             buttons.put(loc, current);
  92.             x++;
  93.         }
  94.     }
  95.  
  96.     public void open() {
  97.         player.getMainScreen().attachPopupScreen(this);
  98.         setDirty(true);
  99.         for (Widget widget : getAttachedWidgets()) {
  100.             widget.setVisible(true);
  101.             widget.setDirty(true);
  102.         }
  103.     }
  104.  
  105.     public void hide() {
  106.         close();
  107.     }
  108.  
  109.     public void handleClick(Button button) {
  110.         if (button.equals(closeWindowButton)) {
  111.             close();
  112.         }
  113.  
  114.         ItemButton ibtn = ItemButton.getByButton(button);
  115.         if (ibtn != null) {
  116.             ItemStack is = ibtn.getItemStack().clone();
  117.             int price = foods.get(is).price;
  118.             if(price>0){
  119.                 if(Rothcraft.getInstance().money.deductPlayer(player, price)){
  120.                     Rothcraft.message.success(player, "Köszönöm hogy vásároltál! Itt a " + foods.get(is).name + ".");
  121.                 } else {
  122.                     return;
  123.                 }
  124.                
  125.             } else {
  126.                 Rothcraft.message.success(player, "Itt van ingyen a " + foods.get(is).name + "."); 
  127.             }
  128.             plugin.giveSingleItem(player, is.getTypeId());
  129.         }
  130.        
  131.     }
  132. }
Add Comment
Please, Sign In to add comment