mirror of
https://github.com/filoghost/ChestCommands.git
synced 2024-11-22 18:16:14 +01:00
Add more Checkstyle checks
This commit is contained in:
parent
5877ec3a22
commit
7e7b5d5427
@ -6,6 +6,7 @@
|
|||||||
<module name="Checker">
|
<module name="Checker">
|
||||||
<property name="fileExtensions" value="java, xml"/>
|
<property name="fileExtensions" value="java, xml"/>
|
||||||
<property name="charset" value="UTF-8"/>
|
<property name="charset" value="UTF-8"/>
|
||||||
|
<property name="severity" value="warning"/>
|
||||||
|
|
||||||
<module name="SuppressionFilter">
|
<module name="SuppressionFilter">
|
||||||
<property name="file" value="checkstyle/suppressions.xml"/>
|
<property name="file" value="checkstyle/suppressions.xml"/>
|
||||||
@ -13,12 +14,187 @@
|
|||||||
|
|
||||||
<!-- Check that Java source files have the correct header -->
|
<!-- Check that Java source files have the correct header -->
|
||||||
<module name="Header">
|
<module name="Header">
|
||||||
|
<property name="severity" value="error"/>
|
||||||
<property name="fileExtensions" value="java"/>
|
<property name="fileExtensions" value="java"/>
|
||||||
<property name="headerFile" value="checkstyle/header.txt"/>
|
<property name="headerFile" value="checkstyle/header.txt"/>
|
||||||
</module>
|
</module>
|
||||||
|
|
||||||
<!-- Check that files dont contain tabs -->
|
<!-- Check that files don't contain tabs -->
|
||||||
<module name="FileTabCharacter">
|
<module name="FileTabCharacter">
|
||||||
|
<property name="severity" value="error"/>
|
||||||
<property name="eachLine" value="true"/>
|
<property name="eachLine" value="true"/>
|
||||||
</module>
|
</module>
|
||||||
|
|
||||||
|
<!-- Trailing spaces -->
|
||||||
|
<module name="RegexpSingleline">
|
||||||
|
<property name="format" value="[^\s\*]\s+$"/>
|
||||||
|
<property name="minimum" value="0"/>
|
||||||
|
<property name="maximum" value="0"/>
|
||||||
|
<property name="message" value="Line has trailing spaces."/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!-- Limit maximum lines in a single file -->
|
||||||
|
<module name="FileLength">
|
||||||
|
<property name="fileExtensions" value="java"/>
|
||||||
|
<property name="max" value="600"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!-- Limit maximum line length for readability -->
|
||||||
|
<module name="LineLength">
|
||||||
|
<property name="fileExtensions" value="java"/>
|
||||||
|
<property name="max" value="160"/> <!-- TODO ideal limit is 120/140 -->
|
||||||
|
<property name="ignorePattern" value="^package.*|^import.*"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="TreeWalker">
|
||||||
|
<!-- Blocks -->
|
||||||
|
<module name="AvoidNestedBlocks"/>
|
||||||
|
<module name="EmptyBlock"/>
|
||||||
|
<module name="EmptyCatchBlock">
|
||||||
|
<property name="exceptionVariableName" value="expected|ignore"/>
|
||||||
|
</module>
|
||||||
|
<module name="LeftCurly"/>
|
||||||
|
<module name="NeedBraces"/>
|
||||||
|
<module name="RightCurly"/>
|
||||||
|
|
||||||
|
<!-- Class design -->
|
||||||
|
<module name="InterfaceIsType"/>
|
||||||
|
<module name="MutableException"/>
|
||||||
|
<module name="OneTopLevelClass"/>
|
||||||
|
<module name="ThrowsCount"/>
|
||||||
|
|
||||||
|
<!-- Coding -->
|
||||||
|
<!-- <module name="AvoidDoubleBraceInitialization"/> Only since Checkstyle v8.30 -->
|
||||||
|
<module name="AvoidNoArgumentSuperConstructorCall"/>
|
||||||
|
<module name="CovariantEquals"/>
|
||||||
|
<module name="DeclarationOrder">
|
||||||
|
<property name="ignoreConstructors" value="true"/>
|
||||||
|
</module>
|
||||||
|
<module name="DefaultComesLast"/>
|
||||||
|
<module name="EmptyStatement"/>
|
||||||
|
<module name="EqualsAvoidNull"/>
|
||||||
|
<module name="EqualsHashCode"/>
|
||||||
|
<module name="FallThrough"/>
|
||||||
|
<module name="IllegalCatch"/>
|
||||||
|
<module name="IllegalThrows"/>
|
||||||
|
<module name="IllegalToken"/>
|
||||||
|
<module name="IllegalType"/>
|
||||||
|
<module name="InnerAssignment"/>
|
||||||
|
<module name="MissingSwitchDefault"/>
|
||||||
|
<module name="ModifiedControlVariable">
|
||||||
|
<property name="skipEnhancedForLoopVariable" value="true"/>
|
||||||
|
</module>
|
||||||
|
<module name="NestedForDepth">
|
||||||
|
<property name="max" value="3"/>
|
||||||
|
</module>
|
||||||
|
<module name="NestedIfDepth">
|
||||||
|
<property name="max" value="3"/>
|
||||||
|
</module>
|
||||||
|
<module name="NestedTryDepth"/>
|
||||||
|
<module name="NoFinalizer"/>
|
||||||
|
<module name="OneStatementPerLine"/>
|
||||||
|
<module name="PackageDeclaration"/>
|
||||||
|
<module name="RequireThis"/>
|
||||||
|
<module name="SimplifyBooleanExpression"/>
|
||||||
|
<module name="StringLiteralEquality"/>
|
||||||
|
<module name="UnnecessaryParentheses">
|
||||||
|
<property name="tokens" value="EXPR, IDENT, NUM_DOUBLE, NUM_FLOAT, NUM_INT, NUM_LONG, STRING_LITERAL,
|
||||||
|
LITERAL_NULL, LITERAL_FALSE, LITERAL_TRUE, ASSIGN, BAND_ASSIGN, BOR_ASSIGN, BSR_ASSIGN,
|
||||||
|
BXOR_ASSIGN, DIV_ASSIGN, MINUS_ASSIGN, MOD_ASSIGN, PLUS_ASSIGN, SL_ASSIGN, SR_ASSIGN,
|
||||||
|
STAR_ASSIGN"/>
|
||||||
|
</module>
|
||||||
|
<!-- <module name="UnnecessarySemicolonAfterOuterTypeDeclaration"/> Only since Checkstyle v8.31 -->
|
||||||
|
<module name="UnnecessarySemicolonAfterTypeMemberDeclaration"/>
|
||||||
|
<module name="UnnecessarySemicolonInTryWithResources"/>
|
||||||
|
|
||||||
|
<!-- Imports -->
|
||||||
|
<module name="AvoidStarImport"/>
|
||||||
|
<module name="AvoidStaticImport"/>
|
||||||
|
<module name="IllegalImport">
|
||||||
|
<property name="illegalPkgs" value="sun"/>
|
||||||
|
<property name="illegalClasses" value="
|
||||||
|
com.google.common.base.Optional,
|
||||||
|
com.google.common.base.Function,
|
||||||
|
com.google.common.base.Supplier"/>
|
||||||
|
</module>
|
||||||
|
<module name="RedundantImport"/>
|
||||||
|
<module name="UnusedImports"/>
|
||||||
|
|
||||||
|
<!-- Javadoc -->
|
||||||
|
<module name="AtclauseOrder"/>
|
||||||
|
<module name="InvalidJavadocPosition"/>
|
||||||
|
<module name="JavadocBlockTagLocation"/>
|
||||||
|
<module name="JavadocContentLocation"/>
|
||||||
|
<module name="JavadocMethod"/>
|
||||||
|
<!-- <module name="JavadocMissingWhitespaceAfterAsterisk"/> Only since Checkstyle v8.32 -->
|
||||||
|
<module name="JavadocStyle"/>
|
||||||
|
<module name="JavadocTagContinuationIndentation"/>
|
||||||
|
<module name="JavadocType"/>
|
||||||
|
<module name="NonEmptyAtclauseDescription"/>
|
||||||
|
<module name="SingleLineJavadoc"/>
|
||||||
|
<module name="SummaryJavadoc"/>
|
||||||
|
|
||||||
|
<!-- Miscellaneous -->
|
||||||
|
<module name="ArrayTypeStyle"/>
|
||||||
|
<module name="AvoidEscapedUnicodeCharacters"/>
|
||||||
|
<module name="CommentsIndentation"/>
|
||||||
|
<module name="Indentation">
|
||||||
|
<property name="basicOffset" value="4"/>
|
||||||
|
<property name="braceAdjustment" value="0"/>
|
||||||
|
<property name="caseIndent" value="4"/>
|
||||||
|
<property name="throwsIndent" value="8"/>
|
||||||
|
<property name="lineWrappingIndentation" value="8"/>
|
||||||
|
<property name="arrayInitIndent" value="4"/>
|
||||||
|
</module>
|
||||||
|
<module name="OuterTypeFilename"/>
|
||||||
|
<module name="UpperEll"/>
|
||||||
|
|
||||||
|
<!-- Modifiers -->
|
||||||
|
<module name="ModifierOrder"/>
|
||||||
|
<module name="RedundantModifier"/>
|
||||||
|
|
||||||
|
<!-- Naming -->
|
||||||
|
<module name="ClassTypeParameterName"/>
|
||||||
|
<module name="InterfaceTypeParameterName"/>
|
||||||
|
<module name="MethodTypeParameterName"/>
|
||||||
|
<module name="LambdaParameterName"/>
|
||||||
|
<module name="LocalVariableName"/>
|
||||||
|
<module name="MemberName"/>
|
||||||
|
<module name="MethodName"/>
|
||||||
|
<module name="PackageName"/>
|
||||||
|
<module name="ParameterName"/>
|
||||||
|
|
||||||
|
<!-- Size -->
|
||||||
|
<module name="MethodCount"/>
|
||||||
|
<module name="OuterTypeNumber"/>
|
||||||
|
<module name="ParameterNumber"/>
|
||||||
|
|
||||||
|
<!-- Whitespace -->
|
||||||
|
<module name="EmptyForInitializerPad"/>
|
||||||
|
<module name="EmptyForIteratorPad"/>
|
||||||
|
<module name="EmptyLineSeparator">
|
||||||
|
<property name="allowNoEmptyLineBetweenFields" value="true"/>
|
||||||
|
<property name="tokens" value="IMPORT, STATIC_IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF, STATIC_INIT,
|
||||||
|
INSTANCE_INIT, METHOD_DEF, CTOR_DEF"/>
|
||||||
|
</module>
|
||||||
|
<module name="GenericWhitespace"/>
|
||||||
|
<module name="MethodParamPad"/>
|
||||||
|
<module name="NoLineWrap"/>
|
||||||
|
<module name="NoWhitespaceAfter"/>
|
||||||
|
<module name="NoWhitespaceBefore"/>
|
||||||
|
<module name="OperatorWrap"/>
|
||||||
|
<module name="ParenPad"/>
|
||||||
|
<module name="SingleSpaceSeparator"/>
|
||||||
|
<module name="TypecastParenPad"/>
|
||||||
|
<module name="WhitespaceAfter"/>
|
||||||
|
<module name="WhitespaceAround">
|
||||||
|
<property name="allowEmptyConstructors" value="true"/>
|
||||||
|
<property name="allowEmptyMethods" value="true"/>
|
||||||
|
<property name="allowEmptyTypes" value="true"/>
|
||||||
|
<property name="allowEmptyLoops" value="true"/>
|
||||||
|
<property name="allowEmptyLambdas" value="true"/>
|
||||||
|
<property name="allowEmptyCatches" value="true"/>
|
||||||
|
<property name="ignoreEnhancedForColon" value="false"/>
|
||||||
|
</module>
|
||||||
|
</module>
|
||||||
</module>
|
</module>
|
@ -4,5 +4,5 @@
|
|||||||
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
|
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
|
||||||
|
|
||||||
<suppressions>
|
<suppressions>
|
||||||
<suppress checks="Header" files=".*[\\/]me[\\/]filoghost[\\/]chestcommands[\\/]util[\\/]nbt[\\/].+\.java"/>
|
<suppress checks="Header|EqualsHashCode" files="[\\/]me[\\/]filoghost[\\/]chestcommands[\\/]util[\\/]nbt[\\/].+\.java"/>
|
||||||
</suppressions>
|
</suppressions>
|
@ -25,7 +25,7 @@ public class DragonBarAction implements Action {
|
|||||||
String[] split = Strings.trimmedSplit(serialiazedAction, "\\|", 2); // Max of 2 pieces
|
String[] split = Strings.trimmedSplit(serialiazedAction, "\\|", 2); // Max of 2 pieces
|
||||||
if (split.length > 1) {
|
if (split.length > 1) {
|
||||||
try {
|
try {
|
||||||
seconds = NumberParser.getStrictlyPositiveInteger(split[0]);
|
seconds = NumberParser.getStrictlyPositiveInteger(split[0]);
|
||||||
message = split[1];
|
message = split[1];
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
throw new ParseException(Errors.Parsing.invalidBossBarTime(split[0]), e);
|
throw new ParseException(Errors.Parsing.invalidBossBarTime(split[0]), e);
|
||||||
|
@ -58,7 +58,8 @@ public class CommandHandler extends CommandFramework {
|
|||||||
|
|
||||||
if (errorCollector.hasErrors()) {
|
if (errorCollector.hasErrors()) {
|
||||||
errorCollector.logToConsole();
|
errorCollector.logToConsole();
|
||||||
sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Last time the plugin loaded, " + errorCollector.getErrorsCount() + " error(s) were found.");
|
sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Last time the plugin loaded, "
|
||||||
|
+ errorCollector.getErrorsCount() + " error(s) were found.");
|
||||||
if (!(sender instanceof ConsoleCommandSender)) {
|
if (!(sender instanceof ConsoleCommandSender)) {
|
||||||
sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Errors were printed on the console.");
|
sender.sendMessage(ChestCommands.CHAT_PREFIX + ChatColor.RED + "Errors were printed on the console.");
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,8 @@ public enum VaultEconomyHook implements PluginHook {
|
|||||||
return balance >= minimum;
|
return balance >= minimum;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* @return true if the operation was successful.
|
* Returns true if the operation was successful.
|
||||||
*/
|
*/
|
||||||
public static boolean takeMoney(Player player, double amount) {
|
public static boolean takeMoney(Player player, double amount) {
|
||||||
INSTANCE.checkEnabledState();
|
INSTANCE.checkEnabledState();
|
||||||
|
@ -5,11 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
package me.filoghost.chestcommands.icon;
|
package me.filoghost.chestcommands.icon;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import me.filoghost.chestcommands.api.Icon;
|
import me.filoghost.chestcommands.api.Icon;
|
||||||
import me.filoghost.chestcommands.placeholder.PlaceholderString;
|
import me.filoghost.chestcommands.placeholder.PlaceholderString;
|
||||||
import me.filoghost.chestcommands.placeholder.PlaceholderStringList;
|
import me.filoghost.chestcommands.placeholder.PlaceholderStringList;
|
||||||
@ -17,7 +12,6 @@ import me.filoghost.chestcommands.util.nbt.parser.MojangsonParseException;
|
|||||||
import me.filoghost.chestcommands.util.nbt.parser.MojangsonParser;
|
import me.filoghost.chestcommands.util.nbt.parser.MojangsonParser;
|
||||||
import me.filoghost.fcommons.Preconditions;
|
import me.filoghost.fcommons.Preconditions;
|
||||||
import me.filoghost.fcommons.collection.CollectionUtils;
|
import me.filoghost.fcommons.collection.CollectionUtils;
|
||||||
import me.filoghost.fcommons.logging.Log;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
@ -33,6 +27,12 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||||
import org.bukkit.inventory.meta.SkullMeta;
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public abstract class BaseConfigurableIcon implements Icon {
|
public abstract class BaseConfigurableIcon implements Icon {
|
||||||
|
|
||||||
private Material material;
|
private Material material;
|
||||||
@ -49,7 +49,7 @@ public abstract class BaseConfigurableIcon implements Icon {
|
|||||||
private List<Pattern> bannerPatterns;
|
private List<Pattern> bannerPatterns;
|
||||||
private boolean placeholdersEnabled;
|
private boolean placeholdersEnabled;
|
||||||
|
|
||||||
protected ItemStack cachedRendering; // Cache the rendered item when possible and if state hasn't changed
|
private ItemStack cachedRendering; // Cache the rendered item when possible and if state hasn't changed
|
||||||
|
|
||||||
public BaseConfigurableIcon(Material material) {
|
public BaseConfigurableIcon(Material material) {
|
||||||
this.material = material;
|
this.material = material;
|
||||||
@ -266,13 +266,7 @@ public abstract class BaseConfigurableIcon implements Icon {
|
|||||||
|
|
||||||
// First try to apply NBT data
|
// First try to apply NBT data
|
||||||
if (nbtData != null) {
|
if (nbtData != null) {
|
||||||
try {
|
Bukkit.getUnsafe().modifyItemStack(itemStack, nbtData);
|
||||||
// Note: this method should not throw any exception. It should log directly to the console
|
|
||||||
Bukkit.getUnsafe().modifyItemStack(itemStack, nbtData);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
this.nbtData = null;
|
|
||||||
Log.warning("Could not apply NBT data to an item.", t);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then apply data from config nodes, overwriting NBT data if there are conflicting values
|
// Then apply data from config nodes, overwriting NBT data if there are conflicting values
|
||||||
|
@ -6,24 +6,26 @@
|
|||||||
package me.filoghost.chestcommands.legacy;
|
package me.filoghost.chestcommands.legacy;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import me.filoghost.chestcommands.config.ConfigManager;
|
||||||
|
import me.filoghost.chestcommands.legacy.upgrade.Upgrade;
|
||||||
|
import me.filoghost.chestcommands.legacy.upgrade.UpgradeTask;
|
||||||
|
import me.filoghost.chestcommands.legacy.upgrade.UpgradeTaskException;
|
||||||
|
import me.filoghost.chestcommands.legacy.v4_0.V4_0_LangUpgradeTask;
|
||||||
|
import me.filoghost.chestcommands.legacy.v4_0.V4_0_MenuNodeRenameUpgradeTask;
|
||||||
|
import me.filoghost.chestcommands.legacy.v4_0.V4_0_MenuReformatUpgradeTask;
|
||||||
|
import me.filoghost.chestcommands.legacy.v4_0.V4_0_PlaceholdersUpgradeTask;
|
||||||
|
import me.filoghost.chestcommands.legacy.v4_0.V4_0_SettingsUpgradeTask;
|
||||||
|
import me.filoghost.chestcommands.logging.Errors;
|
||||||
|
import me.filoghost.fcommons.collection.CollectionUtils;
|
||||||
|
import me.filoghost.fcommons.config.ConfigLoader;
|
||||||
|
import me.filoghost.fcommons.config.exception.ConfigException;
|
||||||
|
import me.filoghost.fcommons.logging.Log;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import me.filoghost.chestcommands.config.ConfigManager;
|
|
||||||
import me.filoghost.chestcommands.legacy.upgrade.Upgrade;
|
|
||||||
import me.filoghost.chestcommands.legacy.upgrade.UpgradeTask;
|
|
||||||
import me.filoghost.chestcommands.legacy.upgrade.UpgradeTaskException;
|
|
||||||
import me.filoghost.chestcommands.legacy.v4_0.v4_0_LangUpgradeTask;
|
|
||||||
import me.filoghost.chestcommands.legacy.v4_0.v4_0_MenuNodeRenameUpgradeTask;
|
|
||||||
import me.filoghost.chestcommands.legacy.v4_0.v4_0_MenuReformatUpgradeTask;
|
|
||||||
import me.filoghost.chestcommands.legacy.v4_0.v4_0_PlaceholdersUpgradeTask;
|
|
||||||
import me.filoghost.chestcommands.legacy.v4_0.v4_0_SettingsUpgradeTask;
|
|
||||||
import me.filoghost.chestcommands.logging.Errors;
|
|
||||||
import me.filoghost.fcommons.collection.CollectionUtils;
|
|
||||||
import me.filoghost.fcommons.config.ConfigLoader;
|
|
||||||
import me.filoghost.fcommons.logging.Log;
|
|
||||||
|
|
||||||
public class UpgradeList {
|
public class UpgradeList {
|
||||||
|
|
||||||
@ -32,20 +34,20 @@ public class UpgradeList {
|
|||||||
*/
|
*/
|
||||||
private static final ImmutableList<Upgrade> orderedUpgrades = ImmutableList.of(
|
private static final ImmutableList<Upgrade> orderedUpgrades = ImmutableList.of(
|
||||||
multiTaskUpgrade("v4.0-menus-rename", (configManager) -> {
|
multiTaskUpgrade("v4.0-menus-rename", (configManager) -> {
|
||||||
return createMenuTasks(configManager, v4_0_MenuNodeRenameUpgradeTask::new);
|
return createMenuTasks(configManager, V4_0_MenuNodeRenameUpgradeTask::new);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// Reformat after nodes have already been renamed
|
// Reformat after nodes have already been renamed
|
||||||
multiTaskUpgrade("v4.0-menus-reformat", (configManager) -> {
|
multiTaskUpgrade("v4.0-menus-reformat", (configManager) -> {
|
||||||
String legacyCommandSeparator = readLegacyCommandSeparator(configManager);
|
String legacyCommandSeparator = readLegacyCommandSeparator(configManager);
|
||||||
return createMenuTasks(configManager,
|
return createMenuTasks(configManager,
|
||||||
file -> new v4_0_MenuReformatUpgradeTask(configManager, file, legacyCommandSeparator));
|
file -> new V4_0_MenuReformatUpgradeTask(configManager, file, legacyCommandSeparator));
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// Upgrade config after reading the command separator for menus
|
// Upgrade config after reading the command separator for menus
|
||||||
singleTaskUpgrade("v4.0-config", v4_0_SettingsUpgradeTask::new),
|
singleTaskUpgrade("v4.0-config", V4_0_SettingsUpgradeTask::new),
|
||||||
singleTaskUpgrade("v4.0-placeholders", v4_0_PlaceholdersUpgradeTask::new),
|
singleTaskUpgrade("v4.0-placeholders", V4_0_PlaceholdersUpgradeTask::new),
|
||||||
singleTaskUpgrade("v4.0-lang", v4_0_LangUpgradeTask::new)
|
singleTaskUpgrade("v4.0-lang", V4_0_LangUpgradeTask::new)
|
||||||
);
|
);
|
||||||
|
|
||||||
private static Upgrade singleTaskUpgrade(String id, Upgrade.SingleTaskSupplier upgradeTaskSupplier) {
|
private static Upgrade singleTaskUpgrade(String id, Upgrade.SingleTaskSupplier upgradeTaskSupplier) {
|
||||||
@ -80,7 +82,7 @@ public class UpgradeList {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
return settingsConfigLoader.load().getString("multiple-commands-separator");
|
return settingsConfigLoader.load().getString("multiple-commands-separator");
|
||||||
} catch (Throwable t) {
|
} catch (ConfigException e) {
|
||||||
Log.warning("Failed to load \"" + settingsConfigLoader.getFile() + "\", assuming default command separator \";\".");
|
Log.warning("Failed to load \"" + settingsConfigLoader.getFile() + "\", assuming default command separator \";\".");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
*/
|
*/
|
||||||
package me.filoghost.chestcommands.legacy;
|
package me.filoghost.chestcommands.legacy;
|
||||||
|
|
||||||
|
import me.filoghost.chestcommands.legacy.upgrade.Upgrade;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@ -13,7 +15,6 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import me.filoghost.chestcommands.legacy.upgrade.Upgrade;
|
|
||||||
|
|
||||||
public class UpgradesDoneRegistry {
|
public class UpgradesDoneRegistry {
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ public class UpgradesDoneRegistry {
|
|||||||
private final Set<String> upgradesDone;
|
private final Set<String> upgradesDone;
|
||||||
private boolean needSave;
|
private boolean needSave;
|
||||||
|
|
||||||
public UpgradesDoneRegistry(Path saveFile) throws IOException {
|
public UpgradesDoneRegistry(Path saveFile) throws IOException {
|
||||||
this.saveFile = saveFile;
|
this.saveFile = saveFile;
|
||||||
this.upgradesDone = new HashSet<>();
|
this.upgradesDone = new HashSet<>();
|
||||||
|
|
||||||
|
@ -9,9 +9,9 @@ import me.filoghost.chestcommands.config.ConfigManager;
|
|||||||
import me.filoghost.chestcommands.legacy.upgrade.YamlUpgradeTask;
|
import me.filoghost.chestcommands.legacy.upgrade.YamlUpgradeTask;
|
||||||
import me.filoghost.fcommons.config.Config;
|
import me.filoghost.fcommons.config.Config;
|
||||||
|
|
||||||
public class v4_0_LangUpgradeTask extends YamlUpgradeTask {
|
public class V4_0_LangUpgradeTask extends YamlUpgradeTask {
|
||||||
|
|
||||||
public v4_0_LangUpgradeTask(ConfigManager configManager) {
|
public V4_0_LangUpgradeTask(ConfigManager configManager) {
|
||||||
super(configManager.getConfigLoader("lang.yml"));
|
super(configManager.getConfigLoader("lang.yml"));
|
||||||
}
|
}
|
||||||
|
|
@ -5,15 +5,17 @@
|
|||||||
*/
|
*/
|
||||||
package me.filoghost.chestcommands.legacy.v4_0;
|
package me.filoghost.chestcommands.legacy.v4_0;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import me.filoghost.chestcommands.legacy.upgrade.RegexUpgradeTask;
|
import me.filoghost.chestcommands.legacy.upgrade.RegexUpgradeTask;
|
||||||
import me.filoghost.chestcommands.parsing.icon.AttributeType;
|
import me.filoghost.chestcommands.parsing.icon.AttributeType;
|
||||||
|
|
||||||
public class v4_0_MenuNodeRenameUpgradeTask extends RegexUpgradeTask {
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public v4_0_MenuNodeRenameUpgradeTask(Path menuFile) {
|
public class V4_0_MenuNodeRenameUpgradeTask extends RegexUpgradeTask {
|
||||||
|
|
||||||
|
public V4_0_MenuNodeRenameUpgradeTask(Path menuFile) {
|
||||||
super(menuFile);
|
super(menuFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void computeRegexChanges() {
|
protected void computeRegexChanges() {
|
||||||
replaceSubNode("command", "commands");
|
replaceSubNode("command", "commands");
|
@ -5,11 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
package me.filoghost.chestcommands.legacy.v4_0;
|
package me.filoghost.chestcommands.legacy.v4_0;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import me.filoghost.chestcommands.config.ConfigManager;
|
import me.filoghost.chestcommands.config.ConfigManager;
|
||||||
import me.filoghost.chestcommands.legacy.upgrade.YamlUpgradeTask;
|
import me.filoghost.chestcommands.legacy.upgrade.YamlUpgradeTask;
|
||||||
import me.filoghost.chestcommands.parsing.icon.AttributeType;
|
import me.filoghost.chestcommands.parsing.icon.AttributeType;
|
||||||
@ -19,11 +14,17 @@ import me.filoghost.fcommons.config.Config;
|
|||||||
import me.filoghost.fcommons.config.ConfigSection;
|
import me.filoghost.fcommons.config.ConfigSection;
|
||||||
import me.filoghost.fcommons.config.ConfigValueType;
|
import me.filoghost.fcommons.config.ConfigValueType;
|
||||||
|
|
||||||
public class v4_0_MenuReformatUpgradeTask extends YamlUpgradeTask {
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class V4_0_MenuReformatUpgradeTask extends YamlUpgradeTask {
|
||||||
|
|
||||||
private final String legacyCommandSeparator;
|
private final String legacyCommandSeparator;
|
||||||
|
|
||||||
public v4_0_MenuReformatUpgradeTask(ConfigManager configManager, Path menuFile, String legacyCommandSeparator) {
|
public V4_0_MenuReformatUpgradeTask(ConfigManager configManager, Path menuFile, String legacyCommandSeparator) {
|
||||||
super(configManager.getConfigLoader(menuFile));
|
super(configManager.getConfigLoader(menuFile));
|
||||||
this.legacyCommandSeparator = legacyCommandSeparator;
|
this.legacyCommandSeparator = legacyCommandSeparator;
|
||||||
}
|
}
|
||||||
@ -78,7 +79,7 @@ public class v4_0_MenuReformatUpgradeTask extends YamlUpgradeTask {
|
|||||||
setSaveRequired();
|
setSaveRequired();
|
||||||
actions.set(i, newAction);
|
actions.set(i, newAction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
config.setStringList(node, actions);
|
config.setStringList(node, actions);
|
||||||
}
|
}
|
@ -5,10 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
package me.filoghost.chestcommands.legacy.v4_0;
|
package me.filoghost.chestcommands.legacy.v4_0;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.List;
|
|
||||||
import me.filoghost.chestcommands.config.ConfigManager;
|
import me.filoghost.chestcommands.config.ConfigManager;
|
||||||
import me.filoghost.chestcommands.legacy.upgrade.UpgradeTask;
|
import me.filoghost.chestcommands.legacy.upgrade.UpgradeTask;
|
||||||
import me.filoghost.fcommons.Strings;
|
import me.filoghost.fcommons.Strings;
|
||||||
@ -19,13 +15,18 @@ import me.filoghost.fcommons.config.exception.ConfigLoadException;
|
|||||||
import me.filoghost.fcommons.config.exception.ConfigSaveException;
|
import me.filoghost.fcommons.config.exception.ConfigSaveException;
|
||||||
import org.apache.commons.lang.StringEscapeUtils;
|
import org.apache.commons.lang.StringEscapeUtils;
|
||||||
|
|
||||||
public class v4_0_PlaceholdersUpgradeTask extends UpgradeTask {
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class V4_0_PlaceholdersUpgradeTask extends UpgradeTask {
|
||||||
|
|
||||||
private final Path oldPlaceholdersFile;
|
private final Path oldPlaceholdersFile;
|
||||||
private final ConfigLoader newPlaceholdersConfigLoader;
|
private final ConfigLoader newPlaceholdersConfigLoader;
|
||||||
private Config updatedConfig;
|
private Config updatedConfig;
|
||||||
|
|
||||||
public v4_0_PlaceholdersUpgradeTask(ConfigManager configManager) {
|
public V4_0_PlaceholdersUpgradeTask(ConfigManager configManager) {
|
||||||
this.oldPlaceholdersFile = configManager.getRootDataFolder().resolve("placeholders.yml");
|
this.oldPlaceholdersFile = configManager.getRootDataFolder().resolve("placeholders.yml");
|
||||||
this.newPlaceholdersConfigLoader = configManager.getConfigLoader("custom-placeholders.yml");
|
this.newPlaceholdersConfigLoader = configManager.getConfigLoader("custom-placeholders.yml");
|
||||||
}
|
}
|
@ -9,9 +9,9 @@ import me.filoghost.chestcommands.config.ConfigManager;
|
|||||||
import me.filoghost.chestcommands.legacy.upgrade.YamlUpgradeTask;
|
import me.filoghost.chestcommands.legacy.upgrade.YamlUpgradeTask;
|
||||||
import me.filoghost.fcommons.config.Config;
|
import me.filoghost.fcommons.config.Config;
|
||||||
|
|
||||||
public class v4_0_SettingsUpgradeTask extends YamlUpgradeTask {
|
public class V4_0_SettingsUpgradeTask extends YamlUpgradeTask {
|
||||||
|
|
||||||
public v4_0_SettingsUpgradeTask(ConfigManager configManager) {
|
public V4_0_SettingsUpgradeTask(ConfigManager configManager) {
|
||||||
super(configManager.getConfigLoader("config.yml"));
|
super(configManager.getConfigLoader("config.yml"));
|
||||||
}
|
}
|
||||||
|
|
@ -14,7 +14,7 @@ class ErrorPrintInfo {
|
|||||||
private final String details;
|
private final String details;
|
||||||
private final Throwable cause;
|
private final Throwable cause;
|
||||||
|
|
||||||
public ErrorPrintInfo(int index, List<String> message, String details, Throwable cause) {
|
protected ErrorPrintInfo(int index, List<String> message, String details, Throwable cause) {
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.details = details;
|
this.details = details;
|
||||||
|
@ -5,13 +5,14 @@
|
|||||||
*/
|
*/
|
||||||
package me.filoghost.chestcommands.logging;
|
package me.filoghost.chestcommands.logging;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import me.filoghost.chestcommands.ChestCommands;
|
import me.filoghost.chestcommands.ChestCommands;
|
||||||
import me.filoghost.chestcommands.parsing.icon.AttributeType;
|
import me.filoghost.chestcommands.parsing.icon.AttributeType;
|
||||||
import me.filoghost.chestcommands.parsing.icon.IconSettings;
|
import me.filoghost.chestcommands.parsing.icon.IconSettings;
|
||||||
import me.filoghost.fcommons.config.ConfigErrors;
|
import me.filoghost.fcommons.config.ConfigErrors;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public class Errors {
|
public class Errors {
|
||||||
|
|
||||||
public static class Config {
|
public static class Config {
|
||||||
@ -41,7 +42,9 @@ public class Errors {
|
|||||||
|
|
||||||
public static final String genericExecutorError = "error while running automatic configuration upgrades";
|
public static final String genericExecutorError = "error while running automatic configuration upgrades";
|
||||||
public static final String menuListIOException = "couldn't obtain a list of menu files";
|
public static final String menuListIOException = "couldn't obtain a list of menu files";
|
||||||
public static final String failedSomeUpgrades = "note: one or more automatic upgrades may have not been applied, configuration files or menus may require manual changes";
|
public static final String failedSomeUpgrades =
|
||||||
|
"note: one or more automatic upgrades may have not been applied, "
|
||||||
|
+ "configuration files or menus may require manual changes";
|
||||||
public static final String failedToPrepareUpgradeTasks = "error while trying to prepare an automatic configuration upgrade";
|
public static final String failedToPrepareUpgradeTasks = "error while trying to prepare an automatic configuration upgrade";
|
||||||
|
|
||||||
public static String metadataReadError(Path metadataFile) {
|
public static String metadataReadError(Path metadataFile) {
|
||||||
|
@ -18,8 +18,8 @@ import org.bukkit.entity.Player;
|
|||||||
public abstract class BaseMenu implements Menu {
|
public abstract class BaseMenu implements Menu {
|
||||||
|
|
||||||
|
|
||||||
protected final String title;
|
private final String title;
|
||||||
protected final Grid<Icon> icons;
|
private final Grid<Icon> icons;
|
||||||
|
|
||||||
|
|
||||||
public BaseMenu(String title, int rows) {
|
public BaseMenu(String title, int rows) {
|
||||||
|
@ -19,7 +19,7 @@ public class ItemStackParser {
|
|||||||
private short durability = 0;
|
private short durability = 0;
|
||||||
private boolean hasExplicitDurability = false;
|
private boolean hasExplicitDurability = false;
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Reads item in the format "material:durability, amount".
|
* Reads item in the format "material:durability, amount".
|
||||||
*/
|
*/
|
||||||
public ItemStackParser(String input, boolean parseAmount) throws ParseException {
|
public ItemStackParser(String input, boolean parseAmount) throws ParseException {
|
||||||
|
@ -5,9 +5,10 @@
|
|||||||
*/
|
*/
|
||||||
package me.filoghost.chestcommands.placeholder.scanner;
|
package me.filoghost.chestcommands.placeholder.scanner;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
import me.filoghost.fcommons.Strings;
|
import me.filoghost.fcommons.Strings;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class PlaceholderMatch {
|
public class PlaceholderMatch {
|
||||||
|
|
||||||
private final String pluginNamespace;
|
private final String pluginNamespace;
|
||||||
@ -32,7 +33,7 @@ public class PlaceholderMatch {
|
|||||||
return argument;
|
return argument;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Valid formats:
|
* Valid formats:
|
||||||
* {pluginName/placeholder: argument}
|
* {pluginName/placeholder: argument}
|
||||||
* {placeholder: argument}
|
* {placeholder: argument}
|
||||||
@ -70,9 +71,9 @@ public class PlaceholderMatch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PlaceholderMatch other = (PlaceholderMatch) obj;
|
PlaceholderMatch other = (PlaceholderMatch) obj;
|
||||||
return Objects.equals(this.pluginNamespace, other.pluginNamespace) &&
|
return Objects.equals(this.pluginNamespace, other.pluginNamespace)
|
||||||
Objects.equals(this.identifier, other.identifier) &&
|
&& Objects.equals(this.identifier, other.identifier)
|
||||||
Objects.equals(this.argument, other.argument);
|
&& Objects.equals(this.argument, other.argument);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,8 +20,9 @@ public final class NBTByteArray extends NBTTag {
|
|||||||
|
|
||||||
public NBTByteArray(Number[] numbers) {
|
public NBTByteArray(Number[] numbers) {
|
||||||
this.value = new byte[numbers.length];
|
this.value = new byte[numbers.length];
|
||||||
for (int i = 0; i < numbers.length; i++)
|
for (int i = 0; i < numbers.length; i++) {
|
||||||
value[i] = numbers[i].byteValue();
|
value[i] = numbers[i].byteValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,7 +61,9 @@ public final class NBTCompound extends NBTTag {
|
|||||||
* @throws NoSuchElementException if there is no tag with given name
|
* @throws NoSuchElementException if there is no tag with given name
|
||||||
*/
|
*/
|
||||||
public NBTTag getTag(String key) {
|
public NBTTag getTag(String key) {
|
||||||
if (!hasKey(key)) throw new NoSuchElementException(key);
|
if (!hasKey(key)) {
|
||||||
|
throw new NoSuchElementException(key);
|
||||||
|
}
|
||||||
return value.get(key);
|
return value.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +76,9 @@ public final class NBTCompound extends NBTTag {
|
|||||||
*/
|
*/
|
||||||
public byte getByte(String key) {
|
public byte getByte(String key) {
|
||||||
NBTTag tag = value.get(key);
|
NBTTag tag = value.get(key);
|
||||||
if (!(tag instanceof NBTByte)) throw new NoSuchElementException(key);
|
if (!(tag instanceof NBTByte)) {
|
||||||
|
throw new NoSuchElementException(key);
|
||||||
|
}
|
||||||
return ((NBTByte) tag).getValue();
|
return ((NBTByte) tag).getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +91,9 @@ public final class NBTCompound extends NBTTag {
|
|||||||
*/
|
*/
|
||||||
public short getShort(String key) {
|
public short getShort(String key) {
|
||||||
NBTTag tag = value.get(key);
|
NBTTag tag = value.get(key);
|
||||||
if (!(tag instanceof NBTShort)) throw new NoSuchElementException(key);
|
if (!(tag instanceof NBTShort)) {
|
||||||
|
throw new NoSuchElementException(key);
|
||||||
|
}
|
||||||
return ((NBTShort) tag).getValue();
|
return ((NBTShort) tag).getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +106,9 @@ public final class NBTCompound extends NBTTag {
|
|||||||
*/
|
*/
|
||||||
public int getInt(String key) {
|
public int getInt(String key) {
|
||||||
NBTTag tag = value.get(key);
|
NBTTag tag = value.get(key);
|
||||||
if (!(tag instanceof NBTInt)) throw new NoSuchElementException(key);
|
if (!(tag instanceof NBTInt)) {
|
||||||
|
throw new NoSuchElementException(key);
|
||||||
|
}
|
||||||
return ((NBTInt) tag).getValue();
|
return ((NBTInt) tag).getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +121,9 @@ public final class NBTCompound extends NBTTag {
|
|||||||
*/
|
*/
|
||||||
public long getLong(String key) {
|
public long getLong(String key) {
|
||||||
NBTTag tag = value.get(key);
|
NBTTag tag = value.get(key);
|
||||||
if (!(tag instanceof NBTLong)) throw new NoSuchElementException(key);
|
if (!(tag instanceof NBTLong)) {
|
||||||
|
throw new NoSuchElementException(key);
|
||||||
|
}
|
||||||
return ((NBTLong) tag).getValue();
|
return ((NBTLong) tag).getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +136,9 @@ public final class NBTCompound extends NBTTag {
|
|||||||
*/
|
*/
|
||||||
public float getFloat(String key) {
|
public float getFloat(String key) {
|
||||||
NBTTag tag = value.get(key);
|
NBTTag tag = value.get(key);
|
||||||
if (!(tag instanceof NBTFloat)) throw new NoSuchElementException(key);
|
if (!(tag instanceof NBTFloat)) {
|
||||||
|
throw new NoSuchElementException(key);
|
||||||
|
}
|
||||||
return ((NBTFloat) tag).getValue();
|
return ((NBTFloat) tag).getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +151,9 @@ public final class NBTCompound extends NBTTag {
|
|||||||
*/
|
*/
|
||||||
public double getDouble(String key) {
|
public double getDouble(String key) {
|
||||||
NBTTag tag = value.get(key);
|
NBTTag tag = value.get(key);
|
||||||
if (!(tag instanceof NBTDouble)) throw new NoSuchElementException(key);
|
if (!(tag instanceof NBTDouble)) {
|
||||||
|
throw new NoSuchElementException(key);
|
||||||
|
}
|
||||||
return ((NBTDouble) tag).getValue();
|
return ((NBTDouble) tag).getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +166,9 @@ public final class NBTCompound extends NBTTag {
|
|||||||
*/
|
*/
|
||||||
public byte[] getByteArray(String key) {
|
public byte[] getByteArray(String key) {
|
||||||
NBTTag tag = value.get(key);
|
NBTTag tag = value.get(key);
|
||||||
if (!(tag instanceof NBTByteArray)) throw new NoSuchElementException(key);
|
if (!(tag instanceof NBTByteArray)) {
|
||||||
|
throw new NoSuchElementException(key);
|
||||||
|
}
|
||||||
return ((NBTByteArray) tag).getValue();
|
return ((NBTByteArray) tag).getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,7 +181,9 @@ public final class NBTCompound extends NBTTag {
|
|||||||
*/
|
*/
|
||||||
public String getString(String key) {
|
public String getString(String key) {
|
||||||
NBTTag tag = value.get(key);
|
NBTTag tag = value.get(key);
|
||||||
if (!(tag instanceof NBTString)) throw new NoSuchElementException(key);
|
if (!(tag instanceof NBTString)) {
|
||||||
|
throw new NoSuchElementException(key);
|
||||||
|
}
|
||||||
return ((NBTString) tag).getValue();
|
return ((NBTString) tag).getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,7 +207,9 @@ public final class NBTCompound extends NBTTag {
|
|||||||
*/
|
*/
|
||||||
public NBTList getTagList(String key) {
|
public NBTList getTagList(String key) {
|
||||||
NBTTag tag = value.get(key);
|
NBTTag tag = value.get(key);
|
||||||
if (!(tag instanceof NBTList)) throw new NoSuchElementException(key);
|
if (!(tag instanceof NBTList)) {
|
||||||
|
throw new NoSuchElementException(key);
|
||||||
|
}
|
||||||
return (NBTList) tag;
|
return (NBTList) tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,7 +233,9 @@ public final class NBTCompound extends NBTTag {
|
|||||||
*/
|
*/
|
||||||
public NBTCompound getCompoundTag(String key) {
|
public NBTCompound getCompoundTag(String key) {
|
||||||
NBTTag tag = value.get(key);
|
NBTTag tag = value.get(key);
|
||||||
if (!(tag instanceof NBTCompound)) throw new NoSuchElementException(key);
|
if (!(tag instanceof NBTCompound)) {
|
||||||
|
throw new NoSuchElementException(key);
|
||||||
|
}
|
||||||
return (NBTCompound) tag;
|
return (NBTCompound) tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +248,9 @@ public final class NBTCompound extends NBTTag {
|
|||||||
*/
|
*/
|
||||||
public int[] getIntArray(String key) {
|
public int[] getIntArray(String key) {
|
||||||
NBTTag tag = value.get(key);
|
NBTTag tag = value.get(key);
|
||||||
if (!(tag instanceof NBTIntArray)) throw new NoSuchElementException(key);
|
if (!(tag instanceof NBTIntArray)) {
|
||||||
|
throw new NoSuchElementException(key);
|
||||||
|
}
|
||||||
return ((NBTIntArray) tag).getValue();
|
return ((NBTIntArray) tag).getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,7 +263,9 @@ public final class NBTCompound extends NBTTag {
|
|||||||
*/
|
*/
|
||||||
public long[] getLongArray(String key) {
|
public long[] getLongArray(String key) {
|
||||||
NBTTag tag = value.get(key);
|
NBTTag tag = value.get(key);
|
||||||
if (!(tag instanceof NBTLongArray)) throw new NoSuchElementException(key);
|
if (!(tag instanceof NBTLongArray)) {
|
||||||
|
throw new NoSuchElementException(key);
|
||||||
|
}
|
||||||
return ((NBTLongArray) tag).getValue();
|
return ((NBTLongArray) tag).getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,8 +26,9 @@ public final class NBTIntArray extends NBTTag implements Cloneable {
|
|||||||
|
|
||||||
public NBTIntArray(Number[] numbers) {
|
public NBTIntArray(Number[] numbers) {
|
||||||
this.value = new int[numbers.length];
|
this.value = new int[numbers.length];
|
||||||
for (int i = 0; i < numbers.length; i++)
|
for (int i = 0; i < numbers.length; i++) {
|
||||||
value[i] = numbers[i].intValue();
|
value[i] = numbers[i].intValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -120,25 +120,29 @@ public final class NBTList extends NBTTag implements Iterable<NBTTag>, Cloneable
|
|||||||
* @param value the tag
|
* @param value the tag
|
||||||
*/
|
*/
|
||||||
public void add(NBTTag value) {
|
public void add(NBTTag value) {
|
||||||
if (this.type == null)
|
if (this.type == null) {
|
||||||
this.type = value.getType();
|
this.type = value.getType();
|
||||||
else if (this.type != value.getType())
|
} else if (this.type != value.getType()) {
|
||||||
throw new IllegalArgumentException(value.getType() + " is not of expected type " + type);
|
throw new IllegalArgumentException(value.getType() + " is not of expected type " + type);
|
||||||
|
}
|
||||||
list.add(value);
|
list.add(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the given tag at the given index in the list.
|
* Add the given tag at the given index in the list.
|
||||||
*
|
*
|
||||||
|
* @param index the index in the list
|
||||||
* @param value the tag
|
* @param value the tag
|
||||||
*/
|
*/
|
||||||
public void add(int index, NBTTag value) {
|
public void add(int index, NBTTag value) {
|
||||||
if (index < 0 || index >= list.size())
|
if (index < 0 || index >= list.size()) {
|
||||||
throw new IndexOutOfBoundsException(Integer.toString(index));
|
throw new IndexOutOfBoundsException(Integer.toString(index));
|
||||||
if (this.type == null)
|
}
|
||||||
|
if (this.type == null) {
|
||||||
this.type = value.getType();
|
this.type = value.getType();
|
||||||
else if (this.type != value.getType())
|
} else if (this.type != value.getType()) {
|
||||||
throw new IllegalArgumentException(value.getType() + " is not of expected type " + type);
|
throw new IllegalArgumentException(value.getType() + " is not of expected type " + type);
|
||||||
|
}
|
||||||
list.add(index, value);
|
list.add(index, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,8 +181,11 @@ public final class NBTList extends NBTTag implements Iterable<NBTTag>, Cloneable
|
|||||||
|
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
if (first) first = false;
|
if (first) {
|
||||||
else builder.append(',');
|
first = false;
|
||||||
|
} else {
|
||||||
|
builder.append(',');
|
||||||
|
}
|
||||||
builder.append(iter.next().toMSONString());
|
builder.append(iter.next().toMSONString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,8 +25,9 @@ public final class NBTLongArray extends NBTTag {
|
|||||||
|
|
||||||
public NBTLongArray(Number[] numbers) {
|
public NBTLongArray(Number[] numbers) {
|
||||||
this.value = new long[numbers.length];
|
this.value = new long[numbers.length];
|
||||||
for (int i = 0; i < numbers.length; i++)
|
for (int i = 0; i < numbers.length; i++) {
|
||||||
value[i] = numbers[i].longValue();
|
value[i] = numbers[i].longValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -5,9 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
package me.filoghost.chestcommands.util.nbt.parser;
|
package me.filoghost.chestcommands.util.nbt.parser;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import me.filoghost.chestcommands.util.nbt.NBTByte;
|
import me.filoghost.chestcommands.util.nbt.NBTByte;
|
||||||
import me.filoghost.chestcommands.util.nbt.NBTByteArray;
|
import me.filoghost.chestcommands.util.nbt.NBTByteArray;
|
||||||
import me.filoghost.chestcommands.util.nbt.NBTCompound;
|
import me.filoghost.chestcommands.util.nbt.NBTCompound;
|
||||||
@ -23,6 +20,10 @@ import me.filoghost.chestcommands.util.nbt.NBTString;
|
|||||||
import me.filoghost.chestcommands.util.nbt.NBTTag;
|
import me.filoghost.chestcommands.util.nbt.NBTTag;
|
||||||
import me.filoghost.chestcommands.util.nbt.NBTType;
|
import me.filoghost.chestcommands.util.nbt.NBTType;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public final class MojangsonParser {
|
public final class MojangsonParser {
|
||||||
|
|
||||||
private static final Pattern
|
private static final Pattern
|
||||||
@ -65,11 +66,13 @@ public final class MojangsonParser {
|
|||||||
|
|
||||||
private NBTTag parseStringOrLiteral() throws MojangsonParseException {
|
private NBTTag parseStringOrLiteral() throws MojangsonParseException {
|
||||||
skipWhitespace();
|
skipWhitespace();
|
||||||
if (currentChar() == '"')
|
if (currentChar() == '"') {
|
||||||
return new NBTString(parseQuotedString());
|
return new NBTString(parseQuotedString());
|
||||||
|
}
|
||||||
String str = parseSimpleString();
|
String str = parseSimpleString();
|
||||||
if (str.isEmpty())
|
if (str.isEmpty()) {
|
||||||
throw parseException("Expected value");
|
throw parseException("Expected value");
|
||||||
|
}
|
||||||
return parseLiteral(str);
|
return parseLiteral(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,16 +153,18 @@ public final class MojangsonParser {
|
|||||||
|
|
||||||
private NBTTag parseAnything() throws MojangsonParseException {
|
private NBTTag parseAnything() throws MojangsonParseException {
|
||||||
skipWhitespace();
|
skipWhitespace();
|
||||||
if (!hasNext())
|
if (!hasNext()) {
|
||||||
throw parseException("Expected value");
|
throw parseException("Expected value");
|
||||||
|
}
|
||||||
|
|
||||||
int c = currentChar();
|
int c = currentChar();
|
||||||
if (c == '{')
|
if (c == '{') {
|
||||||
return parseCompound();
|
return parseCompound();
|
||||||
else if (c == '[')
|
} else if (c == '[') {
|
||||||
return parseDetectedArray();
|
return parseDetectedArray();
|
||||||
else
|
} else {
|
||||||
return parseStringOrLiteral();
|
return parseStringOrLiteral();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private NBTTag parseDetectedArray() throws MojangsonParseException {
|
private NBTTag parseDetectedArray() throws MojangsonParseException {
|
||||||
@ -237,12 +242,13 @@ public final class MojangsonParser {
|
|||||||
if (!hasNext()) {
|
if (!hasNext()) {
|
||||||
throw parseException("Expected value");
|
throw parseException("Expected value");
|
||||||
}
|
}
|
||||||
if (arrayType == 'B')
|
if (arrayType == 'B') {
|
||||||
return new NBTByteArray(parseNumArray(NBTType.BYTE_ARRAY, NBTType.BYTE));
|
return new NBTByteArray(parseNumArray(NBTType.BYTE_ARRAY, NBTType.BYTE));
|
||||||
else if (arrayType == 'L')
|
} else if (arrayType == 'L') {
|
||||||
return new NBTLongArray(parseNumArray(NBTType.LONG_ARRAY, NBTType.LONG));
|
return new NBTLongArray(parseNumArray(NBTType.LONG_ARRAY, NBTType.LONG));
|
||||||
else if (arrayType == 'I')
|
} else if (arrayType == 'I') {
|
||||||
return new NBTIntArray(parseNumArray(NBTType.INT_ARRAY, NBTType.INT));
|
return new NBTIntArray(parseNumArray(NBTType.INT_ARRAY, NBTType.INT));
|
||||||
|
}
|
||||||
throw parseException("Invalid array type '" + arrayType + "' found");
|
throw parseException("Invalid array type '" + arrayType + "' found");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,7 +352,10 @@ public final class MojangsonParser {
|
|||||||
this.index += 1;
|
this.index += 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new MojangsonParseException("Expected '" + c + "' but got '" + (hasNext ? Character.valueOf(currentChar()) : "<End of string>") + "'", this.str, this.index + 1);
|
throw new MojangsonParseException(
|
||||||
|
"Expected '" + c + "' but got '" + (hasNext ? Character.valueOf(currentChar()) : "<End of string>") + "'",
|
||||||
|
this.str,
|
||||||
|
this.index + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user