Add commands for naming items.

This commit is contained in:
William Burns 2016-02-25 15:29:47 +00:00
parent 3a73b05895
commit 009d48659b
4 changed files with 154 additions and 20 deletions

View File

@ -22,26 +22,7 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilWorld;
import mineplex.mapparser.command.AdminCommand;
import mineplex.mapparser.command.AuthorCommand;
import mineplex.mapparser.command.BaseCommand;
import mineplex.mapparser.command.CopyCommand;
import mineplex.mapparser.command.CopySchematicsCommand;
import mineplex.mapparser.command.CreateCommand;
import mineplex.mapparser.command.DeleteCommand;
import mineplex.mapparser.command.GameTypeCommand;
import mineplex.mapparser.command.HubCommand;
import mineplex.mapparser.command.ListCommand;
import mineplex.mapparser.command.MapCommand;
import mineplex.mapparser.command.NameCommand;
import mineplex.mapparser.command.ParseCommand200;
import mineplex.mapparser.command.ParseCommand400;
import mineplex.mapparser.command.ParseCommand600;
import mineplex.mapparser.command.RenameCommand;
import mineplex.mapparser.command.SaveCommand;
import mineplex.mapparser.command.SetSpawnCommand;
import mineplex.mapparser.command.SpawnCommand;
import mineplex.mapparser.command.WorldsCommand;
import mineplex.mapparser.command.*;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -120,6 +101,9 @@ public class MapParser extends JavaPlugin implements Listener
_commands.add(new CopyCommand(this));
_commands.add(new SpawnCommand(this));
_commands.add(new SetSpawnCommand(this));
_commands.add(new ItemNameCommand(this));
_commands.add(new AddLoreCommand(this));
_commands.add(new ClearLoreCommand(this));
}
@Override

View File

@ -0,0 +1,58 @@
package mineplex.mapparser.command;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import mineplex.core.common.util.F;
import mineplex.mapparser.MapParser;
public class AddLoreCommand extends BaseCommand
{
public AddLoreCommand(MapParser plugin)
{
super(plugin, "addlore", "al");
}
@Override
public boolean execute(Player player, String alias, String[] args)
{
if (args == null || args.length < 1)
{
message(player, "Invalid Usage: " + F.elem("/" + alias + " <text>"));
return true;
}
ItemStack is = player.getItemInHand();
if (is == null || is.getType() == Material.AIR)
{
message(player, "You must be holding an item in your hand.");
return true;
}
ItemMeta im = is.getItemMeta();
String line = "";
for (int i = 0; i < args.length; i++)
{
line += args[i] + " ";
}
line = line.replaceAll("&", "§").trim();
List<String> lore = new ArrayList<>(im.getLore());
lore.add(line);
im.setLore(lore);
is.setItemMeta(im);
player.setItemInHand(is);
player.updateInventory();
message(player, "Added lore: " + line);
return true;
}
}

View File

@ -0,0 +1,40 @@
package mineplex.mapparser.command;
import java.util.ArrayList;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import mineplex.mapparser.MapParser;
public class ClearLoreCommand extends BaseCommand
{
public ClearLoreCommand(MapParser plugin)
{
super(plugin, "clearlore", "cl");
}
@Override
public boolean execute(Player player, String alias, String[] args)
{
ItemStack is = player.getItemInHand();
if (is == null || is.getType() == Material.AIR)
{
message(player, "You must be holding an item in your hand.");
return true;
}
ItemMeta im = is.getItemMeta();
im.setLore(new ArrayList<>());
is.setItemMeta(im);
player.setItemInHand(is);
player.updateInventory();
message(player, "Cleared lore on item!");
return true;
}
}

View File

@ -0,0 +1,52 @@
package mineplex.mapparser.command;
import mineplex.core.common.util.F;
import mineplex.mapparser.MapParser;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public class ItemNameCommand extends BaseCommand
{
public ItemNameCommand(MapParser plugin)
{
super(plugin, "itemname", "in");
}
@Override
public boolean execute(Player player, String alias, String[] args)
{
if (args == null || args.length < 1)
{
message(player, "Invalid Usage: " + F.elem("/" + alias + " <name>"));
return true;
}
ItemStack is = player.getItemInHand();
if (is == null || is.getType() == Material.AIR)
{
message(player, "You must be holding an item in your hand.");
return true;
}
ItemMeta im = is.getItemMeta();
String name = "";
for (int i = 0; i < args.length; i++)
{
name += args[i] + " ";
}
name = name.replaceAll("&", "§").trim();
im.setDisplayName(name);
is.setItemMeta(im);
player.setItemInHand(is);
player.updateInventory();
message(player, "Set name: " + name);
return true;
}
}