mirror of
https://code.chipmunk.land/ChomeNS/chipmunkmod.git
synced 2026-03-30 22:51:58 +00:00
Compare commits
2 commits
590b954c30
...
dda3b525a0
| Author | SHA1 | Date | |
|---|---|---|---|
| dda3b525a0 | |||
| 6dc1c26a85 |
8 changed files with 90 additions and 7 deletions
|
|
@ -39,6 +39,7 @@ public class CommandManager {
|
|||
ReloadConfigCommand.register(this.dispatcher);
|
||||
SelfCareCommand.register(this.dispatcher);
|
||||
PrefixCommand.register(this.dispatcher);
|
||||
AutoPrefixCommand.register(this.dispatcher);
|
||||
}
|
||||
|
||||
public static LiteralArgumentBuilder<FabricClientCommandSource> literal (final String name) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
package land.chipmunk.chipmunkmod.commands;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import land.chipmunk.chipmunkmod.modules.SelfCare;
|
||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
import static com.mojang.brigadier.arguments.StringArgumentType.*;
|
||||
import static land.chipmunk.chipmunkmod.command.CommandManager.argument;
|
||||
import static land.chipmunk.chipmunkmod.command.CommandManager.literal;
|
||||
|
||||
|
||||
public class AutoPrefixCommand {
|
||||
public static void register (final CommandDispatcher<FabricClientCommandSource> dispatcher) {
|
||||
dispatcher.register(
|
||||
literal("autoprefix")
|
||||
.then(
|
||||
argument("prefix", greedyString())
|
||||
.executes(AutoPrefixCommand::execute)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static int execute (final CommandContext<FabricClientCommandSource> context) {
|
||||
final FabricClientCommandSource source = context.getSource();
|
||||
|
||||
final String prefix = getString(context, "prefix");
|
||||
|
||||
SelfCare.INSTANCE.targetPrefix = prefix;
|
||||
|
||||
if (prefix.equalsIgnoreCase("off")) {
|
||||
source.sendFeedback(Component.literal("Successfully disabled auto prefix"));
|
||||
} else {
|
||||
SelfCare.INSTANCE.hasPrefix = false;
|
||||
source.sendFeedback(Component.literal("Set your prefix to: " + prefix));
|
||||
}
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
|
@ -30,7 +30,7 @@ public class AutoSkinCommand {
|
|||
|
||||
SelfCare.INSTANCE.targetSkin = username;
|
||||
|
||||
if (username.equals("off")) {
|
||||
if (username.equalsIgnoreCase("off")) {
|
||||
source.sendFeedback(Component.literal("Successfully disabled auto skin"));
|
||||
} else {
|
||||
SelfCare.INSTANCE.hasSkin = false;
|
||||
|
|
|
|||
|
|
@ -12,5 +12,6 @@ public final class ChipmunkModMigrations extends AbstractMigrationManager {
|
|||
this.register(new MigrationV2());
|
||||
this.register(new MigrationV3());
|
||||
this.register(new MigrationV4());
|
||||
this.register(new MigrationV5());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ public class Configuration {
|
|||
public CustomChat customChat = new CustomChat();
|
||||
public SelfCare selfCare = new SelfCare();
|
||||
public String autoSkinUsername = "off";
|
||||
public String autoPrefix = "off";
|
||||
|
||||
@ConfigSerializable
|
||||
public static class CommandManager {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
package land.chipmunk.chipmunkmod.config.migrations;
|
||||
|
||||
import land.chipmunk.chipmunkmod.config.migration.ConfigMigration;
|
||||
import org.spongepowered.configurate.transformation.ConfigurationTransformation;
|
||||
import org.spongepowered.configurate.transformation.TransformAction;
|
||||
|
||||
import static org.spongepowered.configurate.NodePath.path;
|
||||
|
||||
public final class MigrationV5 implements ConfigMigration {
|
||||
@Override
|
||||
public int version () {
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurationTransformation create () {
|
||||
return ConfigurationTransformation.builder()
|
||||
.addAction(path("autoPrefix"), TransformAction.set(String.class, () -> "off"))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
@ -181,7 +181,7 @@ public class CommandCore implements Listener {
|
|||
if (world == null || noPos == null) return;
|
||||
|
||||
// also delete the old core
|
||||
if (withPos != null) {
|
||||
if (withPos != null && !isSingleBlock) {
|
||||
pendingCommands.add(
|
||||
String.format(
|
||||
"fill %d %d %d %d %d %d air",
|
||||
|
|
@ -246,7 +246,7 @@ public class CommandCore implements Listener {
|
|||
if (player == null || connection == null) return;
|
||||
|
||||
final int distanceSquared = player.chunkPosition().distanceSquared(new ChunkPos(origin));
|
||||
final int distance = (int) Math.sqrt(distanceSquared);
|
||||
final int distance = (int) Math.sqrt(Math.abs(distanceSquared));
|
||||
|
||||
final int simulationDistance = connection.getLevel().getServerSimulationDistance();
|
||||
|
||||
|
|
|
|||
|
|
@ -28,12 +28,16 @@ public class SelfCare implements Listener {
|
|||
public String targetSkin;
|
||||
public boolean hasSkin = false;
|
||||
|
||||
public String targetPrefix;
|
||||
public boolean hasPrefix = false;
|
||||
|
||||
private boolean isCommandSpyEnabled = false;
|
||||
|
||||
public SelfCare (final Minecraft client) {
|
||||
this.client = client;
|
||||
|
||||
this.targetSkin = ChipmunkMod.CONFIG.autoSkinUsername == null ? "off" : ChipmunkMod.CONFIG.autoSkinUsername;
|
||||
this.targetPrefix = ChipmunkMod.CONFIG.autoPrefix == null ? "off" : ChipmunkMod.CONFIG.autoPrefix;
|
||||
|
||||
ListenerManager.addListener(this);
|
||||
}
|
||||
|
|
@ -43,6 +47,7 @@ public class SelfCare implements Listener {
|
|||
|
||||
public void cleanup () {
|
||||
hasSkin = false;
|
||||
hasPrefix = false;
|
||||
isCommandSpyEnabled = false;
|
||||
}
|
||||
|
||||
|
|
@ -55,9 +60,18 @@ public class SelfCare implements Listener {
|
|||
|
||||
else if (stringMessage.equals("Successfully set your skin to " + targetSkin + "'s")) hasSkin = true;
|
||||
else if (
|
||||
stringMessage.equals("Successfully removed your skin") ||
|
||||
stringMessage.startsWith("Successfully set your skin to ")
|
||||
stringMessage.equals("Successfully removed your skin")
|
||||
|| stringMessage.startsWith("Successfully set your skin to ")
|
||||
) hasSkin = false;
|
||||
|
||||
else if (
|
||||
stringMessage.equals("You now have the tag: " + targetPrefix)
|
||||
|| stringMessage.equals("Something went wrong while saving the prefix. Please check console.")
|
||||
) hasPrefix = true;
|
||||
else if (
|
||||
stringMessage.startsWith("You no longer have a tag")
|
||||
|| stringMessage.startsWith("You now have the tag: ")
|
||||
) hasPrefix = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -78,7 +92,8 @@ public class SelfCare implements Listener {
|
|||
networkHandler.send(new ServerboundChangeGameModePacket(targetGameMode));
|
||||
} else if (!isCommandSpyEnabled && configCommandSpyEnabled && serverHasCommand("c")) {
|
||||
if (
|
||||
!CommandCore.INSTANCE.ready
|
||||
CommandCore.INSTANCE.isSingleBlock
|
||||
|| !CommandCore.INSTANCE.ready
|
||||
|| !CommandCore.INSTANCE.runFillCommand
|
||||
|| !player.canUseGameMasterBlocks()
|
||||
) {
|
||||
|
|
@ -86,8 +101,10 @@ public class SelfCare implements Listener {
|
|||
} else {
|
||||
CommandCore.INSTANCE.run("c " + player.getStringUUID() + " on");
|
||||
}
|
||||
} else if (!hasSkin && !targetSkin.equalsIgnoreCase("off")) {
|
||||
} else if (!hasSkin && serverHasCommand("skin") && !targetSkin.equalsIgnoreCase("off")) {
|
||||
networkHandler.sendCommand("skin " + targetSkin);
|
||||
} else if (!hasPrefix && serverHasCommand("prefix") && !targetPrefix.equalsIgnoreCase("off")) {
|
||||
networkHandler.sendCommand("prefix " + targetPrefix);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue