Improve comment formatting

This commit is contained in:
filoghost 2018-11-28 16:51:56 +01:00
parent 2eae19e2b3
commit 97af919551
30 changed files with 90 additions and 84 deletions

View File

@ -193,11 +193,11 @@ public class ChestCommands extends JavaPlugin {
getLogger().warning("Unhandled error while reading the placeholders! Please inform the developer."); getLogger().warning("Unhandled error while reading the placeholders! Please inform the developer.");
} }
// Load the menus. // Load the menus
File menusFolder = new File(getDataFolder(), "menu"); File menusFolder = new File(getDataFolder(), "menu");
if (!menusFolder.isDirectory()) { if (!menusFolder.isDirectory()) {
// Create the directory with the default menu. // Create the directory with the default menu
menusFolder.mkdirs(); menusFolder.mkdirs();
Utils.saveResourceSafe(this, "menu" + File.separator + "example.yml"); Utils.saveResourceSafe(this, "menu" + File.separator + "example.yml");
} }
@ -250,7 +250,7 @@ public class ChestCommands extends JavaPlugin {
} }
} }
// Register the BungeeCord plugin channel. // Register the BungeeCord plugin channel
if (!Bukkit.getMessenger().isOutgoingChannelRegistered(this, "BungeeCord")) { if (!Bukkit.getMessenger().isOutgoingChannelRegistered(this, "BungeeCord")) {
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
} }

View File

@ -68,7 +68,7 @@ public final class SimpleUpdater {
JSONArray filesArray = (JSONArray) readJson("https://api.curseforge.com/servermods/files?projectIds=" + projectId); JSONArray filesArray = (JSONArray) readJson("https://api.curseforge.com/servermods/files?projectIds=" + projectId);
if (filesArray.size() == 0) { if (filesArray.size() == 0) {
// The array cannot be empty, there must be at least one file. The project ID is not valid. // The array cannot be empty, there must be at least one file. The project ID is not valid
plugin.getLogger().warning("The project ID (" + projectId + ") provided for updating is invalid or curse had a problem."); plugin.getLogger().warning("The project ID (" + projectId + ") provided for updating is invalid or curse had a problem.");
plugin.getLogger().warning("If the error persists, please inform the author."); plugin.getLogger().warning("If the error persists, please inform the author.");
return; return;
@ -127,16 +127,16 @@ public final class SimpleUpdater {
String pluginVersion = plugin.getDescription().getVersion(); String pluginVersion = plugin.getDescription().getVersion();
if (pluginVersion == null) { if (pluginVersion == null) {
// Do not throw exceptions, just consider it as v0. // Do not throw exceptions, just consider it as v0
pluginVersion = "0"; pluginVersion = "0";
} }
if (!remoteVersion.matches("v?[0-9\\.]+")) { if (!remoteVersion.matches("v?[0-9\\.]+")) {
// Should always be checked before by this class. // Should always be checked before by this class
throw new IllegalArgumentException("fetched version's format is incorrect"); throw new IllegalArgumentException("fetched version's format is incorrect");
} }
// Remove all the "v" from the versions, replace multiple full stops with a single full stop, and split them. // Remove all the "v" from the versions, replace multiple full stops with a single full stop, and split them
String[] pluginVersionSplit = pluginVersion.replace("v", "").replaceAll("[\\.]{2,}", ".").split("\\."); String[] pluginVersionSplit = pluginVersion.replace("v", "").replaceAll("[\\.]{2,}", ".").split("\\.");
String[] remoteVersionSplit = remoteVersion.replace("v", "").replaceAll("[\\.]{2,}", ".").split("\\."); String[] remoteVersionSplit = remoteVersion.replace("v", "").replaceAll("[\\.]{2,}", ".").split("\\.");
@ -161,7 +161,7 @@ public final class SimpleUpdater {
return false; return false;
} }
// Continue the loop. // Continue the loop
} }
return false; return false;

View File

@ -56,7 +56,7 @@ public class Icon {
private Set<Variable> nameVariables; private Set<Variable> nameVariables;
private Map<Integer, Set<Variable>> loreVariables; private Map<Integer, Set<Variable>> loreVariables;
private ItemStack cachedItem; // When there are no variables, we don't recreate the item. private ItemStack cachedItem; // When there are no variables, we don't recreate the item
public Icon() { public Icon() {
enchantments = new HashMap<Enchantment, Integer>(); enchantments = new HashMap<Enchantment, Integer>();
@ -236,7 +236,7 @@ public class Icon {
} }
if (name.isEmpty()) { if (name.isEmpty()) {
// Add a color to display the name empty. // Add a color to display the name empty
return ChatColor.WHITE.toString(); return ChatColor.WHITE.toString();
} else { } else {
return name; return name;
@ -269,7 +269,7 @@ public class Icon {
output.add(line); output.add(line);
} }
} else { } else {
// Otherwise just copy the lines. // Otherwise just copy the lines
output.addAll(lore); output.addAll(lore);
} }
} }
@ -280,7 +280,7 @@ public class Icon {
output = Utils.newArrayList(); output = Utils.newArrayList();
} }
// Add an error message. // Add an error message
output.add(ChatColor.RED + "(Invalid material)"); output.add(ChatColor.RED + "(Invalid material)");
} }
@ -291,17 +291,17 @@ public class Icon {
public ItemStack createItemstack(Player pov) { public ItemStack createItemstack(Player pov) {
if (!this.hasVariables() && cachedItem != null) { if (!this.hasVariables() && cachedItem != null) {
// Performance. // Performance
return cachedItem; return cachedItem;
} }
// If the material is not set, display BEDROCK. // If the material is not set, display BEDROCK
ItemStack itemStack = (material != null) ? new ItemStack(material, amount, dataValue) : new ItemStack(Material.BEDROCK, amount); ItemStack itemStack = (material != null) ? new ItemStack(material, amount, dataValue) : new ItemStack(Material.BEDROCK, amount);
// First try to apply NBT data. // First try to apply NBT data
if (nbtData != null) { if (nbtData != null) {
try { try {
// Note: this method should not throw any exception. It should log directly to the console. // Note: this method should not throw any exception. It should log directly to the console
Bukkit.getUnsafe().modifyItemStack(itemStack, nbtData); Bukkit.getUnsafe().modifyItemStack(itemStack, nbtData);
} catch (Throwable t) { } catch (Throwable t) {
this.nbtData = null; this.nbtData = null;
@ -309,7 +309,7 @@ public class Icon {
} }
} }
// Then apply data from config nodes, overwriting NBT data if there are confliting values. // Then apply data from config nodes, overwriting NBT data if there are confliting values
ItemMeta itemMeta = itemStack.getItemMeta(); ItemMeta itemMeta = itemStack.getItemMeta();
if (hasName()) { if (hasName()) {
@ -336,7 +336,7 @@ public class Icon {
} }
if (!this.hasVariables()) { if (!this.hasVariables()) {
// If there are no variables, cache the item. // If there are no variables, cache the item
cachedItem = itemStack; cachedItem = itemStack;
} }

View File

@ -36,7 +36,7 @@ public class BungeeCordUtils {
DataOutputStream out = new DataOutputStream(byteArray); DataOutputStream out = new DataOutputStream(byteArray);
out.writeUTF("Connect"); out.writeUTF("Connect");
out.writeUTF(server); // Target Server. out.writeUTF(server); // Target Server
player.sendPluginMessage(ChestCommands.getInstance(), "BungeeCord", byteArray.toByteArray()); player.sendPluginMessage(ChestCommands.getInstance(), "BungeeCord", byteArray.toByteArray());

View File

@ -62,7 +62,7 @@ public abstract class CommandFramework implements CommandExecutor {
} catch (CommandException ex) { } catch (CommandException ex) {
if (ex.getMessage() != null && !ex.getMessage().isEmpty()) { if (ex.getMessage() != null && !ex.getMessage().isEmpty()) {
// Use RED by default. // Use RED by default
sender.sendMessage(ChatColor.RED + ex.getMessage()); sender.sendMessage(ChatColor.RED + ex.getMessage());
} }
} }

View File

@ -35,7 +35,7 @@ public class CommandHandler extends CommandFramework {
@Override @Override
public void execute(CommandSender sender, String label, String[] args) { public void execute(CommandSender sender, String label, String[] args) {
if (args.length == 0) { if (args.length == 0) {
// This info is accessible to anyone. Please don't remove it, remember that Chest Commands is developed for FREE. // This info is accessible to anyone. Please don't remove it, remember that Chest Commands is developed for free
sender.sendMessage(ChestCommands.CHAT_PREFIX); sender.sendMessage(ChestCommands.CHAT_PREFIX);
sender.sendMessage(ChatColor.GREEN + "Version: " + ChatColor.GRAY + ChestCommands.getInstance().getDescription().getVersion()); sender.sendMessage(ChatColor.GREEN + "Version: " + ChatColor.GRAY + ChestCommands.getInstance().getDescription().getVersion());
sender.sendMessage(ChatColor.GREEN + "Developer: " + ChatColor.GRAY + "filoghost"); sender.sendMessage(ChatColor.GREEN + "Developer: " + ChatColor.GRAY + "filoghost");

View File

@ -46,7 +46,7 @@ public class AsciiPlaceholders {
List<String> lines = Utils.readLines(file); List<String> lines = Utils.readLines(file);
for (String line : lines) { for (String line : lines) {
// Comment or empty line. // Comment or empty line
if (line.isEmpty() || line.startsWith("#")) { if (line.isEmpty() || line.startsWith("#")) {
continue; continue;
} }
@ -100,7 +100,7 @@ public class AsciiPlaceholders {
private static String unquote(String input) { private static String unquote(String input) {
if (input.length() < 2) { if (input.length() < 2) {
// Cannot be quoted. // Cannot be quoted
return input; return input;
} }
if (input.startsWith("'") && input.endsWith("'")) { if (input.startsWith("'") && input.endsWith("'")) {

View File

@ -27,7 +27,7 @@ public class Lang extends SpecialConfig {
public String menu_not_found = "&cMenu not found! Please inform the staff."; public String menu_not_found = "&cMenu not found! Please inform the staff.";
public String open_menu = "&aOpening the menu \"{menu}\"."; public String open_menu = "&aOpening the menu \"{menu}\".";
public String open_menu_others = "&aOpening the menu \"{menu}\" to {player}."; public String open_menu_others = "&aOpening the menu \"{menu}\" to {player}.";
public String any = "any"; // Used in no_required_item when data value is not restrictive. public String any = "any"; // Used in no_required_item when data value is not restrictive
public Lang(PluginConfig config) { public Lang(PluginConfig config) {
super(config); super(config);

View File

@ -52,7 +52,7 @@ public class PluginConfig extends YamlConfiguration {
} }
} }
// To reset all the values when loading. // To reset all the values when loading
for (String section : this.getKeys(false)) { for (String section : this.getKeys(false)) {
set(section, null); set(section, null);
} }

View File

@ -45,11 +45,11 @@ public class SpecialConfig {
public void load() throws IOException, InvalidConfigurationException, Exception { public void load() throws IOException, InvalidConfigurationException, Exception {
// Check if the configuration was initialized. // Check if the configuration was initialized
if (defaultValuesMap == null) { if (defaultValuesMap == null) {
defaultValuesMap = new HashMap<String, Object>(); defaultValuesMap = new HashMap<String, Object>();
// Put the values in the default values map. // Put the values in the default values map
for (Field field : getClass().getDeclaredFields()) { for (Field field : getClass().getDeclaredFields()) {
if (!isValidField(field)) continue; if (!isValidField(field)) continue;
@ -70,10 +70,10 @@ public class SpecialConfig {
} }
} }
// First of all, try to load the yaml file. // First of all, try to load the yaml file
config.load(); config.load();
// Save default values not set. // Save default values not set
boolean needsSave = false; boolean needsSave = false;
for (Entry<String, Object> entry : defaultValuesMap.entrySet()) { for (Entry<String, Object> entry : defaultValuesMap.entrySet()) {
if (!config.isSet(entry.getKey())) { if (!config.isSet(entry.getKey())) {
@ -87,7 +87,7 @@ public class SpecialConfig {
config.save(); config.save();
} }
// Now read change the fields. // Now read change the fields
for (Field field : getClass().getDeclaredFields()) { for (Field field : getClass().getDeclaredFields()) {
if (!isValidField(field)) continue; if (!isValidField(field)) continue;
@ -110,7 +110,7 @@ public class SpecialConfig {
field.set(this, config.getDouble(configKey)); field.set(this, config.getDouble(configKey));
} else if (type == String.class) { } else if (type == String.class) {
field.set(this, Utils.addColors(config.getString(configKey))); // Always add colors. field.set(this, Utils.addColors(config.getString(configKey))); // Always add colors
} else { } else {
config.getPlugin().getLogger().warning("Unknown field type: " + field.getType().getName() + " (" + field.getName() + "). Please inform the developer."); config.getPlugin().getLogger().warning("Unknown field type: " + field.getType().getName() + " (" + field.getName() + "). Please inform the developer.");

View File

@ -36,7 +36,7 @@ public class BoundItem {
this.menu = menu; this.menu = menu;
this.material = material; this.material = material;
this.clickType = clickType; this.clickType = clickType;
data = -1; // -1 = any. data = -1; // -1 = any
} }
public void setRestrictiveData(short data) { public void setRestrictiveData(short data) {
@ -52,16 +52,16 @@ public class BoundItem {
return false; return false;
} }
// First, they must have the same material. // First, they must have the same material
if (this.material != item.getType()) { if (this.material != item.getType()) {
return false; return false;
} }
// Check if the data value is valid (-1 = any data value). // Check if the data value is valid (-1 = any data value)
if (this.data != -1 && this.data != item.getDurability()) { if (this.data != -1 && this.data != item.getDurability()) {
return false; return false;
} }
// Finally checks the action. // Finally checks the action
return clickType.isValidInteract(action); return clickType.isValidInteract(action);
} }
} }

View File

@ -34,7 +34,7 @@ public class CommandsClickHandler implements ClickHandler {
if (commands != null && commands.size() > 0) { if (commands != null && commands.size() > 0) {
for (IconCommand command : commands) { for (IconCommand command : commands) {
if (command instanceof OpenIconCommand) { if (command instanceof OpenIconCommand) {
// Fix GUI closing if KEEP-OPEN is not set, and a command should open another GUI. // Fix GUI closing if KEEP-OPEN is not set, and a command should open another GUI
this.closeOnClick = false; this.closeOnClick = false;
} }
} }

View File

@ -112,7 +112,7 @@ public class ExtendedIconMenu extends IconMenu {
ItemStack newItem = AttributeRemover.hideAttributes(extIcon.createItemstack(player)); ItemStack newItem = AttributeRemover.hideAttributes(extIcon.createItemstack(player));
inventory.setItem(i, newItem); inventory.setItem(i, newItem);
} else { } else {
// Performance, only update name and lore. // Performance, only update name and lore
ItemStack oldItem = AttributeRemover.hideAttributes(inventory.getItem(i)); ItemStack oldItem = AttributeRemover.hideAttributes(inventory.getItem(i));
ItemMeta meta = oldItem.getItemMeta(); ItemMeta meta = oldItem.getItemMeta();
meta.setDisplayName(extIcon.calculateName(player)); meta.setDisplayName(extIcon.calculateName(player));

View File

@ -23,11 +23,11 @@ import com.gmail.filoghost.chestcommands.util.ClickType;
public class MenuData { public class MenuData {
// Required data. // Required data
private String title; private String title;
private int rows; private int rows;
// Optional data. // Optional data
private String[] commands; private String[] commands;
private Material boundMaterial; private Material boundMaterial;
private short boundDataValue; private short boundDataValue;
@ -38,7 +38,7 @@ public class MenuData {
public MenuData(String title, int rows) { public MenuData(String title, int rows) {
this.title = title; this.title = title;
this.rows = rows; this.rows = rows;
boundDataValue = -1; // -1 = any. boundDataValue = -1; // -1 = any
} }
public String getTitle() { public String getTitle() {

View File

@ -34,10 +34,12 @@ public class MenuInventoryHolder implements InventoryHolder {
@Override @Override
public Inventory getInventory() { public Inventory getInventory() {
// This inventory will not do anything. /*
// I'm 90% sure that it doesn't break any other plugin, * This inventory will not do anything.
// because the only way you can get here is using InventoryClickEvent, * I'm 90% sure that it doesn't break any other plugin,
// that is cancelled by ChestCommands, or using InventoryOpenEvent. * because the only way you can get here is using InventoryClickEvent,
* that is cancelled by ChestCommands, or using InventoryOpenEvent.
*/
return Bukkit.createInventory(null, iconMenu.getSize()); return Bukkit.createInventory(null, iconMenu.getSize());
} }

View File

@ -147,7 +147,7 @@ public class ExtendedIcon extends Icon {
@Override @Override
public boolean onClick(Player player) { public boolean onClick(Player player) {
// Check all the requirements. // Check all the requirements
if (!canClickIcon(player)) { if (!canClickIcon(player)) {
if (permissionMessage != null) { if (permissionMessage != null) {
@ -190,9 +190,9 @@ public class ExtendedIcon extends Icon {
} }
} }
// Take the money and the required item. // Take the money and the required item
boolean changedVariables = false; // To update the placeholders. boolean changedVariables = false; // To update the placeholders
if (moneyPrice > 0) { if (moneyPrice > 0) {
if (!EconomyBridge.takeMoney(player, moneyPrice)) { if (!EconomyBridge.takeMoney(player, moneyPrice)) {

View File

@ -31,7 +31,7 @@ public class DragonBarIconCommand extends IconCommand {
seconds = 1; seconds = 1;
message = command; message = command;
String[] split = command.split("\\|", 2); // Max of 2 pieces. String[] split = command.split("\\|", 2); // Max of 2 pieces
if (split.length > 1 && Utils.isValidPositiveInteger(split[0].trim())) { if (split.length > 1 && Utils.isValidPositiveInteger(split[0].trim())) {
seconds = Integer.parseInt(split[0].trim()); seconds = Integer.parseInt(split[0].trim());
message = split[1].trim(); message = split[1].trim();

View File

@ -33,8 +33,10 @@ public class OpenIconCommand extends IconCommand {
final ExtendedIconMenu menu = ChestCommands.getFileNameToMenuMap().get(command.toLowerCase()); final ExtendedIconMenu menu = ChestCommands.getFileNameToMenuMap().get(command.toLowerCase());
if (menu != null) { if (menu != null) {
// Delay the task, since this command is executed in ClickInventoryEvent /*
// and opening another inventory in the same moment is not a good idea. * Delay the task, since this command is executed in ClickInventoryEvent
* and opening another inventory in the same moment is not a good idea.
*/
Bukkit.getScheduler().scheduleSyncDelayedTask(ChestCommands.getInstance(), new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(ChestCommands.getInstance(), new Runnable() {
public void run() { public void run() {
if (player.hasPermission(menu.getPermission())) { if (player.hasPermission(menu.getPermission())) {

View File

@ -32,7 +32,7 @@ public class CommandListener implements Listener {
return; return;
} }
// Very fast method compared to split & substring. // Very fast method compared to split & substring
String command = StringUtils.getCleanCommand(event.getMessage()); String command = StringUtils.getCleanCommand(event.getMessage());
if (command.isEmpty()) { if (command.isEmpty()) {

View File

@ -57,7 +57,7 @@ public class InventoryListener implements Listener {
public void onInventoryClick(InventoryClickEvent event) { public void onInventoryClick(InventoryClickEvent event) {
if (event.getInventory().getHolder() instanceof MenuInventoryHolder) { if (event.getInventory().getHolder() instanceof MenuInventoryHolder) {
event.setCancelled(true); // First thing to do, if an exception is thrown at least the player doesn't take the item. event.setCancelled(true); // First thing to do, if an exception is thrown at least the player doesn't take the item
IconMenu menu = ((MenuInventoryHolder) event.getInventory().getHolder()).getIconMenu(); IconMenu menu = ((MenuInventoryHolder) event.getInventory().getHolder()).getIconMenu();
int slot = event.getRawSlot(); int slot = event.getRawSlot();
@ -81,7 +81,7 @@ public class InventoryListener implements Listener {
} }
} }
// Closes the inventory and executes commands AFTER the event. // Closes the inventory and executes commands AFTER the event
Bukkit.getScheduler().scheduleSyncDelayedTask(ChestCommands.getInstance(), new ExecuteCommandsTask(clicker, icon)); Bukkit.getScheduler().scheduleSyncDelayedTask(ChestCommands.getInstance(), new ExecuteCommandsTask(clicker, icon));
} }
} }

View File

@ -82,7 +82,7 @@ public class SignListener implements Listener {
@EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onSignChangeMonitor(SignChangeEvent event) { public void onSignChangeMonitor(SignChangeEvent event) {
// Prevent players with permissions for creating colored signs from creating menu signs. // Prevent players with permissions for creating colored signs from creating menu signs
if (event.getLine(0).equalsIgnoreCase(ChatColor.DARK_BLUE + "[menu]") && !event.getPlayer().hasPermission(Permissions.SIGN_CREATE)) { if (event.getLine(0).equalsIgnoreCase(ChatColor.DARK_BLUE + "[menu]") && !event.getPlayer().hasPermission(Permissions.SIGN_CREATE)) {
event.setLine(0, ChatColor.stripColor(event.getLine(0))); event.setLine(0, ChatColor.stripColor(event.getLine(0)));
} }

View File

@ -32,8 +32,8 @@ public class AttributeRemover {
private static Class<?> nbtTagCompoundClass; private static Class<?> nbtTagCompoundClass;
private static Class<?> nbtTagListClass; private static Class<?> nbtTagListClass;
private static Class<?> nmsItemstackClass; private static Class<?> nmsItemstackClass;
private static Method asNmsCopyMethod; // static private static Method asNmsCopyMethod;
private static Method asCraftMirrorMethod; // static private static Method asCraftMirrorMethod;
private static Method hasTagMethod; private static Method hasTagMethod;
private static Method getTagMethod; private static Method getTagMethod;
private static Method setTagMethod; private static Method setTagMethod;
@ -111,10 +111,12 @@ public class AttributeRemover {
nbtSetMethod.invoke(nbtCompound, "AttributeModifiers", nbtList); nbtSetMethod.invoke(nbtCompound, "AttributeModifiers", nbtList);
return (ItemStack) asCraftMirrorMethod.invoke(null, nmsItemstack); return (ItemStack) asCraftMirrorMethod.invoke(null, nmsItemstack);
} catch (Exception e) { } } catch (Throwable t) {
// Ignore
}
} }
// On failure // On failure just return the item
return item; return item;
} }

View File

@ -43,7 +43,7 @@ public class CommandSerializer {
commandTypesMap.put(commandPattern("console:"), ConsoleIconCommand.class); commandTypesMap.put(commandPattern("console:"), ConsoleIconCommand.class);
commandTypesMap.put(commandPattern("op:"), OpIconCommand.class); commandTypesMap.put(commandPattern("op:"), OpIconCommand.class);
commandTypesMap.put(commandPattern("(open|menu):"), OpenIconCommand.class); commandTypesMap.put(commandPattern("(open|menu):"), OpenIconCommand.class);
commandTypesMap.put(commandPattern("server:?"), ServerIconCommand.class); // The colon is optional. commandTypesMap.put(commandPattern("server:?"), ServerIconCommand.class); // The colon is optional
commandTypesMap.put(commandPattern("tell:"), TellIconCommand.class); commandTypesMap.put(commandPattern("tell:"), TellIconCommand.class);
commandTypesMap.put(commandPattern("broadcast:"), BroadcastIconCommand.class); commandTypesMap.put(commandPattern("broadcast:"), BroadcastIconCommand.class);
commandTypesMap.put(commandPattern("give:"), GiveIconCommand.class); commandTypesMap.put(commandPattern("give:"), GiveIconCommand.class);
@ -53,7 +53,7 @@ public class CommandSerializer {
} }
private static Pattern commandPattern(String regex) { private static Pattern commandPattern(String regex) {
return Pattern.compile("^(?i)" + regex); // Case insensitive and only at the beginning. return Pattern.compile("^(?i)" + regex); // Case insensitive and only at the beginning
} }
public static void checkClassConstructors(ErrorLogger errorLogger) { public static void checkClassConstructors(ErrorLogger errorLogger) {
@ -93,18 +93,18 @@ public class CommandSerializer {
for (Entry<Pattern, Class<? extends IconCommand>> entry : commandTypesMap.entrySet()) { for (Entry<Pattern, Class<? extends IconCommand>> entry : commandTypesMap.entrySet()) {
Matcher matcher = entry.getKey().matcher(input); Matcher matcher = entry.getKey().matcher(input);
if (matcher.find()) { if (matcher.find()) {
// Remove the command prefix and trim the spaces. // Remove the command prefix and trim the spaces
String cleanCommand = matcher.replaceFirst("").trim(); String cleanCommand = matcher.replaceFirst("").trim();
try { try {
return entry.getValue().getDeclaredConstructor(String.class).newInstance(cleanCommand); return entry.getValue().getDeclaredConstructor(String.class).newInstance(cleanCommand);
} catch (Exception e) { } catch (Exception e) {
// Checked at startup. // Checked at startup
} }
} }
} }
return new PlayerIconCommand(input); // Normal command, no match found. return new PlayerIconCommand(input); // Normal command, no match found
} }
} }

View File

@ -53,7 +53,7 @@ public class EnchantmentSerializer {
for (Enchantment enchant : Enchantment.values()) { for (Enchantment enchant : Enchantment.values()) {
if (enchant != null) { if (enchant != null) {
// Accepts the ugly default names too. // Accepts the ugly default names too
enchantmentsMap.put(formatLowercase(enchant.getName()), enchant); enchantmentsMap.put(formatLowercase(enchant.getName()), enchant);
} }
} }

View File

@ -89,7 +89,7 @@ public class IconSerializer {
public static Icon loadIconFromSection(ConfigurationSection section, String iconName, String menuFileName, ErrorLogger errorLogger) { public static Icon loadIconFromSection(ConfigurationSection section, String iconName, String menuFileName, ErrorLogger errorLogger) {
Validate.notNull(section, "ConfigurationSection cannot be null"); Validate.notNull(section, "ConfigurationSection cannot be null");
// The icon is valid even without a Material. // The icon is valid even without a Material
ExtendedIcon icon = new ExtendedIcon(); ExtendedIcon icon = new ExtendedIcon();
if (section.isSet(Nodes.ID)) { if (section.isSet(Nodes.ID)) {
@ -116,7 +116,7 @@ public class IconSerializer {
if (section.isSet(Nodes.NBT_DATA)) { if (section.isSet(Nodes.NBT_DATA)) {
String nbtData = section.getString(Nodes.NBT_DATA); String nbtData = section.getString(Nodes.NBT_DATA);
try { try {
// Check that NBT has valid syntax before applying it to the icon. // Check that NBT has valid syntax before applying it to the icon
MojangsonParser.parse(nbtData); MojangsonParser.parse(nbtData);
icon.setNBTData(nbtData); icon.setNBTData(nbtData);
} catch (MojangsonParseException e) { } catch (MojangsonParseException e) {

View File

@ -99,7 +99,7 @@ public class MenuSerializer {
} }
} else { } else {
rows = 6; // Defaults to 6 rows. rows = 6; // Defaults to 6 rows
errorLogger.addError("The menu \"" + config.getFileName() + "\" doesn't have a the number of rows set, it will have 6 rows by default."); errorLogger.addError("The menu \"" + config.getFileName() + "\" doesn't have a the number of rows set, it will have 6 rows by default.");
} }

View File

@ -21,7 +21,7 @@ import com.gmail.filoghost.chestcommands.exception.FormatException;
public class ItemStackReader { public class ItemStackReader {
private Material material = Material.STONE; // In the worst case (bad exception handling) we just get stone. private Material material = Material.STONE; // In the worst case (bad exception handling) we just get stone
private int amount = 1; private int amount = 1;
private short dataValue = 0; private short dataValue = 0;
private boolean explicitDataValue = false; private boolean explicitDataValue = false;
@ -34,11 +34,11 @@ public class ItemStackReader {
public ItemStackReader(String input, boolean parseAmount) throws FormatException { public ItemStackReader(String input, boolean parseAmount) throws FormatException {
Validate.notNull(input, "input cannot be null"); Validate.notNull(input, "input cannot be null");
// Remove spaces, they're not needed. // Remove spaces, they're not needed
input = StringUtils.stripChars(input, " _-"); input = StringUtils.stripChars(input, " _-");
if (parseAmount) { if (parseAmount) {
// Read the optional amount. // Read the optional amount
String[] splitAmount = input.split(","); String[] splitAmount = input.split(",");
if (splitAmount.length > 1) { if (splitAmount.length > 1) {
@ -51,13 +51,13 @@ public class ItemStackReader {
if (amount <= 0) throw new FormatException("invalid amount \"" + splitAmount[1] + "\""); if (amount <= 0) throw new FormatException("invalid amount \"" + splitAmount[1] + "\"");
this.amount = amount; this.amount = amount;
// Only keep the first part as input. // Only keep the first part as input
input = splitAmount[0]; input = splitAmount[0];
} }
} }
// Read the optional data value. // Read the optional data value
String[] splitByColons = input.split(":"); String[] splitByColons = input.split(":");
if (splitByColons.length > 1) { if (splitByColons.length > 1) {
@ -74,7 +74,7 @@ public class ItemStackReader {
this.explicitDataValue = true; this.explicitDataValue = true;
this.dataValue = dataValue; this.dataValue = dataValue;
// Only keep the first part as input. // Only keep the first part as input
input = splitByColons[0]; input = splitByColons[0];
} }

View File

@ -24,19 +24,19 @@ import org.bukkit.Material;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class MaterialsRegistry { public class MaterialsRegistry {
// Material names have been changed in 1.13, when dolphins were added. // Material names have been changed in 1.13, when dolphins were added
private static final boolean USE_NEW_MATERIAL_NAMES = Utils.isClassLoaded("org.bukkit.entity.Dolphin"); private static final boolean USE_NEW_MATERIAL_NAMES = Utils.isClassLoaded("org.bukkit.entity.Dolphin");
// Characters to ignore when searching materials by name. // Characters to ignore when searching materials by name
private static final char[] IGNORE_CHARS = {'-', '_', ' '}; private static final char[] IGNORE_CHARS = {'-', '_', ' '};
// Default material names are ugly. // Default material names are ugly
private static final Map<String, Material> MATERIALS_BY_ALIAS = new HashMap<String, Material>(); private static final Map<String, Material> MATERIALS_BY_ALIAS = new HashMap<String, Material>();
// Materials that are considered air (with 1.13+ compatibility). // Materials that are considered air (with 1.13+ compatibility)
private static final Collection<Material> AIR_MATERIALS = getExistingMaterials("AIR", "CAVE_AIR", "VOID_AIR"); private static final Collection<Material> AIR_MATERIALS = getExistingMaterials("AIR", "CAVE_AIR", "VOID_AIR");
// Materials that have a "Sign" block state (with 1.13+ compatibility). // Materials that have a "Sign" block state (with 1.13+ compatibility)
private static final Collection<Material> SIGN_MATERIALS = getExistingMaterials("SIGN", "SIGN_POST", "WALL_SIGN"); private static final Collection<Material> SIGN_MATERIALS = getExistingMaterials("SIGN", "SIGN_POST", "WALL_SIGN");
@ -48,7 +48,7 @@ public class MaterialsRegistry {
try { try {
addMaterialAlias(name, Material.valueOf(materialEnumName)); addMaterialAlias(name, Material.valueOf(materialEnumName));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// Ignore, do not add a new alias. // Ignore, do not add a new alias
} }
} }
@ -71,7 +71,7 @@ public class MaterialsRegistry {
try { try {
existingMaterials.add(Material.valueOf(materialEnumName)); existingMaterials.add(Material.valueOf(materialEnumName));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// Ignore, not existing. // Ignore, not existing
} }
} }
@ -95,12 +95,12 @@ public class MaterialsRegistry {
addMaterialAlias(material.toString(), material); addMaterialAlias(material.toString(), material);
if (!useNewMaterialNames()) { if (!useNewMaterialNames()) {
// Add numerical IDs in versions before 1.13. // Add numerical IDs in versions before 1.13
addMaterialAlias(String.valueOf(material.getId()), material); addMaterialAlias(String.valueOf(material.getId()), material);
} }
} }
// Add some default useful aliases (when present). // Add some default useful aliases (when present)
tryAddMaterialAlias("iron bar", "IRON_FENCE"); tryAddMaterialAlias("iron bar", "IRON_FENCE");
tryAddMaterialAlias("iron bars", "IRON_FENCE"); tryAddMaterialAlias("iron bars", "IRON_FENCE");
tryAddMaterialAlias("glass pane", "THIN_GLASS"); tryAddMaterialAlias("glass pane", "THIN_GLASS");

View File

@ -24,7 +24,7 @@ public class StringUtils {
return stripChars(input, removed.toCharArray()); return stripChars(input, removed.toCharArray());
} }
// Removes the first slash, and returns the all the chars until a space is encontered. // Removes the first slash, and returns the all the chars until a space is encontered
public static String getCleanCommand(String message) { public static String getCleanCommand(String message) {
char[] chars = message.toCharArray(); char[] chars = message.toCharArray();

View File

@ -228,7 +228,7 @@ public class Utils {
try { try {
plugin.saveResource(name, false); plugin.saveResource(name, false);
} catch (Exception ex) { } catch (Exception ex) {
// Shhh... // Ignore
} }
} }