Advertisement
xLiimited

Class1_Merchant

Jan 26th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.flugzeug21.Merchant;
  2.  
  3. import java.lang.reflect.Proxy;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7. import me.flugzeug21.Merchant.ReflectionUtils.NMSMerchantRecipe;
  8.  
  9. import org.bukkit.Bukkit;
  10. import org.bukkit.entity.Player;
  11.  
  12. public class Merchant {
  13.  
  14.     private NMSMerchant h;
  15.     private String title = null;
  16.  
  17.     public Merchant() {
  18.         this.h = new NMSMerchant();
  19.         this.h.proxy = Proxy.newProxyInstance(Bukkit.class.getClassLoader(), new Class[] { ReflectionUtils.getClassByName(ReflectionUtils.getNMSPackageName() + ".IMerchant") }, this.h);
  20.         //this.h = new NMSMerchant();
  21.     }
  22.  
  23.     public String getTitle() {
  24.         return this.title;
  25.     }
  26.  
  27.     public void setTitle(String title) {
  28.         this.title = title;
  29.     }
  30.  
  31.     @SuppressWarnings("rawtypes")
  32.     public List<MerchantOffer> getOffers() {
  33.         List<MerchantOffer> offerList = new ArrayList<MerchantOffer>();
  34.         for (Object recipe : (List) this.h.getOffers(null)) {
  35.             if (!(recipe.getClass().isInstance(NMSMerchantRecipe.getNMSClass()))) continue;
  36.             offerList.add(new MerchantOffer(new NMSMerchantRecipe(recipe)));
  37.         }
  38.         return offerList;
  39.     }
  40.  
  41.     public Merchant addOffer(MerchantOffer offer) {
  42.         this.h.a(offer.getHandle().getMerchantRecipe());
  43.         return this;
  44.     }
  45.  
  46.     public Merchant addOffers(MerchantOffer[] offers) {
  47.         for (MerchantOffer o : offers) {
  48.             addOffer(o);
  49.         }
  50.         return this;
  51.     }
  52.  
  53.     public Merchant setOffers(List<MerchantOffer> offers) {
  54.         this.h.clearRecipes();
  55.         for (MerchantOffer o : offers)
  56.             this.addOffer(o);
  57.         return this;
  58.     }
  59.  
  60.     /*public Merchant setOffers(MerchantOfferList offers) {
  61.         this.h.setRecipes(offers.getHandle());
  62.         return this;
  63.     }*/
  64.  
  65.     public boolean hasCustomer() {
  66.         return this.h.b() != null;
  67.     }
  68.  
  69.     public Player getCustomer() {
  70.         return (Player)(this.h.b() == null ? null : this.h.getBukkitEntity());
  71.     }
  72.  
  73.     public Merchant setCustomer(Player player) {
  74.         this.h.a_(player == null ? null : ReflectionUtils.toEntityHuman(player));
  75.         return this;
  76.     }
  77.  
  78.     public void openTrading(Player player) {
  79.         this.h.openTrading(ReflectionUtils.toEntityHuman(player), this.title);
  80.     }
  81.  
  82.     protected NMSMerchant getHandle() {
  83.         return this.h;
  84.     }
  85.  
  86.     @Override
  87.     public Merchant clone() {
  88.         return new Merchant().setOffers(getOffers()).setCustomer(getCustomer());
  89.     }
  90.    
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement