mirror of
https://code.chipmunk.land/ChomeNS/chipmunkmod.git
synced 2025-11-14 02:46:27 +00:00
Compare commits
No commits in common. "cebe2629df63c8ae4ba69e4a9c73c1ee8b1039fc" and "00d3be834268c83c2c5bd981dd74707e37819132" have entirely different histories.
cebe2629df
...
00d3be8342
9 changed files with 10 additions and 79 deletions
|
|
@ -29,13 +29,6 @@ public class CustomChatCommand {
|
||||||
.executes(CustomChatCommand::enabled)
|
.executes(CustomChatCommand::enabled)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.then(
|
|
||||||
literal("onlyUseWhenNecessary")
|
|
||||||
.then(
|
|
||||||
argument("boolean", bool())
|
|
||||||
.executes(CustomChatCommand::onlyUseWhenNecessary)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.then(
|
.then(
|
||||||
literal("format")
|
literal("format")
|
||||||
.then(
|
.then(
|
||||||
|
|
@ -55,17 +48,6 @@ public class CustomChatCommand {
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int onlyUseWhenNecessary (final CommandContext<FabricClientCommandSource> context) {
|
|
||||||
final FabricClientCommandSource source = context.getSource();
|
|
||||||
final boolean bool = getBool(context, "boolean");
|
|
||||||
CustomChat.INSTANCE.onlyUseWhenNecessary = bool;
|
|
||||||
|
|
||||||
if (bool) source.sendFeedback(Text.literal("Custom chat now only gets used when necessary"));
|
|
||||||
else source.sendFeedback(Text.literal("Custom chat now always get used"));
|
|
||||||
|
|
||||||
return Command.SINGLE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int setFormat (final CommandContext<FabricClientCommandSource> context) {
|
public static int setFormat (final CommandContext<FabricClientCommandSource> context) {
|
||||||
final FabricClientCommandSource source = context.getSource();
|
final FabricClientCommandSource source = context.getSource();
|
||||||
final String format = getString(context, "format");
|
final String format = getString(context, "format");
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import com.mojang.brigadier.CommandDispatcher;
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
import land.chipmunk.chipmunkmod.ChipmunkMod;
|
import land.chipmunk.chipmunkmod.ChipmunkMod;
|
||||||
import land.chipmunk.chipmunkmod.modules.CommandCore;
|
import land.chipmunk.chipmunkmod.modules.CommandCore;
|
||||||
import land.chipmunk.chipmunkmod.modules.custom_chat.CustomChat;
|
|
||||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
|
@ -26,14 +25,12 @@ public class ReloadConfigCommand {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ChipmunkMod.CONFIG = ChipmunkMod.loadConfig();
|
ChipmunkMod.CONFIG = ChipmunkMod.loadConfig();
|
||||||
|
|
||||||
CommandCore.INSTANCE.reloadRelativeArea();
|
CommandCore.INSTANCE.reloadRelativeArea();
|
||||||
CustomChat.INSTANCE.reloadFromConfig();
|
|
||||||
|
|
||||||
source.sendFeedback(Text.literal("Successfully reloaded the config"));
|
source.sendFeedback(Text.literal("Successfully reloaded the config"));
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
source.sendError(Text.literal("Could not load config, check the logs for stacktrace"));
|
source.sendError(Text.literal("Could not load config, check the logs for stacktrace"));
|
||||||
ChipmunkMod.LOGGER.error("Could not load the config!", e);
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
|
|
|
||||||
|
|
@ -79,9 +79,6 @@ public class Configuration {
|
||||||
|
|
||||||
@ConfigSerializable
|
@ConfigSerializable
|
||||||
public static class CustomChat {
|
public static class CustomChat {
|
||||||
public boolean enabled = true;
|
|
||||||
public boolean onlyUseWhenNecessary = false;
|
|
||||||
|
|
||||||
public @NotNull Component format =
|
public @NotNull Component format =
|
||||||
// chipmunk's custom chat format
|
// chipmunk's custom chat format
|
||||||
// §8[§7Chat§8] §aUSERNAME§8 › §7MESSAGE
|
// §8[§7Chat§8] §aUSERNAME§8 › §7MESSAGE
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import org.spongepowered.configurate.transformation.TransformAction;
|
||||||
|
|
||||||
import static org.spongepowered.configurate.NodePath.path;
|
import static org.spongepowered.configurate.NodePath.path;
|
||||||
|
|
||||||
public final class MigrationV2 implements ConfigMigration {
|
public class MigrationV2 implements ConfigMigration {
|
||||||
@Override
|
@Override
|
||||||
public int version () {
|
public int version () {
|
||||||
return 2;
|
return 2;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import org.spongepowered.configurate.transformation.TransformAction;
|
||||||
|
|
||||||
import static org.spongepowered.configurate.NodePath.path;
|
import static org.spongepowered.configurate.NodePath.path;
|
||||||
|
|
||||||
public final class MigrationV3 implements ConfigMigration {
|
public class MigrationV3 implements ConfigMigration {
|
||||||
@Override
|
@Override
|
||||||
public int version () {
|
public int version () {
|
||||||
return 3;
|
return 3;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package land.chipmunk.chipmunkmod.mixin;
|
package land.chipmunk.chipmunkmod.mixin;
|
||||||
|
|
||||||
import land.chipmunk.chipmunkmod.modules.custom_chat.CustomChat;
|
|
||||||
import net.minecraft.util.StringHelper;
|
import net.minecraft.util.StringHelper;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
|
@ -11,11 +10,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
public class StringHelperMixin {
|
public class StringHelperMixin {
|
||||||
@Inject(method = "isValidChar", at = @At("RETURN"), cancellable = true)
|
@Inject(method = "isValidChar", at = @At("RETURN"), cancellable = true)
|
||||||
private static void isValidChar (final char c, final CallbackInfoReturnable<Boolean> cir) {
|
private static void isValidChar (final char c, final CallbackInfoReturnable<Boolean> cir) {
|
||||||
if (!CustomChat.SHOULD_IGNORE_INVALID_CHAR.get()) {
|
|
||||||
CustomChat.SHOULD_IGNORE_INVALID_CHAR.set(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// very legal [NUL] [LF] § Allowance.
|
// very legal [NUL] [LF] § Allowance.
|
||||||
cir.setReturnValue(true);
|
cir.setReturnValue(true);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,7 @@ import net.minecraft.state.property.Property;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.util.Util;
|
||||||
import net.minecraft.util.hit.BlockHitResult;
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
import net.minecraft.util.math.BlockBox;
|
import net.minecraft.util.math.*;
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.Direction;
|
|
||||||
import net.minecraft.util.math.Vec3d;
|
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
import net.minecraft.world.dimension.DimensionType;
|
import net.minecraft.world.dimension.DimensionType;
|
||||||
|
|
||||||
|
|
@ -454,7 +451,7 @@ public class CommandCore implements Listener {
|
||||||
for (final Property<?> property : oldBlockState.getProperties()) {
|
for (final Property<?> property : oldBlockState.getProperties()) {
|
||||||
command.append(property.getName())
|
command.append(property.getName())
|
||||||
.append('=')
|
.append('=')
|
||||||
.append(Util.getValueAsString(property, property.getValues().getLast())) // water[level=15] instead of water[level=0,level=1,....,level=15]
|
.append(Util.getValueAsString(property, property.getType()))
|
||||||
.append(',');
|
.append(',');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,16 +62,7 @@ public class SelfCare implements Listener {
|
||||||
else if (!player.isInCreativeMode() && gamemodeEnabled)
|
else if (!player.isInCreativeMode() && gamemodeEnabled)
|
||||||
networkHandler.sendChatCommand("gamemode creative");
|
networkHandler.sendChatCommand("gamemode creative");
|
||||||
else if (!cspy && cspyEnabled && serverHasCommand("c"))
|
else if (!cspy && cspyEnabled && serverHasCommand("c"))
|
||||||
if (
|
|
||||||
!CommandCore.INSTANCE.ready
|
|
||||||
|| !CommandCore.INSTANCE.runFillCommand
|
|
||||||
|| !player.isInCreativeMode()
|
|
||||||
|| !player.hasPermissionLevel(2)
|
|
||||||
) {
|
|
||||||
networkHandler.sendChatCommand("c on");
|
networkHandler.sendChatCommand("c on");
|
||||||
} else {
|
|
||||||
CommandCore.INSTANCE.run("c " + player.getUuidAsString() + " on");
|
|
||||||
}
|
|
||||||
else if (!hasSkin && !skin.equalsIgnoreCase("off"))
|
else if (!hasSkin && !skin.equalsIgnoreCase("off"))
|
||||||
networkHandler.sendChatCommand("skin " + skin);
|
networkHandler.sendChatCommand("skin " + skin);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.network.ClientPlayerEntity;
|
import net.minecraft.client.network.ClientPlayerEntity;
|
||||||
import net.minecraft.util.StringHelper;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
@ -52,30 +51,19 @@ public class CustomChat {
|
||||||
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static final ThreadLocal<Boolean> SHOULD_IGNORE_INVALID_CHAR = ThreadLocal.withInitial(() -> true);
|
|
||||||
|
|
||||||
private final MinecraftClient client;
|
private final MinecraftClient client;
|
||||||
|
public boolean enabled = true;
|
||||||
|
|
||||||
public boolean enabled;
|
public Component format = ChipmunkMod.CONFIG.customChat.format;
|
||||||
public boolean onlyUseWhenNecessary;
|
|
||||||
|
|
||||||
public Component format;
|
|
||||||
|
|
||||||
public CustomChat (final MinecraftClient client) {
|
public CustomChat (final MinecraftClient client) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
reloadFromConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reloadFromConfig () {
|
|
||||||
this.format = ChipmunkMod.CONFIG.customChat.format;
|
|
||||||
this.enabled = ChipmunkMod.CONFIG.customChat.enabled;
|
|
||||||
this.onlyUseWhenNecessary = ChipmunkMod.CONFIG.customChat.onlyUseWhenNecessary;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void chat (final String message) {
|
public void chat (final String message) {
|
||||||
final ClientPlayerEntity player = client.player;
|
final ClientPlayerEntity player = client.player;
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
if (shouldUsePlayerChat(player, message)) {
|
if (!enabled || !player.hasPermissionLevel(2) || !player.isCreative()) {
|
||||||
Chat.sendChatMessage(message, true);
|
Chat.sendChatMessage(message, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -92,19 +80,4 @@ public class CustomChat {
|
||||||
|
|
||||||
CommandCore.INSTANCE.run((KaboomCheck.INSTANCE.isKaboom ? "minecraft:tellraw @a " : "tellraw @a ") + json);
|
CommandCore.INSTANCE.run((KaboomCheck.INSTANCE.isKaboom ? "minecraft:tellraw @a " : "tellraw @a ") + json);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldUsePlayerChat (final ClientPlayerEntity player, final String message) {
|
|
||||||
return !enabled || isUnnecessary(message) || !player.hasPermissionLevel(2) || !player.isCreative();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isUnnecessary (final String message) {
|
|
||||||
if (!onlyUseWhenNecessary || message.isEmpty() || message.length() > 256) return false;
|
|
||||||
|
|
||||||
for (final char character : message.toCharArray()) {
|
|
||||||
SHOULD_IGNORE_INVALID_CHAR.set(false);
|
|
||||||
if (!StringHelper.isValidChar(character)) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue