diff --git a/modules/RoyalCommands/pom.xml b/modules/RoyalCommands/pom.xml
index acf7326c..42d3c07e 100644
--- a/modules/RoyalCommands/pom.xml
+++ b/modules/RoyalCommands/pom.xml
@@ -23,7 +23,7 @@
*.yml
*.txt
- items.csv
+ item_aliases.csv
diff --git a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/Config.java b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/Config.java
index cce17d21..55c48d73 100644
--- a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/Config.java
+++ b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/Config.java
@@ -366,15 +366,15 @@ public void reloadConfiguration() {
Reader in = null;
try {
- in = new FileReader(new File(this.plugin.getDataFolder() + File.separator + "items.csv"));
+ in = new FileReader(new File(this.plugin.getDataFolder() + File.separator + "item_aliases.csv"));
CSVReader reader = new CSVReader(in);
RoyalCommands.inm = new ItemNameManager(reader.readAll());
reader.close();
} catch (FileNotFoundException e) {
- this.plugin.getLogger().warning("items.csv was not found! Item aliases will not be used.");
+ this.plugin.getLogger().warning("item_aliases.csv was not found! Item aliases will not be used.");
RoyalCommands.inm = null;
} catch (final IOException e) {
- this.plugin.getLogger().warning("Internal input/output error loading items.csv. Item aliases will not be used.");
+ this.plugin.getLogger().warning("Internal input/output error loading item_aliases.csv. Item aliases will not be used.");
RoyalCommands.inm = null;
} finally {
try {
diff --git a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/ItemNameManager.java b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/ItemNameManager.java
index 92149ac6..469af8d1 100644
--- a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/ItemNameManager.java
+++ b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/ItemNameManager.java
@@ -26,9 +26,10 @@ public class ItemNameManager {
public ItemNameManager(Iterable values) {
for (String[] s : values) {
if (s.length < 1) continue;
+ if (s[0].startsWith("#")) continue;
String[] aliases;
try {
- aliases = s[2].split(",");
+ aliases = s[1].split(",");
} catch (IndexOutOfBoundsException e) {
Logger l = Logger.getLogger("Minecraft");
l.warning("[RoyalCommands] Values passed in ItemNameManager invalid: ");
@@ -36,17 +37,11 @@ public ItemNameManager(Iterable values) {
continue;
}
Material m;
- short data;
+ short data = 0;
try {
m = Material.valueOf(s[0]);
} catch (IllegalArgumentException ex) {
- RoyalCommands.getInstance().getLogger().warning("Material in items.csv is invalid: " + s[0]);
- continue;
- }
- try {
- data = Short.valueOf(s[1]);
- } catch (NumberFormatException e) {
- RoyalCommands.getInstance().getLogger().warning("Data in items.csv file is invalid: " + s[1]);
+ RoyalCommands.getInstance().getLogger().warning("Material in item_aliases.csv is invalid: " + s[0]);
continue;
}
synchronized (items) {
diff --git a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/RUtils.java b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/RUtils.java
index 94a7f128..8212fce0 100644
--- a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/RUtils.java
+++ b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/RUtils.java
@@ -5,6 +5,7 @@
*/
package org.royaldev.royalcommands;
+import org.apache.commons.lang3.ArrayUtils;
import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld;
import org.mvplugins.multiverse.core.world.MultiverseWorld;
@@ -86,6 +87,7 @@
import org.royaldev.royalcommands.rcommands.CmdBack;
import org.royaldev.royalcommands.spawninfo.SpawnInfo;
import org.royaldev.royalcommands.tools.NameFetcher;
+import org.royaldev.royalcommands.tools.Pair;
import org.royaldev.royalcommands.tools.UUIDFetcher;
@SuppressWarnings("unused")
diff --git a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/RoyalCommands.java b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/RoyalCommands.java
index e45fd46b..6e925331 100755
--- a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/RoyalCommands.java
+++ b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/RoyalCommands.java
@@ -392,7 +392,7 @@ public boolean isVanished(Player p, CommandSender cs) {
public void loadConfiguration() {
if (!new File(getDataFolder(), "config.yml").exists()) saveDefaultConfig();
- if (!new File(getDataFolder(), "items.csv").exists()) saveResource("items.csv", false);
+ if (!new File(getDataFolder(), "item_aliases.csv").exists()) saveResource("item_aliases.csv", false);
if (!new File(getDataFolder(), "rules.txt").exists()) saveResource("rules.txt", false);
if (!new File(getDataFolder(), "help.txt").exists()) saveResource("help.txt", false);
if (!new File(getDataFolder(), "warps.yml").exists()) saveResource("warps.yml", false);
diff --git a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdGive.java b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdGive.java
index 807f8710..1178fbe4 100644
--- a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdGive.java
+++ b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdGive.java
@@ -25,7 +25,7 @@
public class CmdGive extends TabCommand {
public CmdGive(final RoyalCommands instance, final String name) {
- super(instance, name, true, new Short[]{CompletionType.ONLINE_PLAYER.getShort(), CompletionType.ITEM_ALIAS.getShort()});
+ super(instance, name, true, new Short[]{CompletionType.ONLINE_PLAYER.getShort(), CompletionType.ITEM.getShort()});
}
public static boolean giveItemStandalone(CommandSender cs, Player target, String itemname, int amount) {
diff --git a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdHelmet.java b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdHelmet.java
index 2be4a16f..5412146f 100644
--- a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdHelmet.java
+++ b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdHelmet.java
@@ -21,7 +21,7 @@
public class CmdHelmet extends TabCommand {
public CmdHelmet(final RoyalCommands instance, final String name) {
- super(instance, name, true, new Short[]{CompletionType.ITEM_ALIAS.getShort()});
+ super(instance, name, true, new Short[]{CompletionType.ITEM.getShort()});
}
/**
* TODO: Add support to add a helmet to another player
diff --git a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdItem.java b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdItem.java
index 30f469aa..6795e6d6 100644
--- a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdItem.java
+++ b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdItem.java
@@ -30,7 +30,7 @@ public class CmdItem extends TabCommand {
private static final Flag loreFlag = new Flag<>(String.class, "description", "lore", "l");
public CmdItem(final RoyalCommands instance, final String name) {
- super(instance, name, true, new Short[]{CompletionType.ITEM_ALIAS.getShort()});
+ super(instance, name, true, new Short[]{CompletionType.ITEM.getShort()});
this.addExpectedFlag(CmdItem.nameFlag);
this.addExpectedFlag(CmdItem.loreFlag);
}
diff --git a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdRecipe.java b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdRecipe.java
index 10806e3e..89a3dbb0 100644
--- a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdRecipe.java
+++ b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdRecipe.java
@@ -38,13 +38,14 @@
import org.royaldev.royalcommands.RoyalCommands;
import org.royaldev.royalcommands.exceptions.InvalidItemNameException;
+
@ReflectCommand
public class CmdRecipe extends TabCommand {
private final Map tasks = new HashMap<>();
public CmdRecipe(final RoyalCommands instance, final String name) {
- super(instance, name, true, new Short[]{CompletionType.ITEM_ALIAS.getShort()});
+ super(instance, name, true, new Short[]{CompletionType.ITEM.getShort()});
this.plugin.getServer().getPluginManager().registerEvents(new WorkbenchCloseListener(), this.plugin);
}
diff --git a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdUses.java b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdUses.java
index ad4e7acf..8a03527a 100644
--- a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdUses.java
+++ b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdUses.java
@@ -47,7 +47,7 @@ public class CmdUses extends TabCommand {
private final Map tasks = new HashMap<>();
public CmdUses(final RoyalCommands instance, final String name) {
- super(instance, name, true, new Short[]{CompletionType.ITEM_ALIAS.getShort()});
+ super(instance, name, true, new Short[]{CompletionType.ITEM.getShort()});
this.plugin.getServer().getPluginManager().registerEvents(new WorkbenchCloseListener(), this.plugin);
}
diff --git a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/TabCommand.java b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/TabCommand.java
index 5cc032f4..1be99166 100644
--- a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/TabCommand.java
+++ b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/TabCommand.java
@@ -112,7 +112,10 @@ protected List getCompletionsFor(final CommandSender cs, final Command c
final String name = m.getKeyOrNull().getKey();
final String lowerCaseName = name.toLowerCase();
if (!lowerCaseName.startsWith(arg)) continue;
+ // Minecraft default item names
possibilities.add(lowerCaseName.equals(arg) ? 0 : possibilities.size(), name);
+ // Custom item names
+ possibilities.addAll(RoyalCommands.inm.getPossibleNames(arg));
}
break;
case ATTRIBUTE:
@@ -279,7 +282,7 @@ protected enum CompletionType {
*/
ONLINE_PLAYER((short) 1),
/**
- * Completes for any item alias in items.csv.
+ * Completes for any item alias in item_aliases.csv.
*/
ITEM_ALIAS((short) 2),
/**
diff --git a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/kits/Kit.java b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/kits/Kit.java
index 61a86c36..b58fe158 100644
--- a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/kits/Kit.java
+++ b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/kits/Kit.java
@@ -12,13 +12,11 @@
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import org.royaldev.royalcommands.RUtils;
-import org.royaldev.royalcommands.RoyalCommands;
import org.royaldev.royalcommands.shaded.com.sk89q.util.config.ConfigurationNode;
import org.royaldev.royalcommands.wrappers.player.RPlayer;
import java.util.ArrayList;
import java.util.List;
-
/**
* A class representing a kit.
*/
@@ -68,11 +66,11 @@ private Enchantment getEnchantment(final ConfigurationNode enchantment) {
* @param item Node representing an ItemStack
* @return ItemStack of null
*/
+ // TODO Handle invalid item names better
private ItemStack getItemStack(final ConfigurationNode item) {
- final ItemStack is = RoyalCommands.inm.getItemStackFromAlias(item.getString("type"));
- final Damageable imd = (Damageable) is.getItemMeta();
+ final ItemStack is = RUtils.getItem(item.getString("type"), item.getInt("amount", 1));
if (is == null) return null;
- is.setAmount(item.getInt("amount", 1));
+ final Damageable imd = (Damageable) is.getItemMeta();
imd.setDamage(item.getShort("damage", (short) 0));
final ItemMeta im = is.getItemMeta();
im.setDisplayName(RUtils.colorize(item.getString("name")));
@@ -92,7 +90,9 @@ private List getItemStacks(final List items) {
final List itemStacks = new ArrayList<>();
for (final ConfigurationNode item : items) {
final ItemStack is = this.getItemStack(item);
- if (is == null) continue;
+ if (is == null) {
+ continue;
+ }
itemStacks.add(is);
}
return itemStacks;
diff --git a/modules/RoyalCommands/src/main/resources/config.yml b/modules/RoyalCommands/src/main/resources/config.yml
index 3122fac8..5bc82257 100644
--- a/modules/RoyalCommands/src/main/resources/config.yml
+++ b/modules/RoyalCommands/src/main/resources/config.yml
@@ -279,7 +279,7 @@ kits:
description: An example kit.
# List of items for this kit
items:
- - type: LOG:OAK
+ - type: OAK_LOG
amount: 1
# You can use colors in lore and names
name: "&rWood of Champions"
@@ -299,9 +299,9 @@ kits:
wool:
description: A kit containing wool.
items:
- - type: WOOL:BLACK
+ - type: BLACK_WOOL
amount: 64
- - type: WOOL:BLUE
+ - type: BLUE_WOOL
amount: 35
# This kit can only be used once (cooldown of -1)
onetime:
diff --git a/modules/RoyalCommands/src/main/resources/item_aliases.csv b/modules/RoyalCommands/src/main/resources/item_aliases.csv
new file mode 100644
index 00000000..f943a28d
--- /dev/null
+++ b/modules/RoyalCommands/src/main/resources/item_aliases.csv
@@ -0,0 +1 @@
+#"DIAMOND_SWORD","stabby_knife"
\ No newline at end of file
diff --git a/modules/RoyalCommands/src/test/java/org/royaldev/royalcommands/TestAliases.java b/modules/RoyalCommands/src/test/java/org/royaldev/royalcommands/TestAliases.java
index 58f6f798..6271bd53 100644
--- a/modules/RoyalCommands/src/test/java/org/royaldev/royalcommands/TestAliases.java
+++ b/modules/RoyalCommands/src/test/java/org/royaldev/royalcommands/TestAliases.java
@@ -1,16 +1,13 @@
package org.royaldev.royalcommands;
-import org.bukkit.Material;
+
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.royaldev.royalcommands.opencsv.CSVReader;
-
import java.io.File;
-import java.io.FileReader;
-import java.io.Reader;
+
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
@@ -19,7 +16,6 @@
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;
-
public class TestAliases {
private YamlConfiguration pluginYml = null;
@@ -33,25 +29,6 @@ private YamlConfiguration getPluginYml() {
return this.pluginYml;
}
- @Test
- public void testAliases() throws Throwable {
- final Logger l = Logger.getLogger("org.royaldev.royalcommands");
- final File csv = new File("src/main/resources/items.csv");
- assertTrue("No items.csv found!", csv.exists());
- final Reader in = new FileReader(csv);
- CSVReader r = new CSVReader(in);
- final ItemNameManager inm = new ItemNameManager(r.readAll());
- boolean allAliasesExist = true;
- for (final Material m : Material.values()) {
- if (inm.aliasExists(m)) continue;
- if (m.name().startsWith("LEGACY")) continue;
- if (allAliasesExist) allAliasesExist = false;
- l.warning("Missing alias for Material " + m.name() + ".");
- }
- r.close();
- assertTrue("Missing aliases!", allAliasesExist);
- }
-
private RoyalCommands makeRoyalCommands() {
final RoyalCommands rc = mock(RoyalCommands.class);
when(rc.getLogger()).thenReturn(Logger.getAnonymousLogger());