ChestShop-3/src/main/java/com/Acrobot/ChestShop/Commands/ItemInfo.java
Phoenix616 6ee7c4759a
Add multi-language and component message support (Requires Spigot)
Message configs are now selected based on the client's language (can be
 toggled in the config) and will use MineDown formatting to allow
 display of component messages as well as usage of RGB colors in 1.16.
If found the legacy local.yml will be used instead of the per-language
 files. Move your local.yml to the correct lang config to if you want to
 use the per-client language option.
Version was also changed to 3.11 due to the many internal changes that
 have accumulated over time
2020-06-28 18:00:09 +01:00

70 lines
2.6 KiB
Java

package com.Acrobot.ChestShop.Commands;
import com.Acrobot.Breeze.Utils.MaterialUtil;
import com.Acrobot.Breeze.Utils.StringUtil;
import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Configuration.Messages;
import com.Acrobot.ChestShop.Events.ItemInfoEvent;
import com.Acrobot.ChestShop.Events.ItemParseEvent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.ItemStack;
import java.util.logging.Level;
import static com.Acrobot.ChestShop.Configuration.Messages.iteminfo;
import static com.Acrobot.ChestShop.Configuration.Messages.iteminfo_fullname;
import static com.Acrobot.ChestShop.Configuration.Messages.iteminfo_shopname;
import static com.Acrobot.ChestShop.Configuration.Messages.replace;
/**
* @author Acrobot
*/
public class ItemInfo implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
ItemStack item;
if (args.length == 0) {
if (!(sender instanceof HumanEntity)) {
return false;
}
item = ((HumanEntity) sender).getItemInHand();
} else {
ItemParseEvent parseEvent = new ItemParseEvent(StringUtil.joinArray(args));
Bukkit.getPluginManager().callEvent(parseEvent);
item = parseEvent.getItem();
}
if (MaterialUtil.isEmpty(item)) {
return false;
}
iteminfo.send(sender);
try {
iteminfo_fullname.send(sender, "item", MaterialUtil.getName(item));
} catch (IllegalArgumentException e) {
sender.sendMessage(ChatColor.RED + "Error while generating full name. Please contact an admin or take a look at the console/log!");
ChestShop.getPlugin().getLogger().log(Level.SEVERE, "Error while generating full item name", e);
return true;
}
try {
iteminfo_shopname.send(sender, "item", MaterialUtil.getSignName(item));
} catch (IllegalArgumentException e) {
sender.sendMessage(ChatColor.RED + "Error while generating shop sign name. Please contact an admin or take a look at the console/log!");
ChestShop.getPlugin().getLogger().log(Level.SEVERE, "Error while generating shop sign item name", e);
return true;
}
ItemInfoEvent event = new ItemInfoEvent(sender, item);
ChestShop.callEvent(event);
return true;
}
}