Permalink
Browse files

Merge branch 'master' of github.com:EngineHub/CommandHelper

  • Loading branch information...
LadyCailin committed Oct 26, 2018
2 parents a7e1798 + afe8873 commit de97884ed9f0bdf56a1a3cdfc4b3061c2fc6f300
@@ -4,8 +4,6 @@
public interface MCFurnaceRecipe extends MCRecipe {
String getKey();
MCItemStack getInput();
void setInput(MCItemStack input);
@@ -32,6 +32,8 @@
MCInventoryView openWorkbench(MCLocation loc, boolean force);
MCInventoryView openMerchant(MCMerchant merchant, boolean force);
void setGameMode(MCGameMode mode);
void setItemInHand(MCItemStack item);
@@ -0,0 +1,16 @@
package com.laytonsmith.abstraction;
import java.util.List;
public interface MCMerchant extends AbstractionObject {
boolean isTrading();
MCHumanEntity getTrader();
List<MCMerchantRecipe> getRecipes();
void setRecipes(List<MCMerchantRecipe> recipes);
String getTitle();
}
@@ -0,0 +1,22 @@
package com.laytonsmith.abstraction;
import java.util.List;
public interface MCMerchantRecipe extends MCRecipe {
int getMaxUses();
void setMaxUses(int maxUses);
int getUses();
void setUses(int uses);
boolean hasExperienceReward();
void setHasExperienceReward(boolean flag);
List<MCItemStack> getIngredients();
void setIngredients(List<MCItemStack> ingredients);
}
@@ -7,4 +7,6 @@
MCItemStack getResult();
MCRecipeType getRecipeType();
String getKey();
}
@@ -165,4 +165,6 @@
MCBossBar createBossBar(String title, MCBarColor color, MCBarStyle style);
MCBlockData createBlockData(String data);
MCMerchant createMerchant(String title);
}
@@ -6,8 +6,6 @@
public interface MCShapedRecipe extends MCRecipe {
String getKey();
Map<Character, MCItemStack> getIngredientMap();
String[] getShape();
@@ -6,8 +6,6 @@
public interface MCShapelessRecipe extends MCRecipe {
String getKey();
MCShapelessRecipe addIngredient(MCItemStack ingredient);
MCShapelessRecipe addIngredient(MCMaterial ingredient);
@@ -120,6 +120,7 @@
import org.bukkit.inventory.FurnaceRecipe;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.MerchantRecipe;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.ShapelessRecipe;
@@ -623,7 +624,11 @@ public void run() {
@Override
public MCRecipe GetNewRecipe(String key, MCRecipeType type, MCItemStack result) {
ItemStack is = ((BukkitMCItemStack) result).asItemStack();
if(type == MCRecipeType.MERCHANT) {
return new BukkitMCMerchantRecipe(new MerchantRecipe(is, Integer.MAX_VALUE));
}
NamespacedKey nskey = new NamespacedKey(CommandHelperPlugin.self, key);
switch(type) {
case FURNACE:
@@ -649,6 +654,8 @@ public static MCRecipe BukkitGetRecipe(Recipe r) {
return new BukkitMCShapedRecipe((ShapedRecipe) r);
} else if(r instanceof FurnaceRecipe) {
return new BukkitMCFurnaceRecipe((FurnaceRecipe) r);
} else if(r instanceof MerchantRecipe) {
return new BukkitMCMerchantRecipe((MerchantRecipe) r);
} else {
return null;
}
@@ -0,0 +1,84 @@
package com.laytonsmith.abstraction.bukkit;
import com.laytonsmith.abstraction.MCHumanEntity;
import com.laytonsmith.abstraction.MCMerchant;
import com.laytonsmith.abstraction.MCMerchantRecipe;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCHumanEntity;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCPlayer;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Merchant;
import org.bukkit.inventory.MerchantRecipe;
import java.util.ArrayList;
import java.util.List;
public class BukkitMCMerchant implements MCMerchant {
private String title;
private Merchant merchant;
public BukkitMCMerchant(Merchant mer, String title) {
merchant = mer;
this.title = title;
}
@Override
public Merchant getHandle() {
return merchant;
}
@Override
public int hashCode() {
return getHandle().hashCode();
}
@Override
public boolean equals(Object obj) {
return getHandle().equals(obj);
}
@Override
public String toString() {
return getHandle().toString();
}
@Override
public boolean isTrading() {
return getHandle().isTrading();
}
@Override
public MCHumanEntity getTrader() {
HumanEntity he = getHandle().getTrader();
if(he == null) {
return null;
}
if(he instanceof Player) {
return new BukkitMCPlayer(he);
}
return new BukkitMCHumanEntity(he);
}
@Override
public List<MCMerchantRecipe> getRecipes() {
List<MCMerchantRecipe> ret = new ArrayList<>();
for(MerchantRecipe mr : getHandle().getRecipes()) {
ret.add(new BukkitMCMerchantRecipe(mr));
}
return ret;
}
@Override
public void setRecipes(List<MCMerchantRecipe> recipes) {
List<MerchantRecipe> ret = new ArrayList<>();
for(MCMerchantRecipe mr : recipes) {
ret.add((MerchantRecipe) mr.getHandle());
}
getHandle().setRecipes(ret);
}
@Override
public String getTitle() {
return title;
}
}
@@ -0,0 +1,103 @@
package com.laytonsmith.abstraction.bukkit;
import com.laytonsmith.abstraction.MCItemStack;
import com.laytonsmith.abstraction.MCMerchantRecipe;
import com.laytonsmith.abstraction.enums.MCRecipeType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.MerchantRecipe;
import java.util.ArrayList;
import java.util.List;
public class BukkitMCMerchantRecipe extends BukkitMCRecipe implements MCMerchantRecipe {
private MerchantRecipe handle;
public BukkitMCMerchantRecipe(MerchantRecipe recipe) {
super(recipe);
handle = recipe;
}
@Override
public String getKey() {
return null;
}
@Override
public MerchantRecipe getHandle() {
return handle;
}
@Override
public boolean equals(Object obj) {
return getHandle().equals(obj);
}
@Override
public int hashCode() {
return getHandle().hashCode();
}
@Override
public String toString() {
return getHandle().toString();
}
@Override
public int getMaxUses() {
return getHandle().getMaxUses();
}
@Override
public void setMaxUses(int maxUses) {
getHandle().setMaxUses(maxUses);
}
@Override
public int getUses() {
return getHandle().getUses();
}
@Override
public void setUses(int uses) {
getHandle().setUses(uses);
}
@Override
public boolean hasExperienceReward() {
return getHandle().hasExperienceReward();
}
@Override
public void setHasExperienceReward(boolean flag) {
getHandle().setExperienceReward(flag);
}
@Override
public List<MCItemStack> getIngredients() {
List<MCItemStack> ret = new ArrayList<>();
for(ItemStack s : getHandle().getIngredients()) {
ret.add(new BukkitMCItemStack(s));
}
return ret;
}
@Override
public void setIngredients(List<MCItemStack> ingredients) {
int i = 0;
List<ItemStack> ings = new ArrayList<>();
for(MCItemStack s : ingredients) {
if(++i > 2) {
break;
// This recipe type only supports two ingredients.
// The Bukkit set method does not include built in enforcement
}
ings.add((ItemStack) s.getHandle());
}
getHandle().setIngredients(ings);
}
@Override
public MCRecipeType getRecipeType() {
return MCRecipeType.MERCHANT;
}
}
@@ -10,6 +10,7 @@
import com.laytonsmith.abstraction.MCInventoryHolder;
import com.laytonsmith.abstraction.MCItemFactory;
import com.laytonsmith.abstraction.MCItemStack;
import com.laytonsmith.abstraction.MCMerchant;
import com.laytonsmith.abstraction.MCOfflinePlayer;
import com.laytonsmith.abstraction.MCPlayer;
import com.laytonsmith.abstraction.MCPluginManager;
@@ -571,4 +572,9 @@ public MCBossBar createBossBar(String title, MCBarColor color, MCBarStyle style)
public MCBlockData createBlockData(String data) {
return new BukkitMCBlockData(s.createBlockData(data));
}
@Override
public MCMerchant createMerchant(String title) {
return new BukkitMCMerchant(__Server().createMerchant(title), title);
}
}
@@ -5,6 +5,7 @@
import com.laytonsmith.abstraction.MCInventoryView;
import com.laytonsmith.abstraction.MCItemStack;
import com.laytonsmith.abstraction.MCLocation;
import com.laytonsmith.abstraction.MCMerchant;
import com.laytonsmith.abstraction.blocks.MCMaterial;
import com.laytonsmith.abstraction.bukkit.BukkitMCInventory;
import com.laytonsmith.abstraction.bukkit.BukkitMCInventoryView;
@@ -16,6 +17,7 @@
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Merchant;
public class BukkitMCHumanEntity extends BukkitMCLivingEntity implements MCHumanEntity {
@@ -121,6 +123,11 @@ public MCInventoryView openWorkbench(MCLocation loc, boolean force) {
return new BukkitMCInventoryView(he.openWorkbench((Location) loc.getHandle(), force));
}
@Override
public MCInventoryView openMerchant(MCMerchant merchant, boolean force) {
return new BukkitMCInventoryView(he.openMerchant((Merchant) merchant.getHandle(), force));
}
@Override
public MCInventoryView openEnchanting(MCLocation loc, boolean force) {
return new BukkitMCInventoryView(he.openEnchanting((Location) loc.getHandle(), force));
@@ -2,7 +2,9 @@
import com.laytonsmith.abstraction.AbstractionObject;
import com.laytonsmith.abstraction.MCInventory;
import com.laytonsmith.abstraction.MCMerchant;
import com.laytonsmith.abstraction.bukkit.BukkitMCInventory;
import com.laytonsmith.abstraction.bukkit.BukkitMCMerchant;
import com.laytonsmith.abstraction.entities.MCVillager;
import com.laytonsmith.abstraction.enums.MCProfession;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCProfession;
@@ -38,4 +40,19 @@ public void setProfession(MCProfession profession) {
public MCInventory getInventory() {
return new BukkitMCInventory(getHandle().getInventory());
}
@Override
public MCMerchant asMerchant() {
return new BukkitMCMerchant(getHandle(), getHandle().getCareer().toString());
}
@Override
public int getRiches() {
return getHandle().getRiches();
}
@Override
public void setRiches(int riches) {
getHandle().setRiches(riches);
}
}
@@ -1,9 +1,14 @@
package com.laytonsmith.abstraction.entities;
import com.laytonsmith.abstraction.MCInventoryHolder;
import com.laytonsmith.abstraction.MCMerchant;
import com.laytonsmith.abstraction.enums.MCProfession;
public interface MCVillager extends MCAgeable, MCInventoryHolder {
MCMerchant asMerchant();
int getRiches();
void setRiches(int riches);
MCProfession getProfession();
void setProfession(MCProfession profession);
}
Oops, something went wrong.

0 comments on commit de97884

Please sign in to comment.