Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
- if(commandLabel.equalsIgnoreCase("give")){ // If the command is /give, it will do the following:
- // Lets catch those stupid terminal errors
- try {
- if(!(sender instanceof Player)) {
- String gname = args[0];//Make the first arguments (/give firstargs) a string
- Player givee = this.getServer().getPlayer(gname);//Get the player from the string, used to specify a player in the command
- String ggname = givee.getDisplayName();//Gets the player's display name, only because 2 of my plugins have setDisplayName() stuff, so this is just an added bonus
- PlayerInventory pinv = givee.getInventory();//Gets the player's inventory, necessary if we want to edit it
- String itemid = args[1];//Sets the second arguments to a string
- Integer id = Integer.parseInt(Items.getItem(itemid));//This is a little complicated, refer to the below:
- //This basically uses the second arguments and runs it through getItem from Items.java, and returns an ID, which it then parses into an Integer
- ItemStack is = new ItemStack(0, 0);//Makes a new itemstack, this is how we add things to the inventory
- is.setTypeId(id);//Sets the ID of the itemstack to whatever was specified earlier
- String itemName = is.getType().name().toLowerCase().replace('_', ' ');//This is used to send the player a message saying "Enjoy the new log" or whatever
- //The following is run if there are more than 2 arguments:
- if(args.length > 2 ) {
- Integer am = Integer.parseInt(args[2]);//Parses the third arg (string) into an integer
- is.setAmount(am);//Sets the amount of the item in the itemstack to the third argument
- } else {
- is.setAmount(64);//If no Item amount was specified, sets it to 64
- }
- //The following is run if there are more than 3 arguments:
- if(args.length > 3 ) {
- String dmg = args[3];//Sets the 4 arguments to a string
- is.setDurability(Short.parseShort(dmg));//Parses the string into a short (the format durability uses), and sets the durability of the itemstack to the 4 arguments
- }
- pinv.addItem(is);//Finally adds the itemstack to the player's inventory
- log.info("[SimpleGive] " + ggname + " has received the " + itemName + "(s)");
- givee.sendMessage(ChatColor.BLUE + "Enjoy your new " + itemName + "(s)");//Sends the player that is receiving items a message, uses the name from earlier
- return true;
- } else {
- if (canUseGive((Player) sender)) {
- Player player = (Player) sender;
- try {
- String gname = args[0];//Make the first arguments (/give firstargs) a string
- Player givee = this.getServer().getPlayer(gname);//Get the player from the string, used to specify a player in the command
- String ggname = givee.getDisplayName();//Gets the player's display name, only because 2 of my plugins have setDisplayName() stuff, so this is just an added bonus
- PlayerInventory pinv = givee.getInventory();//Gets the player's inventory, necessary if we want to edit it
- String itemid = args[1];//Sets the second arguments to a string
- Integer id = Integer.parseInt(Items.getItem(itemid));//This is a little complicated, refer to the below:
- //This basically uses the second arguments and runs it through getItem from Items.java, and returns an ID, which it then parses into an Integer
- if(!canUseAGive(player, id)) {
- player.sendMessage(ChatColor.RED + "You aren't allowed to give " + id.toString());
- return true;
- }
- ItemStack is = new ItemStack(0, 0);//Makes a new itemstack, this is how we add things to the inventory
- is.setTypeId(id);//Sets the ID of the itemstack to whatever was specified earlier
- String itemName = is.getType().name().toLowerCase().replace('_', ' ');//This is used to send the player a message saying "Enjoy the new log" or whatever
- //The following is run if there are more than 2 arguments:
- if(args.length > 2 ) {
- Integer am = Integer.parseInt(args[2]);//Parses the third arg (string) into an integer
- is.setAmount(am);//Sets the amount of the item in the itemstack to the third argument
- } else {
- is.setAmount(64);//If no Item amount was specified, sets it to 64
- }
- //The following is run if there are more than 3 arguments:
- if(args.length > 3 ) {
- String dmg = args[3];//Sets the 4 arguments to a string
- is.setDurability(Short.parseShort(dmg));//Parses the string into a short (the format durability uses), and sets the durability of the itemstack to the 4 arguments
- }
- pinv.addItem(is);//Finally adds the itemstack to the player's inventory
- givee.sendMessage(ChatColor.BLUE + "Enjoy your new " + itemName);//Sends the player that is receiving items a message, uses the name from earlier
- player.sendMessage(ChatColor.RED + ggname + ChatColor.BLUE + " Has received the " + itemName);//Sends the command sender a message, uses the name from earlier
- } catch (NullPointerException e) {
- player.sendMessage(ChatColor.RED + "That Item Doesn't Exist!");
- }
- } else {
- Player s = (Player) sender;//sets the sender to s
- s.sendMessage(ChatColor.RED + "You don't have permisson to: " + ChatColor.AQUA + "Give Items!");//Shows this if the player doesn't have simpleadmin.give node
- }
- return true;//onCommand must return true or false
- }
- } catch(ArrayIndexOutOfBoundsException e) {
- sender.sendMessage(ChatColor.RED + "[SimpleGive]" + ChatColor.AQUA + " Incorrect Command Useage.");
- sender.sendMessage(ChatColor.RED + "[SimpleGive]" + ChatColor.AQUA + " /give <playername> <itemid/name> <amount> <durability>");
- }
- }
- // All of the below is the same as above but without the player argument. Basically exactly the same :)
- if(commandLabel.equalsIgnoreCase("i")){
- try {
- if (canUseI((Player) sender)) {
- Player player = (Player) sender;
- try {
- PlayerInventory pinv = player.getInventory();
- String itemid = args[0].replace("_", "");
- Integer id = Integer.parseInt(Items.getItem(itemid));
- if(!canUseAnI(player, id)) {
- player.sendMessage(ChatColor.RED+ "You aren't allowed to give yourself a " + id.toString());
- return true;
- }
- ItemStack is = new ItemStack(0, 0);
- is.setTypeId(id);
- String itemName = is.getType().name().toLowerCase().replace('_', ' ');
- if(args.length > 1 ) {
- Integer am = Integer.parseInt(args[1]);
- is.setAmount(am);
- } else {
- is.setAmount(64);
- }
- if(args.length > 2 ) {
- String dmg = args[2];
- is.setDurability(Short.parseShort(dmg));
- }
- pinv.addItem(is);
- player.sendMessage(ChatColor.BLUE + "Enjoy your new " + itemName);
- } catch(NullPointerException e) {
- player.sendMessage(ChatColor.RED + "That Item Doesn't Exist!");
- }
- } else {
- Player s = (Player) sender;
- s.sendMessage(ChatColor.RED + "You don't have permisson to: " + ChatColor.AQUA + "Itemize!");
- }
- } catch(ArrayIndexOutOfBoundsException e) {
- sender.sendMessage(ChatColor.RED + "[SimpleGive]" + ChatColor.AQUA + " Incorrect Command Useage.");
- sender.sendMessage(ChatColor.RED + "[SimpleGive]" + ChatColor.AQUA + " /i <itemid/name> <amount> <durability>");
- }
- return true;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement