Add /recipe command

This commit is contained in:
Chris Ward 2012-12-19 14:57:12 +11:00
parent 258fbdb0e8
commit 1f8a0a811f
17 changed files with 343 additions and 1 deletions

View File

@ -538,6 +538,14 @@ public class EssentialsPlayerListener implements Listener
event.setCancelled(true);
}
}
else if (event.getView().getTopInventory().getType() == InventoryType.WORKBENCH)
{
User user = ess.getUser(event.getWhoClicked());
if (user.isRecipeSee())
{
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
@ -553,8 +561,17 @@ public class EssentialsPlayerListener implements Listener
final User user = ess.getUser(event.getPlayer());
user.setEnderSee(false);
}
if (event.getView().getTopInventory().getType() == InventoryType.WORKBENCH)
{
final User user = ess.getUser(event.getPlayer());
if(user.isRecipeSee())
{
user.setRecipeSee(false);
event.getView().getTopInventory().clear();
}
}
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerFishEvent(final PlayerFishEvent event)
{

View File

@ -29,6 +29,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
private boolean rightClickJump = false;
private transient Location afkPosition = null;
private boolean invSee = false;
private boolean recipeSee = false;
private boolean enderSee = false;
private static final Logger logger = Logger.getLogger("Minecraft");
@ -743,4 +744,14 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
{
return this.isAuthorized("essentials.chat.ignoreexempt");
}
public boolean isRecipeSee()
{
return recipeSee;
}
public void setRecipeSee(boolean recipeSee)
{
this.recipeSee = recipeSee;
}
}

View File

@ -0,0 +1,167 @@
package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.FurnaceRecipe;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.ShapelessRecipe;
public class Commandrecipe extends EssentialsCommand
{
public Commandrecipe()
{
super("recipe");
}
@Override
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
if (args.length < 1)
{
throw new NotEnoughArgumentsException();
}
final ItemStack item = ess.getItemDb().get(args[0]);
final List<Recipe> recipes = ess.getServer().getRecipesFor(item);
if (recipes.size() < 1)
{
throw new Exception(_("recipeNone", getMaterialName(item)));
}
int recipeNo = 0;
if (args.length > 1)
{
if (Util.isInt(args[1]))
{
recipeNo = Integer.parseInt(args[1]) - 1;
}
else
{
throw new Exception(_("invalidNumber"));
}
}
if (recipeNo < 0 || recipeNo >= recipes.size())
{
throw new Exception(_("recipeBadIndex"));
}
final Recipe recipe = recipes.get(recipeNo);
sender.sendMessage(_("recipe", getMaterialName(item), recipeNo + 1, recipes.size()));
if (recipe instanceof FurnaceRecipe)
{
furnaceRecipe(sender, (FurnaceRecipe)recipe);
}
else if (recipe instanceof ShapedRecipe)
{
shapedRecipe(sender, (ShapedRecipe)recipe);
}
else if (recipe instanceof ShapelessRecipe)
{
shapelessRecipe(sender, (ShapelessRecipe)recipe);
}
if (recipes.size() > 1 && args.length == 1)
{
sender.sendMessage(_("recipeMore", commandLabel, args[0], getMaterialName(item)));
}
}
public void furnaceRecipe(CommandSender sender, FurnaceRecipe recipe)
{
sender.sendMessage(_("recipeFurnace", getMaterialName(recipe.getInput())));
}
public void shapedRecipe(CommandSender sender, ShapedRecipe recipe)
{
Map<Character, ItemStack> recipeMap = recipe.getIngredientMap();
if (!(sender instanceof Player))
{
HashMap<ItemStack, String> colorMap = new HashMap<ItemStack, String>();
int i = 1;
for (Character c : "abcdefghi".toCharArray())
{
if (!colorMap.containsKey(recipeMap.get(c)))
{
colorMap.put(recipeMap.get(c), String.valueOf(i++));
}
}
sender.sendMessage(_("recipeGrid", colorMap.get(recipeMap.get('a')), colorMap.get(recipeMap.get('b')), colorMap.get(recipeMap.get('c'))));
sender.sendMessage(_("recipeGrid", colorMap.get(recipeMap.get('d')), colorMap.get(recipeMap.get('e')), colorMap.get(recipeMap.get('f'))));
sender.sendMessage(_("recipeGrid", colorMap.get(recipeMap.get('g')), colorMap.get(recipeMap.get('h')), colorMap.get(recipeMap.get('i'))));
StringBuilder s = new StringBuilder();
for (ItemStack items : colorMap.keySet().toArray(new ItemStack[colorMap.size()]))
{
s.append(_("recipeGridItem", colorMap.get(items), getMaterialName(items)));
}
sender.sendMessage(_("recipeWhere", s.toString()));
}
else
{
User user = ess.getUser(sender);
user.setRecipeSee(true);
InventoryView view = user.openWorkbench(null, true);
for (Entry<Character, ItemStack> e : ((ShapedRecipe)recipe).getIngredientMap().entrySet())
{
view.setItem(" abcdefghi".indexOf(e.getKey()), e.getValue());
}
}
}
public void shapelessRecipe(CommandSender sender, ShapelessRecipe recipe)
{
List<ItemStack> ingredients = recipe.getIngredientList();
if (!(sender instanceof Player))
{
StringBuilder s = new StringBuilder();
for (int i = 0; i < ingredients.size(); i++)
{
s.append(getMaterialName(ingredients.get(i)));
if (i != ingredients.size() - 1)
{
s.append(",");
}
s.append(" ");
}
sender.sendMessage(_("recipeShapeless", s.toString()));
}
else
{
User user = ess.getUser(sender);
user.setRecipeSee(true);
InventoryView view = user.openWorkbench(null, true);
for (int i = 0; i < ingredients.size(); i++)
{
view.setItem(i + 1, ingredients.get(i));
}
}
}
public String getMaterialName(ItemStack stack)
{
if (stack == null)
{
return _("recipeNothing");
}
return getMaterialName(stack.getType());
}
public String getMaterialName(Material type)
{
if (type == null)
{
return _("recipeNothing");
}
return type.toString().replace("_", " ").toLowerCase(Locale.ENGLISH);
}
}

View File

@ -467,3 +467,14 @@ teleportationDisabledFor=\u00a76Teleportation disabled for {0}
kitOnce=\u00a74You can't use that kit again.
fullStack=\u00a74You already have a full stack
oversizedTempban=\u00a74You may not ban a player for this period of time.
recipeNone=No recipes exist for {0}
invalidNumber=Invalid Number
recipeBadIndex=There is no recipe by that number
recipeNothing=nothing
recipeShapeless=\u00a7eCombine \u00a7c{0}
recipe=\u00a76Recipe for \u00a7c{0}\u00a76 ({1} of {2})
recipeFurnace=\u00a76Smelt \u00a7c{0}
recipeGrid=\u00a7{0}X \u00a76| \u00a7{1}X \u00a76| \u00a7{2}X
recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1}
recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 <number> to see other recipes for \u00a7c{2}
recipeWhere=\u00a76Where: {0}

View File

@ -470,3 +470,14 @@ teleportationDisabledFor=\u00a76Teleportation disabled for {0}
kitOnce=\u00a74You can't use that kit again.
fullStack=\u00a74You already have a full stack
oversizedTempban=\u00a74You may not ban a player for this period of time.
recipeNone=No recipes exist for {0}
invalidNumber=Invalid Number
recipeBadIndex=There is no recipe by that number
recipeNothing=nothing
recipeShapeless=\u00a7eCombine \u00a7c{0}
recipe=\u00a76Recipe for \u00a7c{0}\u00a76 ({1} of {2})
recipeFurnace=\u00a76Smelt \u00a7c{0}
recipeGrid=\u00a7{0}X \u00a76| \u00a7{1}X \u00a76| \u00a7{2}X
recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1}
recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 <number> to see other recipes for \u00a7c{2}
recipeWhere=\u00a76Where: {0}

View File

@ -467,3 +467,14 @@ teleportationDisabledFor=\u00a76Teleportation disabled for {0}
kitOnce=\u00a74You can't use that kit again.
fullStack=\u00a74You already have a full stack
oversizedTempban=\u00a74You may not ban a player for this period of time.
recipeNone=No recipes exist for {0}
invalidNumber=Invalid Number
recipeBadIndex=There is no recipe by that number
recipeNothing=nothing
recipeShapeless=\u00a7eCombine \u00a7c{0}
recipe=\u00a76Recipe for \u00a7c{0}\u00a76 ({1} of {2})
recipeFurnace=\u00a76Smelt \u00a7c{0}
recipeGrid=\u00a7{0}X \u00a76| \u00a7{1}X \u00a76| \u00a7{2}X
recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1}
recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 <number> to see other recipes for \u00a7c{2}
recipeWhere=\u00a76Where: {0}

View File

@ -467,3 +467,14 @@ teleportationDisabledFor=\u00a76Teleportation disabled for {0}
kitOnce=\u00a74You can't use that kit again.
fullStack=\u00a74You already have a full stack
oversizedTempban=\u00a74You may not ban a player for this period of time.
recipeNone=No recipes exist for {0}
invalidNumber=Invalid Number
recipeBadIndex=There is no recipe by that number
recipeNothing=nothing
recipeShapeless=\u00a7eCombine \u00a7c{0}
recipe=\u00a76Recipe for \u00a7c{0}\u00a76 ({1} of {2})
recipeFurnace=\u00a76Smelt \u00a7c{0}
recipeGrid=\u00a7{0}X \u00a76| \u00a7{1}X \u00a76| \u00a7{2}X
recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1}
recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 <number> to see other recipes for \u00a7c{2}
recipeWhere=\u00a76Where: {0}

View File

@ -467,3 +467,14 @@ teleportationDisabledFor=\u00a76Teleportation disabled for {0}
kitOnce=\u00a74You can't use that kit again.
fullStack=\u00a74You already have a full stack
oversizedTempban=\u00a74You may not ban a player for this period of time.
recipeNone=No recipes exist for {0}
invalidNumber=Invalid Number
recipeBadIndex=There is no recipe by that number
recipeNothing=nothing
recipeShapeless=\u00a7eCombine \u00a7c{0}
recipe=\u00a76Recipe for \u00a7c{0}\u00a76 ({1} of {2})
recipeFurnace=\u00a76Smelt \u00a7c{0}
recipeGrid=\u00a7{0}X \u00a76| \u00a7{1}X \u00a76| \u00a7{2}X
recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1}
recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 <number> to see other recipes for \u00a7c{2}
recipeWhere=\u00a76Where: {0}

View File

@ -467,3 +467,14 @@ teleportationDisabledFor=\u00a76Teleportation disabled for {0}
kitOnce=\u00a74You can't use that kit again.
fullStack=\u00a74You already have a full stack
oversizedTempban=\u00a74You may not ban a player for this period of time.
recipeNone=No recipes exist for {0}
invalidNumber=Invalid Number
recipeBadIndex=There is no recipe by that number
recipeNothing=nothing
recipeShapeless=\u00a7eCombine \u00a7c{0}
recipe=\u00a76Recipe for \u00a7c{0}\u00a76 ({1} of {2})
recipeFurnace=\u00a76Smelt \u00a7c{0}
recipeGrid=\u00a7{0}X \u00a76| \u00a7{1}X \u00a76| \u00a7{2}X
recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1}
recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 <number> to see other recipes for \u00a7c{2}
recipeWhere=\u00a76Where: {0}

View File

@ -467,3 +467,14 @@ teleportationDisabledFor=\u00a76Teleportation disabled for {0}
kitOnce=\u00a74You can't use that kit again.
fullStack=\u00a74You already have a full stack
oversizedTempban=\u00a74You may not ban a player for this period of time.
recipeNone=No recipes exist for {0}
invalidNumber=Invalid Number
recipeBadIndex=There is no recipe by that number
recipeNothing=nothing
recipeShapeless=\u00a7eCombine \u00a7c{0}
recipe=\u00a76Recipe for \u00a7c{0}\u00a76 ({1} of {2})
recipeFurnace=\u00a76Smelt \u00a7c{0}
recipeGrid=\u00a7{0}X \u00a76| \u00a7{1}X \u00a76| \u00a7{2}X
recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1}
recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 <number> to see other recipes for \u00a7c{2}
recipeWhere=\u00a76Where: {0}

View File

@ -467,3 +467,14 @@ teleportationDisabledFor=\u00a76Teleportation disabled for {0}
kitOnce=\u00a74You can't use that kit again.
fullStack=\u00a74You already have a full stack
oversizedTempban=\u00a74You may not ban a player for this period of time.
recipeNone=No recipes exist for {0}
invalidNumber=Invalid Number
recipeBadIndex=There is no recipe by that number
recipeNothing=nothing
recipeShapeless=\u00a7eCombine \u00a7c{0}
recipe=\u00a76Recipe for \u00a7c{0}\u00a76 ({1} of {2})
recipeFurnace=\u00a76Smelt \u00a7c{0}
recipeGrid=\u00a7{0}X \u00a76| \u00a7{1}X \u00a76| \u00a7{2}X
recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1}
recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 <number> to see other recipes for \u00a7c{2}
recipeWhere=\u00a76Where: {0}

View File

@ -467,3 +467,14 @@ teleportationDisabledFor=\u00a76Teleportation disabled for {0}
kitOnce=\u00a74You can't use that kit again.
fullStack=\u00a74You already have a full stack
oversizedTempban=\u00a74You may not ban a player for this period of time.
recipeNone=No recipes exist for {0}
invalidNumber=Invalid Number
recipeBadIndex=There is no recipe by that number
recipeNothing=nothing
recipeShapeless=\u00a7eCombine \u00a7c{0}
recipe=\u00a76Recipe for \u00a7c{0}\u00a76 ({1} of {2})
recipeFurnace=\u00a76Smelt \u00a7c{0}
recipeGrid=\u00a7{0}X \u00a76| \u00a7{1}X \u00a76| \u00a7{2}X
recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1}
recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 <number> to see other recipes for \u00a7c{2}
recipeWhere=\u00a76Where: {0}

View File

@ -467,3 +467,14 @@ teleportationDisabledFor=\u00a76Teleportation disabled for {0}
kitOnce=\u00a74You can't use that kit again.
fullStack=\u00a74You already have a full stack
oversizedTempban=\u00a74You may not ban a player for this period of time.
recipeNone=No recipes exist for {0}
invalidNumber=Invalid Number
recipeBadIndex=There is no recipe by that number
recipeNothing=nothing
recipeShapeless=\u00a7eCombine \u00a7c{0}
recipe=\u00a76Recipe for \u00a7c{0}\u00a76 ({1} of {2})
recipeFurnace=\u00a76Smelt \u00a7c{0}
recipeGrid=\u00a7{0}X \u00a76| \u00a7{1}X \u00a76| \u00a7{2}X
recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1}
recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 <number> to see other recipes for \u00a7c{2}
recipeWhere=\u00a76Where: {0}

View File

@ -467,3 +467,14 @@ teleportationDisabledFor=\u00a76Teleportation disabled for {0}
kitOnce=\u00a74You can't use that kit again.
fullStack=\u00a74You already have a full stack
oversizedTempban=\u00a74You may not ban a player for this period of time.
recipeNone=No recipes exist for {0}
invalidNumber=Invalid Number
recipeBadIndex=There is no recipe by that number
recipeNothing=nothing
recipeShapeless=\u00a7eCombine \u00a7c{0}
recipe=\u00a76Recipe for \u00a7c{0}\u00a76 ({1} of {2})
recipeFurnace=\u00a76Smelt \u00a7c{0}
recipeGrid=\u00a7{0}X \u00a76| \u00a7{1}X \u00a76| \u00a7{2}X
recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1}
recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 <number> to see other recipes for \u00a7c{2}
recipeWhere=\u00a76Where: {0}

View File

@ -467,3 +467,14 @@ teleportationDisabledFor=\u00a76Teleportation disabled for {0}
kitOnce=\u00a74You can't use that kit again.
fullStack=\u00a74You already have a full stack
oversizedTempban=\u00a74You may not ban a player for this period of time.
recipeNone=No recipes exist for {0}
invalidNumber=Invalid Number
recipeBadIndex=There is no recipe by that number
recipeNothing=nothing
recipeShapeless=\u00a7eCombine \u00a7c{0}
recipe=\u00a76Recipe for \u00a7c{0}\u00a76 ({1} of {2})
recipeFurnace=\u00a76Smelt \u00a7c{0}
recipeGrid=\u00a7{0}X \u00a76| \u00a7{1}X \u00a76| \u00a7{2}X
recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1}
recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 <number> to see other recipes for \u00a7c{2}
recipeWhere=\u00a76Where: {0}

View File

@ -467,3 +467,14 @@ teleportationDisabledFor=\u00a76Teleportation disabled for {0}
kitOnce=\u00a74You can't use that kit again.
fullStack=\u00a74You already have a full stack
oversizedTempban=\u00a74You may not ban a player for this period of time.
recipeNone=No recipes exist for {0}
invalidNumber=Invalid Number
recipeBadIndex=There is no recipe by that number
recipeNothing=nothing
recipeShapeless=\u00a7eCombine \u00a7c{0}
recipe=\u00a76Recipe for \u00a7c{0}\u00a76 ({1} of {2})
recipeFurnace=\u00a76Smelt \u00a7c{0}
recipeGrid=\u00a7{0}X \u00a76| \u00a7{1}X \u00a76| \u00a7{2}X
recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1}
recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 <number> to see other recipes for \u00a7c{2}
recipeWhere=\u00a76Where: {0}

View File

@ -278,6 +278,10 @@ commands:
description: Displays the username of a user based on nick.
usage: /<command> <nickname>
aliases: [erealname]
recipe:
description: Displays how to craft items.
usage: /<command> <item> [number]
aliases: [erecipe]
remove:
description: Removes entities in your world
usage: /<command> <drops|arrows|boats|minecarts|xp|paintings> [radius]