I have just recently started to program Bukkit plugins for personal use and for learning purposes. I have decided to make a command-line global shop, since I'd rather not have to build a shop in-game. Here is the code i have currently:
package me.rougelong.globalshop;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.Material;
import java.util.logging.Logger;
public class globalshop extends JavaPlugin{
public final Logger logger = Logger.getLogger("Minecraft");
public static globalshop plugin;
@Override
public void onDisable() {
PluginDescriptionFile pdfFile = this.getDescription();
this.logger.info(pdfFile.getName() + " Has Been Disabled!");
}
@Override
public void onEnable() {
PluginDescriptionFile pdfFile = this.getDescription();
this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has Been Enabled!");
}
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
String itemName = args[0];
String amount = args[1];
if (args.length > 4 && commandLabel.equalsIgnoreCase("shopcheck")) {
sender.sendMessage(ChatColor.RED + "Too many arguments! /shopcheck [item_name] [quantity]");
return false;
}
if (args.length < 2 && commandLabel.equalsIgnoreCase("shopcheck")) {
sender.sendMessage(ChatColor.RED + "Not enough arguments! /shopcheck [item_name] [quantity]");
return false;
}
if (args.length > 4 && commandLabel.equalsIgnoreCase("shopbuy")) {
sender.sendMessage(ChatColor.RED + "Too many arguments! /shopbuy [item_name] [quantity]");
return false;
}
if (args.length < 2 && commandLabel.equalsIgnoreCase("shopbuy")) {
sender.sendMessage(ChatColor.RED + "Not enough arguments! /shopbuy [item_name] [quantity]");
return false;
}
if (args.length > 4 && commandLabel.equalsIgnoreCase("shopsell")) {
sender.sendMessage(ChatColor.RED + "Too many arguments! /shopsell [item_name] [quantity]");
return false;
}
if (args.length < 2 && commandLabel.equalsIgnoreCase("shopsell")) {
sender.sendMessage(ChatColor.RED + "Not enough arguments! /shopsell [item_name] [quantity]");
return false;
}
if (commandLabel.equalsIgnoreCase("shopcheck")){
//I need to get it to compare HERE. :P
return false;
}
return false;
}
}
I need it to compare itemName, or the args[0] (would be a String. Example: "cobblestone") to all the possible items, and I would prefer not to have to write in all the items into this plugin, I was wondering how to reference the lists of items within Bukkit. I am not sure if it would be blocks, or materials, or whatever.
My question(s) is: Which would I need to import to correctly compare the arg to? What code would I use to compare that singular arg to all the items so it can identify it?
Once that code is figured out and works, I'll be moving to have it then identify a price listed either in that program(hopefully not), or in a separate file. AND then having it go to check the balance of the sending player to see if they can buy it, and then have the money subtracted and the item added to their inventory Without removing something else they have in their hand.