Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.rothcraft.npcevents;
- import java.util.HashMap;
- import java.util.Iterator;
- import net.rothcraft.Inv;
- import net.rothcraft.Rothcraft;
- import net.rothcraft.gui.GenericWindow;
- import net.rothcraft.gui.ItemButton;
- import org.bukkit.ChatColor;
- import org.bukkit.inventory.ItemStack;
- import org.getspout.spoutapi.gui.Button;
- import org.getspout.spoutapi.gui.GenericButton;
- import org.getspout.spoutapi.gui.GenericLabel;
- import org.getspout.spoutapi.gui.Label;
- import org.getspout.spoutapi.gui.RenderPriority;
- import org.getspout.spoutapi.gui.Widget;
- import org.getspout.spoutapi.player.SpoutPlayer;
- /**
- *
- * @author Rothens
- */
- public class Butcher extends GenericWindow {
- private SpoutPlayer player;
- private Button closeWindowButton;
- private Label sellLabel;
- private HashMap<GridLocation, ItemButton> buttons = new HashMap<GridLocation, ItemButton>();
- public class GridLocation {
- int x;
- public GridLocation(int x) {
- this.x = x;
- }
- @Override
- public int hashCode() {
- return x * 10000;
- }
- }
- public class Food{
- int price;
- String name;
- public Food(int price, String name){
- this.price = price;
- this.name = name;
- }
- }
- private HashMap<ItemStack, Food> foods = new HashMap<ItemStack, Food>();
- public Butcher(SpoutPlayer player) {
- super("Hentes", player, ChatColor.GOLD + "Üdvözöllek a hentesüzletemben vándor!");
- this.player = player;
- initButcher();
- }
- private void initButcher() {
- foods.put(new ItemStack(319), new Food(20, "disznóhús"));//disznohus
- foods.put(new ItemStack(320), new Food(50, "sült disznóhús"));//sult d.hus
- foods.put(new ItemStack(363), new Food(20, "marhahús"));//marhahus
- foods.put(new ItemStack(364), new Food(50, "sült marhahús"));//sult m.hus
- foods.put(new ItemStack(365), new Food(10, "csirkehús"));//csirek
- foods.put(new ItemStack(366), new Food(40, "sült csirkehús"));//sult csirek
- foods.put(new ItemStack(367), new Food(5, "rothadt hús"));//rotten chunk
- Rothcraft plg = Rothcraft.getInstance();
- closeWindowButton = new GenericButton(ChatColor.RED + "X");
- closeWindowButton.setTooltip("Ablak bezárása");
- closeWindowButton.setWidth(20).setHeight(20).setX(getMarginRight() - 26).setY(getMarginTop() - 2);
- closeWindowButton.setPriority(RenderPriority.Low);
- sellLabel = new GenericLabel(ChatColor.GOLD + "Ezeket adom el:");
- sellLabel.setWidth(380).setHeight(20).setX(getMarginLeft() + 4).setY(getMarginTop() + 34);
- sellLabel.setPriority(RenderPriority.Low);
- this.attachWidget(plg, sellLabel);
- attachWidget(plg, closeWindowButton);
- int x = 0;
- Iterator<ItemStack> it = foods.keySet().iterator();
- while (it.hasNext()) {
- GridLocation loc = new GridLocation(x);
- ItemStack l = it.next();
- ItemButton current = new ItemButton(l, this, foods.get(l).price);
- current.setX(x * ((getMarginRight() - getMarginLeft()-20) / foods.size()) + getMarginLeft());
- current.setY(getMarginTop() + 50);
- current.attachToScreen();
- current.setVisible(true);
- buttons.put(loc, current);
- x++;
- }
- }
- public void open() {
- player.getMainScreen().attachPopupScreen(this);
- setDirty(true);
- for (Widget widget : getAttachedWidgets()) {
- widget.setVisible(true);
- widget.setDirty(true);
- }
- }
- public void hide() {
- close();
- }
- public void handleClick(Button button) {
- if (button.equals(closeWindowButton)) {
- close();
- }
- ItemButton ibtn = ItemButton.getByButton(button);
- if (ibtn != null) {
- ItemStack is = ibtn.getItemStack().clone();
- int price = foods.get(is).price;
- if(price>0){
- if(Rothcraft.getInstance().money.deductPlayer(player, price)){
- Rothcraft.message.success(player, "Köszönöm hogy vásároltál! Itt a " + foods.get(is).name + ".");
- } else {
- return;
- }
- } else {
- Rothcraft.message.success(player, "Itt van ingyen a " + foods.get(is).name + ".");
- }
- plugin.giveSingleItem(player, is.getTypeId());
- }
- }
- }
Add Comment
Please, Sign In to add comment