From 0f9b6f4cdb6047b44616f4248447504513bc5965 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+chomens@users.noreply.github.com> Date: Tue, 15 Apr 2025 09:41:08 +0700 Subject: [PATCH] style: use the same code style as chomens bot --- .../chipmunk/chipmunkmod/ChipmunkMod.java | 39 +- .../chipmunkmod/command/CommandManager.java | 39 +- .../arguments/LocationArgumentType.java | 60 +- .../arguments/TimestampArgumentType.java | 7 +- .../chipmunkmod/commands/AutoSkinCommand.java | 4 +- .../chipmunkmod/commands/CloopCommand.java | 36 +- .../chipmunkmod/commands/CoreCommand.java | 33 +- .../commands/CustomChatCommand.java | 14 +- .../chipmunkmod/commands/EvalCommand.java | 10 +- .../chipmunkmod/commands/ItemCommand.java | 27 +- .../chipmunkmod/commands/MusicCommand.java | 39 +- .../commands/RainbowNameCommand.java | 6 +- .../commands/ReloadConfigCommand.java | 6 +- .../chipmunkmod/commands/SayCommand.java | 4 +- .../chipmunkmod/commands/SelfCareCommand.java | 4 +- .../chipmunkmod/commands/TestCommand.java | 9 +- .../chipmunkmod/commands/UsernameCommand.java | 53 +- .../chipmunkmod/commands/ValidateCommand.java | 2 +- .../config/ChipmunkModMigrations.java | 2 +- .../chipmunkmod/config/Configuration.java | 12 +- .../migration/AbstractMigrationManager.java | 14 +- .../config/migration/ConfigMigration.java | 12 +- .../config/migrations/MigrationV0.java | 4 +- .../config/migrations/MigrationV1.java | 12 +- .../config/migrations/MigrationV2.java | 4 +- .../config/migrations/MigrationV3.java | 4 +- .../chipmunkmod/data/ChomeNSBotCommand.java | 4 +- .../data/MutablePlayerListEntry.java | 4 +- .../chipmunkmod/listeners/Listener.java | 15 +- .../listeners/ListenerManager.java | 2 +- .../mixin/ChatInputSuggestorMixin.java | 27 +- .../chipmunkmod/mixin/ChatScreenMixin.java | 13 +- .../ClientCommonNetworkHandlerAccessor.java | 2 +- .../mixin/ClientConnectionMixin.java | 20 +- .../mixin/ClientPlayNetworkHandlerMixin.java | 34 +- .../mixin/ClientPlayerEntityMixin.java | 8 +- .../ElderGuardianAppearanceParticleMixin.java | 2 +- .../mixin/MinecraftClientAccessor.java | 2 +- .../chipmunkmod/mixin/SoundSystemMixin.java | 2 +- .../chipmunk/chipmunkmod/modules/Chat.java | 5 +- .../modules/ChomeNSBotCommandSuggestions.java | 22 +- .../chipmunkmod/modules/CommandCore.java | 48 +- .../modules/CommandLoopManager.java | 22 +- .../chipmunkmod/modules/KaboomCheck.java | 7 +- .../chipmunkmod/modules/RainbowName.java | 30 +- .../chipmunkmod/modules/SelfCare.java | 41 +- .../chipmunkmod/modules/SongPlayer.java | 39 +- .../modules/custom_chat/CustomChat.java | 11 +- .../CustomChatComponentRenderer.java | 16 +- .../chipmunk/chipmunkmod/song/Instrument.java | 12 +- .../chipmunkmod/song/MidiConverter.java | 532 +++++++++--------- .../chipmunkmod/song/NBSConverter.java | 346 ++++++------ .../land/chipmunk/chipmunkmod/song/Note.java | 4 +- .../land/chipmunk/chipmunkmod/song/Song.java | 30 +- .../chipmunkmod/song/SongLoaderException.java | 6 +- .../chipmunkmod/song/SongLoaderThread.java | 27 +- .../util/BotValidationUtilities.java | 133 ++--- .../chipmunkmod/util/ColorUtilities.java | 4 +- .../chipmunkmod/util/DownloadUtilities.java | 48 +- .../chipmunkmod/util/MathUtilities.java | 4 +- .../chipmunkmod/util/RandomUtilities.java | 6 +- .../chipmunkmod/util/ServerUtilities.java | 2 +- .../chipmunkmod/util/TextUtilities.java | 6 +- .../chipmunkmod/util/UUIDUtilities.java | 8 +- .../configurate/BlockBoxTypeSerializer.java | 11 +- .../configurate/BlockPosTypeSerializer.java | 11 +- .../configurate/ComponentTypeSerializer.java | 10 +- .../configurate/ConfigurateUtilities.java | 8 +- 68 files changed, 1012 insertions(+), 1028 deletions(-) diff --git a/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java b/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java index f9ed1a0..d4a0749 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java +++ b/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java @@ -19,32 +19,14 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class ChipmunkMod implements ModInitializer { + public static final Logger LOGGER = LoggerFactory.getLogger("ChipmunkMod"); private static final Path CONFIG_PATH = FabricLoader.getInstance() .getConfigDir().resolve("chipmunkmod.json"); - - public static final Logger LOGGER = LoggerFactory.getLogger("ChipmunkMod"); public static Configuration CONFIG; public static ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); - @Override - public void onInitialize() { - // This code runs as soon as Minecraft is in a mod-load-ready state. - // However, some things (like resources) may still be uninitialized. - // Proceed with mild caution. - - try { - CONFIG = loadConfig(); - } catch (IOException exception) { - throw new RuntimeException("Could not load the config", exception); - } - - SelfCare.INSTANCE.init(); - - LOGGER.info("Loaded ChipmunkMod (chayapak's fork)"); - } - - public static Configuration loadConfig() throws IOException { + public static Configuration loadConfig () throws IOException { final ChipmunkModMigrations migrations = new ChipmunkModMigrations(); final ObjectMapper.Factory customFactory = ObjectMapper.factoryBuilder() .defaultNamingScheme(NamingSchemes.CAMEL_CASE) @@ -77,4 +59,21 @@ public class ChipmunkMod implements ModInitializer { return node.get(Configuration.class); } + + @Override + public void onInitialize () { + // This code runs as soon as Minecraft is in a mod-load-ready state. + // However, some things (like resources) may still be uninitialized. + // Proceed with mild caution. + + try { + CONFIG = loadConfig(); + } catch (final IOException exception) { + throw new RuntimeException("Could not load the config", exception); + } + + SelfCare.INSTANCE.init(); + + LOGGER.info("Loaded ChipmunkMod (chayapak's fork)"); + } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java b/src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java index 1c07df6..77c34aa 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java +++ b/src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java @@ -5,23 +5,22 @@ import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import land.chipmunk.chipmunkmod.commands.*; +import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; +import net.minecraft.client.MinecraftClient; +import net.minecraft.command.CommandRegistryAccess; import net.minecraft.text.ClickEvent; +import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.text.Texts; -import net.minecraft.text.MutableText; import net.minecraft.util.Formatting; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.client.MinecraftClient; -import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import land.chipmunk.chipmunkmod.commands.*; public class CommandManager { + public static CommandManager INSTANCE; public CommandDispatcher dispatcher = new CommandDispatcher<>(); public String prefix; - public static CommandManager INSTANCE; - - public CommandManager(String prefix, CommandRegistryAccess commandRegistryAccess) { + public CommandManager (final String prefix, final CommandRegistryAccess commandRegistryAccess) { this.prefix = prefix; TestCommand.register(this.dispatcher); @@ -40,23 +39,31 @@ public class CommandManager { SelfCareCommand.register(this.dispatcher); } - public void executeCommand(String command) { + public static LiteralArgumentBuilder literal (final String name) { + return LiteralArgumentBuilder.literal(name); + } + + public static RequiredArgumentBuilder argument (final String name, final ArgumentType type) { + return RequiredArgumentBuilder.argument(name, type); + } + + public void executeCommand (final String command) { final MinecraftClient client = MinecraftClient.getInstance(); final FabricClientCommandSource commandSource = (FabricClientCommandSource) client.getNetworkHandler().getCommandSource(); try { dispatcher.execute(command, commandSource); - } catch (CommandSyntaxException e) { + } catch (final CommandSyntaxException e) { commandSource.sendError(Texts.toText(e.getRawMessage())); final Text context = getContext(e); if (context != null) commandSource.sendError(context); - } catch (Exception e) { + } catch (final Exception e) { commandSource.sendError(Text.of(e.getMessage())); } } - public Text getContext(CommandSyntaxException exception) { + public Text getContext (final CommandSyntaxException exception) { final int _cursor = exception.getCursor(); final String input = exception.getInput(); @@ -80,12 +87,4 @@ public class CommandManager { return text; } - - public static LiteralArgumentBuilder literal(String name) { - return LiteralArgumentBuilder.literal(name); - } - - public static RequiredArgumentBuilder argument(String name, ArgumentType type) { - return RequiredArgumentBuilder.argument(name, type); - } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/command/arguments/LocationArgumentType.java b/src/main/java/land/chipmunk/chipmunkmod/command/arguments/LocationArgumentType.java index b8fecb4..5b758ea 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/command/arguments/LocationArgumentType.java +++ b/src/main/java/land/chipmunk/chipmunkmod/command/arguments/LocationArgumentType.java @@ -22,27 +22,50 @@ public class LocationArgumentType implements ArgumentType { private final boolean allowsPaths; private final Path root; - private LocationArgumentType (boolean allowsUrls, boolean allowsPaths, Path root) { + private LocationArgumentType (final boolean allowsUrls, final boolean allowsPaths, final Path root) { this.allowsUrls = allowsUrls; this.allowsPaths = allowsPaths; this.root = root.toAbsolutePath().normalize(); } - public static LocationArgumentType location (Path rootPath) { return new LocationArgumentType(true, true, rootPath); } + public static LocationArgumentType location (final Path rootPath) { return new LocationArgumentType(true, true, rootPath); } + public static LocationArgumentType url () { return new LocationArgumentType(true, false, null); } - public static LocationArgumentType filepath (Path rootPath) { return new LocationArgumentType(false, true, rootPath); } + + public static LocationArgumentType filepath (final Path rootPath) { return new LocationArgumentType(false, true, rootPath); } + + private static Object getLocation (final CommandContext context, final String name) { + return context.getArgument(name, Object.class); + } + + public static URL getUrl (final CommandContext context, final String name) { + final Object location = getLocation(context, name); + if (location instanceof URL) return (URL) location; + try { + if (location instanceof Path) return new URI("file", "", "", -1, location.toString(), "", "").toURL(); + } catch (final MalformedURLException | URISyntaxException ignored) { + return null; // The real question is whether this will actually ever get called + } + return null; + } + + public static Path getPath (final CommandContext context, final String name) { + final Object location = getLocation(context, name); + if (location instanceof Path) return (Path) location; + return null; + } @Override - public Object parse (StringReader reader) throws CommandSyntaxException { + public Object parse (final StringReader reader) throws CommandSyntaxException { final String remaining = reader.getString().substring(reader.getCursor()); if (allowsUrls && isUrlStart(remaining)) return parseUrl(reader); if (allowsPaths) return parsePath(reader); return null; } - public boolean isUrlStart (String string) { return string.startsWith("http://") || string.startsWith("https://") || string.startsWith("ftp://"); } + public boolean isUrlStart (final String string) { return string.startsWith("http://") || string.startsWith("https://") || string.startsWith("ftp://"); } - public URL parseUrl (StringReader reader) throws CommandSyntaxException { + public URL parseUrl (final StringReader reader) throws CommandSyntaxException { final StringBuilder sb = new StringBuilder(); while (reader.canRead() && reader.peek() != ' ') { sb.append(reader.read()); @@ -50,37 +73,16 @@ public class LocationArgumentType implements ArgumentType { try { return new URI(sb.toString()).toURL(); - } catch (MalformedURLException | URISyntaxException exception) { + } catch (final MalformedURLException | URISyntaxException exception) { throw new SimpleCommandExceptionType(Text.literal(exception.getMessage())).create(); } } - public Path parsePath (StringReader reader) throws CommandSyntaxException { + public Path parsePath (final StringReader reader) throws CommandSyntaxException { final String pathString = reader.readString(); return Path.of(root.toString(), pathString).toAbsolutePath().normalize(); } - private static Object getLocation (CommandContext context, String name) { - return context.getArgument(name, Object.class); - } - - public static URL getUrl (CommandContext context, String name) { - final Object location = getLocation(context, name); - if (location instanceof URL) return (URL) location; - try { - if (location instanceof Path) return new URI("file", "", "", -1, location.toString(), "", "").toURL(); - } catch (MalformedURLException | URISyntaxException ignored) { - return null; // The real question is whether this will actually ever get called - } - return null; - } - - public static Path getPath (CommandContext context, String name) { - final Object location = getLocation(context, name); - if (location instanceof Path) return (Path) location; - return null; - } - @Override public Collection getExamples () { return EXAMPLES; } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/command/arguments/TimestampArgumentType.java b/src/main/java/land/chipmunk/chipmunkmod/command/arguments/TimestampArgumentType.java index 6c6d71c..2619cbb 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/command/arguments/TimestampArgumentType.java +++ b/src/main/java/land/chipmunk/chipmunkmod/command/arguments/TimestampArgumentType.java @@ -1,10 +1,11 @@ package land.chipmunk.chipmunkmod.command.arguments; -import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import java.util.Collection; + import java.util.Arrays; +import java.util.Collection; public class TimestampArgumentType implements ArgumentType { private static final Collection EXAMPLES = Arrays.asList("0:01", "1:23", "6:09"); @@ -15,7 +16,7 @@ public class TimestampArgumentType implements ArgumentType { public static TimestampArgumentType timestamp () { return new TimestampArgumentType(); } @Override - public Long parse (StringReader reader) throws CommandSyntaxException { + public Long parse (final StringReader reader) throws CommandSyntaxException { long seconds = 0L; long minutes = 0L; diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/AutoSkinCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/AutoSkinCommand.java index 50de716..cb1c6b7 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/AutoSkinCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/AutoSkinCommand.java @@ -13,7 +13,7 @@ import static land.chipmunk.chipmunkmod.command.CommandManager.argument; import static land.chipmunk.chipmunkmod.command.CommandManager.literal; public class AutoSkinCommand { - public static void register (CommandDispatcher dispatcher) { + public static void register (final CommandDispatcher dispatcher) { dispatcher.register( literal("autoskin") .then( @@ -23,7 +23,7 @@ public class AutoSkinCommand { ); } - public static int execute(CommandContext context) { + public static int execute (final CommandContext context) { final FabricClientCommandSource source = context.getSource(); final String username = getString(context, "username"); diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/CloopCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/CloopCommand.java index 5db68b9..c36e9c1 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/CloopCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/CloopCommand.java @@ -5,23 +5,25 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; -import static land.chipmunk.chipmunkmod.command.CommandManager.literal; -import static land.chipmunk.chipmunkmod.command.CommandManager.argument; -import static com.mojang.brigadier.arguments.LongArgumentType.longArg; -import static com.mojang.brigadier.arguments.LongArgumentType.getLong; -import static com.mojang.brigadier.arguments.StringArgumentType.greedyString; -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static com.mojang.brigadier.arguments.IntegerArgumentType.integer; -import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger; +import land.chipmunk.chipmunkmod.modules.CommandLoopManager; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.text.Text; -import land.chipmunk.chipmunkmod.modules.CommandLoopManager; + import java.util.List; +import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger; +import static com.mojang.brigadier.arguments.IntegerArgumentType.integer; +import static com.mojang.brigadier.arguments.LongArgumentType.getLong; +import static com.mojang.brigadier.arguments.LongArgumentType.longArg; +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static com.mojang.brigadier.arguments.StringArgumentType.greedyString; +import static land.chipmunk.chipmunkmod.command.CommandManager.argument; +import static land.chipmunk.chipmunkmod.command.CommandManager.literal; + public class CloopCommand { private static final DynamicCommandExceptionType INVALID_CLOOP_ID_EXCEPTION = new DynamicCommandExceptionType(id -> Text.translatable("Invalid cloop id: %s", Text.literal(String.valueOf(id)))); - public static void register (CommandDispatcher dispatcher) { + public static void register (final CommandDispatcher dispatcher) { dispatcher.register( literal("cloop") .then( @@ -52,18 +54,18 @@ public class CloopCommand { ); } - public static int addCloop (CommandContext context) { + public static int addCloop (final CommandContext context) { final FabricClientCommandSource source = context.getSource(); final long interval = getLong(context, "interval"); final String command = getString(context, "command"); - int id = CommandLoopManager.INSTANCE.loopCommand(command, interval); + final int id = CommandLoopManager.INSTANCE.loopCommand(command, interval); source.sendFeedback(Text.translatable("Successfully created a loop for command '%s' with id %s", Text.literal(command), Text.literal(String.valueOf(id)))); return Command.SINGLE_SUCCESS; } - public static int removeCloop (CommandContext context) throws CommandSyntaxException { + public static int removeCloop (final CommandContext context) throws CommandSyntaxException { final FabricClientCommandSource source = context.getSource(); final CommandLoopManager manager = CommandLoopManager.INSTANCE; final int id = getInteger(context, "id"); @@ -76,7 +78,7 @@ public class CloopCommand { return Command.SINGLE_SUCCESS; } - public static int clearCloops (CommandContext context) { + public static int clearCloops (final CommandContext context) { final FabricClientCommandSource source = context.getSource(); final CommandLoopManager manager = CommandLoopManager.INSTANCE; @@ -86,13 +88,13 @@ public class CloopCommand { return Command.SINGLE_SUCCESS; } - public static int listCloops (CommandContext context) { + public static int listCloops (final CommandContext context) { final FabricClientCommandSource source = context.getSource(); final List loops = CommandLoopManager.INSTANCE.commandLoops; int id = 0; - for (CommandLoopManager.CommandLoop loop : loops) { - source.sendFeedback(Text.translatable("%s: %s (%s)", Text.literal(String.valueOf(id)), Text.literal(loop.command), Text.literal(String.valueOf(loop.interval)))); + for (final CommandLoopManager.CommandLoop loop : loops) { + source.sendFeedback(Text.translatable("%s: %s (%s)", Text.literal(String.valueOf(id)), Text.literal(loop.command), Text.literal(String.valueOf(loop.interval)))); id++; } diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/CoreCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/CoreCommand.java index 00f3fcd..c69cac7 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/CoreCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/CoreCommand.java @@ -1,28 +1,25 @@ package land.chipmunk.chipmunkmod.commands; -import com.google.common.base.Suppliers; import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.context.CommandContext; - -import static com.mojang.brigadier.arguments.BoolArgumentType.bool; -import static com.mojang.brigadier.arguments.BoolArgumentType.getBool; -import static land.chipmunk.chipmunkmod.command.CommandManager.literal; -import static land.chipmunk.chipmunkmod.command.CommandManager.argument; -import static com.mojang.brigadier.arguments.StringArgumentType.greedyString; -import static com.mojang.brigadier.arguments.StringArgumentType.getString; - +import land.chipmunk.chipmunkmod.modules.CommandCore; import land.chipmunk.chipmunkmod.util.TextUtilities; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import net.minecraft.text.Text; import net.minecraft.nbt.NbtCompound; +import net.minecraft.text.Text; import java.util.concurrent.CompletableFuture; -import land.chipmunk.chipmunkmod.modules.CommandCore; +import static com.mojang.brigadier.arguments.BoolArgumentType.bool; +import static com.mojang.brigadier.arguments.BoolArgumentType.getBool; +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static com.mojang.brigadier.arguments.StringArgumentType.greedyString; +import static land.chipmunk.chipmunkmod.command.CommandManager.argument; +import static land.chipmunk.chipmunkmod.command.CommandManager.literal; public class CoreCommand { - public static void register(CommandDispatcher dispatcher) { + public static void register (final CommandDispatcher dispatcher) { dispatcher.register( literal("core") .then( @@ -54,13 +51,13 @@ public class CoreCommand { ); } - public static int run(CommandContext context) { + public static int run (final CommandContext context) { CommandCore.INSTANCE.run(getString(context, "command")); return Command.SINGLE_SUCCESS; } - public static int runTracked(CommandContext context) { + public static int runTracked (final CommandContext context) { final FabricClientCommandSource source = context.getSource(); final String command = getString(context, "command"); @@ -70,7 +67,7 @@ public class CoreCommand { try { final String output = tag.getString("LastOutput"); if (output != null) source.sendFeedback(TextUtilities.fromJson(output)); - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); } @@ -80,13 +77,13 @@ public class CoreCommand { return Command.SINGLE_SUCCESS; } - public static int refill(CommandContext context) { + public static int refill (final CommandContext context) { CommandCore.INSTANCE.refill(); return Command.SINGLE_SUCCESS; } - public static int move(CommandContext context) { + public static int move (final CommandContext context) { final FabricClientCommandSource source = context.getSource(); CommandCore.INSTANCE.move(source.getClient().player.getPos()); @@ -94,7 +91,7 @@ public class CoreCommand { return Command.SINGLE_SUCCESS; } - public static int runFillCommand(CommandContext context) { + public static int runFillCommand (final CommandContext context) { final FabricClientCommandSource source = context.getSource(); final boolean bool = getBool(context, "enabled"); diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/CustomChatCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/CustomChatCommand.java index c861df1..8845ac9 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/CustomChatCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/CustomChatCommand.java @@ -15,15 +15,15 @@ import static land.chipmunk.chipmunkmod.command.CommandManager.argument; import static land.chipmunk.chipmunkmod.command.CommandManager.literal; public class CustomChatCommand { - public static void register (CommandDispatcher dispatcher) { + public static void register (final CommandDispatcher dispatcher) { dispatcher.register( literal("customchat") .then( literal("enabled") - .then( - argument("boolean", bool()) - .executes(CustomChatCommand::enabled) - ) + .then( + argument("boolean", bool()) + .executes(CustomChatCommand::enabled) + ) ) .then( literal("format") @@ -35,7 +35,7 @@ public class CustomChatCommand { ); } - public static int enabled (CommandContext context) { + public static int enabled (final CommandContext context) { final FabricClientCommandSource source = context.getSource(); final boolean bool = getBool(context, "boolean"); CustomChat.INSTANCE.enabled = bool; @@ -44,7 +44,7 @@ public class CustomChatCommand { return Command.SINGLE_SUCCESS; } - public static int setFormat (CommandContext context) { + public static int setFormat (final CommandContext context) { final FabricClientCommandSource source = context.getSource(); final String format = getString(context, "format"); CustomChat.INSTANCE.format = format; diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/EvalCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/EvalCommand.java index 4ead74d..fd35c4c 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/EvalCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/EvalCommand.java @@ -18,17 +18,17 @@ import static land.chipmunk.chipmunkmod.command.CommandManager.argument; import static land.chipmunk.chipmunkmod.command.CommandManager.literal; public class EvalCommand { - public static void register (CommandDispatcher dispatcher) { + public static void register (final CommandDispatcher dispatcher) { dispatcher.register( literal("eval") .then( argument("code", greedyString()) - .executes(EvalCommand::eval) + .executes(EvalCommand::eval) ) ); } - public static int eval (CommandContext context) { + public static int eval (final CommandContext context) { final String code = getString(context, "code"); try { @@ -38,10 +38,10 @@ public class EvalCommand { globals.set("context", CoerceJavaToLua.coerce(context)); globals.set("class", CoerceJavaToLua.coerce(Class.class)); - LuaValue chunk = globals.load(code); + final LuaValue chunk = globals.load(code); context.getSource().sendFeedback(Text.literal(chunk.call().toString()).formatted(Formatting.GREEN)); - } catch (Exception e) { + } catch (final Exception e) { context.getSource().sendError(Text.literal(e.toString())); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/ItemCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/ItemCommand.java index 59c92dd..7f8a092 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/ItemCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/ItemCommand.java @@ -4,23 +4,22 @@ import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; - -import static land.chipmunk.chipmunkmod.command.CommandManager.literal; -import static land.chipmunk.chipmunkmod.command.CommandManager.argument; -import static com.mojang.brigadier.arguments.IntegerArgumentType.integer; -import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger; -import static net.minecraft.command.argument.ItemStackArgumentType.itemStack; -import static net.minecraft.command.argument.ItemStackArgumentType.getItemStackArgument; - import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import net.minecraft.command.CommandRegistryAccess; import net.minecraft.client.MinecraftClient; -import net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket; +import net.minecraft.command.CommandRegistryAccess; import net.minecraft.item.ItemStack; +import net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket; import net.minecraft.text.Text; +import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger; +import static com.mojang.brigadier.arguments.IntegerArgumentType.integer; +import static land.chipmunk.chipmunkmod.command.CommandManager.argument; +import static land.chipmunk.chipmunkmod.command.CommandManager.literal; +import static net.minecraft.command.argument.ItemStackArgumentType.getItemStackArgument; +import static net.minecraft.command.argument.ItemStackArgumentType.itemStack; + public class ItemCommand { - public static void register(CommandDispatcher dispatcher, CommandRegistryAccess commandRegistryAccess) { + public static void register (final CommandDispatcher dispatcher, final CommandRegistryAccess commandRegistryAccess) { dispatcher.register( literal("item") .then( @@ -34,17 +33,17 @@ public class ItemCommand { ); } - public static int setItem(CommandContext context) throws CommandSyntaxException { + public static int setItem (final CommandContext context) throws CommandSyntaxException { return setItem(context, getInteger(context, "count")); } - public static int setItem(CommandContext context, int count) throws CommandSyntaxException { + public static int setItem (final CommandContext context, final int count) throws CommandSyntaxException { final FabricClientCommandSource source = context.getSource(); final MinecraftClient client = source.getClient(); final ItemStack stack = getItemStackArgument(context, "item").createStack(count, false); - int slot = 36 + client.player.getInventory().selectedSlot; + final int slot = 36 + client.player.getInventory().selectedSlot; client.getNetworkHandler().getConnection().send(new CreativeInventoryActionC2SPacket(slot, stack)); diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/MusicCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/MusicCommand.java index c51660c..4a3fba2 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/MusicCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/MusicCommand.java @@ -39,10 +39,10 @@ public class MusicCommand { private static final SimpleCommandExceptionType OOB_TIMESTAMP = new SimpleCommandExceptionType(Text.translatable("Invalid timestamp for the current song")); private static final SimpleCommandExceptionType DIRECTORY_DOES_NOT_EXIST = new SimpleCommandExceptionType(Text.translatable("The specified directory does not exist")); - public static void register (CommandDispatcher dispatcher) { + public static void register (final CommandDispatcher dispatcher) { final MusicCommand instance = new MusicCommand(); - Path root = Path.of(SongPlayer.SONG_DIR.getPath()); + final Path root = Path.of(SongPlayer.SONG_DIR.getPath()); dispatcher.register( literal("music") @@ -110,7 +110,7 @@ public class MusicCommand { ); } - public int play (CommandContext context) { + public int play (final CommandContext context) { final SongPlayer songPlayer = SongPlayer.INSTANCE; final Path path = getPath(context, "location"); @@ -121,7 +121,7 @@ public class MusicCommand { return 1; } - public int stop (CommandContext context) throws CommandSyntaxException { + public int stop (final CommandContext context) throws CommandSyntaxException { final FabricClientCommandSource source = context.getSource(); final SongPlayer songPlayer = SongPlayer.INSTANCE; @@ -134,7 +134,7 @@ public class MusicCommand { return 1; } - public int skip (CommandContext context) throws CommandSyntaxException { + public int skip (final CommandContext context) throws CommandSyntaxException { final FabricClientCommandSource source = context.getSource(); final SongPlayer songPlayer = SongPlayer.INSTANCE; @@ -146,7 +146,7 @@ public class MusicCommand { return 1; } - public int pause (CommandContext context) throws CommandSyntaxException { + public int pause (final CommandContext context) throws CommandSyntaxException { final FabricClientCommandSource source = context.getSource(); final SongPlayer songPlayer = SongPlayer.INSTANCE; final Song currentSong = songPlayer.currentSong; @@ -164,7 +164,7 @@ public class MusicCommand { return 1; } - public int list (Path path) throws CommandSyntaxException { + public int list (final Path path) throws CommandSyntaxException { final CommandManager commandManager = CommandManager.INSTANCE; final String prefix = commandManager.prefix; @@ -174,15 +174,16 @@ public class MusicCommand { if (filenames == null) throw DIRECTORY_DOES_NOT_EXIST.create(); final Path root = Path.of(SongPlayer.SONG_DIR.getAbsoluteFile().getPath()).toAbsolutePath(); - String relativePath; - if (path.getNameCount() - root.getNameCount() > 0) relativePath = path.subpath(root.getNameCount(), path.getNameCount()).toString(); + final String relativePath; + if (path.getNameCount() - root.getNameCount() > 0) + relativePath = path.subpath(root.getNameCount(), path.getNameCount()).toString(); else relativePath = ""; final List directories = new ArrayList<>(); final List files = new ArrayList<>(); int i = 0; - for (String filename : filenames) { + for (final String filename : filenames) { final File file = new File(directory, filename); if (!file.isDirectory()) continue; @@ -198,7 +199,7 @@ public class MusicCommand { ); } - for (String filename : filenames) { + for (final String filename : filenames) { final File file = new File(directory, filename); if (file.isDirectory()) continue; @@ -225,10 +226,10 @@ public class MusicCommand { } // TODO: Move this into some utility class, as it is more related to brigadier strings in general than to the list command in specific - private String escapePath (String path) { + private String escapePath (final String path) { final StringBuilder sb = new StringBuilder("'"); - for (char character : path.toCharArray()) { + for (final char character : path.toCharArray()) { if (character == '\'' || character == '\\') sb.append('\\'); sb.append(character); } @@ -237,7 +238,7 @@ public class MusicCommand { return sb.toString(); } - public int toggleLoop (CommandContext context) throws CommandSyntaxException { + public int toggleLoop (final CommandContext context) throws CommandSyntaxException { final FabricClientCommandSource source = context.getSource(); final SongPlayer songPlayer = SongPlayer.INSTANCE; final Song currentSong = songPlayer.currentSong; @@ -252,7 +253,7 @@ public class MusicCommand { } - public int loop (CommandContext context) throws CommandSyntaxException { + public int loop (final CommandContext context) throws CommandSyntaxException { final FabricClientCommandSource source = context.getSource(); final SongPlayer songPlayer = SongPlayer.INSTANCE; final Song currentSong = songPlayer.currentSong; @@ -268,7 +269,7 @@ public class MusicCommand { return 1; } - public int gotoCommand (CommandContext context) throws CommandSyntaxException { + public int gotoCommand (final CommandContext context) throws CommandSyntaxException { final FabricClientCommandSource source = context.getSource(); final SongPlayer songPlayer = SongPlayer.INSTANCE; final Song currentSong = songPlayer.currentSong; @@ -285,7 +286,7 @@ public class MusicCommand { return 1; } - public int useCore (CommandContext context) { + public int useCore (final CommandContext context) { final FabricClientCommandSource source = context.getSource(); final boolean enabled = getBool(context, "boolean"); @@ -297,7 +298,7 @@ public class MusicCommand { return 1; } - public int actionbar (CommandContext context) { + public int actionbar (final CommandContext context) { final FabricClientCommandSource source = context.getSource(); final boolean enabled = getBool(context, "boolean"); @@ -309,7 +310,7 @@ public class MusicCommand { return 1; } - public int pitch (CommandContext context) { + public int pitch (final CommandContext context) { final FabricClientCommandSource source = context.getSource(); final float pitch = getFloat(context, "pitch"); diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/RainbowNameCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/RainbowNameCommand.java index 24a4a54..c1a3810 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/RainbowNameCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/RainbowNameCommand.java @@ -15,7 +15,7 @@ import static land.chipmunk.chipmunkmod.command.CommandManager.argument; import static land.chipmunk.chipmunkmod.command.CommandManager.literal; public class RainbowNameCommand { - public static void register (CommandDispatcher dispatcher) { + public static void register (final CommandDispatcher dispatcher) { dispatcher.register( literal("rainbowname") .then( @@ -35,7 +35,7 @@ public class RainbowNameCommand { ); } - public static int enabled (CommandContext context) { + public static int enabled (final CommandContext context) { final FabricClientCommandSource source = context.getSource(); final boolean bool = getBool(context, "boolean"); @@ -51,7 +51,7 @@ public class RainbowNameCommand { return Command.SINGLE_SUCCESS; } - public static int setName (CommandContext context) { + public static int setName (final CommandContext context) { final FabricClientCommandSource source = context.getSource(); final String name = getString(context, "name"); diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/ReloadConfigCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/ReloadConfigCommand.java index ee1caba..cbc0d46 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/ReloadConfigCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/ReloadConfigCommand.java @@ -13,14 +13,14 @@ import java.io.IOException; import static land.chipmunk.chipmunkmod.command.CommandManager.literal; public class ReloadConfigCommand { - public static void register (CommandDispatcher dispatcher) { + public static void register (final CommandDispatcher dispatcher) { dispatcher.register( literal("reloadconfig") .executes(ReloadConfigCommand::reload) ); } - public static int reload(CommandContext context) { + public static int reload (final CommandContext context) { final FabricClientCommandSource source = context.getSource(); try { @@ -28,7 +28,7 @@ public class ReloadConfigCommand { CommandCore.INSTANCE.reloadRelativeArea(); source.sendFeedback(Text.literal("Successfully reloaded the config")); - } catch (IOException e) { + } catch (final IOException e) { source.sendError(Text.literal("Could not load config, check the logs for stacktrace")); e.printStackTrace(); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/SayCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/SayCommand.java index 61c0f9b..fe8122d 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/SayCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/SayCommand.java @@ -12,7 +12,7 @@ import static land.chipmunk.chipmunkmod.command.CommandManager.argument; import static land.chipmunk.chipmunkmod.command.CommandManager.literal; public class SayCommand { - public static void register (CommandDispatcher dispatcher) { + public static void register (final CommandDispatcher dispatcher) { dispatcher.register( literal("say") .then( @@ -22,7 +22,7 @@ public class SayCommand { ); } - public static int say (CommandContext context) { + public static int say (final CommandContext context) { Chat.sendChatMessage(getString(context, "message"), true); return Command.SINGLE_SUCCESS; diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/SelfCareCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/SelfCareCommand.java index d624c2c..041ae08 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/SelfCareCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/SelfCareCommand.java @@ -13,7 +13,7 @@ import static land.chipmunk.chipmunkmod.command.CommandManager.argument; import static land.chipmunk.chipmunkmod.command.CommandManager.literal; public class SelfCareCommand { - public static void register (CommandDispatcher dispatcher) { + public static void register (final CommandDispatcher dispatcher) { dispatcher.register( literal("selfcare") .then( @@ -40,7 +40,7 @@ public class SelfCareCommand { ); } - public static int setSelfCare (CommandContext context, String type) { + public static int setSelfCare (final CommandContext context, final String type) { final FabricClientCommandSource source = context.getSource(); final boolean bool = getBool(context, "boolean"); diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/TestCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/TestCommand.java index 7bbaa5c..1de0113 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/TestCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/TestCommand.java @@ -3,21 +3,20 @@ package land.chipmunk.chipmunkmod.commands; import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.context.CommandContext; - -import static land.chipmunk.chipmunkmod.command.CommandManager.literal; - import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.text.Text; +import static land.chipmunk.chipmunkmod.command.CommandManager.literal; + public class TestCommand { - public static void register(CommandDispatcher dispatcher) { + public static void register (final CommandDispatcher dispatcher) { dispatcher.register( literal("test") .executes(c -> helloWorld(c)) ); } - public static int helloWorld(CommandContext context) { + public static int helloWorld (final CommandContext context) { final FabricClientCommandSource source = context.getSource(); source.sendFeedback(Text.literal("Hello, world!")); diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/UsernameCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/UsernameCommand.java index 5f208ac..b39b7fc 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/UsernameCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/UsernameCommand.java @@ -3,12 +3,10 @@ package land.chipmunk.chipmunkmod.commands; import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.context.CommandContext; - -import static com.mojang.brigadier.arguments.StringArgumentType.*; -import static land.chipmunk.chipmunkmod.command.CommandManager.literal; -import static land.chipmunk.chipmunkmod.command.CommandManager.argument; - +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import land.chipmunk.chipmunkmod.mixin.ClientCommonNetworkHandlerAccessor; +import land.chipmunk.chipmunkmod.mixin.MinecraftClientAccessor; import land.chipmunk.chipmunkmod.util.RandomUtilities; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.client.MinecraftClient; @@ -16,20 +14,21 @@ import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.TitleScreen; import net.minecraft.client.gui.screen.multiplayer.ConnectScreen; import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.client.network.ServerInfo; import net.minecraft.client.network.ServerAddress; +import net.minecraft.client.network.ServerInfo; import net.minecraft.client.session.Session; import net.minecraft.network.ClientConnection; import net.minecraft.text.Text; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; +import net.minecraft.util.Uuids; import java.util.Objects; import java.util.Optional; import java.util.Random; -import land.chipmunk.chipmunkmod.mixin.MinecraftClientAccessor; -import net.minecraft.util.Uuids; +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static com.mojang.brigadier.arguments.StringArgumentType.greedyString; +import static land.chipmunk.chipmunkmod.command.CommandManager.argument; +import static land.chipmunk.chipmunkmod.command.CommandManager.literal; public class UsernameCommand { private static final SimpleCommandExceptionType USERNAME_TOO_LONG = new SimpleCommandExceptionType(Text.translatable("The specified username is longer than 16 characters")); @@ -40,31 +39,31 @@ public class UsernameCommand { private static final Session ORIGINAL_SESSION = MinecraftClient.getInstance().getSession(); private static final Random RANDOM = new Random(); - public static void register(CommandDispatcher dispatcher) { + public static void register (final CommandDispatcher dispatcher) { dispatcher.register(literal("username") - .then(literal("set") - .then(argument("username", greedyString()) - .executes(c -> changeOffline(c, getString(c, "username"))))) - .then(literal("revert") - .executes(c -> changeSession(c, ORIGINAL_SESSION))) + .then(literal("set") + .then(argument("username", greedyString()) + .executes(c -> changeOffline(c, getString(c, "username"))))) + .then(literal("revert") + .executes(c -> changeSession(c, ORIGINAL_SESSION))) - .then(literal("random") - .then(literal("blank") - .executes(c -> changeOffline(c, RandomUtilities.emptyUsername(RANDOM, SECTION_CHAR)))) - .executes(c -> changeOffline(c, RandomUtilities.randomString(RANDOM, PREMIUM_CHARS, RANDOM.nextInt(3, 16))))) - .then(literal("empty") - .executes(c -> changeOffline(c, ""))) + .then(literal("random") + .then(literal("blank") + .executes(c -> changeOffline(c, RandomUtilities.emptyUsername(RANDOM, SECTION_CHAR)))) + .executes(c -> changeOffline(c, RandomUtilities.randomString(RANDOM, PREMIUM_CHARS, RANDOM.nextInt(3, 16))))) + .then(literal("empty") + .executes(c -> changeOffline(c, ""))) ); } - private static Session offline(final String username) { + private static Session offline (final String username) { // This is how Minecraft's Main class does it return new Session(username, Uuids.getOfflinePlayerUuid(username), - "", Optional.empty(), Optional.empty(), Session.AccountType.LEGACY); + "", Optional.empty(), Optional.empty(), Session.AccountType.LEGACY); } // TODO: Put this in a separate class - private static void reconnect(final MinecraftClient client) { + private static void reconnect (final MinecraftClient client) { final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); if (networkHandler == null) return; // single-player? @@ -86,7 +85,7 @@ public class UsernameCommand { }); } - private static int changeSession(final CommandContext context, final Session session) { + private static int changeSession (final CommandContext context, final Session session) { final MinecraftClient client = context.getSource().getClient(); ((MinecraftClientAccessor) client).session(session); @@ -94,7 +93,7 @@ public class UsernameCommand { return Command.SINGLE_SUCCESS; } - private static int changeOffline(final CommandContext context, final String username) throws CommandSyntaxException { + private static int changeOffline (final CommandContext context, final String username) throws CommandSyntaxException { if (username.length() > 16) throw USERNAME_TOO_LONG.create(); return changeSession(context, offline(username)); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/ValidateCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/ValidateCommand.java index 8e5e7e9..8083123 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/ValidateCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/ValidateCommand.java @@ -10,7 +10,7 @@ import static land.chipmunk.chipmunkmod.command.CommandManager.literal; import static land.chipmunk.chipmunkmod.util.BotValidationUtilities.*; public class ValidateCommand { - public static void register(CommandDispatcher dispatcher) { + public static void register (final CommandDispatcher dispatcher) { dispatcher.register( literal("validate") .then(literal("hbot").then(argument("command", greedyString()).executes(c -> hbot(getString(c, "command"))))) diff --git a/src/main/java/land/chipmunk/chipmunkmod/config/ChipmunkModMigrations.java b/src/main/java/land/chipmunk/chipmunkmod/config/ChipmunkModMigrations.java index 3f0fa32..70920c0 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/config/ChipmunkModMigrations.java +++ b/src/main/java/land/chipmunk/chipmunkmod/config/ChipmunkModMigrations.java @@ -7,7 +7,7 @@ import land.chipmunk.chipmunkmod.config.migrations.MigrationV2; import land.chipmunk.chipmunkmod.config.migrations.MigrationV3; public final class ChipmunkModMigrations extends AbstractMigrationManager { - public ChipmunkModMigrations() { + public ChipmunkModMigrations () { super("version"); this.register(new MigrationV0()); // unversioned -> v0 diff --git a/src/main/java/land/chipmunk/chipmunkmod/config/Configuration.java b/src/main/java/land/chipmunk/chipmunkmod/config/Configuration.java index 2c50abc..cbc0d34 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/config/Configuration.java +++ b/src/main/java/land/chipmunk/chipmunkmod/config/Configuration.java @@ -44,10 +44,10 @@ public class Configuration { public String prefix; public @Nullable String webhookUrl; - public TestBotInfo() { + public TestBotInfo () { } - public TestBotInfo(String prefix, @Nullable String webhookUrl) { + public TestBotInfo (final String prefix, @Nullable final String webhookUrl) { this.prefix = prefix; this.webhookUrl = webhookUrl; } @@ -58,10 +58,10 @@ public class Configuration { public String prefix; public @Nullable String key; - public BotInfo() { + public BotInfo () { } - public BotInfo(String prefix, @Nullable String key) { + public BotInfo (final String prefix, @Nullable final String key) { this.prefix = prefix; this.key = key; } @@ -78,8 +78,8 @@ public class Configuration { public static class CustomChat { public @NotNull Component format = Component.translatable("chat.type.text", - Component.selector("@s"), - Component.text("MESSAGE") + Component.selector("@s"), + Component.text("MESSAGE") ); } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/config/migration/AbstractMigrationManager.java b/src/main/java/land/chipmunk/chipmunkmod/config/migration/AbstractMigrationManager.java index c5239a1..2f60be3 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/config/migration/AbstractMigrationManager.java +++ b/src/main/java/land/chipmunk/chipmunkmod/config/migration/AbstractMigrationManager.java @@ -14,19 +14,19 @@ public abstract class AbstractMigrationManager { private final List migrations = new ArrayList<>(); private final Object[] versionKey; - public AbstractMigrationManager(final Object... versionKey) { + public AbstractMigrationManager (final Object... versionKey) { this.versionKey = versionKey; } - protected void register(final ConfigMigration migration) { + protected void register (final ConfigMigration migration) { this.migrations.add(migration); } - protected void registerFrom(final int version, final Supplier supplier) { + protected void registerFrom (final int version, final Supplier supplier) { this.migrations.add(ConfigMigration.from(version, supplier)); } - public ConfigurationTransformation.Versioned create() { + public ConfigurationTransformation.Versioned create () { final ConfigurationTransformation.VersionedBuilder builder = ConfigurationTransformation.versionedBuilder() .versionKey(versionKey); @@ -35,18 +35,18 @@ public abstract class AbstractMigrationManager { return builder.build(); } - public void setLatest(final N config) throws ConfigurateException { + public void setLatest (final N config) throws ConfigurateException { final ConfigurationTransformation.Versioned transforms = this.create(); config.node(transforms.versionKey()).set(Integer.class, transforms.latestVersion()); } - public boolean migrate(final N config) throws ConfigurateException { + public boolean migrate (final N config) throws ConfigurateException { final ConfigurationTransformation.Versioned transforms = this.create(); final int version = transforms.version(config); if (version > transforms.latestVersion()) { ChipmunkMod.LOGGER.warn("Latest config version is {}, but yours is {}! Are you from the future?", - transforms.latestVersion(), version); + transforms.latestVersion(), version); return false; } diff --git a/src/main/java/land/chipmunk/chipmunkmod/config/migration/ConfigMigration.java b/src/main/java/land/chipmunk/chipmunkmod/config/migration/ConfigMigration.java index 54b384a..501f02f 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/config/migration/ConfigMigration.java +++ b/src/main/java/land/chipmunk/chipmunkmod/config/migration/ConfigMigration.java @@ -5,17 +5,17 @@ import org.spongepowered.configurate.transformation.ConfigurationTransformation; import java.util.function.Supplier; public interface ConfigMigration { - int version(); - - ConfigurationTransformation create(); - - static ConfigMigration from(final int version, final Supplier supplier) { + static ConfigMigration from (final int version, final Supplier supplier) { return new ConfigMigrationImpl(version, supplier); } + int version (); + + ConfigurationTransformation create (); + record ConfigMigrationImpl(int version, Supplier supplier) implements ConfigMigration { @Override - public ConfigurationTransformation create() { + public ConfigurationTransformation create () { return this.supplier.get(); } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/config/migrations/MigrationV0.java b/src/main/java/land/chipmunk/chipmunkmod/config/migrations/MigrationV0.java index b2a3cda..bd0f391 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/config/migrations/MigrationV0.java +++ b/src/main/java/land/chipmunk/chipmunkmod/config/migrations/MigrationV0.java @@ -8,12 +8,12 @@ import static org.spongepowered.configurate.NodePath.path; public final class MigrationV0 implements ConfigMigration { @Override - public int version() { + public int version () { return 0; } @Override - public ConfigurationTransformation create() { + public ConfigurationTransformation create () { return ConfigurationTransformation.builder() .addAction(path("fullbright"), TransformAction.remove()) .build(); diff --git a/src/main/java/land/chipmunk/chipmunkmod/config/migrations/MigrationV1.java b/src/main/java/land/chipmunk/chipmunkmod/config/migrations/MigrationV1.java index c410194..45dde75 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/config/migrations/MigrationV1.java +++ b/src/main/java/land/chipmunk/chipmunkmod/config/migrations/MigrationV1.java @@ -15,22 +15,22 @@ import static org.spongepowered.configurate.NodePath.path; public final class MigrationV1 implements ConfigMigration { @Override - public int version() { + public int version () { return 1; } @Override - public ConfigurationTransformation create() { + public ConfigurationTransformation create () { return ConfigurationTransformation.builder() .addAction(path("customChat", "format"), - ConfigurateUtilities.componentTransformer(new CustomChatFormatMigrator(), null)) + ConfigurateUtilities.componentTransformer(new CustomChatFormatMigrator(), null)) .build(); } private static final class CustomChatFormatMigrator extends TranslatableComponentRenderer { @Override - protected @NotNull Component renderSelector(final @NotNull SelectorComponent component, - final @NotNull Void context) { + protected @NotNull Component renderSelector (final @NotNull SelectorComponent component, + final @NotNull Void context) { final String pattern = component.pattern(); if (pattern.equals("USERNAME") || pattern.equals("UUID")) { final SelectorComponent.Builder builder = Component.selector() @@ -45,7 +45,7 @@ public final class MigrationV1 implements ConfigMigration { // Older configs had things like: `{ "text": "", "extra": ["MESSAGE"] }` // We don't need that anymore, transform it to `{ "text": "MESSAGE" }` @Override - protected @NotNull Component renderText(@NotNull TextComponent component, @NotNull Void context) { + protected @NotNull Component renderText (@NotNull final TextComponent component, @NotNull final Void context) { if (!component.content().isEmpty() || component.children().size() != 1) { return super.renderText(component, context); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/config/migrations/MigrationV2.java b/src/main/java/land/chipmunk/chipmunkmod/config/migrations/MigrationV2.java index 4af3200..258b9d5 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/config/migrations/MigrationV2.java +++ b/src/main/java/land/chipmunk/chipmunkmod/config/migrations/MigrationV2.java @@ -8,12 +8,12 @@ import static org.spongepowered.configurate.NodePath.path; public class MigrationV2 implements ConfigMigration { @Override - public int version() { + public int version () { return 2; } @Override - public ConfigurationTransformation create() { + public ConfigurationTransformation create () { return ConfigurationTransformation.builder() .addAction(path("bots", "chomens", "authKey"), TransformAction.remove()) .build(); diff --git a/src/main/java/land/chipmunk/chipmunkmod/config/migrations/MigrationV3.java b/src/main/java/land/chipmunk/chipmunkmod/config/migrations/MigrationV3.java index 9b97ae1..c78ac58 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/config/migrations/MigrationV3.java +++ b/src/main/java/land/chipmunk/chipmunkmod/config/migrations/MigrationV3.java @@ -8,12 +8,12 @@ import static org.spongepowered.configurate.NodePath.path; public class MigrationV3 implements ConfigMigration { @Override - public int version() { + public int version () { return 3; } @Override - public ConfigurationTransformation create() { + public ConfigurationTransformation create () { return ConfigurationTransformation.builder() .addAction(path("bots", "chomens", "formatKey"), TransformAction.remove()) .build(); diff --git a/src/main/java/land/chipmunk/chipmunkmod/data/ChomeNSBotCommand.java b/src/main/java/land/chipmunk/chipmunkmod/data/ChomeNSBotCommand.java index 18864ab..0e284b5 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/data/ChomeNSBotCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/data/ChomeNSBotCommand.java @@ -9,7 +9,7 @@ import java.util.List; import java.util.Objects; public record ChomeNSBotCommand(String name, TrustLevel trustLevel, List aliases) { - public static @Nullable ChomeNSBotCommand fromText(final Text component) { + public static @Nullable ChomeNSBotCommand fromText (final Text component) { final String name = TextUtilities.plainOrNull(component); if (name == null) return null; @@ -41,7 +41,7 @@ public record ChomeNSBotCommand(String name, TrustLevel trustLevel, List ADMIN, OWNER; - public static TrustLevel fromText(final Text component) { + public static TrustLevel fromText (final Text component) { final String trustLevelString = TextUtilities.plainOrNull(component); if (trustLevelString == null) return null; diff --git a/src/main/java/land/chipmunk/chipmunkmod/data/MutablePlayerListEntry.java b/src/main/java/land/chipmunk/chipmunkmod/data/MutablePlayerListEntry.java index 6b5a966..c299e7e 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/data/MutablePlayerListEntry.java +++ b/src/main/java/land/chipmunk/chipmunkmod/data/MutablePlayerListEntry.java @@ -11,14 +11,14 @@ public class MutablePlayerListEntry { public int latency; public Text displayName; - public MutablePlayerListEntry(GameProfile profile, GameMode gamemode, int latency, Text displayName) { + public MutablePlayerListEntry (final GameProfile profile, final GameMode gamemode, final int latency, final Text displayName) { this.profile = profile; this.gamemode = gamemode; this.latency = latency; this.displayName = displayName; } - public MutablePlayerListEntry (PlayerListS2CPacket.Entry entry) { + public MutablePlayerListEntry (final PlayerListS2CPacket.Entry entry) { this(entry.profile(), entry.gameMode(), entry.latency(), entry.displayName()); } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/listeners/Listener.java b/src/main/java/land/chipmunk/chipmunkmod/listeners/Listener.java index bdbd9b0..200262a 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/listeners/Listener.java +++ b/src/main/java/land/chipmunk/chipmunkmod/listeners/Listener.java @@ -4,12 +4,15 @@ import net.minecraft.network.packet.Packet; import net.minecraft.text.Text; public interface Listener { - default void packetReceived (Packet packet) {} - default void packetSent (Packet packet) {} + default void packetReceived (final Packet packet) { } - default void chatMessageReceived (Text message) {} - default void overlayMessageReceived (Text message) {} + default void packetSent (final Packet packet) { } - default void coreReady () {} - default void coreMoved () {} + default void chatMessageReceived (final Text message) { } + + default void overlayMessageReceived (final Text message) { } + + default void coreReady () { } + + default void coreMoved () { } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/listeners/ListenerManager.java b/src/main/java/land/chipmunk/chipmunkmod/listeners/ListenerManager.java index 061aca4..1deadbb 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/listeners/ListenerManager.java +++ b/src/main/java/land/chipmunk/chipmunkmod/listeners/ListenerManager.java @@ -6,7 +6,7 @@ import java.util.List; public class ListenerManager { public static List listeners = new ArrayList<>(); - public static void addListener (Listener listener) { + public static void addListener (final Listener listener) { listeners.add(listener); } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatInputSuggestorMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatInputSuggestorMixin.java index 143d298..71222a2 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatInputSuggestorMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatInputSuggestorMixin.java @@ -27,29 +27,28 @@ import java.util.concurrent.CompletableFuture; @Mixin(net.minecraft.client.gui.screen.ChatInputSuggestor.class) public class ChatInputSuggestorMixin { - @Shadow - private CompletableFuture pendingSuggestions; - - @Shadow - public void show(boolean narrateFirstSuggestion) { - } - - @Shadow - private static int getStartOfCurrentWord(String input) { - return 0; - } - @Mutable @Final @Shadow final TextFieldWidget textField; + @Shadow + private CompletableFuture pendingSuggestions; - public ChatInputSuggestorMixin() { + public ChatInputSuggestorMixin () { textField = null; } + @Shadow + private static int getStartOfCurrentWord (final String input) { + return 0; + } + + @Shadow + public void show (final boolean narrateFirstSuggestion) { + } + @Inject(at = @At("TAIL"), method = "refresh()V") - public void refresh(CallbackInfo ci) { + public void refresh (final CallbackInfo ci) { final CommandManager commandManager = CommandManager.INSTANCE; if (this.textField == null) return; diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java index 09e3cc4..3eabaa8 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java @@ -27,18 +27,19 @@ import java.util.List; @Mixin(value = ChatScreen.class) public abstract class ChatScreenMixin { - @Shadow protected TextFieldWidget chatField; + @Shadow + protected TextFieldWidget chatField; // infinite chat // can't use ModifyConstant due to VFP, see: // https://github.com/ViaVersion/ViaFabricPlus/blob/main/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/limitation/max_chat_length/MixinChatScreen.java @Inject(method = "init", at = @At("RETURN")) - private void init(final CallbackInfo ci) { + private void init (final CallbackInfo ci) { chatField.setMaxLength(Integer.MAX_VALUE); } @WrapMethod(method = "sendMessage") - private void sendMessage(final String chatText, final boolean addToHistory, final Operation original) { + private void sendMessage (final String chatText, final boolean addToHistory, final Operation original) { final MinecraftClient client = MinecraftClient.getInstance(); if (addToHistory) { @@ -68,7 +69,7 @@ public abstract class ChatScreenMixin { connection.getInputStream().close(); connection.disconnect(); - } catch (IOException | URISyntaxException e) { + } catch (final IOException | URISyntaxException e) { ChipmunkMod.LOGGER.error("Error while trying to request TestBot webhook", e); } }); @@ -81,7 +82,7 @@ public abstract class ChatScreenMixin { .toList(); final List aliases = new ArrayList<>(); - for (ChomeNSBotCommand command : commands) { + for (final ChomeNSBotCommand command : commands) { if (command.trustLevel() == ChomeNSBotCommand.TrustLevel.PUBLIC) continue; aliases.addAll(command.aliases()); @@ -98,7 +99,7 @@ public abstract class ChatScreenMixin { try { BotValidationUtilities.chomens(chatText.substring(prefixLength)); return; - } catch (Exception ignored) { + } catch (final Exception ignored) { } } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientCommonNetworkHandlerAccessor.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientCommonNetworkHandlerAccessor.java index 29d6cb6..77c9079 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientCommonNetworkHandlerAccessor.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientCommonNetworkHandlerAccessor.java @@ -8,5 +8,5 @@ import org.spongepowered.asm.mixin.gen.Accessor; @Mixin(ClientCommonNetworkHandler.class) public interface ClientCommonNetworkHandlerAccessor { @Accessor("postDisconnectScreen") - Screen getPostDisconnectScreen(); + Screen getPostDisconnectScreen (); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java index 2c532fa..c5b5547 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java @@ -29,12 +29,12 @@ public class ClientConnectionMixin { private static final Pattern CUSTOM_PITCH_PATTERN = Pattern.compile(".*\\.pitch\\.(.*)"); @WrapMethod(method = "handlePacket") - private static void handlePacket( + private static void handlePacket ( final Packet packet, final PacketListener packetListener, final Operation original ) { - for (Listener listener : ListenerManager.listeners) { + for (final Listener listener : ListenerManager.listeners) { listener.packetReceived(packet); } @@ -42,11 +42,11 @@ public class ClientConnectionMixin { // this check is very easy to bypass in 2025 if ( - packet instanceof ParticleS2CPacket t_packet - && t_packet.getCount() > MAX_PARTICLES_PER_PACKET + packet instanceof final ParticleS2CPacket t_packet + && t_packet.getCount() > MAX_PARTICLES_PER_PACKET ) { return; - } else if (packet instanceof PlaySoundS2CPacket t_packet) { + } else if (packet instanceof final PlaySoundS2CPacket t_packet) { final SoundEvent soundEvent = t_packet.getSound().value(); final Identifier sound = soundEvent.id(); @@ -94,7 +94,7 @@ public class ClientConnectionMixin { )); return; - } catch (NumberFormatException e) { + } catch (final NumberFormatException e) { ChipmunkMod.LOGGER.error("Failed to parse custom pitch", e); } @@ -105,18 +105,18 @@ public class ClientConnectionMixin { } @WrapMethod(method = "send(Lnet/minecraft/network/packet/Packet;Lnet/minecraft/network/PacketCallbacks;Z)V") - private void sendPacket( + private void sendPacket ( final Packet packet, final PacketCallbacks callbacks, final boolean flush, final Operation original ) { if ( - packet instanceof RequestCommandCompletionsC2SPacket t_packet - && t_packet.getPartialCommand().length() > 2048 + packet instanceof final RequestCommandCompletionsC2SPacket t_packet + && t_packet.getPartialCommand().length() > 2048 ) return; - for (Listener listener : ListenerManager.listeners) { + for (final Listener listener : ListenerManager.listeners) { listener.packetSent(packet); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java index cf97bab..4e4d06c 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java @@ -41,7 +41,7 @@ public class ClientPlayNetworkHandlerMixin { private CommandDispatcher commandDispatcher; @Inject(method = "onGameJoin", at = @At("TAIL")) - private void onGameJoin(GameJoinS2CPacket packet, CallbackInfo ci) { + private void onGameJoin (final GameJoinS2CPacket packet, final CallbackInfo ci) { final CommandRegistryAccess commandRegistryAccess = CommandRegistryAccess.of(this.combinedDynamicRegistries, this.enabledFeatures); KaboomCheck.INSTANCE.onJoin(); @@ -55,7 +55,7 @@ public class ClientPlayNetworkHandlerMixin { } @Inject(method = "onCommandTree", at = @At("TAIL")) - private void onCommandTree(final CommandTreeS2CPacket packet, final CallbackInfo ci) { + private void onCommandTree (final CommandTreeS2CPacket packet, final CallbackInfo ci) { KaboomCheck.INSTANCE.onCommandTree(this.commandDispatcher); } @@ -66,7 +66,7 @@ public class ClientPlayNetworkHandlerMixin { target = "Lnet/minecraft/client/network/message/MessageHandler;onGameMessage(Lnet/minecraft/text/Text;Z)V" ) ) - private void onGameMessage(MessageHandler instance, Text message, boolean overlay, Operation original) { + private void onGameMessage (final MessageHandler instance, final Text message, final boolean overlay, final Operation original) { try { if ( ( @@ -76,25 +76,25 @@ public class ClientPlayNetworkHandlerMixin { message.getString().startsWith("Nickname changed.") ) ) || - ( - message.getContent() instanceof TranslatableTextContent translatableTextContent && - ( - translatableTextContent.getKey().equals("advMode.setCommand.success") - || translatableTextContent.getKey().equals("قيادة المجموعة: %s") - ) - ) + ( + message.getContent() instanceof final TranslatableTextContent translatableTextContent && + ( + translatableTextContent.getKey().equals("advMode.setCommand.success") + || translatableTextContent.getKey().equals("قيادة المجموعة: %s") + ) + ) ) return; - for (Listener listener : ListenerManager.listeners) { + for (final Listener listener : ListenerManager.listeners) { listener.chatMessageReceived(message); } if ( message.getSiblings().size() > 1 - && message.getSiblings().getFirst().getContent() instanceof PlainTextContent textContent - && textContent.string().equals(ChomeNSBotCommandSuggestions.REQUEST_SUGGESTIONS_ID) + && message.getSiblings().getFirst().getContent() instanceof final PlainTextContent textContent + && textContent.string().equals(ChomeNSBotCommandSuggestions.REQUEST_SUGGESTIONS_ID) ) return; - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); } @@ -108,8 +108,8 @@ public class ClientPlayNetworkHandlerMixin { target = "Lnet/minecraft/client/gui/hud/InGameHud;setOverlayMessage(Lnet/minecraft/text/Text;Z)V" ) ) - private void onOverlayMessage(InGameHud instance, Text message, boolean tinted, Operation original) { - for (Listener listener : ListenerManager.listeners) { + private void onOverlayMessage (final InGameHud instance, final Text message, final boolean tinted, final Operation original) { + for (final Listener listener : ListenerManager.listeners) { listener.overlayMessageReceived(message); } @@ -122,7 +122,7 @@ public class ClientPlayNetworkHandlerMixin { } @WrapMethod(method = "sendChatMessage") - private void sendChatMessage(String content, Operation original) { + private void sendChatMessage (final String content, final Operation original) { final CommandManager commandManager = CommandManager.INSTANCE; if (content.startsWith(commandManager.prefix)) { commandManager.executeCommand(content.substring(commandManager.prefix.length())); diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayerEntityMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayerEntityMixin.java index 9f1fa36..cd81b15 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayerEntityMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayerEntityMixin.java @@ -17,14 +17,16 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ClientPlayerEntity.class) public abstract class ClientPlayerEntityMixin extends Entity { - @Shadow @Final public ClientPlayNetworkHandler networkHandler; + @Shadow + @Final + public ClientPlayNetworkHandler networkHandler; - public ClientPlayerEntityMixin(final EntityType type, final World world) { + public ClientPlayerEntityMixin (final EntityType type, final World world) { super(type, world); } @Inject(at = @At("TAIL"), method = "move") - public void move(CallbackInfo ci) { + public void move (final CallbackInfo ci) { final BlockPos origin = CommandCore.INSTANCE.origin; if (origin == null) { CommandCore.INSTANCE.move(this.getPos()); diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ElderGuardianAppearanceParticleMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ElderGuardianAppearanceParticleMixin.java index e0a2682..75d4e7e 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ElderGuardianAppearanceParticleMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ElderGuardianAppearanceParticleMixin.java @@ -13,7 +13,7 @@ public class ElderGuardianAppearanceParticleMixin { @WrapMethod( method = "createParticle(Lnet/minecraft/particle/SimpleParticleType;Lnet/minecraft/client/world/ClientWorld;DDDDDD)Lnet/minecraft/client/particle/Particle;" ) - private Particle createParticle( + private Particle createParticle ( final SimpleParticleType simpleParticleType, final ClientWorld clientWorld, final double d, diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/MinecraftClientAccessor.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/MinecraftClientAccessor.java index 0f93627..6e67418 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/MinecraftClientAccessor.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/MinecraftClientAccessor.java @@ -10,5 +10,5 @@ import org.spongepowered.asm.mixin.gen.Accessor; public interface MinecraftClientAccessor { @Mutable @Accessor("session") - void session(Session session); + void session (Session session); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/SoundSystemMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/SoundSystemMixin.java index 2fe8a22..b016ab4 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/SoundSystemMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/SoundSystemMixin.java @@ -9,7 +9,7 @@ import org.spongepowered.asm.mixin.Mixin; @Mixin(SoundSystem.class) public class SoundSystemMixin { @WrapMethod(method = "getAdjustedPitch") - private float getAdjustedPitch(final SoundInstance sound, final Operation original) { + private float getAdjustedPitch (final SoundInstance sound, final Operation original) { return sound.getPitch(); } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/Chat.java b/src/main/java/land/chipmunk/chipmunkmod/modules/Chat.java index 5ac6f06..1559b47 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/Chat.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/Chat.java @@ -6,8 +6,9 @@ import net.minecraft.client.network.ClientPlayNetworkHandler; public class Chat { public static final ThreadLocal NEXT_CHAT_PLAYER = ThreadLocal.withInitial(() -> false); - public static void sendChatMessage (String message) { sendChatMessage(message, false); } - public static void sendChatMessage (String message, boolean usePlayerChat) { + public static void sendChatMessage (final String message) { sendChatMessage(message, false); } + + public static void sendChatMessage (final String message, final boolean usePlayerChat) { if (message == null) return; if (usePlayerChat) NEXT_CHAT_PLAYER.set(true); diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/ChomeNSBotCommandSuggestions.java b/src/main/java/land/chipmunk/chipmunkmod/modules/ChomeNSBotCommandSuggestions.java index 85b69bc..0a571e5 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/ChomeNSBotCommandSuggestions.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/ChomeNSBotCommandSuggestions.java @@ -29,13 +29,13 @@ public class ChomeNSBotCommandSuggestions implements Listener { public List commands = new ArrayList<>(); - public ChomeNSBotCommandSuggestions (MinecraftClient client) { + public ChomeNSBotCommandSuggestions (final MinecraftClient client) { this.client = client; ListenerManager.addListener(this); } - public void init () {} + public void init () { } @Override public void coreMoved () { @@ -67,21 +67,21 @@ public class ChomeNSBotCommandSuggestions implements Listener { } @Override - public void overlayMessageReceived (Text message) { + public void overlayMessageReceived (final Text message) { if ( - !(message.getContent() instanceof TranslatableTextContent translatableTextContent) + !(message.getContent() instanceof final TranslatableTextContent translatableTextContent) || !translatableTextContent.getKey().isEmpty() || translatableTextContent.getArgs().length != 2 - || !(translatableTextContent.getArgs()[0] instanceof String id) + || !(translatableTextContent.getArgs()[0] instanceof final String id) || !id.equals(BOT_SELECTOR_ID) - || !(translatableTextContent.getArgs()[1] instanceof String selector) + || !(translatableTextContent.getArgs()[1] instanceof final String selector) ) return; this.botSelector = selector; } @Override - public void chatMessageReceived(Text message) { + public void chatMessageReceived (final Text message) { final List children = message.getSiblings(); if (children.isEmpty()) return; @@ -89,10 +89,10 @@ public class ChomeNSBotCommandSuggestions implements Listener { if (!textComponent.getString().equals(REQUEST_SUGGESTIONS_ID)) return; commands = children.stream() - .skip(1) - .map(ChomeNSBotCommand::fromText) - .filter(Objects::nonNull) - .toList(); + .skip(1) + .map(ChomeNSBotCommand::fromText) + .filter(Objects::nonNull) + .toList(); receivedSuggestions = true; } diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java b/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java index 7a90400..223f1f2 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java @@ -23,42 +23,36 @@ import java.util.TimerTask; import java.util.concurrent.CompletableFuture; public class CommandCore { + public static CommandCore INSTANCE = new CommandCore(MinecraftClient.getInstance()); private final MinecraftClient client; public boolean ready = false; public BlockPos origin; public BlockBox noPos; public BlockPos block; public BlockBox withPos; - + public boolean runFillCommand = true; + public boolean clientPlayerEntityFilled = false; private Timer timer; - private boolean shouldRefill = false; - private DimensionType oldDimension; - public boolean runFillCommand = true; - - public boolean clientPlayerEntityFilled = false; - - public static CommandCore INSTANCE = new CommandCore(MinecraftClient.getInstance()); - - public CommandCore(MinecraftClient client) { + public CommandCore (final MinecraftClient client) { this.client = client; reloadRelativeArea(); } - public void init() { + public void init () { if (timer != null) cleanup(); final TimerTask task = new TimerTask() { - public void run() { + public void run () { tick(); } }; final TimerTask refillTask = new TimerTask() { @Override - public void run() { + public void run () { if (clientPlayerEntityFilled) { clientPlayerEntityFilled = false; return; @@ -83,7 +77,7 @@ public class CommandCore { move(client.player.getPos()); } - private void tick() { + private void tick () { final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); if (networkHandler == null) { @@ -95,11 +89,11 @@ public class CommandCore { reloadRelativeArea(); } - public void reloadRelativeArea() { + public void reloadRelativeArea () { noPos = ChipmunkMod.CONFIG.core.relativeArea; } - public void check() { + public void check () { final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); if (networkHandler == null || withPos == null || !ready) return; @@ -129,12 +123,12 @@ public class CommandCore { } } } - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); } } - public void move(Vec3d position) { + public void move (final Vec3d position) { final ClientWorld world = client.world; if (world == null || noPos == null) return; @@ -159,15 +153,15 @@ public class CommandCore { block = new BlockPos(withPos.getMinX(), withPos.getMinY(), withPos.getMinZ()); refill(); - for (Listener listener : ListenerManager.listeners) listener.coreMoved(); + for (final Listener listener : ListenerManager.listeners) listener.coreMoved(); if (!ready) { ready = true; - for (Listener listener : ListenerManager.listeners) listener.coreReady(); + for (final Listener listener : ListenerManager.listeners) listener.coreReady(); } } - public void refill() { + public void refill () { if (!runFillCommand || withPos == null) return; final String command = String.format( @@ -185,7 +179,7 @@ public class CommandCore { client.getNetworkHandler().sendChatCommand(command); } - public void incrementCurrentBlock() { + public void incrementCurrentBlock () { if (withPos == null) return; int x = block.getX() + 1; @@ -207,7 +201,7 @@ public class CommandCore { block = new BlockPos(x, y, z); } - public void run(String command) { + public void run (final String command) { if (command.length() > 32767) return; final ClientConnection connection = client.getNetworkHandler().getConnection(); @@ -254,7 +248,7 @@ public class CommandCore { incrementCurrentBlock(); } - public CompletableFuture runTracked(String command) { + public CompletableFuture runTracked (final String command) { final ClientConnection connection = client.getNetworkHandler().getConnection(); if (block == null) return new CompletableFuture<>(); @@ -296,12 +290,12 @@ public class CommandCore { incrementCurrentBlock(); - CompletableFuture future = new CompletableFuture<>(); + final CompletableFuture future = new CompletableFuture<>(); final Timer timer = new Timer(); final TimerTask queryTask = new TimerTask() { - public void run() { + public void run () { client.getNetworkHandler().getDataQueryHandler().queryBlockNbt(block, future::complete); timer.cancel(); // ? Is this necesary? @@ -314,7 +308,7 @@ public class CommandCore { return future; } - public void cleanup() { + public void cleanup () { if (timer == null) return; timer.cancel(); diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/CommandLoopManager.java b/src/main/java/land/chipmunk/chipmunkmod/modules/CommandLoopManager.java index 3b3e75b..1db88fb 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/CommandLoopManager.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/CommandLoopManager.java @@ -1,37 +1,36 @@ package land.chipmunk.chipmunkmod.modules; -import java.util.List; import java.util.ArrayList; +import java.util.List; import java.util.Timer; import java.util.TimerTask; public class CommandLoopManager { + public static final CommandLoopManager INSTANCE = new CommandLoopManager(CommandCore.INSTANCE); private final CommandCore core; public List commandLoops = new ArrayList<>(); - public CommandLoopManager (CommandCore core) { + public CommandLoopManager (final CommandCore core) { this.core = core; } - public static final CommandLoopManager INSTANCE = new CommandLoopManager(CommandCore.INSTANCE); - - public int loopCommand (String command, long interval) { + public int loopCommand (final String command, final long interval) { final CommandLoop loop = new CommandLoop(this.core, command, interval); commandLoops.add(loop); return commandLoops.size() - 1; } - public boolean removeAndStop (CommandLoop loop) { + public boolean removeAndStop (final CommandLoop loop) { loop.stop(); return commandLoops.remove(loop); } - public boolean removeAndStop (int id) { + public boolean removeAndStop (final int id) { return removeAndStop(commandLoops.get(id)); } public void clearLoops () { - for (CommandLoop loop : this.commandLoops) loop.stop(); + for (final CommandLoop loop : this.commandLoops) loop.stop(); commandLoops.clear(); } @@ -43,7 +42,7 @@ public class CommandLoopManager { public long interval; private Timer timer; - public CommandLoop (CommandCore core, String command, long interval) { + public CommandLoop (final CommandCore core, final String command, final long interval) { this.core = core; this.command = command; this.interval = interval; @@ -51,8 +50,9 @@ public class CommandLoopManager { timer.schedule(this.createTimerTask(), interval, interval); } - private long interval (long interval) { - if (timer == null) throw new IllegalStateException("Attempted to set the interval of a stopped command loop"); + private long interval (final long interval) { + if (timer == null) + throw new IllegalStateException("Attempted to set the interval of a stopped command loop"); timer.cancel(); timer.purge(); diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/KaboomCheck.java b/src/main/java/land/chipmunk/chipmunkmod/modules/KaboomCheck.java index 84747e7..4138c01 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/KaboomCheck.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/KaboomCheck.java @@ -5,18 +5,17 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.command.CommandSource; public class KaboomCheck { + public static final KaboomCheck INSTANCE = new KaboomCheck(); private static final String CHECKED_COMMAND_OP = "extras:prefix"; // Added circa 2018 private static final String CHECKED_COMMAND = "minecraft:op"; // It'd be a bit weird for non-Kaboom servers to allow /op without OP... - public static final KaboomCheck INSTANCE = new KaboomCheck(); - private final MinecraftClient client = MinecraftClient.getInstance(); public boolean isKaboom = false; - public void onJoin() { + public void onJoin () { this.isKaboom = false; } - public void onCommandTree(final CommandDispatcher dispatcher) { + public void onCommandTree (final CommandDispatcher dispatcher) { assert client.player != null; // We can only receive this packet while in a server final String checkedCommand = client.player.getPermissionLevel() == 4 ? CHECKED_COMMAND_OP : CHECKED_COMMAND; diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/RainbowName.java b/src/main/java/land/chipmunk/chipmunkmod/modules/RainbowName.java index 88fb5d5..fc62c3a 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/RainbowName.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/RainbowName.java @@ -3,7 +3,6 @@ package land.chipmunk.chipmunkmod.modules; import com.mojang.authlib.GameProfile; import land.chipmunk.chipmunkmod.ChipmunkMod; import land.chipmunk.chipmunkmod.util.ColorUtilities; - import land.chipmunk.chipmunkmod.util.RandomUtilities; import land.chipmunk.chipmunkmod.util.UUIDUtilities; import net.kyori.adventure.text.Component; @@ -17,19 +16,21 @@ import java.util.Timer; import java.util.TimerTask; public class RainbowName { - private final MinecraftClient client; - public static final RainbowName INSTANCE = new RainbowName(MinecraftClient.getInstance()); - + private final MinecraftClient client; private final Random random = new Random(); public boolean enabled = false; - private Timer timer = null; - - private String team; public String displayName; + private Timer timer = null; + private String team; private int startHue = 0; + public RainbowName (final MinecraftClient client) { + this.client = client; + this.displayName = client.getSession().getUsername(); + } + public void init () { final TimerTask task = new TimerTask() { public void run () { @@ -73,11 +74,6 @@ public class RainbowName { enabled = false; } - public RainbowName (MinecraftClient client) { - this.client = client; - this.displayName = client.getSession().getUsername(); - } - private void tick () { try { final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); @@ -91,13 +87,13 @@ public class RainbowName { final GameProfile profile = networkHandler.getProfile(); int hue = startHue; - int increment = (int) (360.0 / Math.max(displayName.length(), 20)); + final int increment = (int) (360.0 / Math.max(displayName.length(), 20)); Component component = Component.empty(); - StringBuilder essentialsNickname = new StringBuilder(); + final StringBuilder essentialsNickname = new StringBuilder(); - for (char character : displayName.toCharArray()) { - String color = String.format("%06x", ColorUtilities.hsvToRgb(hue, 100, 100)); + for (final char character : displayName.toCharArray()) { + final String color = String.format("%06x", ColorUtilities.hsvToRgb(hue, 100, 100)); component = component.append(Component.text(character).color(TextColor.fromHexString("#" + color))); essentialsNickname.append("§#").append(color).append(character != ' ' ? character : '_'); hue = (hue + increment) % 360; @@ -107,7 +103,7 @@ public class RainbowName { CommandCore.INSTANCE.run("essentials:nick " + profile.getId() + " " + essentialsNickname); startHue = (startHue + increment) % 360; - } catch (Exception e) { + } catch (final Exception e) { ChipmunkMod.LOGGER.error("Error while ticking rainbow name", e); } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/SelfCare.java b/src/main/java/land/chipmunk/chipmunkmod/modules/SelfCare.java index ceb8e90..7d5f5e8 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/SelfCare.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/SelfCare.java @@ -17,27 +17,21 @@ import java.util.TimerTask; import static land.chipmunk.chipmunkmod.util.ServerUtilities.serverHasCommand; public class SelfCare implements Listener { - private final MinecraftClient client; + public static final SelfCare INSTANCE = new SelfCare(MinecraftClient.getInstance(), 70L, 500L); // make the intervals in config? public final long interval; public final long chatInterval; - + private final MinecraftClient client; public boolean opEnabled = ChipmunkMod.CONFIG.selfCare.op; public boolean gamemodeEnabled = ChipmunkMod.CONFIG.selfCare.gameMode; public boolean cspyEnabled = ChipmunkMod.CONFIG.selfCare.cspy; - - private int gameMode; - public String skin; - + public boolean hasSkin = false; + private int gameMode; private Timer timer; private Timer chatTimer; - private boolean cspy = false; - public boolean hasSkin = false; - public static final SelfCare INSTANCE = new SelfCare(MinecraftClient.getInstance(), 70L, 500L); // make the intervals in config? - - public SelfCare(MinecraftClient client, long interval, long chatInterval) { + public SelfCare (final MinecraftClient client, final long interval, final long chatInterval) { this.client = client; this.interval = interval; this.chatInterval = chatInterval; @@ -47,18 +41,18 @@ public class SelfCare implements Listener { ListenerManager.addListener(this); } - public void init() { + public void init () { } - public void onJoin() { + public void onJoin () { final TimerTask task = new TimerTask() { - public void run() { + public void run () { tick(); } }; final TimerTask chatTask = new TimerTask() { - public void run() { + public void run () { chatTick(); } }; @@ -70,7 +64,7 @@ public class SelfCare implements Listener { chatTimer.schedule(chatTask, chatInterval, chatInterval); } - public void cleanup() { + public void cleanup () { if (timer == null || chatTimer == null) return; timer.cancel(); @@ -86,7 +80,7 @@ public class SelfCare implements Listener { } @Override - public void chatMessageReceived(Text message) { + public void chatMessageReceived (final Text message) { final String stringMessage = message.getString(); if (stringMessage.equals("Successfully enabled CommandSpy")) cspy = true; @@ -99,7 +93,7 @@ public class SelfCare implements Listener { ) hasSkin = false; } - public void tick() { + public void tick () { final ClientPlayerEntity player = client.player; final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); @@ -108,11 +102,12 @@ public class SelfCare implements Listener { return; } - if (player != null && !player.hasPermissionLevel(2) && opEnabled && serverHasCommand("op")) networkHandler.sendChatCommand("op @s[type=player]"); + if (player != null && !player.hasPermissionLevel(2) && opEnabled && serverHasCommand("op")) + networkHandler.sendChatCommand("op @s[type=player]"); else if (gameMode != 1 && gamemodeEnabled) networkHandler.sendChatCommand("gamemode creative"); } - public void chatTick() { + public void chatTick () { final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); if (networkHandler == null) return; @@ -125,16 +120,16 @@ public class SelfCare implements Listener { } @Override - public void packetReceived(Packet packet) { + public void packetReceived (final Packet packet) { if (packet instanceof GameJoinS2CPacket) packetReceived((GameJoinS2CPacket) packet); else if (packet instanceof GameStateChangeS2CPacket) packetReceived((GameStateChangeS2CPacket) packet); } - public void packetReceived(GameJoinS2CPacket packet) { + public void packetReceived (final GameJoinS2CPacket packet) { gameMode = packet.commonPlayerSpawnInfo().gameMode().getId(); } - public void packetReceived(GameStateChangeS2CPacket packet) { + public void packetReceived (final GameStateChangeS2CPacket packet) { if (packet.getReason() != GameStateChangeS2CPacket.GAME_MODE_CHANGED) return; gameMode = (int) packet.getValue(); diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java b/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java index cae9dc6..23e9eb6 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java @@ -24,36 +24,34 @@ import java.util.Timer; import java.util.TimerTask; public class SongPlayer { - public static final String SELECTOR = "@a[tag=!nomusic,tag=!chipmunkmod_nomusic]"; + public static final String SELECTOR = "@a[tag=!nomusic,tag=!chipmunkmod_nomusic]"; + public static final SongPlayer INSTANCE = new SongPlayer(MinecraftClient.getInstance()); public static File SONG_DIR = new File("songs"); + static { if (!SONG_DIR.exists()) { SONG_DIR.mkdir(); } } - public static final SongPlayer INSTANCE = new SongPlayer(MinecraftClient.getInstance()); - + private final MinecraftClient client; public Song currentSong; public LinkedList songQueue = new LinkedList<>(); public Timer playTimer; public SongLoaderThread loaderThread; - private int ticksUntilPausedActionbar = 20; - public boolean useCore = true; public boolean actionbar = true; public float pitch = 0; + private int ticksUntilPausedActionbar = 20; - private final MinecraftClient client; - - public SongPlayer (MinecraftClient client) { + public SongPlayer (final MinecraftClient client) { this.client = client; } // TODO: Less duplicate code - public void loadSong (Path location) { + public void loadSong (final Path location) { final ClientPlayerEntity player = client.player; if (player == null) return; @@ -68,13 +66,13 @@ public class SongPlayer { player.sendMessage(Component.translatable("Loading %s", Component.text(location.toString(), NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN)); _loaderThread.start(); loaderThread = _loaderThread; - } catch (SongLoaderException e) { + } catch (final SongLoaderException e) { player.sendMessage(Component.translatable("Failed to load song: %s", Component.text(e.message.getString())).color(NamedTextColor.RED)); loaderThread = null; } } - public void loadSong (URL location) { + public void loadSong (final URL location) { final ClientPlayerEntity player = client.player; if (player == null) return; @@ -89,7 +87,7 @@ public class SongPlayer { player.sendMessage(Component.translatable("Loading %s", Component.text(location.toString(), NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN)); _loaderThread.start(); loaderThread = _loaderThread; - } catch (SongLoaderException e) { + } catch (final SongLoaderException e) { player.sendMessage(Component.translatable("Failed to load song: %s", Component.text(e.message.getString())).color(NamedTextColor.RED)); loaderThread = null; } @@ -139,9 +137,11 @@ public class SongPlayer { else ticksUntilPausedActionbar = 20; try { - if (!useCore && actionbar && client.player != null) client.player.sendActionBar(generateActionbar()); - else if (actionbar) CommandCore.INSTANCE.run("title " + SELECTOR + " actionbar " + GsonComponentSerializer.gson().serialize(generateActionbar())); - } catch (Exception e) { + if (!useCore && actionbar && client.player != null) + client.player.sendActionBar(generateActionbar()); + else if (actionbar) + CommandCore.INSTANCE.run("title " + SELECTOR + " actionbar " + GsonComponentSerializer.gson().serialize(generateActionbar())); + } catch (final Exception e) { e.printStackTrace(); } @@ -150,7 +150,8 @@ public class SongPlayer { handlePlaying(); if (currentSong.finished()) { - if (client.player != null) client.player.sendMessage(Component.translatable("Finished playing %s", Component.empty().append(currentSong.name).color(NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN)); + if (client.player != null) + client.player.sendMessage(Component.translatable("Finished playing %s", Component.empty().append(currentSong.name).color(NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN)); currentSong = null; } } @@ -164,7 +165,7 @@ public class SongPlayer { public Component generateActionbar () { final ClientPlayerEntity player = client.player; - Component component = Component.empty() + final Component component = Component.empty() .append(Component.translatable("%s", player.getName().getString()).color(NamedTextColor.GREEN)) .append(Component.translatable(" | ", NamedTextColor.DARK_GRAY)) .append(Component.translatable("Now playing %s", Component.empty().append(currentSong.name).color(NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN)) @@ -194,7 +195,7 @@ public class SongPlayer { return component; } - public Component formatTime (long millis) { + public Component formatTime (final long millis) { final int seconds = (int) millis / 1000; final String minutePart = String.valueOf(seconds / 60); @@ -259,7 +260,7 @@ public class SongPlayer { ) ); } - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/custom_chat/CustomChat.java b/src/main/java/land/chipmunk/chipmunkmod/modules/custom_chat/CustomChat.java index 962b7a2..ac98bc4 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/custom_chat/CustomChat.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/custom_chat/CustomChat.java @@ -1,7 +1,6 @@ package land.chipmunk.chipmunkmod.modules.custom_chat; import land.chipmunk.chipmunkmod.ChipmunkMod; - import land.chipmunk.chipmunkmod.modules.Chat; import land.chipmunk.chipmunkmod.modules.CommandCore; import land.chipmunk.chipmunkmod.modules.KaboomCheck; @@ -22,9 +21,9 @@ import java.util.TimerTask; import java.util.regex.Pattern; public class CustomChat { + public static final CustomChat INSTANCE = new CustomChat(MinecraftClient.getInstance()); private static final GsonComponentSerializer GSON = GsonComponentSerializer.gson(); private static final CustomChatComponentRenderer RENDERER = new CustomChatComponentRenderer(); - private static final LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer // https://sus.red/abc?a=b&c=d will still break the click events, though @@ -53,18 +52,14 @@ public class CustomChat { .useUnusualXRepeatedCharacterHexFormat() // &x&1&2&3&4&5&6abc .build(); - private final MinecraftClient client; - - public static final CustomChat INSTANCE = new CustomChat(MinecraftClient.getInstance()); - public boolean enabled = true; public String format; private Timer timer; - public CustomChat (MinecraftClient client) { + public CustomChat (final MinecraftClient client) { this.client = client; } @@ -94,7 +89,7 @@ public class CustomChat { timer.purge(); } - public void chat (String message) { + public void chat (final String message) { final ClientPlayerEntity player = client.player; if (player == null) return; if (!enabled || !player.hasPermissionLevel(2) || !player.isCreative()) { diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/custom_chat/CustomChatComponentRenderer.java b/src/main/java/land/chipmunk/chipmunkmod/modules/custom_chat/CustomChatComponentRenderer.java index 69b19d4..6bae9b3 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/custom_chat/CustomChatComponentRenderer.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/custom_chat/CustomChatComponentRenderer.java @@ -12,8 +12,8 @@ import org.jetbrains.annotations.NotNull; // We don't do any translatable rendering here, but extending from that makes it easier to work with. public final class CustomChatComponentRenderer extends TranslatableComponentRenderer { @Override - protected @NotNull Component renderSelector(final @NotNull SelectorComponent component, - final @NotNull CustomChatContext context) { + protected @NotNull Component renderSelector (final @NotNull SelectorComponent component, + final @NotNull CustomChatContext context) { final String pattern = component.pattern(); if (pattern.equals("@s")) { final SelectorComponent.Builder builder = Component.selector() @@ -26,8 +26,8 @@ public final class CustomChatComponentRenderer extends TranslatableComponentRend } @Override - protected @NotNull Component renderText(final @NotNull TextComponent component, - final @NotNull CustomChatContext context) { + protected @NotNull Component renderText (final @NotNull TextComponent component, + final @NotNull CustomChatContext context) { final String content = component.content(); if (content.equals("MESSAGE")) { return this.mergeMessage(component, context.message(), context); @@ -46,8 +46,8 @@ public final class CustomChatComponentRenderer extends TranslatableComponentRend @SuppressWarnings("NonExtendableApiUsage") // we're not extending it silly @Override - protected > void mergeStyle(final Component component, final B builder, - final CustomChatContext context) { + protected > void mergeStyle (final Component component, final B builder, + final CustomChatContext context) { super.mergeStyle(component, builder, context); // render clickEvent that may contain something like "MESSAGE" @@ -55,7 +55,7 @@ public final class CustomChatComponentRenderer extends TranslatableComponentRend builder.clickEvent(this.mergeClickEvent(component.clickEvent(), context)); } - private Component mergeMessage(final Component root, final Component msg, final CustomChatContext context) { + private Component mergeMessage (final Component root, final Component msg, final CustomChatContext context) { Component result = msg.applyFallbackStyle(root.style()); // applyFallbackStyle will apply everything that isn't content final ClickEvent clickEvent = result.clickEvent(); @@ -71,7 +71,7 @@ public final class CustomChatComponentRenderer extends TranslatableComponentRend return result; } - private ClickEvent mergeClickEvent(final ClickEvent clickEvent, final CustomChatContext context) { + private ClickEvent mergeClickEvent (final ClickEvent clickEvent, final CustomChatContext context) { if (clickEvent == null) return null; final String value = clickEvent.value(); diff --git a/src/main/java/land/chipmunk/chipmunkmod/song/Instrument.java b/src/main/java/land/chipmunk/chipmunkmod/song/Instrument.java index b6e5cd7..475e5f1 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/song/Instrument.java +++ b/src/main/java/land/chipmunk/chipmunkmod/song/Instrument.java @@ -17,33 +17,31 @@ public class Instrument { public static final Instrument BIT = new Instrument(13, "bit", 54); public static final Instrument BANJO = new Instrument(14, "banjo", 54); public static final Instrument PLING = new Instrument(15, "pling", 54); - + private static final Instrument[] VALUES = { HARP, BASEDRUM, SNARE, HAT, BASS, FLUTE, BELL, GUITAR, CHIME, XYLOPHONE, IRON_XYLOPHONE, COW_BELL, DIDGERIDOO, BIT, BANJO, PLING }; public final int id; public final String name; public final int offset; public final String sound; - private Instrument(int id, String name, int offset, String sound) { + private Instrument (final int id, final String name, final int offset, final String sound) { this.id = id; this.name = name; this.offset = offset; this.sound = sound; } - private Instrument(int id, String name, int offset) { + private Instrument (final int id, final String name, final int offset) { this.id = id; this.name = name; this.offset = offset; this.sound = "block.note_block." + name; } - public static Instrument of(String sound) { + public static Instrument of (final String sound) { return new Instrument(-1, null, 0, sound); } - private static final Instrument[] VALUES = {HARP, BASEDRUM, SNARE, HAT, BASS, FLUTE, BELL, GUITAR, CHIME, XYLOPHONE, IRON_XYLOPHONE, COW_BELL, DIDGERIDOO, BIT, BANJO, PLING}; - - public static Instrument fromId(int id) { + public static Instrument fromId (final int id) { return VALUES[id]; } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/song/MidiConverter.java b/src/main/java/land/chipmunk/chipmunkmod/song/MidiConverter.java index fda950e..b5340f9 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/song/MidiConverter.java +++ b/src/main/java/land/chipmunk/chipmunkmod/song/MidiConverter.java @@ -3,8 +3,12 @@ package land.chipmunk.chipmunkmod.song; import land.chipmunk.chipmunkmod.util.DownloadUtilities; import net.minecraft.util.math.Vec3d; -import java.io.*; -import java.net.*; +import javax.sound.midi.*; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; import java.nio.file.Paths; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; @@ -12,310 +16,166 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; -import javax.sound.midi.*; - public class MidiConverter { public static final int SET_INSTRUMENT = 0xC0; public static final int SET_TEMPO = 0x51; public static final int NOTE_ON = 0x90; public static final int NOTE_OFF = 0x80; - - public static Song getSongFromUrl(URL url) throws IOException, InvalidMidiDataException, URISyntaxException, NoSuchAlgorithmException, KeyManagementException { - Sequence sequence = MidiSystem.getSequence(DownloadUtilities.DownloadToInputStream(url)); - return getSong(sequence, Paths.get(url.toURI().getPath()).getFileName().toString()); - } - - public static Song getSongFromFile(File file) throws InvalidMidiDataException, IOException { - Sequence sequence = MidiSystem.getSequence(file); - return getSong(sequence, file.getName()); - } - - public static Song getSongFromBytes(byte[] bytes, String name) throws InvalidMidiDataException, IOException { - Sequence sequence = MidiSystem.getSequence(new ByteArrayInputStream(bytes)); - return getSong(sequence, name); - } - - public static Song getSong(Sequence sequence, String name) { - Song song = new Song(name); - - long tpq = sequence.getResolution(); - - ArrayList tempoEvents = new ArrayList<>(); - for (Track track : sequence.getTracks()) { - for (int i = 0; i < track.size(); i++) { - MidiEvent event = track.get(i); - MidiMessage message = event.getMessage(); - if (message instanceof MetaMessage) { - MetaMessage mm = (MetaMessage) message; - if (mm.getType() == SET_TEMPO) { - tempoEvents.add(event); - } - } - } - } - - Collections.sort(tempoEvents, (a, b) -> Long.compare(a.getTick(), b.getTick())); - - for (Track track : sequence.getTracks()) { - - long microTime = 0; - int[] ids = new int[16]; - int mpq = 500000; - int tempoEventIdx = 0; - long prevTick = 0; - - for (int i = 0; i < track.size(); i++) { - MidiEvent event = track.get(i); - MidiMessage message = event.getMessage(); - - while (tempoEventIdx < tempoEvents.size() && event.getTick() > tempoEvents.get(tempoEventIdx).getTick()) { - long deltaTick = tempoEvents.get(tempoEventIdx).getTick() - prevTick; - prevTick = tempoEvents.get(tempoEventIdx).getTick(); - microTime += (mpq / tpq) * deltaTick; - - MetaMessage mm = (MetaMessage) tempoEvents.get(tempoEventIdx).getMessage(); - byte[] data = mm.getData(); - int new_mpq = (data[2] & 0xFF) | ((data[1] & 0xFF) << 8) | ((data[0] & 0xFF) << 16); - if (new_mpq != 0) mpq = new_mpq; - tempoEventIdx++; - } - - if (message instanceof ShortMessage) { - ShortMessage sm = (ShortMessage) message; - if (sm.getCommand() == SET_INSTRUMENT) { - ids[sm.getChannel()] = sm.getData1(); - } else if (sm.getCommand() == NOTE_ON) { - if (sm.getData2() == 0) continue; - int pitch = sm.getData1(); - int velocity = sm.getData2(); - long deltaTick = event.getTick() - prevTick; - prevTick = event.getTick(); - microTime += (mpq / tpq) * deltaTick; - - Note note; - if (sm.getChannel() == 9) { - note = getMidiPercussionNote(pitch, velocity, microTime); - } else { - note = getMidiInstrumentNote(ids[sm.getChannel()], pitch, velocity, microTime); - } - if (note != null) { - song.add(note); - } - - long time = microTime / 1000L; - if (time > song.length) { - song.length = time; - } - } else if (sm.getCommand() == NOTE_OFF) { - long deltaTick = event.getTick() - prevTick; - prevTick = event.getTick(); - microTime += (mpq / tpq) * deltaTick; - long time = microTime / 1000L; - if (time > song.length) { - song.length = time; - } - } - } - } - } - - song.sort(); - - return song; - } - - public static Note getMidiInstrumentNote(int midiInstrument, int midiPitch, int velocity, long microTime) { - Instrument instrument = null; - Instrument[] instrumentList = instrumentMap.get(midiInstrument); - if (instrumentList != null) { - for (Instrument candidateInstrument : instrumentList) { - if (midiPitch >= candidateInstrument.offset && midiPitch <= candidateInstrument.offset + 24) { - instrument = candidateInstrument; - break; - } - } - } - - if (instrument == null) { - return null; - } - - int pitch = midiPitch - instrument.offset; - float volume = (float) velocity / 127.0f; - long time = microTime / 1000L; - - return new Note(instrument, pitch, volume, time, Vec3d.ZERO); - } - - private static Note getMidiPercussionNote(int midiPitch, int velocity, long microTime) { - if (percussionMap.containsKey(midiPitch)) { - int noteId = percussionMap.get(midiPitch); - int pitch = noteId % 25; - float volume = (float) velocity / 127.0f; - Instrument instrument = Instrument.fromId(noteId / 25); - long time = microTime / 1000L; - - return new Note(instrument, pitch, volume, time, Vec3d.ZERO); - } - return null; - } - public static HashMap instrumentMap = new HashMap<>(); + public static HashMap percussionMap = new HashMap<>(); static { // Piano (HARP BASS BELL) - instrumentMap.put(0, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Acoustic Grand Piano - instrumentMap.put(1, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Bright Acoustic Piano - instrumentMap.put(2, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL}); // Electric Grand Piano - instrumentMap.put(3, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Honky-tonk Piano - instrumentMap.put(4, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL}); // Electric Piano 1 - instrumentMap.put(5, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL}); // Electric Piano 2 - instrumentMap.put(6, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Harpsichord - instrumentMap.put(7, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Clavinet + instrumentMap.put(0, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); // Acoustic Grand Piano + instrumentMap.put(1, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); // Bright Acoustic Piano + instrumentMap.put(2, new Instrument[] { Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL }); // Electric Grand Piano + instrumentMap.put(3, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); // Honky-tonk Piano + instrumentMap.put(4, new Instrument[] { Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL }); // Electric Piano 1 + instrumentMap.put(5, new Instrument[] { Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL }); // Electric Piano 2 + instrumentMap.put(6, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); // Harpsichord + instrumentMap.put(7, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); // Clavinet // Chromatic Percussion (IRON_XYLOPHONE XYLOPHONE BASS) - instrumentMap.put(8, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); // Celesta - instrumentMap.put(9, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); // Glockenspiel - instrumentMap.put(10, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); // Music Box - instrumentMap.put(11, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); // Vibraphone - instrumentMap.put(12, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); // Marimba - instrumentMap.put(13, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); // Xylophone - instrumentMap.put(14, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); // Tubular Bells - instrumentMap.put(15, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); // Dulcimer + instrumentMap.put(8, new Instrument[] { Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE }); // Celesta + instrumentMap.put(9, new Instrument[] { Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE }); // Glockenspiel + instrumentMap.put(10, new Instrument[] { Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE }); // Music Box + instrumentMap.put(11, new Instrument[] { Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE }); // Vibraphone + instrumentMap.put(12, new Instrument[] { Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE }); // Marimba + instrumentMap.put(13, new Instrument[] { Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE }); // Xylophone + instrumentMap.put(14, new Instrument[] { Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE }); // Tubular Bells + instrumentMap.put(15, new Instrument[] { Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE }); // Dulcimer // Organ (BIT DIDGERIDOO BELL) - instrumentMap.put(16, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Drawbar Organ - instrumentMap.put(17, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Percussive Organ - instrumentMap.put(18, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Rock Organ - instrumentMap.put(19, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Church Organ - instrumentMap.put(20, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Reed Organ - instrumentMap.put(21, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Accordian - instrumentMap.put(22, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Harmonica - instrumentMap.put(23, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Tango Accordian + instrumentMap.put(16, new Instrument[] { Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE }); // Drawbar Organ + instrumentMap.put(17, new Instrument[] { Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE }); // Percussive Organ + instrumentMap.put(18, new Instrument[] { Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE }); // Rock Organ + instrumentMap.put(19, new Instrument[] { Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE }); // Church Organ + instrumentMap.put(20, new Instrument[] { Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE }); // Reed Organ + instrumentMap.put(21, new Instrument[] { Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE }); // Accordian + instrumentMap.put(22, new Instrument[] { Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE }); // Harmonica + instrumentMap.put(23, new Instrument[] { Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE }); // Tango Accordian // Guitar (BIT DIDGERIDOO BELL) - instrumentMap.put(24, new Instrument[]{Instrument.GUITAR, Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Acoustic Guitar (nylon) - instrumentMap.put(25, new Instrument[]{Instrument.GUITAR, Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Acoustic Guitar (steel) - instrumentMap.put(26, new Instrument[]{Instrument.GUITAR, Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Electric Guitar (jazz) - instrumentMap.put(27, new Instrument[]{Instrument.GUITAR, Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Electric Guitar (clean) - instrumentMap.put(28, new Instrument[]{Instrument.GUITAR, Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Electric Guitar (muted) - instrumentMap.put(29, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Overdriven Guitar - instrumentMap.put(30, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Distortion Guitar - instrumentMap.put(31, new Instrument[]{Instrument.GUITAR, Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Guitar Harmonics + instrumentMap.put(24, new Instrument[] { Instrument.GUITAR, Instrument.HARP, Instrument.BASS, Instrument.BELL }); // Acoustic Guitar (nylon) + instrumentMap.put(25, new Instrument[] { Instrument.GUITAR, Instrument.HARP, Instrument.BASS, Instrument.BELL }); // Acoustic Guitar (steel) + instrumentMap.put(26, new Instrument[] { Instrument.GUITAR, Instrument.HARP, Instrument.BASS, Instrument.BELL }); // Electric Guitar (jazz) + instrumentMap.put(27, new Instrument[] { Instrument.GUITAR, Instrument.HARP, Instrument.BASS, Instrument.BELL }); // Electric Guitar (clean) + instrumentMap.put(28, new Instrument[] { Instrument.GUITAR, Instrument.HARP, Instrument.BASS, Instrument.BELL }); // Electric Guitar (muted) + instrumentMap.put(29, new Instrument[] { Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE }); // Overdriven Guitar + instrumentMap.put(30, new Instrument[] { Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE }); // Distortion Guitar + instrumentMap.put(31, new Instrument[] { Instrument.GUITAR, Instrument.HARP, Instrument.BASS, Instrument.BELL }); // Guitar Harmonics // Bass - instrumentMap.put(32, new Instrument[]{Instrument.BASS, Instrument.HARP, Instrument.BELL}); // Acoustic Bass - instrumentMap.put(33, new Instrument[]{Instrument.BASS, Instrument.HARP, Instrument.BELL}); // Electric Bass (finger) - instrumentMap.put(34, new Instrument[]{Instrument.BASS, Instrument.HARP, Instrument.BELL}); // Electric Bass (pick) - instrumentMap.put(35, new Instrument[]{Instrument.BASS, Instrument.HARP, Instrument.BELL}); // Fretless Bass - instrumentMap.put(36, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Slap Bass 1 - instrumentMap.put(37, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Slap Bass 2 - instrumentMap.put(38, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Synth Bass 1 - instrumentMap.put(39, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Synth Bass 2 + instrumentMap.put(32, new Instrument[] { Instrument.BASS, Instrument.HARP, Instrument.BELL }); // Acoustic Bass + instrumentMap.put(33, new Instrument[] { Instrument.BASS, Instrument.HARP, Instrument.BELL }); // Electric Bass (finger) + instrumentMap.put(34, new Instrument[] { Instrument.BASS, Instrument.HARP, Instrument.BELL }); // Electric Bass (pick) + instrumentMap.put(35, new Instrument[] { Instrument.BASS, Instrument.HARP, Instrument.BELL }); // Fretless Bass + instrumentMap.put(36, new Instrument[] { Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE }); // Slap Bass 1 + instrumentMap.put(37, new Instrument[] { Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE }); // Slap Bass 2 + instrumentMap.put(38, new Instrument[] { Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE }); // Synth Bass 1 + instrumentMap.put(39, new Instrument[] { Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE }); // Synth Bass 2 // Strings - instrumentMap.put(40, new Instrument[]{Instrument.FLUTE, Instrument.GUITAR, Instrument.BASS, Instrument.BELL}); // Violin - instrumentMap.put(41, new Instrument[]{Instrument.FLUTE, Instrument.GUITAR, Instrument.BASS, Instrument.BELL}); // Viola - instrumentMap.put(42, new Instrument[]{Instrument.FLUTE, Instrument.GUITAR, Instrument.BASS, Instrument.BELL}); // Cello - instrumentMap.put(43, new Instrument[]{Instrument.FLUTE, Instrument.GUITAR, Instrument.BASS, Instrument.BELL}); // Contrabass - instrumentMap.put(44, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL}); // Tremolo Strings - instrumentMap.put(45, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Pizzicato Strings - instrumentMap.put(46, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.CHIME}); // Orchestral Harp - instrumentMap.put(47, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Timpani + instrumentMap.put(40, new Instrument[] { Instrument.FLUTE, Instrument.GUITAR, Instrument.BASS, Instrument.BELL }); // Violin + instrumentMap.put(41, new Instrument[] { Instrument.FLUTE, Instrument.GUITAR, Instrument.BASS, Instrument.BELL }); // Viola + instrumentMap.put(42, new Instrument[] { Instrument.FLUTE, Instrument.GUITAR, Instrument.BASS, Instrument.BELL }); // Cello + instrumentMap.put(43, new Instrument[] { Instrument.FLUTE, Instrument.GUITAR, Instrument.BASS, Instrument.BELL }); // Contrabass + instrumentMap.put(44, new Instrument[] { Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL }); // Tremolo Strings + instrumentMap.put(45, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); // Pizzicato Strings + instrumentMap.put(46, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.CHIME }); // Orchestral Harp + instrumentMap.put(47, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); // Timpani // Ensenble - instrumentMap.put(48, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // String Ensemble 1 - instrumentMap.put(49, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // String Ensemble 2 - instrumentMap.put(50, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Synth Strings 1 - instrumentMap.put(51, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Synth Strings 2 - instrumentMap.put(52, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Choir Aahs - instrumentMap.put(53, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Voice Oohs - instrumentMap.put(54, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Synth Choir - instrumentMap.put(55, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Orchestra Hit + instrumentMap.put(48, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); // String Ensemble 1 + instrumentMap.put(49, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); // String Ensemble 2 + instrumentMap.put(50, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); // Synth Strings 1 + instrumentMap.put(51, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); // Synth Strings 2 + instrumentMap.put(52, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); // Choir Aahs + instrumentMap.put(53, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); // Voice Oohs + instrumentMap.put(54, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); // Synth Choir + instrumentMap.put(55, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); // Orchestra Hit // Brass - instrumentMap.put(56, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL}); - instrumentMap.put(57, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL}); - instrumentMap.put(58, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL}); - instrumentMap.put(59, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL}); - instrumentMap.put(60, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL}); - instrumentMap.put(61, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL}); - instrumentMap.put(62, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL}); - instrumentMap.put(63, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL}); + instrumentMap.put(56, new Instrument[] { Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL }); + instrumentMap.put(57, new Instrument[] { Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL }); + instrumentMap.put(58, new Instrument[] { Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL }); + instrumentMap.put(59, new Instrument[] { Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL }); + instrumentMap.put(60, new Instrument[] { Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL }); + instrumentMap.put(61, new Instrument[] { Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL }); + instrumentMap.put(62, new Instrument[] { Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL }); + instrumentMap.put(63, new Instrument[] { Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL }); // Reed - instrumentMap.put(64, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL}); - instrumentMap.put(65, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL}); - instrumentMap.put(66, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL}); - instrumentMap.put(67, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL}); - instrumentMap.put(68, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL}); - instrumentMap.put(69, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL}); - instrumentMap.put(70, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL}); - instrumentMap.put(71, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL}); + instrumentMap.put(64, new Instrument[] { Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL }); + instrumentMap.put(65, new Instrument[] { Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL }); + instrumentMap.put(66, new Instrument[] { Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL }); + instrumentMap.put(67, new Instrument[] { Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL }); + instrumentMap.put(68, new Instrument[] { Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL }); + instrumentMap.put(69, new Instrument[] { Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL }); + instrumentMap.put(70, new Instrument[] { Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL }); + instrumentMap.put(71, new Instrument[] { Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL }); // Pipe - instrumentMap.put(72, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL}); - instrumentMap.put(73, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL}); - instrumentMap.put(74, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL}); - instrumentMap.put(75, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL}); - instrumentMap.put(76, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL}); - instrumentMap.put(77, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL}); - instrumentMap.put(78, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL}); - instrumentMap.put(79, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL}); + instrumentMap.put(72, new Instrument[] { Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL }); + instrumentMap.put(73, new Instrument[] { Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL }); + instrumentMap.put(74, new Instrument[] { Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL }); + instrumentMap.put(75, new Instrument[] { Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL }); + instrumentMap.put(76, new Instrument[] { Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL }); + instrumentMap.put(77, new Instrument[] { Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL }); + instrumentMap.put(78, new Instrument[] { Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL }); + instrumentMap.put(79, new Instrument[] { Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL }); // Synth Lead - instrumentMap.put(80, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); - instrumentMap.put(81, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); - instrumentMap.put(82, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); - instrumentMap.put(83, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); - instrumentMap.put(84, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); - instrumentMap.put(85, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); - instrumentMap.put(86, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); - instrumentMap.put(87, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); + instrumentMap.put(80, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); + instrumentMap.put(81, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); + instrumentMap.put(82, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); + instrumentMap.put(83, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); + instrumentMap.put(84, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); + instrumentMap.put(85, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); + instrumentMap.put(86, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); + instrumentMap.put(87, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); // Synth Pad - instrumentMap.put(88, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); - instrumentMap.put(89, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); - instrumentMap.put(90, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); - instrumentMap.put(91, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); - instrumentMap.put(92, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); - instrumentMap.put(93, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); - instrumentMap.put(94, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); - instrumentMap.put(95, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); + instrumentMap.put(88, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); + instrumentMap.put(89, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); + instrumentMap.put(90, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); + instrumentMap.put(91, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); + instrumentMap.put(92, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); + instrumentMap.put(93, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); + instrumentMap.put(94, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); + instrumentMap.put(95, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); // Synth Effects -// instrumentMap.put(96, new Instrument[]{}); -// instrumentMap.put(97, new Instrument[]{}); - instrumentMap.put(98, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL}); - instrumentMap.put(99, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); - instrumentMap.put(100, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); - instrumentMap.put(101, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); - instrumentMap.put(102, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); - instrumentMap.put(103, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); + // instrumentMap.put(96, new Instrument[]{}); + // instrumentMap.put(97, new Instrument[]{}); + instrumentMap.put(98, new Instrument[] { Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL }); + instrumentMap.put(99, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); + instrumentMap.put(100, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); + instrumentMap.put(101, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); + instrumentMap.put(102, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); + instrumentMap.put(103, new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BELL }); // Ethnic - instrumentMap.put(104, new Instrument[]{Instrument.BANJO, Instrument.BASS, Instrument.BELL}); - instrumentMap.put(105, new Instrument[]{Instrument.BANJO, Instrument.BASS, Instrument.BELL}); - instrumentMap.put(106, new Instrument[]{Instrument.BANJO, Instrument.BASS, Instrument.BELL}); - instrumentMap.put(107, new Instrument[]{Instrument.BANJO, Instrument.BASS, Instrument.BELL}); - instrumentMap.put(108, new Instrument[]{Instrument.BANJO, Instrument.BASS, Instrument.BELL}); - instrumentMap.put(109, new Instrument[]{Instrument.HARP, Instrument.DIDGERIDOO, Instrument.BELL}); - instrumentMap.put(110, new Instrument[]{Instrument.HARP, Instrument.DIDGERIDOO, Instrument.BELL}); - instrumentMap.put(111, new Instrument[]{Instrument.HARP, Instrument.DIDGERIDOO, Instrument.BELL}); + instrumentMap.put(104, new Instrument[] { Instrument.BANJO, Instrument.BASS, Instrument.BELL }); + instrumentMap.put(105, new Instrument[] { Instrument.BANJO, Instrument.BASS, Instrument.BELL }); + instrumentMap.put(106, new Instrument[] { Instrument.BANJO, Instrument.BASS, Instrument.BELL }); + instrumentMap.put(107, new Instrument[] { Instrument.BANJO, Instrument.BASS, Instrument.BELL }); + instrumentMap.put(108, new Instrument[] { Instrument.BANJO, Instrument.BASS, Instrument.BELL }); + instrumentMap.put(109, new Instrument[] { Instrument.HARP, Instrument.DIDGERIDOO, Instrument.BELL }); + instrumentMap.put(110, new Instrument[] { Instrument.HARP, Instrument.DIDGERIDOO, Instrument.BELL }); + instrumentMap.put(111, new Instrument[] { Instrument.HARP, Instrument.DIDGERIDOO, Instrument.BELL }); // Percussive - instrumentMap.put(112, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); - instrumentMap.put(113, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); - instrumentMap.put(114, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); - instrumentMap.put(115, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); - instrumentMap.put(116, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); - instrumentMap.put(117, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); - instrumentMap.put(118, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); - instrumentMap.put(119, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); + instrumentMap.put(112, new Instrument[] { Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE }); + instrumentMap.put(113, new Instrument[] { Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE }); + instrumentMap.put(114, new Instrument[] { Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE }); + instrumentMap.put(115, new Instrument[] { Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE }); + instrumentMap.put(116, new Instrument[] { Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE }); + instrumentMap.put(117, new Instrument[] { Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE }); + instrumentMap.put(118, new Instrument[] { Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE }); + instrumentMap.put(119, new Instrument[] { Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE }); } - public static HashMap percussionMap = new HashMap<>(); - static { percussionMap.put(35, 10 + 25 * Instrument.BASEDRUM.id); percussionMap.put(36, 6 + 25 * Instrument.BASEDRUM.id); @@ -371,4 +231,142 @@ public class MidiConverter { percussionMap.put(86, 14 + 25 * Instrument.BASEDRUM.id); percussionMap.put(87, 7 + 25 * Instrument.BASEDRUM.id); } + + public static Song getSongFromUrl (final URL url) throws IOException, InvalidMidiDataException, URISyntaxException, NoSuchAlgorithmException, KeyManagementException { + final Sequence sequence = MidiSystem.getSequence(DownloadUtilities.DownloadToInputStream(url)); + return getSong(sequence, Paths.get(url.toURI().getPath()).getFileName().toString()); + } + + public static Song getSongFromFile (final File file) throws InvalidMidiDataException, IOException { + final Sequence sequence = MidiSystem.getSequence(file); + return getSong(sequence, file.getName()); + } + + public static Song getSongFromBytes (final byte[] bytes, final String name) throws InvalidMidiDataException, IOException { + final Sequence sequence = MidiSystem.getSequence(new ByteArrayInputStream(bytes)); + return getSong(sequence, name); + } + + public static Song getSong (final Sequence sequence, final String name) { + final Song song = new Song(name); + + final long tpq = sequence.getResolution(); + + final ArrayList tempoEvents = new ArrayList<>(); + for (final Track track : sequence.getTracks()) { + for (int i = 0; i < track.size(); i++) { + final MidiEvent event = track.get(i); + final MidiMessage message = event.getMessage(); + if (message instanceof final MetaMessage mm) { + if (mm.getType() == SET_TEMPO) { + tempoEvents.add(event); + } + } + } + } + + Collections.sort(tempoEvents, (a, b) -> Long.compare(a.getTick(), b.getTick())); + + for (final Track track : sequence.getTracks()) { + + long microTime = 0; + final int[] ids = new int[16]; + int mpq = 500000; + int tempoEventIdx = 0; + long prevTick = 0; + + for (int i = 0; i < track.size(); i++) { + final MidiEvent event = track.get(i); + final MidiMessage message = event.getMessage(); + + while (tempoEventIdx < tempoEvents.size() && event.getTick() > tempoEvents.get(tempoEventIdx).getTick()) { + final long deltaTick = tempoEvents.get(tempoEventIdx).getTick() - prevTick; + prevTick = tempoEvents.get(tempoEventIdx).getTick(); + microTime += (mpq / tpq) * deltaTick; + + final MetaMessage mm = (MetaMessage) tempoEvents.get(tempoEventIdx).getMessage(); + final byte[] data = mm.getData(); + final int new_mpq = (data[2] & 0xFF) | ((data[1] & 0xFF) << 8) | ((data[0] & 0xFF) << 16); + if (new_mpq != 0) mpq = new_mpq; + tempoEventIdx++; + } + + if (message instanceof final ShortMessage sm) { + if (sm.getCommand() == SET_INSTRUMENT) { + ids[sm.getChannel()] = sm.getData1(); + } else if (sm.getCommand() == NOTE_ON) { + if (sm.getData2() == 0) continue; + final int pitch = sm.getData1(); + final int velocity = sm.getData2(); + final long deltaTick = event.getTick() - prevTick; + prevTick = event.getTick(); + microTime += (mpq / tpq) * deltaTick; + + final Note note; + if (sm.getChannel() == 9) { + note = getMidiPercussionNote(pitch, velocity, microTime); + } else { + note = getMidiInstrumentNote(ids[sm.getChannel()], pitch, velocity, microTime); + } + if (note != null) { + song.add(note); + } + + final long time = microTime / 1000L; + if (time > song.length) { + song.length = time; + } + } else if (sm.getCommand() == NOTE_OFF) { + final long deltaTick = event.getTick() - prevTick; + prevTick = event.getTick(); + microTime += (mpq / tpq) * deltaTick; + final long time = microTime / 1000L; + if (time > song.length) { + song.length = time; + } + } + } + } + } + + song.sort(); + + return song; + } + + public static Note getMidiInstrumentNote (final int midiInstrument, final int midiPitch, final int velocity, final long microTime) { + Instrument instrument = null; + final Instrument[] instrumentList = instrumentMap.get(midiInstrument); + if (instrumentList != null) { + for (final Instrument candidateInstrument : instrumentList) { + if (midiPitch >= candidateInstrument.offset && midiPitch <= candidateInstrument.offset + 24) { + instrument = candidateInstrument; + break; + } + } + } + + if (instrument == null) { + return null; + } + + final int pitch = midiPitch - instrument.offset; + final float volume = (float) velocity / 127.0f; + final long time = microTime / 1000L; + + return new Note(instrument, pitch, volume, time, Vec3d.ZERO); + } + + private static Note getMidiPercussionNote (final int midiPitch, final int velocity, final long microTime) { + if (percussionMap.containsKey(midiPitch)) { + final int noteId = percussionMap.get(midiPitch); + final int pitch = noteId % 25; + final float volume = (float) velocity / 127.0f; + final Instrument instrument = Instrument.fromId(noteId / 25); + final long time = microTime / 1000L; + + return new Note(instrument, pitch, volume, time, Vec3d.ZERO); + } + return null; + } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/song/NBSConverter.java b/src/main/java/land/chipmunk/chipmunkmod/song/NBSConverter.java index ce8deab..fc33564 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/song/NBSConverter.java +++ b/src/main/java/land/chipmunk/chipmunkmod/song/NBSConverter.java @@ -8,7 +8,7 @@ import java.nio.ByteOrder; import java.util.ArrayList; public class NBSConverter { - public static Instrument[] instrumentIndex = new Instrument[]{ + public static Instrument[] instrumentIndex = new Instrument[] { Instrument.HARP, Instrument.BASS, Instrument.BASEDRUM, @@ -27,6 +27,178 @@ public class NBSConverter { Instrument.PLING, }; + public static Song getSongFromBytes (final byte[] bytes, final String fileName) throws IOException { + final ByteBuffer buffer = ByteBuffer.wrap(bytes); + buffer.order(ByteOrder.LITTLE_ENDIAN); + + short songLength = 0; + byte format = 0; + byte vanillaInstrumentCount = 0; + songLength = buffer.getShort(); // If it's not 0, then it uses the old format + if (songLength == 0) { + format = buffer.get(); + } + + if (format >= 1) { + vanillaInstrumentCount = buffer.get(); + } + if (format >= 3) { + songLength = buffer.getShort(); + } + + final short layerCount = buffer.getShort(); + final String songName = getString(buffer, bytes.length); + final String songAuthor = getString(buffer, bytes.length); + final String songOriginalAuthor = getString(buffer, bytes.length); + final String songDescription = getString(buffer, bytes.length); + final short tempo = buffer.getShort(); + final byte autoSaving = buffer.get(); + final byte autoSavingDuration = buffer.get(); + final byte timeSignature = buffer.get(); + final int minutesSpent = buffer.getInt(); + final int leftClicks = buffer.getInt(); + final int rightClicks = buffer.getInt(); + final int blocksAdded = buffer.getInt(); + final int blocksRemoved = buffer.getInt(); + final String origFileName = getString(buffer, bytes.length); + + byte loop = 0; + byte maxLoopCount = 0; + short loopStartTick = 0; + if (format >= 4) { + loop = buffer.get(); + maxLoopCount = buffer.get(); + loopStartTick = buffer.getShort(); + } + + final ArrayList nbsNotes = new ArrayList<>(); + short tick = -1; + while (true) { + final int tickJumps = buffer.getShort(); + if (tickJumps == 0) break; + tick += tickJumps; + + short layer = -1; + while (true) { + final int layerJumps = buffer.getShort(); + if (layerJumps == 0) break; + layer += layerJumps; + final NBSNote note = new NBSNote(); + note.tick = tick; + note.layer = layer; + note.instrument = buffer.get(); + note.key = buffer.get(); + if (format >= 4) { + note.velocity = buffer.get(); + note.panning = buffer.get(); + note.pitch = buffer.getShort(); + } + nbsNotes.add(note); + } + } + + final ArrayList nbsLayers = new ArrayList<>(); + if (buffer.hasRemaining()) { + for (int i = 0; i < layerCount; i++) { + final NBSLayer layer = new NBSLayer(); + layer.name = getString(buffer, bytes.length); + if (format >= 4) { + layer.lock = buffer.get(); + } + layer.volume = buffer.get(); + if (format >= 2) { + layer.stereo = buffer.get(); + } + nbsLayers.add(layer); + } + } + + final ArrayList customInstruments = new ArrayList<>(); + if (buffer.hasRemaining()) { + final byte customInstrumentCount = buffer.get(); + for (int i = 0; i < customInstrumentCount; i++) { + final NBSCustomInstrument customInstrument = new NBSCustomInstrument(); + customInstrument.name = getString(buffer, bytes.length); + customInstrument.file = getString(buffer, bytes.length); + customInstrument.pitch = buffer.get(); + customInstrument.key = buffer.get() != 0; + customInstruments.add(customInstrument); + } + } + + final Song song = new Song(songName.trim().length() > 0 ? songName : fileName); + if (loop > 0) { + song.looping = true; + song.loopPosition = getMilliTime(loopStartTick, tempo); + song.loopCount = maxLoopCount; + } + for (final NBSNote note : nbsNotes) { + final Instrument instrument; + double key; + if (note.instrument < instrumentIndex.length) { + instrument = instrumentIndex[note.instrument]; + + key = (double) ((note.key * 100) + note.pitch) / 100; + } else { + final int index = note.instrument - instrumentIndex.length; + + if (index >= customInstruments.size()) continue; + + final NBSCustomInstrument customInstrument = customInstruments.get(index); + instrument = Instrument.of(customInstrument.name); + + key = (note.key) + (customInstrument.pitch + (double) note.pitch / 100); + } + + byte layerVolume = 100; + if (nbsLayers.size() > note.layer) { + layerVolume = nbsLayers.get(note.layer).volume; + } + + while (key < 33) key += 12; + while (key > 57) key -= 12; + + final double pitch = key - 33; + + final int layerStereo = Byte.toUnsignedInt(nbsLayers.get(note.layer).stereo); + final int notePanning = Byte.toUnsignedInt(note.panning); + + final double value; + + if (layerStereo == 100 && notePanning != 100) value = notePanning; + else if (notePanning == 100 && layerStereo != 100) value = layerStereo; + else value = (double) (layerStereo + notePanning) / 2; + + final double x; + + if (value > 100) x = (value - 100) / -100; + else if (value == 100) x = 0; + else x = ((value - 100) * -1) / 100; + + final Vec3d position = new Vec3d(x, 0, 0); + + song.add(new Note(instrument, pitch, (float) note.velocity * (float) layerVolume / 10000f, getMilliTime(note.tick, tempo), position)); + } + + song.length = song.get(song.size() - 1).time + 50; + + return song; + } + + private static String getString (final ByteBuffer buffer, final int maxSize) throws IOException { + final int length = buffer.getInt(); + if (length > maxSize) { + throw new IOException("String is too large"); + } + final byte[] arr = new byte[length]; + buffer.get(arr, 0, length); + return new String(arr); + } + + private static int getMilliTime (final int tick, final int tempo) { + return 1000 * tick * 100 / tempo; + } + private static class NBSNote { public int tick; public short layer; @@ -50,176 +222,4 @@ public class NBSConverter { public byte pitch = 0; public boolean key = false; } - - public static Song getSongFromBytes(byte[] bytes, String fileName) throws IOException { - ByteBuffer buffer = ByteBuffer.wrap(bytes); - buffer.order(ByteOrder.LITTLE_ENDIAN); - - short songLength = 0; - byte format = 0; - byte vanillaInstrumentCount = 0; - songLength = buffer.getShort(); // If it's not 0, then it uses the old format - if (songLength == 0) { - format = buffer.get(); - } - - if (format >= 1) { - vanillaInstrumentCount = buffer.get(); - } - if (format >= 3) { - songLength = buffer.getShort(); - } - - short layerCount = buffer.getShort(); - String songName = getString(buffer, bytes.length); - String songAuthor = getString(buffer, bytes.length); - String songOriginalAuthor = getString(buffer, bytes.length); - String songDescription = getString(buffer, bytes.length); - short tempo = buffer.getShort(); - byte autoSaving = buffer.get(); - byte autoSavingDuration = buffer.get(); - byte timeSignature = buffer.get(); - int minutesSpent = buffer.getInt(); - int leftClicks = buffer.getInt(); - int rightClicks = buffer.getInt(); - int blocksAdded = buffer.getInt(); - int blocksRemoved = buffer.getInt(); - String origFileName = getString(buffer, bytes.length); - - byte loop = 0; - byte maxLoopCount = 0; - short loopStartTick = 0; - if (format >= 4) { - loop = buffer.get(); - maxLoopCount = buffer.get(); - loopStartTick = buffer.getShort(); - } - - ArrayList nbsNotes = new ArrayList<>(); - short tick = -1; - while (true) { - int tickJumps = buffer.getShort(); - if (tickJumps == 0) break; - tick += tickJumps; - - short layer = -1; - while (true) { - int layerJumps = buffer.getShort(); - if (layerJumps == 0) break; - layer += layerJumps; - NBSNote note = new NBSNote(); - note.tick = tick; - note.layer = layer; - note.instrument = buffer.get(); - note.key = buffer.get(); - if (format >= 4) { - note.velocity = buffer.get(); - note.panning = buffer.get(); - note.pitch = buffer.getShort(); - } - nbsNotes.add(note); - } - } - - ArrayList nbsLayers = new ArrayList<>(); - if (buffer.hasRemaining()) { - for (int i = 0; i < layerCount; i++) { - NBSLayer layer = new NBSLayer(); - layer.name = getString(buffer, bytes.length); - if (format >= 4) { - layer.lock = buffer.get(); - } - layer.volume = buffer.get(); - if (format >= 2) { - layer.stereo = buffer.get(); - } - nbsLayers.add(layer); - } - } - - ArrayList customInstruments = new ArrayList<>(); - if (buffer.hasRemaining()) { - byte customInstrumentCount = buffer.get(); - for (int i = 0; i < customInstrumentCount; i++) { - NBSCustomInstrument customInstrument = new NBSCustomInstrument(); - customInstrument.name = getString(buffer, bytes.length); - customInstrument.file = getString(buffer, bytes.length); - customInstrument.pitch = buffer.get(); - customInstrument.key = buffer.get() == 0 ? false : true; - customInstruments.add(customInstrument); - } - } - - Song song = new Song(songName.trim().length() > 0 ? songName : fileName); - if (loop > 0) { - song.looping = true; - song.loopPosition = getMilliTime(loopStartTick, tempo); - song.loopCount = maxLoopCount; - } - for (NBSNote note : nbsNotes) { - Instrument instrument; - double key; - if (note.instrument < instrumentIndex.length) { - instrument = instrumentIndex[note.instrument]; - - key = (double) ((note.key * 100) + note.pitch) / 100; - } else { - int index = note.instrument - instrumentIndex.length; - - if (index >= customInstruments.size()) continue; - - NBSCustomInstrument customInstrument = customInstruments.get(index); - instrument = Instrument.of(customInstrument.name); - - key = (note.key) + (customInstrument.pitch + (double) note.pitch / 100); - } - - byte layerVolume = 100; - if (nbsLayers.size() > note.layer) { - layerVolume = nbsLayers.get(note.layer).volume; - } - - while (key < 33) key += 12; - while (key > 57) key -= 12; - - double pitch = key - 33; - - final int layerStereo = Byte.toUnsignedInt(nbsLayers.get(note.layer).stereo); - final int notePanning = Byte.toUnsignedInt(note.panning); - - double value; - - if (layerStereo == 100 && notePanning != 100) value = notePanning; - else if (notePanning == 100 && layerStereo != 100) value = layerStereo; - else value = (double) (layerStereo + notePanning) / 2; - - double x; - - if (value > 100) x = (value - 100) / -100; - else if (value == 100) x = 0; - else x = ((value - 100) * -1) / 100; - - final Vec3d position = new Vec3d(x, 0 ,0); - - song.add(new Note(instrument, pitch, (float) note.velocity * (float) layerVolume / 10000f, getMilliTime(note.tick, tempo), position)); - } - - song.length = song.get(song.size() - 1).time + 50; - - return song; - } - - private static String getString(ByteBuffer buffer, int maxSize) throws IOException { - int length = buffer.getInt(); - if (length > maxSize) { - throw new IOException("String is too large"); - } - byte arr[] = new byte[length]; - buffer.get(arr, 0, length); - return new String(arr); - } - - private static int getMilliTime(int tick, int tempo) { - return 1000 * tick * 100 / tempo; - } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/song/Note.java b/src/main/java/land/chipmunk/chipmunkmod/song/Note.java index 638eea4..ee8beca 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/song/Note.java +++ b/src/main/java/land/chipmunk/chipmunkmod/song/Note.java @@ -10,7 +10,7 @@ public class Note implements Comparable { public long time; public Vec3d position; - public Note(Instrument instrument, double pitch, float volume, long time, Vec3d position) { + public Note (final Instrument instrument, final double pitch, final float volume, final long time, final Vec3d position) { this.instrument = instrument; this.pitch = pitch; this.volume = volume; @@ -19,7 +19,7 @@ public class Note implements Comparable { } @Override - public int compareTo(Note other) { + public int compareTo (final Note other) { return Long.compare(time, other.time); } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/song/Song.java b/src/main/java/land/chipmunk/chipmunkmod/song/Song.java index af5e64c..cea39e1 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/song/Song.java +++ b/src/main/java/land/chipmunk/chipmunkmod/song/Song.java @@ -18,30 +18,30 @@ public class Song { public int loopCount = 0; // Number of times to loop public int currentLoop = 0; // Number of loops so far - public Song(Component name) { + public Song (final Component name) { this.name = name; } - public Song(String name) { + public Song (final String name) { this(Component.text(name)); } - public Note get(int i) { + public Note get (final int i) { return notes.get(i); } - public void add(Note e) { + public void add (final Note e) { notes.add(e); } - public void sort() { + public void sort () { Collections.sort(notes); } /** * Starts playing song (does nothing if already playing) */ - public void play() { + public void play () { if (paused) { paused = false; startTime = System.currentTimeMillis() - time; @@ -51,7 +51,7 @@ public class Song { /** * Pauses song (does nothing if already paused) */ - public void pause() { + public void pause () { if (!paused) { paused = true; // Recalculates time so that the song will continue playing after the exact point it was paused @@ -59,7 +59,7 @@ public class Song { } } - public void setTime(long t) { + public void setTime (final long t) { time = t; startTime = System.currentTimeMillis() - time; position = 0; @@ -68,11 +68,11 @@ public class Song { } } - public void advanceTime() { + public void advanceTime () { time = System.currentTimeMillis() - startTime; } - public boolean reachedNextNote() { + public boolean reachedNextNote () { if (position < notes.size()) { return notes.get(position).time <= time; } else { @@ -89,7 +89,7 @@ public class Song { } } - public Note getNextNote() { + public Note getNextNote () { if (position >= notes.size()) { if (shouldLoop()) { loop(); @@ -100,11 +100,11 @@ public class Song { return notes.get(position++); } - public boolean finished() { + public boolean finished () { return time > length && !shouldLoop(); } - private void loop() { + private void loop () { position = 0; startTime += length - loopPosition; time -= length - loopPosition; @@ -114,7 +114,7 @@ public class Song { currentLoop++; } - private boolean shouldLoop() { + private boolean shouldLoop () { if (looping) { if (loopCount == 0) { return true; @@ -126,7 +126,7 @@ public class Song { } } - public int size() { + public int size () { return notes.size(); } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/song/SongLoaderException.java b/src/main/java/land/chipmunk/chipmunkmod/song/SongLoaderException.java index 9bb272e..bf1feb3 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/song/SongLoaderException.java +++ b/src/main/java/land/chipmunk/chipmunkmod/song/SongLoaderException.java @@ -5,18 +5,18 @@ import net.minecraft.text.Text; public class SongLoaderException extends Exception { public final Text message; - public SongLoaderException(Text message) { + public SongLoaderException (final Text message) { super(); this.message = message; } - public SongLoaderException(Text message, Throwable cause) { + public SongLoaderException (final Text message, final Throwable cause) { super(null, cause); this.message = message; } @Override - public String getMessage() { + public String getMessage () { return message.getString(); } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/song/SongLoaderThread.java b/src/main/java/land/chipmunk/chipmunkmod/song/SongLoaderThread.java index 9a95ad8..a519368 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/song/SongLoaderThread.java +++ b/src/main/java/land/chipmunk/chipmunkmod/song/SongLoaderThread.java @@ -6,32 +6,31 @@ import net.minecraft.text.Text; import java.io.File; import java.net.URL; -import java.nio.file.Path; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; public class SongLoaderThread extends Thread { + public SongLoaderException exception; + public Song song; private String location; private File songPath; private URL songUrl; - public SongLoaderException exception; - public Song song; + private final boolean isUrl; - private boolean isUrl; - - public SongLoaderThread(URL location) throws SongLoaderException { + public SongLoaderThread (final URL location) throws SongLoaderException { isUrl = true; songUrl = location; } - public SongLoaderThread(Path location) throws SongLoaderException { + public SongLoaderThread (final Path location) throws SongLoaderException { isUrl = false; songPath = location.toFile(); } - public void run() { - byte[] bytes; - String name; + public void run () { + final byte[] bytes; + final String name; try { if (isUrl) { bytes = DownloadUtilities.DownloadToByteArray(songUrl); @@ -40,20 +39,20 @@ public class SongLoaderThread extends Thread { bytes = Files.readAllBytes(songPath.toPath()); name = songPath.getName(); } - } catch (Exception e) { + } catch (final Exception e) { exception = new SongLoaderException(Text.literal(e.getMessage()), e); return; } try { song = MidiConverter.getSongFromBytes(bytes, name); - } catch (Exception e) { + } catch (final Exception e) { } if (song == null) { try { song = NBSConverter.getSongFromBytes(bytes, name); - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); } } @@ -63,7 +62,7 @@ public class SongLoaderThread extends Thread { } } - private File getSongFile(String name) { + private File getSongFile (final String name) { return new File(SongPlayer.SONG_DIR, name); } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/util/BotValidationUtilities.java b/src/main/java/land/chipmunk/chipmunkmod/util/BotValidationUtilities.java index 4c9fbe3..1384006 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/util/BotValidationUtilities.java +++ b/src/main/java/land/chipmunk/chipmunkmod/util/BotValidationUtilities.java @@ -17,57 +17,59 @@ import java.security.NoSuchAlgorithmException; import java.util.Arrays; public class BotValidationUtilities { - public static int hbot (String command) throws RuntimeException { + public static int hbot (final String command) throws RuntimeException { final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.hbot; final MinecraftClient client = MinecraftClient.getInstance(); final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); final String prefix = info.prefix; final String key = info.key; - if (key == null) throw new RuntimeException("The key of the bot is unspecified (null), did you incorrectly add it to your config?"); + if (key == null) + throw new RuntimeException("The key of the bot is unspecified (null), did you incorrectly add it to your config?"); try { - MessageDigest md = MessageDigest.getInstance("SHA-256"); - String time = String.valueOf(System.currentTimeMillis() / 10000); - String input = prefix + command.replaceAll("&[0-9a-fklmnor]", "") + ";" + client.player.getUuidAsString() + ";" + time + ";" + key; - byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8)); - BigInteger bigInt = new BigInteger(1, Arrays.copyOfRange(hash, 0, 4)); - String stringHash = bigInt.toString(Character.MAX_RADIX); + final MessageDigest md = MessageDigest.getInstance("SHA-256"); + final String time = String.valueOf(System.currentTimeMillis() / 10000); + final String input = prefix + command.replaceAll("&[0-9a-fklmnor]", "") + ";" + client.player.getUuidAsString() + ";" + time + ";" + key; + final byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8)); + final BigInteger bigInt = new BigInteger(1, Arrays.copyOfRange(hash, 0, 4)); + final String stringHash = bigInt.toString(Character.MAX_RADIX); Chat.sendChatMessage(prefix + command + " " + stringHash, true); - } catch (NoSuchAlgorithmException e) { + } catch (final NoSuchAlgorithmException e) { e.printStackTrace(); } return Command.SINGLE_SUCCESS; } - public static int sbot (String command) throws RuntimeException { + public static int sbot (final String command) throws RuntimeException { final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.sbot; final MinecraftClient client = MinecraftClient.getInstance(); final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); final String prefix = info.prefix; final String key = info.key; - if (key == null) throw new RuntimeException("The key of the bot is unspecified (null), did you incorrectly add it to your config?"); + if (key == null) + throw new RuntimeException("The key of the bot is unspecified (null), did you incorrectly add it to your config?"); try { - MessageDigest md = MessageDigest.getInstance("MD5"); - String time = String.valueOf(System.currentTimeMillis() / 20000); - String input = prefix + command.replaceAll("&[0-9a-fklmnorx]", "") + ";" + client.player.getName().getString() + ";" + time + ";" + key; - byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8)); - BigInteger bigInt = new BigInteger(1, Arrays.copyOfRange(hash, 0, 4)); - String stringHash = bigInt.toString(Character.MAX_RADIX); + final MessageDigest md = MessageDigest.getInstance("MD5"); + final String time = String.valueOf(System.currentTimeMillis() / 20000); + final String input = prefix + command.replaceAll("&[0-9a-fklmnorx]", "") + ";" + client.player.getName().getString() + ";" + time + ";" + key; + final byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8)); + final BigInteger bigInt = new BigInteger(1, Arrays.copyOfRange(hash, 0, 4)); + final String stringHash = bigInt.toString(Character.MAX_RADIX); Chat.sendChatMessage(prefix + command + " " + stringHash, true); - } catch (NoSuchAlgorithmException e) { + } catch (final NoSuchAlgorithmException e) { e.printStackTrace(); } return Command.SINGLE_SUCCESS; } - public static int chomens (String command) throws RuntimeException { + public static int chomens (final String command) throws RuntimeException { final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.chomens; final MinecraftClient client = MinecraftClient.getInstance(); @@ -76,24 +78,25 @@ public class BotValidationUtilities { final String prefix = info.prefix; final String key = info.key; - if (key == null) throw new RuntimeException("The key of the bot is unspecified (null), did you incorrectly add it to your config?"); + if (key == null) + throw new RuntimeException("The key of the bot is unspecified (null), did you incorrectly add it to your config?"); try { - String[] arguments = command.split(" "); + final String[] arguments = command.split(" "); - MessageDigest md = MessageDigest.getInstance("SHA-256"); - String time = String.valueOf(System.currentTimeMillis() / 5_000); - String input = client.player.getUuidAsString() + arguments[0] + time + key; - byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8)); + final MessageDigest md = MessageDigest.getInstance("SHA-256"); + final String time = String.valueOf(System.currentTimeMillis() / 5_000); + final String input = client.player.getUuidAsString() + arguments[0] + time + key; + final byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8)); String stringHash = new String(Hex.encodeHex(hash)).substring(0, 16); final boolean shouldSectionSign = CustomChat.INSTANCE.enabled && player.hasPermissionLevel(2) && player.isCreative(); if (shouldSectionSign) { stringHash = String.join("", - Arrays.stream(stringHash.split("")) - .map((letter) -> "§" + letter) - .toArray(String[]::new) + Arrays.stream(stringHash.split("")) + .map((letter) -> "§" + letter) + .toArray(String[]::new) ); } @@ -108,57 +111,59 @@ public class BotValidationUtilities { String.join(" ", restArguments); Chat.sendChatMessage(toSend); - } catch (NoSuchAlgorithmException e) { + } catch (final NoSuchAlgorithmException e) { e.printStackTrace(); } return Command.SINGLE_SUCCESS; } - public static int qilk (String command) throws RuntimeException { + public static int qilk (final String command) throws RuntimeException { final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.qilk; final MinecraftClient client = MinecraftClient.getInstance(); final String prefix = info.prefix; final String key = info.key; - if (key == null) throw new RuntimeException("The key of the bot is unspecified (null), did you incorrectly add it to your config?"); + if (key == null) + throw new RuntimeException("The key of the bot is unspecified (null), did you incorrectly add it to your config?"); try { - MessageDigest md = MessageDigest.getInstance("SHA-256"); - long time = Math.floorDiv(System.currentTimeMillis(), 2000); + final MessageDigest md = MessageDigest.getInstance("SHA-256"); + final long time = Math.floorDiv(System.currentTimeMillis(), 2000); - String[] wholeArguments = command.split(" "); - String[] restArguments = Arrays.copyOfRange(wholeArguments, 1, wholeArguments.length); + final String[] wholeArguments = command.split(" "); + final String[] restArguments = Arrays.copyOfRange(wholeArguments, 1, wholeArguments.length); // lol this is literally chomens bot input with uwu and : - String input = "uwu:" + key + ":" + client.player.getUuidAsString() + ":" + wholeArguments[0] + ":" + time; + final String input = "uwu:" + key + ":" + client.player.getUuidAsString() + ":" + wholeArguments[0] + ":" + time; - byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8)); - String stringHash = new String(Hex.encodeHex(hash)); + final byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8)); + final String stringHash = new String(Hex.encodeHex(hash)); Chat.sendChatMessage(prefix + wholeArguments[0] + " " + stringHash + " " + String.join(" ", restArguments), true); - } catch (NoSuchAlgorithmException e) { + } catch (final NoSuchAlgorithmException e) { e.printStackTrace(); } return Command.SINGLE_SUCCESS; } - public static int fnfboyfriend (String command) { + public static int fnfboyfriend (final String command) { try { final String prefix = ChipmunkMod.CONFIG.bots.fnfboyfriend.prefix; - String[] arguments = command.split(" "); + final String[] arguments = command.split(" "); - long currentTime = System.currentTimeMillis() / 2000; + final long currentTime = System.currentTimeMillis() / 2000; final String key = ChipmunkMod.CONFIG.bots.fnfboyfriend.key; - if (key == null) throw new RuntimeException("The key of the bot is unspecified (null), did you incorrectly add it to your config?"); - String input = currentTime + key; - MessageDigest digest = MessageDigest.getInstance("SHA-256"); - byte[] hash = digest.digest(input.getBytes()); - StringBuilder hexString = new StringBuilder(); - for (byte b : hash) { - String hex = Integer.toHexString(0xff & b); + if (key == null) + throw new RuntimeException("The key of the bot is unspecified (null), did you incorrectly add it to your config?"); + final String input = currentTime + key; + final MessageDigest digest = MessageDigest.getInstance("SHA-256"); + final byte[] hash = digest.digest(input.getBytes()); + final StringBuilder hexString = new StringBuilder(); + for (final byte b : hash) { + final String hex = Integer.toHexString(0xff & b); if (hex.length() == 1) hexString.append('0'); hexString.append(hex); } @@ -168,24 +173,25 @@ public class BotValidationUtilities { final String result = hexString.substring(0, 16); Chat.sendChatMessage(prefix + arguments[0] + " " + result + " " + String.join(" ", restArguments)); - } catch (NoSuchAlgorithmException e) { + } catch (final NoSuchAlgorithmException e) { e.printStackTrace(); } return Command.SINGLE_SUCCESS; } - public static int nbot (String command) throws RuntimeException { + public static int nbot (final String command) throws RuntimeException { final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.nbot; final MinecraftClient client = MinecraftClient.getInstance(); final String prefix = info.prefix; final String key = info.key; - if (key == null) throw new RuntimeException("The key of the bot is unspecified (null), did you incorrectly add it to your config?"); + if (key == null) + throw new RuntimeException("The key of the bot is unspecified (null), did you incorrectly add it to your config?"); try { - String[] arguments = command.split(" "); + final String[] arguments = command.split(" "); final MessageDigest md = MessageDigest.getInstance("SHA-256"); @@ -215,31 +221,32 @@ public class BotValidationUtilities { String.join(" ", restArguments); Chat.sendChatMessage(toSend, true); - } catch (NoSuchAlgorithmException e) { + } catch (final NoSuchAlgorithmException e) { e.printStackTrace(); } return Command.SINGLE_SUCCESS; } - public static int kittycorp (String command) throws RuntimeException { + public static int kittycorp (final String command) throws RuntimeException { final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.kittycorp; final ClientPlayNetworkHandler networkHandler = MinecraftClient.getInstance().getNetworkHandler(); final String prefix = info.prefix; final String key = info.key; - if (key == null) throw new RuntimeException("The key of the bot is unspecified (null), did you incorrectly add it to your config?"); + if (key == null) + throw new RuntimeException("The key of the bot is unspecified (null), did you incorrectly add it to your config?"); try { - MessageDigest md = MessageDigest.getInstance("SHA-256"); - String time = String.valueOf(System.currentTimeMillis() / 10000); - String input = prefix + command.replaceAll("&[0-9a-fklmnorx]", "") + ";" + time + ";" + key; - byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8)); - BigInteger bigInt = new BigInteger(1, Arrays.copyOfRange(hash, 0, 4)); - String stringHash = bigInt.toString(Character.MAX_RADIX); + final MessageDigest md = MessageDigest.getInstance("SHA-256"); + final String time = String.valueOf(System.currentTimeMillis() / 10000); + final String input = prefix + command.replaceAll("&[0-9a-fklmnorx]", "") + ";" + time + ";" + key; + final byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8)); + final BigInteger bigInt = new BigInteger(1, Arrays.copyOfRange(hash, 0, 4)); + final String stringHash = bigInt.toString(Character.MAX_RADIX); Chat.sendChatMessage(prefix + command + " " + stringHash, true); - } catch (NoSuchAlgorithmException e) { + } catch (final NoSuchAlgorithmException e) { e.printStackTrace(); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/util/ColorUtilities.java b/src/main/java/land/chipmunk/chipmunkmod/util/ColorUtilities.java index 3ffb4a5..87ac466 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/util/ColorUtilities.java +++ b/src/main/java/land/chipmunk/chipmunkmod/util/ColorUtilities.java @@ -3,8 +3,8 @@ package land.chipmunk.chipmunkmod.util; import java.awt.*; public class ColorUtilities { - public static int hsvToRgb (int hue, int saturation, int value) { - Color color = Color.getHSBColor(hue / 360.0f, saturation / 100.0f, value / 100.0f); + public static int hsvToRgb (final int hue, final int saturation, final int value) { + final Color color = Color.getHSBColor(hue / 360.0f, saturation / 100.0f, value / 100.0f); return color.getRGB() & 0xFFFFFF; } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/util/DownloadUtilities.java b/src/main/java/land/chipmunk/chipmunkmod/util/DownloadUtilities.java index 091cde2..4d21638 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/util/DownloadUtilities.java +++ b/src/main/java/land/chipmunk/chipmunkmod/util/DownloadUtilities.java @@ -14,34 +14,18 @@ import java.security.cert.X509Certificate; public class DownloadUtilities { - private static class DefaultTrustManager implements X509TrustManager { - - @Override - public void checkClientTrusted(X509Certificate[] arg0, String arg1) { - } - - @Override - public void checkServerTrusted(X509Certificate[] arg0, String arg1) { - } - - @Override - public X509Certificate[] getAcceptedIssuers() { - return null; - } - } - - public static byte[] DownloadToByteArray(URL url) throws IOException, KeyManagementException, NoSuchAlgorithmException { - SSLContext ctx = SSLContext.getInstance("TLS"); - ctx.init(new KeyManager[0], new TrustManager[]{new DefaultTrustManager()}, new SecureRandom()); + public static byte[] DownloadToByteArray (final URL url) throws IOException, KeyManagementException, NoSuchAlgorithmException { + final SSLContext ctx = SSLContext.getInstance("TLS"); + ctx.init(new KeyManager[0], new TrustManager[] { new DefaultTrustManager() }, new SecureRandom()); SSLContext.setDefault(ctx); - URLConnection conn = url.openConnection(); + final URLConnection conn = url.openConnection(); conn.setConnectTimeout(5000); conn.setReadTimeout(10000); conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0"); - try (BufferedInputStream downloadStream = new BufferedInputStream(conn.getInputStream())) { - ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(); - byte[] buf = new byte[1024]; + try (final BufferedInputStream downloadStream = new BufferedInputStream(conn.getInputStream())) { + final ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(); + final byte[] buf = new byte[1024]; int n; while ((n = downloadStream.read(buf)) > 0) { byteArrayStream.write(buf, 0, n); @@ -55,7 +39,23 @@ public class DownloadUtilities { // Closing a ByteArrayInputStream has no effect, so I do not close it. } - public static InputStream DownloadToInputStream(URL url) throws KeyManagementException, NoSuchAlgorithmException, IOException { + public static InputStream DownloadToInputStream (final URL url) throws KeyManagementException, NoSuchAlgorithmException, IOException { return new ByteArrayInputStream(DownloadToByteArray(url)); } + + private static class DefaultTrustManager implements X509TrustManager { + + @Override + public void checkClientTrusted (final X509Certificate[] arg0, final String arg1) { + } + + @Override + public void checkServerTrusted (final X509Certificate[] arg0, final String arg1) { + } + + @Override + public X509Certificate[] getAcceptedIssuers () { + return null; + } + } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/util/MathUtilities.java b/src/main/java/land/chipmunk/chipmunkmod/util/MathUtilities.java index 981e98e..0a924ec 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/util/MathUtilities.java +++ b/src/main/java/land/chipmunk/chipmunkmod/util/MathUtilities.java @@ -1,11 +1,11 @@ package land.chipmunk.chipmunkmod.util; public class MathUtilities { - public static double clamp (double value, double min, double max) { + public static double clamp (final double value, final double min, final double max) { return Math.max(Math.min(value, max), min); } - public static float clamp (float value, float min, float max) { + public static float clamp (final float value, final float min, final float max) { return Math.max(Math.min(value, max), min); } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/util/RandomUtilities.java b/src/main/java/land/chipmunk/chipmunkmod/util/RandomUtilities.java index 47e3615..56a6357 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/util/RandomUtilities.java +++ b/src/main/java/land/chipmunk/chipmunkmod/util/RandomUtilities.java @@ -8,11 +8,11 @@ public final class RandomUtilities { public static final char[] TEAM_ALLOWED_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-.+" .toCharArray(); - public static String emptyUsername(final Random random) { + public static String emptyUsername (final Random random) { return RandomUtilities.emptyUsername(random, '&'); } - public static String emptyUsername(final Random random, char colorChar) { + public static String emptyUsername (final Random random, final char colorChar) { final char[] buf = new char[16]; for (int i = 0; i < 16; i += 2) { @@ -25,7 +25,7 @@ public final class RandomUtilities { return new String(buf); } - public static String randomString(final Random random, final char[] charset, final int length) { + public static String randomString (final Random random, final char[] charset, final int length) { final char[] buf = new char[length]; for (int i = 0; i < length; i++) { diff --git a/src/main/java/land/chipmunk/chipmunkmod/util/ServerUtilities.java b/src/main/java/land/chipmunk/chipmunkmod/util/ServerUtilities.java index 104ef63..ac6cd5d 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/util/ServerUtilities.java +++ b/src/main/java/land/chipmunk/chipmunkmod/util/ServerUtilities.java @@ -4,7 +4,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; public class ServerUtilities { - public static boolean serverHasCommand (String name) { + public static boolean serverHasCommand (final String name) { final MinecraftClient client = MinecraftClient.getInstance(); final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); diff --git a/src/main/java/land/chipmunk/chipmunkmod/util/TextUtilities.java b/src/main/java/land/chipmunk/chipmunkmod/util/TextUtilities.java index d72e10a..8dee4c1 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/util/TextUtilities.java +++ b/src/main/java/land/chipmunk/chipmunkmod/util/TextUtilities.java @@ -9,16 +9,16 @@ import net.minecraft.text.Text; import net.minecraft.text.TextContent; public class TextUtilities { - public static MutableText fromJson (String json) { + public static MutableText fromJson (final String json) { return Text.Serialization.fromJson( json, Suppliers.ofInstance(DynamicRegistryManager.of(Registries.REGISTRIES)).get() ); } - public static String plainOrNull(final Text text) { + public static String plainOrNull (final Text text) { final TextContent content = text.getContent(); - if (!(content instanceof PlainTextContent plainContent)) return null; + if (!(content instanceof final PlainTextContent plainContent)) return null; return plainContent.string(); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/util/UUIDUtilities.java b/src/main/java/land/chipmunk/chipmunkmod/util/UUIDUtilities.java index 277c709..6b4640e 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/util/UUIDUtilities.java +++ b/src/main/java/land/chipmunk/chipmunkmod/util/UUIDUtilities.java @@ -4,7 +4,7 @@ import java.nio.ByteBuffer; import java.util.UUID; public class UUIDUtilities { - public static int[] intArray (UUID uuid) { + public static int[] intArray (final UUID uuid) { final ByteBuffer buffer = ByteBuffer.wrap(new byte[16]); buffer.putLong(0, uuid.getMostSignificantBits()); buffer.putLong(8, uuid.getLeastSignificantBits()); @@ -15,10 +15,10 @@ public class UUIDUtilities { return intArray; } - public static String snbt (UUID uuid) { - int[] array = intArray(uuid); + public static String snbt (final UUID uuid) { + final int[] array = intArray(uuid); return "[I;" + array[0] + "," + array[1] + "," + array[2] + "," + array[3] + "]"; // TODO: improve lol } - public static String selector (UUID uuid) { return "@a[limit=1,nbt={UUID:" + snbt(uuid) + "}]"; } + public static String selector (final UUID uuid) { return "@a[limit=1,nbt={UUID:" + snbt(uuid) + "}]"; } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/util/configurate/BlockBoxTypeSerializer.java b/src/main/java/land/chipmunk/chipmunkmod/util/configurate/BlockBoxTypeSerializer.java index c432272..5f28d54 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/util/configurate/BlockBoxTypeSerializer.java +++ b/src/main/java/land/chipmunk/chipmunkmod/util/configurate/BlockBoxTypeSerializer.java @@ -10,16 +10,15 @@ import org.spongepowered.configurate.serialize.TypeSerializer; import java.lang.reflect.Type; public class BlockBoxTypeSerializer implements TypeSerializer { + public static final BlockBoxTypeSerializer INSTANCE = new BlockBoxTypeSerializer(); private static final String START = "start"; private static final String END = "end"; - public static final BlockBoxTypeSerializer INSTANCE = new BlockBoxTypeSerializer(); - - private BlockBoxTypeSerializer() { + private BlockBoxTypeSerializer () { } @Override - public BlockBox deserialize(final Type type, final ConfigurationNode source) throws SerializationException { + public BlockBox deserialize (final Type type, final ConfigurationNode source) throws SerializationException { final BlockPos start = ConfigurateUtilities.getNodeOrThrow(source, START).require(BlockPos.class); final BlockPos end = ConfigurateUtilities.getNodeOrThrow(source, END).require(BlockPos.class); @@ -27,8 +26,8 @@ public class BlockBoxTypeSerializer implements TypeSerializer { } @Override - public void serialize(final Type type, final @Nullable BlockBox box, - final ConfigurationNode target) throws SerializationException { + public void serialize (final Type type, final @Nullable BlockBox box, + final ConfigurationNode target) throws SerializationException { if (box == null) { target.raw(null); return; diff --git a/src/main/java/land/chipmunk/chipmunkmod/util/configurate/BlockPosTypeSerializer.java b/src/main/java/land/chipmunk/chipmunkmod/util/configurate/BlockPosTypeSerializer.java index 1971373..578bd69 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/util/configurate/BlockPosTypeSerializer.java +++ b/src/main/java/land/chipmunk/chipmunkmod/util/configurate/BlockPosTypeSerializer.java @@ -9,17 +9,16 @@ import org.spongepowered.configurate.serialize.TypeSerializer; import java.lang.reflect.Type; public class BlockPosTypeSerializer implements TypeSerializer { + public static final BlockPosTypeSerializer INSTANCE = new BlockPosTypeSerializer(); private static final String X = "x"; private static final String Y = "y"; private static final String Z = "z"; - public static final BlockPosTypeSerializer INSTANCE = new BlockPosTypeSerializer(); - - private BlockPosTypeSerializer() { + private BlockPosTypeSerializer () { } @Override - public BlockPos deserialize(final Type type, final ConfigurationNode source) throws SerializationException { + public BlockPos deserialize (final Type type, final ConfigurationNode source) throws SerializationException { final int x = ConfigurateUtilities.getNodeOrThrow(source, X).getInt(); final int y = ConfigurateUtilities.getNodeOrThrow(source, Y).getInt(); final int z = ConfigurateUtilities.getNodeOrThrow(source, Z).getInt(); @@ -28,8 +27,8 @@ public class BlockPosTypeSerializer implements TypeSerializer { } @Override - public void serialize(final Type type, final @Nullable BlockPos pos, - final ConfigurationNode target) throws SerializationException { + public void serialize (final Type type, final @Nullable BlockPos pos, + final ConfigurationNode target) throws SerializationException { if (pos == null) { target.raw(null); return; diff --git a/src/main/java/land/chipmunk/chipmunkmod/util/configurate/ComponentTypeSerializer.java b/src/main/java/land/chipmunk/chipmunkmod/util/configurate/ComponentTypeSerializer.java index 735dbd0..51c0420 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/util/configurate/ComponentTypeSerializer.java +++ b/src/main/java/land/chipmunk/chipmunkmod/util/configurate/ComponentTypeSerializer.java @@ -11,14 +11,14 @@ import org.spongepowered.configurate.serialize.TypeSerializer; import java.lang.reflect.Type; public class ComponentTypeSerializer implements TypeSerializer { - private static final GsonComponentSerializer GSON = GsonComponentSerializer.gson(); public static final ComponentTypeSerializer INSTANCE = new ComponentTypeSerializer(); + private static final GsonComponentSerializer GSON = GsonComponentSerializer.gson(); - private ComponentTypeSerializer() { + private ComponentTypeSerializer () { } @Override - public Component deserialize(final Type type, final ConfigurationNode source) throws SerializationException { + public Component deserialize (final Type type, final ConfigurationNode source) throws SerializationException { final JsonElement elem = source.get(JsonElement.class); if (elem == null) { return null; @@ -28,8 +28,8 @@ public class ComponentTypeSerializer implements TypeSerializer { } @Override - public void serialize(final Type type, final @Nullable Component component, - final ConfigurationNode target) throws SerializationException { + public void serialize (final Type type, final @Nullable Component component, + final ConfigurationNode target) throws SerializationException { if (component == null) { target.raw(null); return; diff --git a/src/main/java/land/chipmunk/chipmunkmod/util/configurate/ConfigurateUtilities.java b/src/main/java/land/chipmunk/chipmunkmod/util/configurate/ConfigurateUtilities.java index 53e4f54..8b9f492 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/util/configurate/ConfigurateUtilities.java +++ b/src/main/java/land/chipmunk/chipmunkmod/util/configurate/ConfigurateUtilities.java @@ -20,14 +20,14 @@ public final class ConfigurateUtilities { .register(Component.class, ComponentTypeSerializer.INSTANCE) .build(); - private ConfigurateUtilities() { + private ConfigurateUtilities () { } - public static TypeSerializerCollection customSerializers() { + public static TypeSerializerCollection customSerializers () { return CUSTOM_SERIALIZER_COLLECTION; } - public static ConfigurationNode getNodeOrThrow(final ConfigurationNode source, final Object... path) throws SerializationException { + public static ConfigurationNode getNodeOrThrow (final ConfigurationNode source, final Object... path) throws SerializationException { if (!source.hasChild(path)) { throw new SerializationException("Required field " + Arrays.toString(path) + " was not present in node"); } @@ -35,7 +35,7 @@ public final class ConfigurateUtilities { return source.node(path); } - public static TransformAction componentTransformer(final ComponentRenderer renderer, final C ctx) { + public static TransformAction componentTransformer (final ComponentRenderer renderer, final C ctx) { return (path, value) -> { final Component originalComponent = value.get(Component.class); if (originalComponent == null) return null;