forked from ChomeNS/chipmunkmod
add auto skin
useful for me because i don't need to do /skin popbob every time i join
This commit is contained in:
parent
cc07c2b4d6
commit
6f115eef52
5 changed files with 88 additions and 6 deletions
|
@ -10,6 +10,7 @@ public class Configuration {
|
||||||
public CommandCore core = new CommandCore();
|
public CommandCore core = new CommandCore();
|
||||||
public Bots bots = new Bots();
|
public Bots bots = new Bots();
|
||||||
public CustomChat customChat = new CustomChat();
|
public CustomChat customChat = new CustomChat();
|
||||||
|
public String autoSkinUsername = "off";
|
||||||
|
|
||||||
public static class CommandManager {
|
public static class CommandManager {
|
||||||
public String prefix = ".";
|
public String prefix = ".";
|
||||||
|
|
|
@ -38,6 +38,7 @@ public class CommandManager {
|
||||||
RainbowNameCommand.register(this.dispatcher);
|
RainbowNameCommand.register(this.dispatcher);
|
||||||
SayCommand.register(this.dispatcher);
|
SayCommand.register(this.dispatcher);
|
||||||
SelfCareCommand.register(this.dispatcher);
|
SelfCareCommand.register(this.dispatcher);
|
||||||
|
AutoSkinCommand.register(this.dispatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void executeCommand (String command) {
|
public void executeCommand (String command) {
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
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.text.Text;
|
||||||
|
|
||||||
|
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
|
||||||
|
import static com.mojang.brigadier.arguments.StringArgumentType.string;
|
||||||
|
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) {
|
||||||
|
dispatcher.register(
|
||||||
|
literal("autoskin")
|
||||||
|
.then(
|
||||||
|
argument("username", string()) // i don't think theres an account with space(s)
|
||||||
|
.executes(AutoSkinCommand::execute)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int execute(CommandContext<FabricClientCommandSource> context) {
|
||||||
|
final FabricClientCommandSource source = context.getSource();
|
||||||
|
|
||||||
|
final String username = getString(context, "username");
|
||||||
|
|
||||||
|
SelfCare.INSTANCE.skin(username);
|
||||||
|
|
||||||
|
if (username.equals("off")) source.sendFeedback(Text.literal("Successfully disabled auto skin"));
|
||||||
|
else {
|
||||||
|
SelfCare.INSTANCE.hasSkin(false);
|
||||||
|
source.sendFeedback(Text.literal("Set your auto skin username to: " + username));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package land.chipmunk.chipmunkmod.modules;
|
package land.chipmunk.chipmunkmod.modules;
|
||||||
|
|
||||||
|
import land.chipmunk.chipmunkmod.ChipmunkMod;
|
||||||
import land.chipmunk.chipmunkmod.listeners.Listener;
|
import land.chipmunk.chipmunkmod.listeners.Listener;
|
||||||
import land.chipmunk.chipmunkmod.listeners.ListenerManager;
|
import land.chipmunk.chipmunkmod.listeners.ListenerManager;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
@ -17,20 +18,28 @@ import java.util.TimerTask;
|
||||||
public class SelfCare extends Listener {
|
public class SelfCare extends Listener {
|
||||||
private final MinecraftClient client;
|
private final MinecraftClient client;
|
||||||
@Getter private final long interval;
|
@Getter private final long interval;
|
||||||
|
@Getter private final long chatInterval;
|
||||||
|
|
||||||
@Getter @Setter private boolean opEnabled = true;
|
@Getter @Setter private boolean opEnabled = true;
|
||||||
@Getter @Setter private boolean gamemodeEnabled = true;
|
@Getter @Setter private boolean gamemodeEnabled = true;
|
||||||
@Getter @Setter private boolean cspyEnabled = true;
|
@Getter @Setter private boolean cspyEnabled = true;
|
||||||
|
|
||||||
|
@Getter @Setter private String skin;
|
||||||
|
|
||||||
private boolean cspy = false;
|
private boolean cspy = false;
|
||||||
|
@Getter @Setter private boolean hasSkin = false;
|
||||||
|
|
||||||
private Timer timer = null;
|
private Timer timer = null;
|
||||||
|
private Timer chatTimer = null;
|
||||||
|
|
||||||
public static final SelfCare INSTANCE = new SelfCare(MinecraftClient.getInstance(), 70L);
|
public static final SelfCare INSTANCE = new SelfCare(MinecraftClient.getInstance(), 70L, 500L); // make the intervals in config?
|
||||||
|
|
||||||
public SelfCare (MinecraftClient client, long interval) {
|
public SelfCare (MinecraftClient client, long interval, long chatInterval) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.interval = interval;
|
this.interval = interval;
|
||||||
|
this.chatInterval = chatInterval;
|
||||||
|
|
||||||
|
this.skin = ChipmunkMod.CONFIG.autoSkinUsername == null ? "off" : ChipmunkMod.CONFIG.autoSkinUsername; // can this be null?
|
||||||
|
|
||||||
ListenerManager.addListener(this);
|
ListenerManager.addListener(this);
|
||||||
}
|
}
|
||||||
|
@ -42,18 +51,34 @@ public class SelfCare extends Listener {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (timer != null) cleanup();
|
final TimerTask chatTask = new TimerTask() {
|
||||||
|
public void run () {
|
||||||
|
chatTick();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (timer != null || chatTimer != null) cleanup();
|
||||||
|
|
||||||
timer = new Timer();
|
timer = new Timer();
|
||||||
|
chatTimer = new Timer();
|
||||||
|
|
||||||
timer.schedule(task, interval, interval);
|
timer.schedule(task, interval, interval);
|
||||||
|
chatTimer.schedule(chatTask, chatInterval, chatInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cleanup () {
|
public void cleanup () {
|
||||||
if (timer == null) return;
|
if (timer == null || chatTimer == null) return;
|
||||||
|
|
||||||
timer.cancel();
|
timer.cancel();
|
||||||
timer.purge();
|
timer.purge();
|
||||||
timer = null;
|
timer = null;
|
||||||
|
|
||||||
|
chatTimer.cancel();
|
||||||
|
chatTimer.purge();
|
||||||
|
chatTimer = null;
|
||||||
|
|
||||||
|
hasSkin = false;
|
||||||
|
// cspy too mabe?
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -62,6 +87,12 @@ public class SelfCare extends Listener {
|
||||||
|
|
||||||
if (stringMessage.equals("Successfully enabled CommandSpy")) cspy = true;
|
if (stringMessage.equals("Successfully enabled CommandSpy")) cspy = true;
|
||||||
else if (stringMessage.equals("Successfully disabled CommandSpy")) cspy = false;
|
else if (stringMessage.equals("Successfully disabled CommandSpy")) cspy = false;
|
||||||
|
|
||||||
|
else if (stringMessage.equals("Successfully set your skin to " + skin + "'s")) hasSkin = true;
|
||||||
|
else if (
|
||||||
|
stringMessage.equals("Successfully removed your skin") ||
|
||||||
|
stringMessage.startsWith("Successfully set your skin to ")
|
||||||
|
) hasSkin = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tick () {
|
public void tick () {
|
||||||
|
@ -75,7 +106,13 @@ public class SelfCare extends Listener {
|
||||||
|
|
||||||
if (player != null && !player.hasPermissionLevel(2) && opEnabled) { if (serverHasCommand("op")) networkHandler.sendChatCommand("op @s[type=player]"); }
|
if (player != null && !player.hasPermissionLevel(2) && opEnabled) { if (serverHasCommand("op")) networkHandler.sendChatCommand("op @s[type=player]"); }
|
||||||
else if (client.player != null && !client.player.isCreative() && gamemodeEnabled) networkHandler.sendChatCommand("gamemode creative");
|
else if (client.player != null && !client.player.isCreative() && gamemodeEnabled) networkHandler.sendChatCommand("gamemode creative");
|
||||||
else if (!cspy && cspyEnabled) { if (serverHasCommand("c")) networkHandler.sendChatCommand("c on"); }
|
}
|
||||||
|
|
||||||
|
public void chatTick () {
|
||||||
|
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
||||||
|
|
||||||
|
if (!cspy && cspyEnabled) { if (serverHasCommand("c")) networkHandler.sendChatCommand("c on"); }
|
||||||
|
else if (!hasSkin && !skin.equals("off")) { if (serverHasCommand("skin")) networkHandler.sendChatCommand("skin " + skin); }
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Move this into a separate class related to server info gathering (and yes, I plan on making this d y n a m i c and require little to no configuration for most servers)
|
// TODO: Move this into a separate class related to server info gathering (and yes, I plan on making this d y n a m i c and require little to no configuration for most servers)
|
||||||
|
|
|
@ -30,5 +30,7 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
|
||||||
|
"autoSkinUsername": "off"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue