mirror of
https://code.chipmunk.land/ChomeNS/chipmunkmod.git
synced 2025-11-13 22:16:14 +00:00
Compare commits
No commits in common. "3e05e6b89d997e5afa2be87965f2d3073ab53fe7" and "c9594fe2483af69848d0811ad7cb2bab2c77947c" have entirely different histories.
3e05e6b89d
...
c9594fe248
5 changed files with 44 additions and 47 deletions
|
|
@ -37,9 +37,17 @@ public class SelfCareCommand {
|
|||
.executes(m -> setSelfCare(m, "cspy"))
|
||||
)
|
||||
)
|
||||
.then(
|
||||
literal("icu")
|
||||
.then(
|
||||
argument("boolean", bool())
|
||||
.executes(m -> setSelfCare(m, "icu"))
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// setSelfCare is probably not a good name for this
|
||||
public static int setSelfCare (CommandContext<FabricClientCommandSource> context, String type) {
|
||||
final FabricClientCommandSource source = context.getSource();
|
||||
final boolean bool = getBool(context, "boolean");
|
||||
|
|
@ -57,6 +65,10 @@ public class SelfCareCommand {
|
|||
SelfCare.INSTANCE.cspyEnabled = bool;
|
||||
source.sendFeedback(Text.literal("The CommandSpy self care is now " + (bool ? "enabled" : "disabled")));
|
||||
}
|
||||
case "icu" -> {
|
||||
SelfCare.INSTANCE.icuEnabled = bool;
|
||||
source.sendFeedback(Text.literal("The iControlU self care is now " + (bool ? "enabled" : "disabled")));
|
||||
}
|
||||
}
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
|
|
|
|||
|
|
@ -5,10 +5,8 @@ import net.minecraft.text.Text;
|
|||
|
||||
public interface Listener {
|
||||
default void packetReceived (Packet<?> packet) {}
|
||||
default void packetSent (Packet<?> packet) {}
|
||||
|
||||
default void chatMessageReceived (Text message) {}
|
||||
default void overlayMessageReceived (Text message) {}
|
||||
default void packetSent (Packet<?> packet) {}
|
||||
|
||||
default void coreReady () {}
|
||||
default void coreMoved () {}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ 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.Text;
|
||||
|
|
@ -86,24 +85,13 @@ public class ClientPlayNetworkHandlerMixin {
|
|||
if (message.getSiblings().size() > 1) {
|
||||
final String suggestionId = message.getSiblings().getFirst().getString();
|
||||
|
||||
if (suggestionId.equals(ChomeNSBotCommandSuggestions.REQUEST_SUGGESTIONS_ID)) {
|
||||
if (suggestionId.equals(ChomeNSBotCommandSuggestions.ID)) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
@Inject(method = "onOverlayMessage", at = @At("TAIL"))
|
||||
private void onOverlayMessage(OverlayMessageS2CPacket packet, CallbackInfo ci) {
|
||||
for (Listener listener : ListenerManager.listeners) {
|
||||
listener.overlayMessageReceived(packet.text());
|
||||
}
|
||||
|
||||
// checking for the bot selector message doesn't really
|
||||
// do much here since the message is just an empty string,
|
||||
// so I do not ignore them
|
||||
}
|
||||
|
||||
@Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true)
|
||||
private void sendChatMessage(String chatText, CallbackInfo ci) {
|
||||
final CommandManager commandManager = CommandManager.INSTANCE;
|
||||
|
|
|
|||
|
|
@ -9,15 +9,13 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
|||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableTextContent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ChomeNSBotCommandSuggestions implements Listener {
|
||||
public static final String BOT_SELECTOR_ID = "chomens_bot_selector";
|
||||
public static final String REQUEST_SUGGESTIONS_ID = "chomens_bot_request_command_suggestion";
|
||||
public static final String ID = "chomens_bot_request_command_suggestion";
|
||||
|
||||
public static ChomeNSBotCommandSuggestions INSTANCE = new ChomeNSBotCommandSuggestions(MinecraftClient.getInstance());
|
||||
|
||||
|
|
@ -25,8 +23,6 @@ public class ChomeNSBotCommandSuggestions implements Listener {
|
|||
|
||||
public boolean receivedSuggestions = false; // can be set through eval
|
||||
|
||||
public String botSelector = null;
|
||||
|
||||
public List<ChomeNSBotCommand> commands = new ArrayList<>();
|
||||
|
||||
public ChomeNSBotCommandSuggestions (MinecraftClient client) {
|
||||
|
|
@ -45,39 +41,17 @@ public class ChomeNSBotCommandSuggestions implements Listener {
|
|||
public void forceRequest () {
|
||||
final ClientPlayerEntity player = client.player;
|
||||
|
||||
if (botSelector == null || player == null) return;
|
||||
if (player == null) return;
|
||||
|
||||
final String selector = UUIDUtilities.selector(player.getUuid());
|
||||
|
||||
final Component component = Component
|
||||
.text(REQUEST_SUGGESTIONS_ID)
|
||||
.text(ID)
|
||||
.append(Component.text(selector));
|
||||
|
||||
final String serialized = GsonComponentSerializer.gson().serialize(component);
|
||||
|
||||
// minecraft:tellraw @p[nbt={UUID:[I;6,9,6,9]} {...}
|
||||
CommandCore.INSTANCE.run(
|
||||
String.format(
|
||||
"%s %s %s",
|
||||
(KaboomCheck.INSTANCE.isKaboom ? "minecraft:tellraw" : "tellraw"),
|
||||
botSelector,
|
||||
serialized
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void overlayMessageReceived (Text message) {
|
||||
if (
|
||||
!(message.getContent() instanceof TranslatableTextContent translatableTextContent)
|
||||
|| !translatableTextContent.getKey().isEmpty()
|
||||
|| translatableTextContent.getArgs().length != 2
|
||||
|| !(translatableTextContent.getArgs()[0] instanceof String id)
|
||||
|| !id.equals(BOT_SELECTOR_ID)
|
||||
|| !(translatableTextContent.getArgs()[1] instanceof String selector)
|
||||
) return;
|
||||
|
||||
this.botSelector = selector;
|
||||
CommandCore.INSTANCE.run((KaboomCheck.INSTANCE.isKaboom ? "minecraft:tellraw " : "tellraw ") + "@a[team=chomens_bot] " + serialized);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -86,7 +60,7 @@ public class ChomeNSBotCommandSuggestions implements Listener {
|
|||
if (children.isEmpty()) return;
|
||||
|
||||
final Text textComponent = children.getFirst();
|
||||
if (!textComponent.getString().equals(REQUEST_SUGGESTIONS_ID)) return;
|
||||
if (!textComponent.getString().equals(ID)) return;
|
||||
|
||||
commands = children.stream()
|
||||
.skip(1)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import net.minecraft.client.network.ClientPlayerEntity;
|
|||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.GameStateChangeS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import java.util.Timer;
|
||||
|
|
@ -24,6 +25,7 @@ public class SelfCare implements Listener {
|
|||
public boolean opEnabled = true;
|
||||
public boolean gamemodeEnabled = true;
|
||||
public boolean cspyEnabled = true;
|
||||
public boolean icuEnabled = true;
|
||||
|
||||
private int gameMode;
|
||||
|
||||
|
|
@ -31,10 +33,13 @@ public class SelfCare implements Listener {
|
|||
|
||||
private Timer timer;
|
||||
private Timer chatTimer;
|
||||
private Timer icuTimer;
|
||||
|
||||
private boolean cspy = false;
|
||||
public boolean hasSkin = false;
|
||||
|
||||
private int positionPacketsPerSecond = 0;
|
||||
|
||||
public static final SelfCare INSTANCE = new SelfCare(MinecraftClient.getInstance(), 70L, 500L); // make the intervals in config?
|
||||
|
||||
public SelfCare(MinecraftClient client, long interval, long chatInterval) {
|
||||
|
|
@ -63,11 +68,20 @@ public class SelfCare implements Listener {
|
|||
}
|
||||
};
|
||||
|
||||
final TimerTask icuTask = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
positionPacketsPerSecond = 0;
|
||||
}
|
||||
};
|
||||
|
||||
timer = new Timer();
|
||||
chatTimer = new Timer();
|
||||
icuTimer = new Timer();
|
||||
|
||||
timer.schedule(task, interval, interval);
|
||||
chatTimer.schedule(chatTask, chatInterval, chatInterval);
|
||||
icuTimer.schedule(icuTask, 1000L, 1000L);
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
|
|
@ -79,6 +93,9 @@ public class SelfCare implements Listener {
|
|||
chatTimer.cancel();
|
||||
chatTimer.purge();
|
||||
|
||||
icuTimer.cancel();
|
||||
icuTimer.purge();
|
||||
|
||||
gameMode = -1;
|
||||
|
||||
hasSkin = false;
|
||||
|
|
@ -110,6 +127,7 @@ public class SelfCare implements Listener {
|
|||
|
||||
if (player != null && !player.hasPermissionLevel(2) && opEnabled && serverHasCommand("op")) networkHandler.sendChatCommand("op @s[type=player]");
|
||||
else if (gameMode != 1 && gamemodeEnabled) networkHandler.sendChatCommand("gamemode creative");
|
||||
else if (positionPacketsPerSecond >= 10 && icuEnabled) CommandCore.INSTANCE.run("sudo * icu stop");
|
||||
}
|
||||
|
||||
public void chatTick() {
|
||||
|
|
@ -126,6 +144,7 @@ public class SelfCare implements Listener {
|
|||
public void packetReceived(Packet<?> packet) {
|
||||
if (packet instanceof GameJoinS2CPacket) packetReceived((GameJoinS2CPacket) packet);
|
||||
else if (packet instanceof GameStateChangeS2CPacket) packetReceived((GameStateChangeS2CPacket) packet);
|
||||
else if (packet instanceof PlayerPositionLookS2CPacket) packetReceived((PlayerPositionLookS2CPacket) packet);
|
||||
}
|
||||
|
||||
public void packetReceived(GameJoinS2CPacket packet) {
|
||||
|
|
@ -137,4 +156,10 @@ public class SelfCare implements Listener {
|
|||
|
||||
gameMode = (int) packet.getValue();
|
||||
}
|
||||
|
||||
public void packetReceived(PlayerPositionLookS2CPacket packet) {
|
||||
if (timer == null) return;
|
||||
|
||||
positionPacketsPerSecond++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue