2011-05-29 13:25:25 +02:00
|
|
|
package com.Acrobot.ChestShop.Commands;
|
|
|
|
|
2012-06-08 15:28:36 +02:00
|
|
|
import com.Acrobot.Breeze.Utils.MaterialUtil;
|
|
|
|
import com.Acrobot.Breeze.Utils.StringUtil;
|
|
|
|
import com.Acrobot.ChestShop.ChestShop;
|
|
|
|
import com.Acrobot.ChestShop.Events.ItemInfoEvent;
|
2019-01-17 19:50:47 +01:00
|
|
|
import com.Acrobot.ChestShop.Events.ItemParseEvent;
|
2021-01-03 01:55:01 +01:00
|
|
|
import com.Acrobot.ChestShop.Utils.ItemUtil;
|
2019-01-17 19:50:47 +01:00
|
|
|
import org.bukkit.Bukkit;
|
2011-08-13 12:08:34 +02:00
|
|
|
import org.bukkit.ChatColor;
|
2011-05-29 13:25:25 +02:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2012-06-08 15:28:36 +02:00
|
|
|
import org.bukkit.entity.HumanEntity;
|
2011-05-29 13:25:25 +02:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
2019-03-19 19:08:53 +01:00
|
|
|
import java.util.logging.Level;
|
|
|
|
|
2012-11-23 21:04:13 +01:00
|
|
|
import static com.Acrobot.ChestShop.Configuration.Messages.iteminfo;
|
2020-05-03 16:05:24 +02:00
|
|
|
import static com.Acrobot.ChestShop.Configuration.Messages.iteminfo_fullname;
|
|
|
|
import static com.Acrobot.ChestShop.Configuration.Messages.iteminfo_shopname;
|
2012-11-23 21:04:13 +01:00
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
/**
|
|
|
|
* @author Acrobot
|
|
|
|
*/
|
|
|
|
public class ItemInfo implements CommandExecutor {
|
|
|
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
2011-08-13 12:08:34 +02:00
|
|
|
ItemStack item;
|
2012-06-08 15:28:36 +02:00
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
if (args.length == 0) {
|
2012-06-08 15:28:36 +02:00
|
|
|
if (!(sender instanceof HumanEntity)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
item = ((HumanEntity) sender).getItemInHand();
|
2011-05-29 13:25:25 +02:00
|
|
|
} else {
|
2019-01-17 19:50:47 +01:00
|
|
|
ItemParseEvent parseEvent = new ItemParseEvent(StringUtil.joinArray(args));
|
|
|
|
Bukkit.getPluginManager().callEvent(parseEvent);
|
|
|
|
item = parseEvent.getItem();
|
2011-08-13 12:08:34 +02:00
|
|
|
}
|
2011-05-29 13:25:25 +02:00
|
|
|
|
2012-06-08 15:28:36 +02:00
|
|
|
if (MaterialUtil.isEmpty(item)) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-03-17 15:00:25 +01:00
|
|
|
|
2020-06-28 19:00:09 +02:00
|
|
|
iteminfo.send(sender);
|
2018-03-16 18:24:52 +01:00
|
|
|
try {
|
2021-01-03 01:55:01 +01:00
|
|
|
iteminfo_fullname.send(sender, "item", ItemUtil.getName(item));
|
2018-03-16 18:24:52 +01:00
|
|
|
} catch (IllegalArgumentException e) {
|
2019-03-19 19:08:53 +01:00
|
|
|
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;
|
2018-03-16 18:24:52 +01:00
|
|
|
}
|
2018-05-07 16:32:51 +02:00
|
|
|
|
2018-03-16 18:24:52 +01:00
|
|
|
try {
|
2021-01-03 01:55:01 +01:00
|
|
|
iteminfo_shopname.send(sender, "item", ItemUtil.getSignName(item));
|
2018-03-16 18:24:52 +01:00
|
|
|
} catch (IllegalArgumentException e) {
|
2019-03-19 19:08:53 +01:00
|
|
|
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;
|
2018-03-16 18:24:52 +01:00
|
|
|
}
|
2011-12-16 17:20:09 +01:00
|
|
|
|
2012-06-08 15:28:36 +02:00
|
|
|
ItemInfoEvent event = new ItemInfoEvent(sender, item);
|
|
|
|
ChestShop.callEvent(event);
|
2011-12-16 17:20:09 +01:00
|
|
|
|
2011-08-13 12:08:34 +02:00
|
|
|
return true;
|
2012-06-08 15:28:36 +02:00
|
|
|
}
|
2011-05-29 13:25:25 +02:00
|
|
|
}
|