Compare commits

...

4 commits

Author SHA1 Message Date
0b31a366cb
style: also commit the styles and info in readme 2025-04-15 10:25:17 +07:00
7ed4d1ee84
refactor: remove 2025-04-15 10:08:53 +07:00
0f9b6f4cdb
style: use the same code style as chomens bot 2025-04-15 09:41:08 +07:00
1afb5583b4
refactor: use Wrap* for mixins
refactor: remove TransactionManager since it's unused
refactor: fix some warnings about ClientPlayNetworkHandler being nullable

and some more stuff i might have forgor to put here
more stuff coming in the next commits !!!
2025-04-15 09:31:54 +07:00
73 changed files with 1176 additions and 1111 deletions

View file

@ -1,4 +1,13 @@
# ChipmunkMod
My fork of [Chipmunk Sex Mod](https://code.chipmunk.land/ChipmunkMC/chipmunkmod)
My fork of [Chipmunk's ChipmunkMod](https://code.chipmunk.land/ChipmunkMC/chipmunkmod)
ignore messy code pls,. .,,.,...,.,.,
# Development
When commiting your changes, please use my code style.
In IntelliJ IDEA:
`Ctrl + Alt + S`, search `Code Style`, go to `Java`, click gear icon, `Import Scheme -> IntelliJ IDEA code style XML`,
use the `codestyle.xml` file in this repository
`Ctrl + Alt + Shift + H`, click `Configure Inspections...`, click gear icon, `Import Profile...`,
use the `inspections.xml` file in this repository

29
codestyle.xml Normal file
View file

@ -0,0 +1,29 @@
<code_scheme name="Project" version="173">
<JavaCodeStyleSettings>
<option name="GENERATE_FINAL_LOCALS" value="true" />
<option name="GENERATE_FINAL_PARAMETERS" value="true" />
<option name="VISIBILITY" value="protected" />
<option name="SPACE_BEFORE_OPENING_ANGLE_BRACKET_IN_TYPE_PARAMETER" value="true" />
<option name="SPACE_BEFORE_DECONSTRUCTION_LIST" value="true" />
</JavaCodeStyleSettings>
<JetCodeStyleSettings>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<codeStyleSettings language="JAVA">
<option name="RIGHT_MARGIN" value="120" />
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
<option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
<option name="SPACE_WITHIN_BRACES" value="true" />
<option name="SPACE_WITHIN_ARRAY_INITIALIZER_BRACES" value="true" />
<option name="SPACE_BEFORE_METHOD_PARENTHESES" value="true" />
<option name="SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE" value="true" />
<option name="KEEP_SIMPLE_BLOCKS_IN_ONE_LINE" value="true" />
<option name="KEEP_SIMPLE_METHODS_IN_ONE_LINE" value="true" />
<option name="KEEP_SIMPLE_LAMBDAS_IN_ONE_LINE" value="true" />
<option name="KEEP_SIMPLE_CLASSES_IN_ONE_LINE" value="true" />
<option name="KEEP_MULTIPLE_EXPRESSIONS_IN_ONE_LINE" value="true" />
</codeStyleSettings>
<codeStyleSettings language="kotlin">
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</codeStyleSettings>
</code_scheme>

9
inspections.xml Normal file
View file

@ -0,0 +1,9 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="LocalCanBeFinal" enabled="true" level="WARNING" enabled_by_default="true">
<option name="REPORT_VARIABLES" value="true" />
<option name="REPORT_PARAMETERS" value="true" />
</inspection_tool>
</profile>
</component>

View file

@ -19,31 +19,13 @@ 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 {
final ChipmunkModMigrations migrations = new ChipmunkModMigrations();
final ObjectMapper.Factory customFactory = ObjectMapper.factoryBuilder()
@ -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)");
}
}

View file

@ -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<FabricClientCommandSource> 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<FabricClientCommandSource> literal (final String name) {
return LiteralArgumentBuilder.literal(name);
}
public static <T> RequiredArgumentBuilder<FabricClientCommandSource, T> argument (final String name, final ArgumentType<T> 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<FabricClientCommandSource> literal(String name) {
return LiteralArgumentBuilder.literal(name);
}
public static <T> RequiredArgumentBuilder<FabricClientCommandSource, T> argument(String name, ArgumentType<T> type) {
return RequiredArgumentBuilder.argument(name, type);
}
}

View file

@ -22,27 +22,50 @@ public class LocationArgumentType implements ArgumentType<Object> {
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<Object> {
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<String> getExamples () { return EXAMPLES; }
}

View file

@ -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<Long> {
private static final Collection<String> EXAMPLES = Arrays.asList("0:01", "1:23", "6:09");
@ -15,7 +16,7 @@ public class TimestampArgumentType implements ArgumentType<Long> {
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;

View file

@ -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<FabricClientCommandSource> dispatcher) {
public static void register (final CommandDispatcher<FabricClientCommandSource> dispatcher) {
dispatcher.register(
literal("autoskin")
.then(
@ -23,7 +23,7 @@ public class AutoSkinCommand {
);
}
public static int execute(CommandContext<FabricClientCommandSource> context) {
public static int execute (final CommandContext<FabricClientCommandSource> context) {
final FabricClientCommandSource source = context.getSource();
final String username = getString(context, "username");

View file

@ -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<FabricClientCommandSource> dispatcher) {
public static void register (final CommandDispatcher<FabricClientCommandSource> dispatcher) {
dispatcher.register(
literal("cloop")
.then(
@ -52,18 +54,18 @@ public class CloopCommand {
);
}
public static int addCloop (CommandContext<FabricClientCommandSource> context) {
public static int addCloop (final CommandContext<FabricClientCommandSource> 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<FabricClientCommandSource> context) throws CommandSyntaxException {
public static int removeCloop (final CommandContext<FabricClientCommandSource> 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<FabricClientCommandSource> context) {
public static int clearCloops (final CommandContext<FabricClientCommandSource> context) {
final FabricClientCommandSource source = context.getSource();
final CommandLoopManager manager = CommandLoopManager.INSTANCE;
@ -86,12 +88,12 @@ public class CloopCommand {
return Command.SINGLE_SUCCESS;
}
public static int listCloops (CommandContext<FabricClientCommandSource> context) {
public static int listCloops (final CommandContext<FabricClientCommandSource> context) {
final FabricClientCommandSource source = context.getSource();
final List<CommandLoopManager.CommandLoop> loops = CommandLoopManager.INSTANCE.commandLoops;
int id = 0;
for (CommandLoopManager.CommandLoop loop : loops) {
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++;
}

View file

@ -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<FabricClientCommandSource> dispatcher) {
public static void register (final CommandDispatcher<FabricClientCommandSource> dispatcher) {
dispatcher.register(
literal("core")
.then(
@ -54,13 +51,13 @@ public class CoreCommand {
);
}
public static int run(CommandContext<FabricClientCommandSource> context) {
public static int run (final CommandContext<FabricClientCommandSource> context) {
CommandCore.INSTANCE.run(getString(context, "command"));
return Command.SINGLE_SUCCESS;
}
public static int runTracked(CommandContext<FabricClientCommandSource> context) {
public static int runTracked (final CommandContext<FabricClientCommandSource> 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<FabricClientCommandSource> context) {
public static int refill (final CommandContext<FabricClientCommandSource> context) {
CommandCore.INSTANCE.refill();
return Command.SINGLE_SUCCESS;
}
public static int move(CommandContext<FabricClientCommandSource> context) {
public static int move (final CommandContext<FabricClientCommandSource> 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<FabricClientCommandSource> context) {
public static int runFillCommand (final CommandContext<FabricClientCommandSource> context) {
final FabricClientCommandSource source = context.getSource();
final boolean bool = getBool(context, "enabled");

View file

@ -15,7 +15,7 @@ import static land.chipmunk.chipmunkmod.command.CommandManager.argument;
import static land.chipmunk.chipmunkmod.command.CommandManager.literal;
public class CustomChatCommand {
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher) {
public static void register (final CommandDispatcher<FabricClientCommandSource> dispatcher) {
dispatcher.register(
literal("customchat")
.then(
@ -35,7 +35,7 @@ public class CustomChatCommand {
);
}
public static int enabled (CommandContext<FabricClientCommandSource> context) {
public static int enabled (final CommandContext<FabricClientCommandSource> 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<FabricClientCommandSource> context) {
public static int setFormat (final CommandContext<FabricClientCommandSource> context) {
final FabricClientCommandSource source = context.getSource();
final String format = getString(context, "format");
CustomChat.INSTANCE.format = format;

View file

@ -18,7 +18,7 @@ import static land.chipmunk.chipmunkmod.command.CommandManager.argument;
import static land.chipmunk.chipmunkmod.command.CommandManager.literal;
public class EvalCommand {
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher) {
public static void register (final CommandDispatcher<FabricClientCommandSource> dispatcher) {
dispatcher.register(
literal("eval")
.then(
@ -28,7 +28,7 @@ public class EvalCommand {
);
}
public static int eval (CommandContext<FabricClientCommandSource> context) {
public static int eval (final CommandContext<FabricClientCommandSource> 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()));
}

View file

@ -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<FabricClientCommandSource> dispatcher, CommandRegistryAccess commandRegistryAccess) {
public static void register (final CommandDispatcher<FabricClientCommandSource> dispatcher, final CommandRegistryAccess commandRegistryAccess) {
dispatcher.register(
literal("item")
.then(
@ -34,17 +33,17 @@ public class ItemCommand {
);
}
public static int setItem(CommandContext<FabricClientCommandSource> context) throws CommandSyntaxException {
public static int setItem (final CommandContext<FabricClientCommandSource> context) throws CommandSyntaxException {
return setItem(context, getInteger(context, "count"));
}
public static int setItem(CommandContext<FabricClientCommandSource> context, int count) throws CommandSyntaxException {
public static int setItem (final CommandContext<FabricClientCommandSource> 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));

View file

@ -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<FabricClientCommandSource> dispatcher) {
public static void register (final CommandDispatcher<FabricClientCommandSource> 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<FabricClientCommandSource> context) {
public int play (final CommandContext<FabricClientCommandSource> 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<FabricClientCommandSource> context) throws CommandSyntaxException {
public int stop (final CommandContext<FabricClientCommandSource> 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<FabricClientCommandSource> context) throws CommandSyntaxException {
public int skip (final CommandContext<FabricClientCommandSource> 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<FabricClientCommandSource> context) throws CommandSyntaxException {
public int pause (final CommandContext<FabricClientCommandSource> 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<Component> directories = new ArrayList<>();
final List<Component> 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<FabricClientCommandSource> context) throws CommandSyntaxException {
public int toggleLoop (final CommandContext<FabricClientCommandSource> 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<FabricClientCommandSource> context) throws CommandSyntaxException {
public int loop (final CommandContext<FabricClientCommandSource> 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<FabricClientCommandSource> context) throws CommandSyntaxException {
public int gotoCommand (final CommandContext<FabricClientCommandSource> 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<FabricClientCommandSource> context) {
public int useCore (final CommandContext<FabricClientCommandSource> 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<FabricClientCommandSource> context) {
public int actionbar (final CommandContext<FabricClientCommandSource> 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<FabricClientCommandSource> context) {
public int pitch (final CommandContext<FabricClientCommandSource> context) {
final FabricClientCommandSource source = context.getSource();
final float pitch = getFloat(context, "pitch");

View file

@ -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<FabricClientCommandSource> dispatcher) {
public static void register (final CommandDispatcher<FabricClientCommandSource> dispatcher) {
dispatcher.register(
literal("rainbowname")
.then(
@ -35,7 +35,7 @@ public class RainbowNameCommand {
);
}
public static int enabled (CommandContext<FabricClientCommandSource> context) {
public static int enabled (final CommandContext<FabricClientCommandSource> 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<FabricClientCommandSource> context) {
public static int setName (final CommandContext<FabricClientCommandSource> context) {
final FabricClientCommandSource source = context.getSource();
final String name = getString(context, "name");

View file

@ -13,14 +13,14 @@ import java.io.IOException;
import static land.chipmunk.chipmunkmod.command.CommandManager.literal;
public class ReloadConfigCommand {
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher) {
public static void register (final CommandDispatcher<FabricClientCommandSource> dispatcher) {
dispatcher.register(
literal("reloadconfig")
.executes(ReloadConfigCommand::reload)
);
}
public static int reload(CommandContext<FabricClientCommandSource> context) {
public static int reload (final CommandContext<FabricClientCommandSource> 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();
}

View file

@ -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<FabricClientCommandSource> dispatcher) {
public static void register (final CommandDispatcher<FabricClientCommandSource> dispatcher) {
dispatcher.register(
literal("say")
.then(
@ -22,7 +22,7 @@ public class SayCommand {
);
}
public static int say (CommandContext<FabricClientCommandSource> context) {
public static int say (final CommandContext<FabricClientCommandSource> context) {
Chat.sendChatMessage(getString(context, "message"), true);
return Command.SINGLE_SUCCESS;

View file

@ -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<FabricClientCommandSource> dispatcher) {
public static void register (final CommandDispatcher<FabricClientCommandSource> dispatcher) {
dispatcher.register(
literal("selfcare")
.then(
@ -40,7 +40,7 @@ public class SelfCareCommand {
);
}
public static int setSelfCare (CommandContext<FabricClientCommandSource> context, String type) {
public static int setSelfCare (final CommandContext<FabricClientCommandSource> context, final String type) {
final FabricClientCommandSource source = context.getSource();
final boolean bool = getBool(context, "boolean");

View file

@ -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<FabricClientCommandSource> dispatcher) {
public static void register (final CommandDispatcher<FabricClientCommandSource> dispatcher) {
dispatcher.register(
literal("test")
.executes(c -> helloWorld(c))
);
}
public static int helloWorld(CommandContext<FabricClientCommandSource> context) {
public static int helloWorld (final CommandContext<FabricClientCommandSource> context) {
final FabricClientCommandSource source = context.getSource();
source.sendFeedback(Text.literal("Hello, world!"));

View file

@ -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,7 +39,7 @@ public class UsernameCommand {
private static final Session ORIGINAL_SESSION = MinecraftClient.getInstance().getSession();
private static final Random RANDOM = new Random();
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher) {
public static void register (final CommandDispatcher<FabricClientCommandSource> dispatcher) {
dispatcher.register(literal("username")
.then(literal("set")
.then(argument("username", greedyString())

View file

@ -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<FabricClientCommandSource> dispatcher) {
public static void register (final CommandDispatcher<FabricClientCommandSource> dispatcher) {
dispatcher.register(
literal("validate")
.then(literal("hbot").then(argument("command", greedyString()).executes(c -> hbot(getString(c, "command")))))

View file

@ -47,7 +47,7 @@ public class Configuration {
public TestBotInfo () {
}
public TestBotInfo(String prefix, @Nullable String webhookUrl) {
public TestBotInfo (final String prefix, @Nullable final String webhookUrl) {
this.prefix = prefix;
this.webhookUrl = webhookUrl;
}
@ -61,7 +61,7 @@ public class Configuration {
public BotInfo () {
}
public BotInfo(String prefix, @Nullable String key) {
public BotInfo (final String prefix, @Nullable final String key) {
this.prefix = prefix;
this.key = key;
}

View file

@ -5,14 +5,14 @@ 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<ConfigurationTransformation> supplier) {
return new ConfigMigrationImpl(version, supplier);
}
int version ();
ConfigurationTransformation create ();
record ConfigMigrationImpl(int version, Supplier<ConfigurationTransformation> supplier) implements ConfigMigration {
@Override
public ConfigurationTransformation create () {

View file

@ -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);
}

View file

@ -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());
}
}

View file

@ -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 chatMessageReceived (final Text message) { }
default void overlayMessageReceived (final Text message) { }
default void coreReady () { }
default void coreMoved () { }
}

View file

@ -6,7 +6,7 @@ import java.util.List;
public class ListenerManager {
public static List<Listener> listeners = new ArrayList<>();
public static void addListener (Listener listener) {
public static void addListener (final Listener listener) {
listeners.add(listener);
}
}

View file

@ -27,31 +27,32 @@ import java.util.concurrent.CompletableFuture;
@Mixin(net.minecraft.client.gui.screen.ChatInputSuggestor.class)
public class ChatInputSuggestorMixin {
@Shadow
private CompletableFuture<Suggestions> 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<Suggestions> pendingSuggestions;
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;
final String text = this.textField.getText();
final int cursor = this.textField.getCursor();

View file

@ -25,7 +25,8 @@ 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:
@ -36,7 +37,7 @@ public abstract class ChatScreenMixin {
}
@Inject(method = "sendMessage", at = @At("HEAD"), cancellable = true)
private void sendMessage(String chatText, boolean addToHistory, CallbackInfo cir) {
private void sendMessage (final String chatText, final boolean addToHistory, final CallbackInfo ci) {
final MinecraftClient client = MinecraftClient.getInstance();
if (addToHistory) {
@ -66,8 +67,8 @@ public abstract class ChatScreenMixin {
connection.getInputStream().close();
connection.disconnect();
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
} catch (final IOException | URISyntaxException e) {
ChipmunkMod.LOGGER.error("Error while trying to request TestBot webhook", e);
}
});
} else if (chatText.startsWith(ChipmunkMod.CONFIG.bots.chomens.prefix)) {
@ -79,7 +80,7 @@ public abstract class ChatScreenMixin {
.toList();
final List<String> aliases = new ArrayList<>();
for (ChomeNSBotCommand command : commands) {
for (final ChomeNSBotCommand command : commands) {
if (command.trustLevel() == ChomeNSBotCommand.TrustLevel.PUBLIC) continue;
aliases.addAll(command.aliases());
@ -95,11 +96,9 @@ public abstract class ChatScreenMixin {
) {
try {
BotValidationUtilities.chomens(chatText.substring(prefixLength));
cir.cancel();
ci.cancel();
return;
} catch (Exception ignored) {
} catch (final Exception ignored) {
}
}
}
@ -112,6 +111,6 @@ public abstract class ChatScreenMixin {
client.player.networkHandler.sendChatMessage(chatText);
}
cir.cancel();
ci.cancel();
}
}

View file

@ -1,10 +1,13 @@
package land.chipmunk.chipmunkmod.mixin;
import io.netty.channel.ChannelHandlerContext;
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import land.chipmunk.chipmunkmod.ChipmunkMod;
import land.chipmunk.chipmunkmod.listeners.Listener;
import land.chipmunk.chipmunkmod.listeners.ListenerManager;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.network.PacketCallbacks;
import net.minecraft.network.listener.PacketListener;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.c2s.play.RequestCommandCompletionsC2SPacket;
@ -28,27 +31,25 @@ public class ClientConnectionMixin {
@Unique
private static final Pattern CUSTOM_PITCH_PATTERN = Pattern.compile(".*\\.pitch\\.(.*)");
@Inject(method = "exceptionCaught", at = @At("HEAD"), cancellable = true)
private void exceptionCaught(ChannelHandlerContext context, Throwable ex, CallbackInfo ci) {
ci.cancel();
ex.printStackTrace();
}
@Inject(method = "handlePacket", at = @At("HEAD"), cancellable = true)
private static void handlePacket(Packet<?> packet, PacketListener _listener, CallbackInfo ci) {
for (Listener listener : ListenerManager.listeners) {
private static <T extends PacketListener> void handlePacket (
final Packet<T> packet,
final PacketListener packetListener,
final CallbackInfo ci
) {
for (final Listener listener : ListenerManager.listeners) {
listener.packetReceived(packet);
}
final MinecraftClient client = MinecraftClient.getInstance();
// please don't skid this.,.
// mabe mabe mabe
if (packet instanceof ParticleS2CPacket t_packet) {
if (t_packet.getCount() > MAX_PARTICLES_PER_PACKET) {
// this check is very easy to bypass in 2025
if (
packet instanceof final ParticleS2CPacket t_packet
&& t_packet.getCount() > MAX_PARTICLES_PER_PACKET
) {
ci.cancel();
}
} 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();
@ -90,25 +91,33 @@ public class ClientConnectionMixin {
));
ci.cancel();
} catch (NumberFormatException e) {
e.printStackTrace();
}
if (t_packet.getVolume() == 1 && sound.getPath().equals("entity.enderman.scream")) ci.cancel();
}
}
@Inject(at = @At("HEAD"), method = "send(Lnet/minecraft/network/packet/Packet;)V", cancellable = true)
private void sendPacket(Packet<?> packet, CallbackInfo ci) {
if (packet instanceof RequestCommandCompletionsC2SPacket t_packet) {
if (t_packet.getPartialCommand().length() > 2048) {
ci.cancel();
return;
} catch (final NumberFormatException e) {
ChipmunkMod.LOGGER.error("Failed to parse custom pitch", e);
}
if (t_packet.getVolume() == 1 && sound.getPath().equals("entity.enderman.scream")) {
ci.cancel();
}
}
}
for (Listener listener : ListenerManager.listeners) {
@WrapMethod(method = "send(Lnet/minecraft/network/packet/Packet;Lnet/minecraft/network/PacketCallbacks;Z)V")
private void sendPacket (
final Packet<?> packet,
final PacketCallbacks callbacks,
final boolean flush,
final Operation<Void> original
) {
if (
packet instanceof final RequestCommandCompletionsC2SPacket t_packet
&& t_packet.getPartialCommand().length() > 2048
) return;
for (final Listener listener : ListenerManager.listeners) {
listener.packetSent(packet);
}
original.call(packet, callbacks, flush);
}
}

View file

@ -1,5 +1,7 @@
package land.chipmunk.chipmunkmod.mixin;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.mojang.brigadier.CommandDispatcher;
import land.chipmunk.chipmunkmod.ChipmunkMod;
import land.chipmunk.chipmunkmod.command.CommandManager;
@ -7,14 +9,16 @@ import land.chipmunk.chipmunkmod.listeners.Listener;
import land.chipmunk.chipmunkmod.listeners.ListenerManager;
import land.chipmunk.chipmunkmod.modules.*;
import land.chipmunk.chipmunkmod.modules.custom_chat.CustomChat;
import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.command.CommandSource;
import net.minecraft.network.packet.s2c.play.CommandTreeS2CPacket;
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket;
import net.minecraft.network.packet.s2c.play.OverlayMessageS2CPacket;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.resource.featuretoggle.FeatureSet;
import net.minecraft.text.PlainTextContent;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableTextContent;
import org.spongepowered.asm.mixin.Final;
@ -24,7 +28,7 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(value = net.minecraft.client.network.ClientPlayNetworkHandler.class, priority = 1001)
@Mixin(value = ClientPlayNetworkHandler.class, priority = 1001)
public class ClientPlayNetworkHandlerMixin {
@Final
@Shadow
@ -36,7 +40,7 @@ public class ClientPlayNetworkHandlerMixin {
private CommandDispatcher<CommandSource> 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();
@ -54,61 +58,73 @@ public class ClientPlayNetworkHandlerMixin {
KaboomCheck.INSTANCE.onCommandTree(this.commandDispatcher);
}
@Inject(method = "onGameMessage", at = @At("HEAD"), cancellable = true)
private void onGameMessage(GameMessageS2CPacket packet, CallbackInfo ci) {
@Inject(
method = "onGameMessage",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/network/message/MessageHandler;onGameMessage(Lnet/minecraft/text/Text;Z)V"
),
cancellable = true
)
private void onGameMessage (final GameMessageS2CPacket packet, final CallbackInfo ci) {
final Text message = packet.content();
try {
if (
(
RainbowName.INSTANCE.enabled &&
(
message.getString().contains("Your nickname is now ") ||
message.getString().contains("Nickname changed.")
message.getString().startsWith("Your nickname is now ") ||
message.getString().startsWith("Nickname changed.")
)
) ||
(
message.getContent() instanceof final TranslatableTextContent translatableTextContent &&
(
translatableTextContent.getKey().equals("advMode.setCommand.success")
|| translatableTextContent.getKey().equals("قيادة المجموعة: %s")
)
)
) {
ci.cancel();
return;
}
if (message.getContent() instanceof TranslatableTextContent translatableTextContent) {
final String key = translatableTextContent.getKey();
if (key.equals("advMode.setCommand.success") || key.equals("قيادة المجموعة: %s")) {
ci.cancel();
return;
}
}
for (Listener listener : ListenerManager.listeners) {
for (final Listener listener : ListenerManager.listeners) {
listener.chatMessageReceived(message);
}
if (message.getSiblings().size() > 1) {
final String suggestionId = message.getSiblings().getFirst().getString();
if (suggestionId.equals(ChomeNSBotCommandSuggestions.REQUEST_SUGGESTIONS_ID)) {
ci.cancel();
}
}
} catch (Exception ignored) {}
if (
message.getSiblings().size() > 1
&& message.getSiblings().getFirst().getContent() instanceof final PlainTextContent textContent
&& textContent.string().equals(ChomeNSBotCommandSuggestions.REQUEST_SUGGESTIONS_ID)
) ci.cancel();
}
@Inject(method = "onOverlayMessage", at = @At("TAIL"))
private void onOverlayMessage(OverlayMessageS2CPacket packet, CallbackInfo ci) {
for (Listener listener : ListenerManager.listeners) {
listener.overlayMessageReceived(packet.text());
@WrapOperation(
method = "onOverlayMessage",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/hud/InGameHud;setOverlayMessage(Lnet/minecraft/text/Text;Z)V"
)
)
private void onOverlayMessage (final InGameHud instance, final Text message, final boolean tinted, final Operation<Void> original) {
for (final Listener listener : ListenerManager.listeners) {
listener.overlayMessageReceived(message);
}
// checking for the bot selector message doesn't really
// do much here since the message is just an empty string,
original.call(instance, message, tinted);
// checking for the chomens bot selector message doesn't really
// do much here since the message is just an empty string
// that gets sent only when you join (or the bot restarts),
// so I do not ignore them
}
@Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true)
private void sendChatMessage(String chatText, CallbackInfo ci) {
private void sendChatMessage (final String content, final CallbackInfo ci) {
final CommandManager commandManager = CommandManager.INSTANCE;
if (chatText.startsWith(commandManager.prefix)) {
commandManager.executeCommand(chatText.substring(commandManager.prefix.length()));
if (content.startsWith(commandManager.prefix)) {
commandManager.executeCommand(content.substring(commandManager.prefix.length()));
ci.cancel();
return;
}
@ -118,7 +134,7 @@ public class ClientPlayNetworkHandlerMixin {
return;
}
CustomChat.INSTANCE.chat(chatText);
CustomChat.INSTANCE.chat(content);
ci.cancel();
}
}

View file

@ -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) {
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());

View file

@ -2,6 +2,8 @@ package land.chipmunk.chipmunkmod.mixin;
import net.minecraft.client.particle.ElderGuardianAppearanceParticle;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.particle.SimpleParticleType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@ -11,9 +13,21 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
public class ElderGuardianAppearanceParticleMixin {
@Inject(
method = "createParticle(Lnet/minecraft/particle/SimpleParticleType;Lnet/minecraft/client/world/ClientWorld;DDDDDD)Lnet/minecraft/client/particle/Particle;",
at = @At("HEAD"),
cancellable = true)
private void createParticle(final CallbackInfoReturnable<Particle> cir) {
at = @At("RETURN"),
cancellable = true
)
private void createParticle (
final SimpleParticleType simpleParticleType,
final ClientWorld clientWorld,
final double d,
final double e,
final double f,
final double g,
final double h,
final double i,
final CallbackInfoReturnable<Particle> cir
) {
// slash scare command
cir.setReturnValue(null);
}
}

View file

@ -9,8 +9,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(SoundSystem.class)
public class SoundSystemMixin {
@Inject(method = "getAdjustedPitch", at = @At("HEAD"), cancellable = true)
private void getAdjustedPitch (SoundInstance sound, CallbackInfoReturnable<Float> cir) {
@Inject(method = "getAdjustedPitch", at = @At("RETURN"), cancellable = true)
private void getAdjustedPitch (final SoundInstance sound, final CallbackInfoReturnable<Float> cir) {
cir.setReturnValue(sound.getPitch());
}
}

View file

@ -8,8 +8,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(StringHelper.class)
public class StringHelperMixin {
@Inject(method = "isValidChar", at = @At("HEAD"), cancellable = true)
private static void isValidChar (char chr, CallbackInfoReturnable<Boolean> cir) {
cir.setReturnValue(chr >= ' ' && chr != '\u007f');
@Inject(method = "isValidChar", at = @At("RETURN"), cancellable = true)
private static void isValidChar (final char c, final CallbackInfoReturnable<Boolean> cir) {
// very legal [NUL] [LF] § Allowance.
cir.setReturnValue(true);
}
}

View file

@ -6,13 +6,15 @@ import net.minecraft.client.network.ClientPlayNetworkHandler;
public class Chat {
public static final ThreadLocal<Boolean> 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);
final ClientPlayNetworkHandler networkHandler = MinecraftClient.getInstance().getNetworkHandler();
if (networkHandler == null) return;
networkHandler.sendChatMessage(message);
}
}

View file

@ -29,7 +29,7 @@ public class ChomeNSBotCommandSuggestions implements Listener {
public List<ChomeNSBotCommand> commands = new ArrayList<>();
public ChomeNSBotCommandSuggestions (MinecraftClient client) {
public ChomeNSBotCommandSuggestions (final MinecraftClient client) {
this.client = client;
ListenerManager.addListener(this);
@ -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<Text> children = message.getSiblings();
if (children.isEmpty()) return;

View file

@ -17,33 +17,26 @@ import net.minecraft.util.math.BlockBox;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.dimension.DimensionType;
import org.slf4j.Logger;
import java.util.Timer;
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();
}
@ -130,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;
@ -160,11 +153,11 @@ 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();
}
}
@ -208,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();
@ -255,7 +248,7 @@ public class CommandCore {
incrementCurrentBlock();
}
public CompletableFuture<NbtCompound> runTracked(String command) {
public CompletableFuture<NbtCompound> runTracked (final String command) {
final ClientConnection connection = client.getNetworkHandler().getConnection();
if (block == null) return new CompletableFuture<>();
@ -297,7 +290,7 @@ public class CommandCore {
incrementCurrentBlock();
CompletableFuture<NbtCompound> future = new CompletableFuture<>();
final CompletableFuture<NbtCompound> future = new CompletableFuture<>();
final Timer timer = new Timer();

View file

@ -1,39 +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<CommandLoop> 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);
if (!commandLoops.add(loop)) return -1;
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();
}
@ -45,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;
@ -53,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();

View file

@ -5,10 +5,9 @@ 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;

View file

@ -1,9 +1,8 @@
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 () {
@ -45,6 +46,7 @@ public class RainbowName {
public void enable () {
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
if (networkHandler == null) return;
final GameProfile profile = networkHandler.getProfile();
final String username = RandomUtilities.emptyUsername(random);
@ -60,6 +62,10 @@ public class RainbowName {
public void disable () {
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
if (networkHandler == null) {
enabled = false;
return;
}
final GameProfile profile = networkHandler.getProfile();
CommandCore.INSTANCE.run("essentials:nick " + profile.getId() + " off");
@ -68,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();
@ -86,15 +87,15 @@ 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("\u00a7#").append(color).append(character != ' ' ? character : '_');
essentialsNickname.append("§#").append(color).append(character != ' ' ? character : '_');
hue = (hue + increment) % 360;
}
@ -102,8 +103,8 @@ public class RainbowName {
CommandCore.INSTANCE.run("essentials:nick " + profile.getId() + " " + essentialsNickname);
startHue = (startHue + increment) % 360;
} catch (Exception e) {
e.printStackTrace();
} catch (final Exception e) {
ChipmunkMod.LOGGER.error("Error while ticking rainbow name", e);
}
}

View file

@ -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;
@ -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;
@ -108,13 +102,16 @@ 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 () {
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
if (networkHandler == null) return;
if (!cspy && cspyEnabled) {
if (serverHasCommand("c")) networkHandler.sendChatCommand("c on");
} else if (!hasSkin && !skin.equals("off")) {
@ -123,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();

View file

@ -25,35 +25,33 @@ import java.util.TimerTask;
public class SongPlayer {
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<Song> 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();
}
}

View file

@ -1,11 +0,0 @@
package land.chipmunk.chipmunkmod.modules;
public class TransactionManager {
public static final TransactionManager INSTANCE = new TransactionManager();
private int transactionId = 0;
public int transactionId () { return transactionId; }
public int nextTransactionId () { return transactionId++; }
}

View file

@ -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()) {

View file

@ -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];
}
}

View file

@ -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,155 +16,13 @@ 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<MidiEvent> 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<Integer, Instrument[]> instrumentMap = new HashMap<>();
public static HashMap<Integer, Integer> percussionMap = new HashMap<>();
static {
// Piano (HARP BASS BELL)
@ -314,8 +176,6 @@ public class MidiConverter {
instrumentMap.put(119, new Instrument[] { Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE });
}
public static HashMap<Integer, Integer> 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<MidiEvent> 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;
}
}

View file

@ -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<NBSNote> 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<NBSLayer> 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<NBSCustomInstrument> 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<NBSNote> 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<NBSLayer> 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<NBSCustomInstrument> 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;
}
}

View file

@ -10,7 +10,7 @@ public class Note implements Comparable<Note> {
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<Note> {
}
@Override
public int compareTo(Note other) {
public int compareTo (final Note other) {
return Long.compare(time, other.time);
}
}

View file

@ -18,19 +18,19 @@ 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);
}
@ -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;

View file

@ -5,12 +5,12 @@ 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;
}

View file

@ -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;
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);
}
}

View file

@ -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,15 +78,16 @@ 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();
@ -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();
}

View file

@ -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;
}
}

View file

@ -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");
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;
}
}
}

View file

@ -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);
}
}

View file

@ -12,7 +12,7 @@ public final class RandomUtilities {
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) {

View file

@ -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();

View file

@ -9,7 +9,7 @@ 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()
@ -18,7 +18,7 @@ public class TextUtilities {
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();
}

View file

@ -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) + "}]"; }
}

View file

@ -10,11 +10,10 @@ import org.spongepowered.configurate.serialize.TypeSerializer;
import java.lang.reflect.Type;
public class BlockBoxTypeSerializer implements TypeSerializer<BlockBox> {
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 () {
}

View file

@ -9,12 +9,11 @@ import org.spongepowered.configurate.serialize.TypeSerializer;
import java.lang.reflect.Type;
public class BlockPosTypeSerializer implements TypeSerializer<BlockPos> {
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 () {
}

View file

@ -11,8 +11,8 @@ import org.spongepowered.configurate.serialize.TypeSerializer;
import java.lang.reflect.Type;
public class ComponentTypeSerializer implements TypeSerializer<Component> {
private static final GsonComponentSerializer GSON = GsonComponentSerializer.gson();
public static final ComponentTypeSerializer INSTANCE = new ComponentTypeSerializer();
private static final GsonComponentSerializer GSON = GsonComponentSerializer.gson();
private ComponentTypeSerializer () {
}