Guest User

Untitled

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