Commit the current mod (experimental)

This commit is contained in:
Chipmunk 2023-04-04 10:52:09 -04:00
parent 3935c0f71d
commit 4c6ceaa045
26 changed files with 835 additions and 63 deletions

View file

@ -21,7 +21,7 @@ dependencies {
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
// Fabric API. This is technically optional, but you probably want it anyway. // Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" // modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
// Uncomment the following line to enable the deprecated Fabric API modules. // Uncomment the following line to enable the deprecated Fabric API modules.
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time. // These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.

View file

@ -10,8 +10,8 @@ org.gradle.parallel=true
# Mod Properties # Mod Properties
mod_version = 1.0.0 mod_version = 1.0.0
maven_group = com.example maven_group = land.chipmunk.fabrickaboom
archives_base_name = fabric-example-mod archives_base_name = extras
# Dependencies # Dependencies
fabric_version=0.75.3+1.19.4 fabric_version=0.75.3+1.19.4

View file

@ -0,0 +1,55 @@
package land.chipmunk.kaboomfabric.extras;
import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.minecraft.util.Formatting;
import com.mojang.brigadier.CommandDispatcher;
import land.chipmunk.kaboomfabric.extras.commands.*;
public class Extras implements ModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("extras");
private static final char[] escapeCodes = "0123456789abcdefklmnorx".toCharArray();
@Override
public void onInitialize() {
}
public static void registerCommands (CommandDispatcher dispatcher) {
// CommandBroadcastMM.register(dispatcher);
// CommandBroadcastVanilla.register(dispatcher);
CommandClearChat.register(dispatcher);
CommandConsole.register(dispatcher);
CommandDestroyEntities.register(dispatcher);
CommandEnchantAll.register(dispatcher);
// CommandGetJSON.register(dispatcher);
CommandJumpscare.register(dispatcher);
CommandKaboom.register(dispatcher);
CommandPing.register(dispatcher);
// CommandPrefix.register(dispatcher);
CommandPumpkin.register(dispatcher);
CommandServerInfo.register(dispatcher);
// CommandSkin.register(dispatcher);
CommandSpawn.register(dispatcher);
// CommandSpidey.register(dispatcher);
// CommandTellraw.register(dispatcher);
// CommandUsername.register(dispatcher);
}
public static String parseEscapeSequences (String string) {
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < string.length(); i++) {
char character = string.charAt(i);
if (character == '&' && string.length() > (i + 1) && validateEscapeCode(string.charAt(i + 1))) sb.append(Formatting.FORMATTING_CODE_PREFIX);
else sb.append(character);
}
return sb.toString();
}
public static boolean validateEscapeCode (char c) {
for (char candidate : escapeCodes) if (c == candidate) return true;
return false;
}
}

View file

@ -0,0 +1,36 @@
package land.chipmunk.kaboomfabric.extras.commands;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.tree.LiteralCommandNode;
import static net.minecraft.server.command.CommandManager.literal;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text;
import net.minecraft.text.MutableText;
import net.minecraft.util.Formatting;
import net.minecraft.server.network.ServerPlayerEntity;
public interface CommandClearChat {
static void register (CommandDispatcher dispatcher) {
final LiteralCommandNode node = dispatcher.register(
literal("clearchat")
.requires(source -> source.hasPermissionLevel(2))
.executes(CommandClearChat::clearChatCommand)
);
dispatcher.register(literal("cc").redirect(node));
}
static int clearChatCommand (CommandContext<ServerCommandSource> context) {
final MutableText text = Text.literal("");
for (int i = 0; i < 100; i++) text.append(Text.literal("\n"));
text.append(Text.literal("The chat has been cleared").formatted(Formatting.DARK_GREEN));
for (ServerPlayerEntity player : context.getSource().getServer().getPlayerManager().getPlayerList()) {
player.sendMessage(text);
}
return Command.SINGLE_SUCCESS;
}
}

View file

@ -0,0 +1,40 @@
package land.chipmunk.kaboomfabric.extras.commands;
import land.chipmunk.kaboomfabric.extras.Extras;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.server.command.CommandManager.argument;
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
public interface CommandConsole {
static void register (CommandDispatcher dispatcher) {
dispatcher.register(
literal("console")
.requires(source -> source.hasPermissionLevel(2))
.then(
argument("message", greedyString())
.executes(CommandConsole::consoleCommand)
)
);
}
static int consoleCommand (CommandContext<ServerCommandSource> context) {
// ? Should I optimize this to manually create a ParseResults object, or just not wrap the say command in the first place?
final ServerCommandSource source = context.getSource();
final MinecraftServer server = source.getServer();
final ServerCommandSource console = server.getCommandSource();
final String command = "say " + Extras.parseEscapeSequences(getString(context, "message"));
final CommandManager commandManager = server.getCommandManager();
commandManager.execute(commandManager.getDispatcher().parse(command, source), command);
return Command.SINGLE_SUCCESS;
}
}

View file

@ -0,0 +1,56 @@
package land.chipmunk.kaboomfabric.extras.commands;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.tree.LiteralCommandNode;
import static net.minecraft.server.command.CommandManager.literal;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.MinecraftServer;
import net.minecraft.text.Text;
// Currently broken
public interface CommandDestroyEntities {
static void register (CommandDispatcher dispatcher) {
final LiteralCommandNode node = dispatcher.register(
literal("destroyentities")
.requires(source -> source.hasPermissionLevel(2))
// .executes(CommandDestroyEntities::destroyEntitiesCommand)
);
dispatcher.register(literal("de").redirect(node));
}
static int destroyEntitiesCommand (CommandContext<ServerCommandSource> context) {
final ServerCommandSource source = context.getSource();
final MinecraftServer server = source.getServer();
int entityCount = 0;
int worldCount = 0;
for (ServerWorld world : server.getWorlds()) {
for (Entity entity : world.iterateEntities()) {
if (entity instanceof PlayerEntity) continue;
try {
entity.discard();
entityCount++;
} catch (Exception ignored) {
}
}
worldCount++;
}
source.sendFeedback(
Text.literal("Successfully destroyed ")
.append(Text.literal(String.valueOf(entityCount)))
.append(Text.literal(" entities in "))
.append(Text.literal(String.valueOf(worldCount)))
.append(Text.literal(" worlds")),
true);
return Command.SINGLE_SUCCESS;
}
}

View file

@ -0,0 +1,60 @@
package land.chipmunk.kaboomfabric.extras.commands;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import static net.minecraft.server.command.CommandManager.literal;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.registry.Registries;
import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
public abstract class CommandEnchantAll {
private static final SimpleCommandExceptionType EMPTY_ITEM_EXCEPTION = new SimpleCommandExceptionType(Text.literal("Please hold an item in your hand to enchant it"));
public static void register (CommandDispatcher dispatcher) {
dispatcher.register(
literal("enchantall")
.requires(source -> source.hasPermissionLevel(2))
.executes(CommandEnchantAll::enchantAllCommand)
);
}
public static int enchantAllCommand (CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
final ServerCommandSource source = context.getSource();
final ServerPlayerEntity player = source.getPlayerOrThrow();
final PlayerInventory inventory = player.getInventory();
final NbtList enchantments = new NbtList();
for (Identifier identifier : Registries.ENCHANTMENT.getIds()) {
final NbtCompound enchantment = new NbtCompound();
enchantment.putString("id", identifier.toString());
enchantment.putShort("lvl", (short) 0xFF);
enchantments.add(enchantment);
}
final ItemStack stack = inventory.getStack(inventory.selectedSlot).copy();
if (stack.isEmpty()) throw EMPTY_ITEM_EXCEPTION.create();
NbtCompound nbt = stack.getNbt();
if (nbt == null) {
nbt = new NbtCompound();
stack.setNbt(nbt);
}
stack.getNbt().put("Enchantments", enchantments);
inventory.setStack(inventory.selectedSlot, stack);
source.sendFeedback(Text.literal("I killed Martin."), false);
return Command.SINGLE_SUCCESS;
}
}

View file

@ -0,0 +1,68 @@
package land.chipmunk.kaboomfabric.extras.commands;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.LiteralCommandNode;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.command.argument.EntityArgumentType.players;
import static net.minecraft.command.argument.EntityArgumentType.getPlayers;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.math.Vec3d;
import net.minecraft.text.Text;
import java.util.Collection;
public interface CommandJumpscare {
static void register (CommandDispatcher dispatcher) {
final LiteralCommandNode node = dispatcher.register(
literal("jumpscare")
.requires(source -> source.hasPermissionLevel(2))
.then(
argument("targets", players())
.executes(CommandJumpscare::jumpscareCommand)
)
);
dispatcher.register(literal("scare").redirect(node));
}
static int jumpscareCommand (CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
final ServerCommandSource source = context.getSource();
final Collection<ServerPlayerEntity> players = getPlayers(context, "targets");
final ParticleEffect particle = (ParticleEffect) Registries.PARTICLE_TYPE.get(new Identifier("minecraft", "elder_guardian"));
final SoundEvent soundEvent = Registries.SOUND_EVENT.get(new Identifier("minecraft", "entity.enderman.scream"));
for (ServerPlayerEntity player : players) {
final ServerWorld world = player.getWorld();
final Vec3d position = player.getPos();
world.<ParticleEffect>spawnParticles(player, particle, false, position.getX(), position.getY(), position.getZ(), 4, 0, 0, 0, 1);
for (int i = 0; i < 10; i++) player.playSound(soundEvent, SoundCategory.MASTER, 1, 0);
}
if (players.size() == 1) {
final ServerPlayerEntity player = (ServerPlayerEntity) players.toArray()[0];
source.sendFeedback(
Text.literal("Successfully created jumpscare for player \"")
.append(Text.literal(player.getGameProfile().getName()))
.append(Text.literal("\""))
, true);
return Command.SINGLE_SUCCESS;
}
source.sendFeedback(Text.literal("Successfully created jumpscare for multiple players"), true);
return Command.SINGLE_SUCCESS;
}
}

View file

@ -0,0 +1,69 @@
package land.chipmunk.kaboomfabric.extras.commands;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import static net.minecraft.server.command.CommandManager.literal;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.world.World;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.registry.Registries;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.BlockPos;
import net.minecraft.text.Text;
import java.util.concurrent.ThreadLocalRandom;
public interface CommandKaboom {
static void register (CommandDispatcher dispatcher) {
dispatcher.register(
literal("kaboom")
.requires(source -> source.hasPermissionLevel(2))
.executes(CommandKaboom::kaboomCommand)
);
}
static int kaboomCommand (CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
final ServerPlayerEntity player = context.getSource().getPlayerOrThrow();
boolean explode = ThreadLocalRandom.current().nextBoolean();
if (explode) {
final Vec3d position = player.getPos();
final ServerWorld world = player.getWorld();
final int explosionCount = 20;
final int power = 8;
world.createExplosion(player, position.getX(), position.getY(), position.getZ(), power, true, World.ExplosionSourceType.MOB);
final int power2 = 4;
final BlockState lava = Registries.BLOCK.get(new Identifier("minecraft", "lava")).getDefaultState();
for (int i = 0; i < explosionCount; i++) {
final double posX = position.getX() + ThreadLocalRandom.current().nextInt(-15, 15);
final double posY = position.getY() + ThreadLocalRandom.current().nextInt(-6, 6);
final double posZ = position.getZ() + ThreadLocalRandom.current().nextInt(-15, 15);
world.createExplosion(player, posX, posY, posZ, power2, true, World.ExplosionSourceType.MOB);
final BlockPos blockPos = new BlockPos((int) posX, (int) posY, (int) posZ);
if (!world.canSetBlock(blockPos)) continue;
if (world.getBlockState(blockPos).hasBlockEntity()) world.removeBlockEntity(blockPos);
world.setBlockState(blockPos, lava);
}
player.sendMessage(Text.literal("Forgive me :c"));
return Command.SINGLE_SUCCESS;
}
final PlayerInventory inventory = player.getInventory();
inventory.setStack(inventory.selectedSlot, new ItemStack(Registries.ITEM.get(new Identifier("minecraft", "cake"))));
player.sendMessage(Text.literal("Have a nice day :)"));
return Command.SINGLE_SUCCESS;
}
}

View file

@ -0,0 +1,92 @@
package land.chipmunk.kaboomfabric.extras.commands;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.LiteralCommandNode;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.command.argument.EntityArgumentType.player;
import static net.minecraft.command.argument.EntityArgumentType.getPlayer;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.server.network.ServerPlayerEntity;
public abstract class CommandPing {
public static void register (CommandDispatcher dispatcher) {
final LiteralCommandNode node = dispatcher.register(
literal("ping")
.requires(source -> source.hasPermissionLevel(2))
.executes(CommandPing::pingCommand)
.then(
argument("target", player())
.executes(CommandPing::targettedPingCommand)
)
);
dispatcher.register(literal("delay").redirect(node));
dispatcher.register(literal("ms").redirect(node));
}
public static int pingCommand (CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
final ServerCommandSource source = context.getSource();
final ServerPlayerEntity player = source.getPlayerOrThrow();
final int ping = player.pingMilliseconds;
final Formatting highlighting = getHighlighting(ping);
source.sendFeedback(
Text.literal("Your")
.append(Text.literal(" ping is "))
.append(Text.literal(String.valueOf(ping)).formatted(highlighting))
.append(Text.literal("ms.").formatted(highlighting))
, false);
return Command.SINGLE_SUCCESS;
}
public static int targettedPingCommand (CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
final ServerCommandSource source = context.getSource();
final ServerPlayerEntity target = getPlayer(context, "target");
final int ping = target.pingMilliseconds;
final Formatting highlighting = getHighlighting(ping);
source.sendFeedback(
Text.literal(target.getGameProfile().getName())
.append(Text.literal("'s"))
.append(Text.literal(" ping is "))
.append(Text.literal(String.valueOf(ping)).formatted(highlighting))
.append(Text.literal("ms.").formatted(highlighting))
, false);
return Command.SINGLE_SUCCESS;
}
private static Formatting getHighlighting (int ping) {
final int d = (int) Math.floor((float) ping / 100);
Formatting highlighting = Formatting.WHITE;
switch (d) {
case 0:
highlighting = Formatting.GREEN;
break;
case 1:
case 2:
case 3:
case 4:
highlighting = Formatting.YELLOW;
break;
case 5:
highlighting = Formatting.RED;
break;
default:
if (d > 5) {
highlighting = Formatting.DARK_RED;
}
break;
}
return highlighting;
}
}

View file

@ -0,0 +1,60 @@
package land.chipmunk.kaboomfabric.extras.commands;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.command.argument.EntityArgumentType.players;
import static net.minecraft.command.argument.EntityArgumentType.getPlayers;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import java.util.Collection;
// Not currently working because I don't understand the player inventory numbers
public interface CommandPumpkin {
static void register (CommandDispatcher dispatcher) {
dispatcher.register(
literal("pumpkin")
.requires(source -> source.hasPermissionLevel(2))
.then(
argument("targets", players())
// .executes(CommandPumpkin::pumpkinCommand)
)
);
}
static int pumpkinCommand (CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
final ServerCommandSource source = context.getSource();
final Collection<ServerPlayerEntity> players = getPlayers(context, "targets");
final Item pumpkin = Registries.ITEM.get(new Identifier("minecraft", "pumpkin"));
for (ServerPlayerEntity player : players) {
final PlayerInventory inventory = player.getInventory();
inventory.setStack(PlayerInventory.ARMOR_SLOTS[3], new ItemStack(pumpkin));
}
if (players.size() == 1) {
final ServerPlayerEntity player = (ServerPlayerEntity) players.toArray()[0];
source.sendFeedback(
Text.literal("Player \"")
.append(Text.literal(player.getGameProfile().getName()))
.append(Text.literal("\" is now a pumpkin"))
, true);
return Command.SINGLE_SUCCESS;
}
source.sendFeedback(Text.literal("Multiple players are now pumpkins"), true);
return Command.SINGLE_SUCCESS;
}
}

View file

@ -0,0 +1,96 @@
package land.chipmunk.kaboomfabric.extras.commands;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import static net.minecraft.server.command.CommandManager.literal;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text;
import net.minecraft.text.MutableText;
import net.minecraft.util.Formatting;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.management.*;
import java.net.InetAddress;
public abstract class CommandServerInfo {
public static void register (CommandDispatcher dispatcher) {
dispatcher.register(
literal("serverinfo")
.requires(source -> source.hasPermissionLevel(2))
.executes(CommandServerInfo::serverInfoCommand)
);
}
private static void sendInfoMessage (ServerCommandSource source, String description, String value) {
source.sendFeedback(
Text.literal(description).formatted(Formatting.GRAY)
.append(Text.literal(": " + value).formatted(Formatting.WHITE))
, false);
}
public static int serverInfoCommand (CommandContext<ServerCommandSource> context) {
final ServerCommandSource source = context.getSource();
final OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
final RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
final Runtime runtime = Runtime.getRuntime();
try {
final InetAddress localhost = InetAddress.getLocalHost();
sendInfoMessage(source, "Hostname", localhost.getHostName());
sendInfoMessage(source, "IP address", localhost.getHostAddress());
} catch (Exception ignored) {
}
sendInfoMessage(source, "OS name", operatingSystemMXBean.getName());
sendInfoMessage(source, "OS architecture", operatingSystemMXBean.getArch());
sendInfoMessage(source, "OS version", operatingSystemMXBean.getVersion());
sendInfoMessage(source, "Java VM", runtimeMXBean.getVmName());
sendInfoMessage(source, "Java version", runtimeMXBean.getSpecVersion());
try {
final String[] shCommand = {
"/bin/sh",
"-c",
"cat /proc/cpuinfo | grep 'model name' | cut -f 2 -d ':' | awk '{$1=$1}1' | head -1"
};
final Process process = runtime.exec(shCommand);
final InputStreamReader isr = new InputStreamReader(process.getInputStream());
final BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
sendInfoMessage(source, "CPU model", line);
}
br.close();
} catch (Exception ignored) {
}
sendInfoMessage(source, "CPU cores", String.valueOf(runtime.availableProcessors()));
sendInfoMessage(source, "CPU load", String.valueOf(operatingSystemMXBean.getSystemLoadAverage()));
final long heapUsage = memoryMXBean.getHeapMemoryUsage().getUsed();
final long nonHeapUsage = memoryMXBean.getNonHeapMemoryUsage().getUsed();
final long memoryMax = (
memoryMXBean.getHeapMemoryUsage().getMax() +
memoryMXBean.getNonHeapMemoryUsage().getMax()
);
final long memoryUsage = (heapUsage + nonHeapUsage);
sendInfoMessage(source, "Available memory", (memoryMax / 1024 / 1024) + "MB");
sendInfoMessage(source, "Heap memory usage", (heapUsage / 1024 / 1024) + "MB");
sendInfoMessage(source, "Non-heap memory usage", (nonHeapUsage / 1024 / 1024) + "MB");
sendInfoMessage(source, "Total memory usage", (memoryUsage / 1024 / 1024) + "MB");
final long minutes = (runtimeMXBean.getUptime() / 1000) / 60;
final long seconds = (runtimeMXBean.getUptime() / 1000) % 60;
sendInfoMessage(source, "Server uptime", minutes + " minute(s) " + seconds + " second(s)");
return Command.SINGLE_SUCCESS;
}
}

View file

@ -0,0 +1,42 @@
package land.chipmunk.kaboomfabric.extras.commands;
import land.chipmunk.kaboomfabric.extras.Extras;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import static net.minecraft.server.command.CommandManager.literal;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.Vec3d;
import net.minecraft.network.packet.s2c.play.PositionFlag;
import net.minecraft.text.Text;
import java.util.Set;
import java.util.HashSet;
public interface CommandSpawn {
static void register (CommandDispatcher dispatcher) {
dispatcher.register(
literal("spawn")
.requires(source -> source.hasPermissionLevel(2))
.executes(CommandSpawn::spawnCommand)
);
}
static int spawnCommand (CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
final ServerCommandSource source = context.getSource();
final Entity entity = source.getEntityOrThrow();
final ServerWorld world = source.getServer().getOverworld();
final Vec3d spawn = Vec3d.ofCenter(world.getSpawnPos());
final float spawnAngle = world.getSpawnAngle();
final Set<PositionFlag> positionFlags = new HashSet<>();
entity.teleport(world, spawn.getX(), spawn.getY(), spawn.getZ(), positionFlags, spawnAngle, 0);
source.sendFeedback(Text.literal("Successfully moved to spawn"), false);
return Command.SINGLE_SUCCESS;
}
}

View file

@ -0,0 +1,23 @@
package land.chipmunk.kaboomfabric.extras.mixin;
import land.chipmunk.kaboomfabric.extras.Extras;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.command.CommandRegistryAccess;
import com.mojang.brigadier.CommandDispatcher;
@Mixin(CommandManager.class)
public abstract class CommandManagerMixin {
@Shadow
private CommandDispatcher<ServerCommandSource> dispatcher;
@Inject(at = @At(value = "INVOKE", target = "Lcom/mojang/brigadier/CommandDispatcher;setConsumer(Lcom/mojang/brigadier/ResultConsumer;)V", remap = false), method = "<init>")
private void init (CommandManager.RegistrationEnvironment environment, CommandRegistryAccess commandRegistryAccess, CallbackInfo info) {
Extras.registerCommands(dispatcher);
}
}

View file

@ -0,0 +1,15 @@
package land.chipmunk.kaboomfabric.extras.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.server.command.ServerCommandSource;
@Mixin(net.minecraft.command.EntitySelector.class)
public abstract class EntitySelectorMixin {
@Inject(at = @At("HEAD"), method = "checkSourcePermission", cancellable = true)
private void checkSourcePermission (ServerCommandSource source, CallbackInfo info) {
info.cancel();
}
}

View file

@ -0,0 +1,15 @@
package land.chipmunk.kaboomfabric.extras.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.minecraft.server.command.ServerCommandSource;
@Mixin(net.minecraft.server.dedicated.command.OpCommand.class)
public abstract class OpCommandMixin {
@Inject(at = @At("RETURN"), method = "method_13470", cancellable = true)
private static void requirement (ServerCommandSource source, CallbackInfoReturnable<Boolean> info) {
info.setReturnValue(true);
}
}

View file

@ -0,0 +1,17 @@
package land.chipmunk.kaboomfabric.extras.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.minecraft.text.Text;
import com.mojang.authlib.GameProfile;
import java.net.SocketAddress;
@Mixin(net.minecraft.server.PlayerManager.class)
public abstract class PlayerManagerMixin {
@Inject(at = @At("RETURN"), method = "checkCanJoin", cancellable = true)
private void checkCanJoin (SocketAddress address, GameProfile profile, CallbackInfoReturnable<Text> info) {
info.setReturnValue(null); // TODO: Config
}
}

View file

@ -0,0 +1,16 @@
package land.chipmunk.kaboomfabric.extras.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.server.command.ServerCommandSource;
import java.util.Collection;
@Mixin(net.minecraft.server.command.ReloadCommand.class)
public abstract class ReloadCommandMixin {
@Inject(at = @At("HEAD"), method = "tryReloadDataPacks", cancellable = true)
private static void tryReloadDataPacks (Collection<?> datapacks, ServerCommandSource source, CallbackInfo info) {
info.cancel();
}
}

View file

@ -0,0 +1,15 @@
package land.chipmunk.kaboomfabric.extras.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.text.Text;
@Mixin(net.minecraft.server.network.ServerPlayNetworkHandler.class)
public abstract class ServerPlayNetworkHandlerMixin {
@Inject(at = @At("HEAD"), method = "disconnect", cancellable = true)
private void disconnect (Text disconnectReason, CallbackInfo info) {
info.cancel();
}
}

View file

@ -0,0 +1,17 @@
package land.chipmunk.kaboomfabric.extras.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.mojang.brigadier.context.CommandContext;
import net.minecraft.server.command.ServerCommandSource;
import com.mojang.brigadier.Command;
@Mixin(net.minecraft.server.dedicated.command.StopCommand.class)
public abstract class StopCommandMixin {
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;stop(Z)V"), method = "method_13676", cancellable = true)
private static void stop (CommandContext<ServerCommandSource> context, CallbackInfoReturnable<Integer> info) {
info.setReturnValue(Command.SINGLE_SUCCESS);
}
}

View file

@ -0,0 +1,8 @@
package land.chipmunk.kaboomfabric.modules.text.TextSerializer;
import net.minecraft.text.Text;
public interface TextSerializer<I extends Text, O extends Text, R> {
R serialize (I input);
O deserialize (R input);
}

View file

@ -1,21 +0,0 @@
package net.fabricmc.example;
import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ExampleMod implements ModInitializer {
// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors.
public static final Logger LOGGER = LoggerFactory.getLogger("modid");
@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.
LOGGER.info("Hello Fabric world!");
}
}

View file

@ -1,16 +0,0 @@
package net.fabricmc.example.mixin;
import net.fabricmc.example.ExampleMod;
import net.minecraft.client.gui.screen.TitleScreen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(TitleScreen.class)
public class ExampleMixin {
@Inject(at = @At("HEAD"), method = "init()V")
private void init(CallbackInfo info) {
ExampleMod.LOGGER.info("This line is printed by an example mod mixin!");
}
}

View file

@ -0,0 +1,18 @@
{
"required": true,
"minVersion": "0.8",
"package": "land.chipmunk.kaboomfabric.extras.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"CommandManagerMixin",
"ServerPlayNetworkHandlerMixin",
"PlayerManagerMixin",
"StopCommandMixin",
"ReloadCommandMixin",
"OpCommandMixin",
"EntitySelectorMixin"
],
"injectors": {
"defaultRequire": 1
}
}

View file

@ -1,16 +1,22 @@
{ {
"schemaVersion": 1, "schemaVersion": 1,
"id": "modid", "id": "extras",
"version": "${version}", "version": "${version}",
"name": "Example Mod", "name": "Extras",
"description": "This is an example description! Tell everyone what your mod is about!", "description": "Fabric port of the Extras plugin from the kaboom server",
"authors": [ "authors": [
"Me!" "MissingTexture",
"G6_",
"maniaplay",
"QuadraticKid",
"hhhzzzsss",
"Breakdxwn",
"_ChipMC_"
], ],
"contact": { "contact": {
"homepage": "https://fabricmc.net/", "homepage": "https://code.chipmunk.land/kaboom-fabric",
"sources": "https://github.com/FabricMC/fabric-example-mod" "sources": "https://code.chipmunk.land/kaboom-fabric/extras"
}, },
"license": "CC0-1.0", "license": "CC0-1.0",
@ -19,16 +25,15 @@
"environment": "*", "environment": "*",
"entrypoints": { "entrypoints": {
"main": [ "main": [
"net.fabricmc.example.ExampleMod" "land.chipmunk.kaboomfabric.extras.Extras"
] ]
}, },
"mixins": [ "mixins": [
"modid.mixins.json" "extras.mixins.json"
], ],
"depends": { "depends": {
"fabricloader": ">=0.14.17", "fabricloader": ">=0.14.17",
"fabric-api": "*",
"minecraft": "~1.19.4", "minecraft": "~1.19.4",
"java": ">=17" "java": ">=17"
}, },

View file

@ -1,14 +0,0 @@
{
"required": true,
"minVersion": "0.8",
"package": "net.fabricmc.example.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
],
"client": [
"ExampleMixin"
],
"injectors": {
"defaultRequire": 1
}
}