Compare commits
7 commits
1.19
...
20w14infin
Author | SHA1 | Date | |
---|---|---|---|
a8e579b07f | |||
e4e49f10e2 | |||
9e8c3333c0 | |||
34fc390183 | |||
6740cf9d4b | |||
7449a5bb46 | |||
ec2f02c347 |
31 changed files with 217 additions and 363 deletions
28
build.gradle
28
build.gradle
|
@ -1,11 +1,15 @@
|
|||
plugins {
|
||||
id 'fabric-loom' version '1.1-SNAPSHOT'
|
||||
id 'fabric-loom' version '1.6-SNAPSHOT'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
version = project.mod_version
|
||||
group = project.maven_group
|
||||
|
||||
base {
|
||||
archivesName = project.archives_base_name
|
||||
}
|
||||
|
||||
repositories {
|
||||
// Add repositories to retrieve artifacts from in here.
|
||||
// You should only use this when depending on other mods because
|
||||
|
@ -22,15 +26,7 @@ dependencies {
|
|||
|
||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||
// modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
|
||||
// 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.
|
||||
|
||||
// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"
|
||||
}
|
||||
|
||||
base {
|
||||
archivesName = project.archives_base_name
|
||||
|
||||
}
|
||||
|
||||
processResources {
|
||||
|
@ -42,8 +38,7 @@ processResources {
|
|||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
|
||||
it.options.release = 17
|
||||
it.options.release = 8
|
||||
}
|
||||
|
||||
java {
|
||||
|
@ -52,20 +47,21 @@ java {
|
|||
// If you remove this line, sources will not be generated.
|
||||
withSourcesJar()
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
jar {
|
||||
from("LICENSE") {
|
||||
rename { "${it}_${base.archivesName.get()}"}
|
||||
rename { "${it}_${project.base.archivesName.get()}"}
|
||||
}
|
||||
}
|
||||
|
||||
// configure the maven publication
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
create("mavenJava", MavenPublication) {
|
||||
artifactId = project.archives_base_name
|
||||
from components.java
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,15 +3,12 @@ org.gradle.jvmargs=-Xmx1G
|
|||
org.gradle.parallel=true
|
||||
|
||||
# Fabric Properties
|
||||
# check these on https://fabricmc.net/develop
|
||||
minecraft_version=1.19.4
|
||||
yarn_mappings=1.19.4+build.1
|
||||
loader_version=0.14.17
|
||||
# check these on https://fabricmc.net/develop
|
||||
minecraft_version=20w14infinite
|
||||
yarn_mappings=20w14infinite+build.4
|
||||
loader_version=0.15.11
|
||||
|
||||
# Mod Properties
|
||||
mod_version = rolling
|
||||
maven_group = land.chipmunk.kaboomfabric
|
||||
archives_base_name = extras
|
||||
|
||||
# Dependencies
|
||||
fabric_version=0.75.3+1.19.4
|
||||
mod_version=rolling
|
||||
maven_group=land.chipmunk.kaboomfabric
|
||||
archives_base_name=extras
|
||||
|
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -1,6 +1,7 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
|
29
gradlew
vendored
29
gradlew
vendored
|
@ -83,10 +83,8 @@ done
|
|||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
@ -133,10 +131,13 @@ location of your Java installation."
|
|||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
|
@ -144,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
|||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
|
@ -152,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
|||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
|
@ -197,11 +198,15 @@ if "$cygwin" || "$msys" ; then
|
|||
done
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
|
|
20
gradlew.bat
vendored
20
gradlew.bat
vendored
|
@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
|
|||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
|
@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
pluginManagement {
|
||||
repositories {
|
||||
maven {
|
||||
name = 'Fabric'
|
||||
url = 'https://maven.fabricmc.net/'
|
||||
}
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
maven {
|
||||
name = 'Fabric'
|
||||
url = 'https://maven.fabricmc.net/'
|
||||
}
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
|
@ -1,14 +1,13 @@
|
|||
package land.chipmunk.kaboomfabric.extras;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import net.minecraft.util.Formatting;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import land.chipmunk.kaboomfabric.extras.commands.*;
|
||||
|
||||
public class Extras implements ModInitializer {
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger("extras");
|
||||
public static final Logger LOGGER = LogManager.getLogger("infinite-fixes");
|
||||
private static final char[] escapeCodes = "0123456789abcdefklmnorx".toCharArray();
|
||||
|
||||
@Override
|
||||
|
@ -17,7 +16,7 @@ public class Extras implements ModInitializer {
|
|||
|
||||
public static void registerCommands (CommandDispatcher dispatcher) {
|
||||
// CommandBroadcastMM.register(dispatcher);
|
||||
CommandBroadcastVanilla.register(dispatcher);
|
||||
// CommandBroadcastVanilla.register(dispatcher);
|
||||
CommandClearChat.register(dispatcher);
|
||||
CommandConsole.register(dispatcher);
|
||||
CommandDestroyEntities.register(dispatcher);
|
||||
|
@ -32,8 +31,8 @@ public class Extras implements ModInitializer {
|
|||
// CommandSkin.register(dispatcher);
|
||||
CommandSpawn.register(dispatcher);
|
||||
CommandSpidey.register(dispatcher);
|
||||
CommandTellraw.register(dispatcher);
|
||||
CommandUsername.register(dispatcher);
|
||||
// CommandTellraw.register(dispatcher);
|
||||
// CommandUsername.register(dispatcher);
|
||||
}
|
||||
|
||||
public static String parseEscapeSequences (String string) {
|
||||
|
@ -41,7 +40,7 @@ public class Extras implements ModInitializer {
|
|||
|
||||
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);
|
||||
if (character == '&' && string.length() > (i + 1) && validateEscapeCode(string.charAt(i + 1))) sb.append((char) 0xa7);
|
||||
else sb.append(character);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
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 net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.text.Text;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
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;
|
||||
|
||||
public interface CommandBroadcastVanilla {
|
||||
static void register (CommandDispatcher dispatcher) {
|
||||
final LiteralCommandNode node = dispatcher.register(
|
||||
literal("broadcastvanilla")
|
||||
.requires(CommandBroadcastVanilla::requirement)
|
||||
.then(
|
||||
argument("message", greedyString())
|
||||
.executes(CommandBroadcastVanilla::tellrawCommand)
|
||||
)
|
||||
);
|
||||
|
||||
dispatcher.register(literal("bcv").requires(CommandBroadcastVanilla::requirement).executes(CommandTellraw::tellrawCommand).redirect(node));
|
||||
}
|
||||
|
||||
static int tellrawCommand (CommandContext<ServerCommandSource> context) {
|
||||
String string = getString(context, "message");
|
||||
Text text = Text.literal(Extras.parseEscapeSequences(string));
|
||||
|
||||
context.getSource().sendFeedback(text, true);
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
static boolean requirement (ServerCommandSource source) {
|
||||
return source.hasPermissionLevel(2);
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ 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.text.LiteralText;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
|
||||
|
@ -23,11 +23,11 @@ public interface CommandClearChat {
|
|||
}
|
||||
|
||||
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));
|
||||
final Text text = new LiteralText("");
|
||||
for (int i = 0; i < 100; i++) text.append(new LiteralText("\n"));
|
||||
text.append(new LiteralText("The chat has been cleared").formatted(Formatting.DARK_GREEN));
|
||||
|
||||
for (ServerPlayerEntity player : context.getSource().getServer().getPlayerManager().getPlayerList()) {
|
||||
for (ServerPlayerEntity player : context.getSource().getMinecraftServer().getPlayerManager().getPlayerList()) {
|
||||
player.sendMessage(text);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,13 +27,13 @@ public interface CommandConsole {
|
|||
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 MinecraftServer server = source.getMinecraftServer();
|
||||
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);
|
||||
commandManager.execute(console, command);
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,9 @@ 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;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import land.chipmunk.kaboomfabric.extras.mixin.ServerWorldAccessor;
|
||||
import land.chipmunk.kaboomfabric.extras.mixin.EntityAccessor;
|
||||
|
||||
// Currently broken
|
||||
public interface CommandDestroyEntities {
|
||||
|
@ -27,15 +29,15 @@ public interface CommandDestroyEntities {
|
|||
|
||||
static int destroyEntitiesCommand (CommandContext<ServerCommandSource> context) {
|
||||
final ServerCommandSource source = context.getSource();
|
||||
final MinecraftServer server = source.getServer();
|
||||
final MinecraftServer server = source.getMinecraftServer();
|
||||
|
||||
int entityCount = 0;
|
||||
int worldCount = 0;
|
||||
for (ServerWorld world : server.getWorlds()) {
|
||||
for (Entity entity : world.iterateEntities()) {
|
||||
for (Entity entity : ((ServerWorldAccessor)(Object)world).entitiesById().values()) {
|
||||
if (entity instanceof PlayerEntity) continue;
|
||||
try {
|
||||
entity.discard();
|
||||
((EntityAccessor)(Object)entity).destroy();
|
||||
entityCount++;
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
@ -44,11 +46,11 @@ public interface CommandDestroyEntities {
|
|||
}
|
||||
|
||||
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")),
|
||||
new LiteralText("Successfully destroyed ")
|
||||
.append(new LiteralText(String.valueOf(entityCount)))
|
||||
.append(new LiteralText(" entities in "))
|
||||
.append(new LiteralText(String.valueOf(worldCount)))
|
||||
.append(new LiteralText(" worlds")),
|
||||
true);
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
|
|
|
@ -7,19 +7,19 @@ 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.text.LiteralText;
|
||||
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.util.registry.Registry;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
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"));
|
||||
private static final SimpleCommandExceptionType EMPTY_ITEM_EXCEPTION = new SimpleCommandExceptionType(new LiteralText("Please hold an item in your hand to enchant it"));
|
||||
|
||||
public static void register (CommandDispatcher dispatcher) {
|
||||
dispatcher.register(
|
||||
|
@ -31,12 +31,12 @@ public abstract class CommandEnchantAll {
|
|||
|
||||
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 ServerPlayerEntity player = source.getPlayer();
|
||||
final PlayerInventory inventory = player.inventory;
|
||||
|
||||
final NbtList enchantments = new NbtList();
|
||||
for (Identifier identifier : Registries.ENCHANTMENT.getIds()) {
|
||||
final NbtCompound enchantment = new NbtCompound();
|
||||
final ListTag enchantments = new ListTag();
|
||||
for (Identifier identifier : Registry.ENCHANTMENT.getIds()) {
|
||||
final CompoundTag enchantment = new CompoundTag();
|
||||
enchantment.putString("id", identifier.toString());
|
||||
enchantment.putShort("lvl", (short) 0xFF);
|
||||
enchantments.add(enchantment);
|
||||
|
@ -45,15 +45,15 @@ public abstract class CommandEnchantAll {
|
|||
final ItemStack stack = inventory.getStack(inventory.selectedSlot).copy();
|
||||
if (stack.isEmpty()) throw EMPTY_ITEM_EXCEPTION.create();
|
||||
|
||||
NbtCompound nbt = stack.getNbt();
|
||||
CompoundTag nbt = stack.getTag();
|
||||
if (nbt == null) {
|
||||
nbt = new NbtCompound();
|
||||
stack.setNbt(nbt);
|
||||
nbt = new CompoundTag();
|
||||
stack.setTag(nbt);
|
||||
}
|
||||
stack.getNbt().put("Enchantments", enchantments);
|
||||
stack.getTag().put("Enchantments", enchantments);
|
||||
inventory.setStack(inventory.selectedSlot, stack);
|
||||
|
||||
source.sendFeedback(Text.literal("I killed Martin."), false);
|
||||
source.sendFeedback(new LiteralText("I killed Martin."), false);
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -7,18 +7,18 @@ 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 static net.minecraft.command.arguments.EntityArgumentType.players;
|
||||
import static net.minecraft.command.arguments.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.registry.Registry;
|
||||
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 net.minecraft.text.LiteralText;
|
||||
import java.util.Collection;
|
||||
|
||||
public interface CommandJumpscare {
|
||||
|
@ -38,11 +38,11 @@ public interface CommandJumpscare {
|
|||
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"));
|
||||
final ParticleEffect particle = (ParticleEffect) Registry.PARTICLE_TYPE.get(new Identifier("minecraft", "elder_guardian"));
|
||||
final SoundEvent soundEvent = Registry.SOUND_EVENT.get(new Identifier("minecraft", "entity.enderman.scream"));
|
||||
|
||||
for (ServerPlayerEntity player : players) {
|
||||
final ServerWorld world = player.getWorld();
|
||||
final ServerWorld world = player.getServerWorld();
|
||||
final Vec3d position = player.getPos();
|
||||
world.<ParticleEffect>spawnParticles(player, particle, false, position.getX(), position.getY(), position.getZ(), 4, 0, 0, 0, 1);
|
||||
|
||||
|
@ -53,15 +53,15 @@ public interface CommandJumpscare {
|
|||
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("\""))
|
||||
new LiteralText("Successfully created jumpscare for player \"")
|
||||
.append(new LiteralText(player.getGameProfile().getName()))
|
||||
.append(new LiteralText("\""))
|
||||
, true);
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
source.sendFeedback(Text.literal("Successfully created jumpscare for multiple players"), true);
|
||||
source.sendFeedback(new LiteralText("Successfully created jumpscare for multiple players"), true);
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -6,17 +6,18 @@ 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.world.explosion.Explosion.DestructionType;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
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 net.minecraft.text.LiteralText;
|
||||
import net.minecraft.util.Clearable;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public interface CommandKaboom {
|
||||
|
@ -29,41 +30,40 @@ public interface CommandKaboom {
|
|||
}
|
||||
|
||||
static int kaboomCommand (CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
final ServerPlayerEntity player = context.getSource().getPlayerOrThrow();
|
||||
final ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
boolean explode = ThreadLocalRandom.current().nextBoolean();
|
||||
|
||||
if (explode) {
|
||||
final Vec3d position = player.getPos();
|
||||
final ServerWorld world = player.getWorld();
|
||||
final ServerWorld world = player.getServerWorld();
|
||||
final int explosionCount = 20;
|
||||
final int power = 8;
|
||||
|
||||
world.createExplosion(player, position.getX(), position.getY(), position.getZ(), power, true, World.ExplosionSourceType.MOB);
|
||||
|
||||
world.createExplosion(player, position.getX(), position.getY(), position.getZ(), power, true, DestructionType.DESTROY);
|
||||
|
||||
final int power2 = 4;
|
||||
final BlockState lava = Registries.BLOCK.get(new Identifier("minecraft", "lava")).getDefaultState();
|
||||
final BlockState lava = Registry.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);
|
||||
world.createExplosion(player, posX, posY, posZ, power2, true, DestructionType.DESTROY);
|
||||
|
||||
final BlockPos blockPos = new BlockPos((int) posX, (int) posY, (int) posZ);
|
||||
if (!world.canSetBlock(blockPos)) continue;
|
||||
if (world.getBlockState(blockPos).hasBlockEntity()) world.removeBlockEntity(blockPos);
|
||||
Clearable.clear(world.getBlockEntity(blockPos));
|
||||
world.setBlockState(blockPos, lava);
|
||||
}
|
||||
|
||||
player.sendMessage(Text.literal("Forgive me :c"));
|
||||
player.sendMessage(new LiteralText("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 :)"));
|
||||
final PlayerInventory inventory = player.inventory;
|
||||
inventory.setStack(inventory.selectedSlot, new ItemStack(Registry.ITEM.get(new Identifier("minecraft", "cake"))));
|
||||
player.sendMessage(new LiteralText("Have a nice day :)"));
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,10 +7,10 @@ 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 static net.minecraft.command.arguments.EntityArgumentType.player;
|
||||
import static net.minecraft.command.arguments.EntityArgumentType.getPlayer;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
|
||||
|
@ -32,15 +32,15 @@ public abstract class CommandPing {
|
|||
|
||||
public static int pingCommand (CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
final ServerCommandSource source = context.getSource();
|
||||
final ServerPlayerEntity player = source.getPlayerOrThrow();
|
||||
final ServerPlayerEntity player = source.getPlayer();
|
||||
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))
|
||||
new LiteralText("Your")
|
||||
.append(new LiteralText(" ping is "))
|
||||
.append(new LiteralText(String.valueOf(ping)).formatted(highlighting))
|
||||
.append(new LiteralText("ms.").formatted(highlighting))
|
||||
, false);
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
|
@ -53,11 +53,11 @@ public abstract class CommandPing {
|
|||
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))
|
||||
new LiteralText(target.getGameProfile().getName())
|
||||
.append(new LiteralText("'s"))
|
||||
.append(new LiteralText(" ping is "))
|
||||
.append(new LiteralText(String.valueOf(ping)).formatted(highlighting))
|
||||
.append(new LiteralText("ms.").formatted(highlighting))
|
||||
, false);
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
|
|
|
@ -6,16 +6,16 @@ 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 static net.minecraft.command.arguments.EntityArgumentType.players;
|
||||
import static net.minecraft.command.arguments.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.registry.Registry;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import java.util.Collection;
|
||||
|
||||
public interface CommandPumpkin {
|
||||
|
@ -33,10 +33,10 @@ public interface CommandPumpkin {
|
|||
static int pumpkinCommand (CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
final ServerCommandSource source = context.getSource();
|
||||
final Collection<ServerPlayerEntity> players = getPlayers(context, "targets");
|
||||
final Item carvedPumpkin = Registries.ITEM.get(new Identifier("minecraft", "carved_pumpkin"));
|
||||
final Item carvedPumpkin = Registry.ITEM.get(new Identifier("minecraft", "carved_pumpkin"));
|
||||
|
||||
for (ServerPlayerEntity player : players) {
|
||||
final PlayerInventory inventory = player.getInventory();
|
||||
final PlayerInventory inventory = player.inventory;
|
||||
inventory.setStack(39, new ItemStack(carvedPumpkin));
|
||||
}
|
||||
|
||||
|
@ -44,15 +44,15 @@ public interface CommandPumpkin {
|
|||
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"))
|
||||
new LiteralText("Player \"")
|
||||
.append(new LiteralText(player.getGameProfile().getName()))
|
||||
.append(new LiteralText("\" is now a pumpkin"))
|
||||
, true);
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
source.sendFeedback(Text.literal("Multiple players are now pumpkins"), true);
|
||||
source.sendFeedback(new LiteralText("Multiple players are now pumpkins"), true);
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -6,8 +6,7 @@ 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.text.LiteralText;
|
||||
import net.minecraft.util.Formatting;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
|
@ -27,8 +26,8 @@ public abstract class CommandServerInfo {
|
|||
|
||||
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))
|
||||
new LiteralText(description).formatted(Formatting.GRAY)
|
||||
.append(new LiteralText(": " + value).formatted(Formatting.WHITE))
|
||||
, false);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,10 +8,11 @@ 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.world.level.LevelProperties;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
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 net.minecraft.text.LiteralText;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
|
||||
|
@ -27,15 +28,13 @@ public interface CommandSpawn {
|
|||
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 ServerWorld world = source.getMinecraftServer().getWorld(DimensionType.OVERWORLD);
|
||||
final LevelProperties properties = world.getLevelProperties();
|
||||
|
||||
final Vec3d spawn = Vec3d.ofCenter(world.getSpawnPos());
|
||||
final float spawnAngle = world.getSpawnAngle();
|
||||
entity.setWorld(world);
|
||||
entity.teleport(properties.getSpawnX() + 0.5, properties.getSpawnY(), properties.getSpawnZ() + 0.5);
|
||||
|
||||
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);
|
||||
source.sendFeedback(new LiteralText("Successfully moved to spawn"), false);
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -9,11 +9,12 @@ import static net.minecraft.server.command.CommandManager.argument;
|
|||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
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.util.Clearable;
|
||||
import land.chipmunk.kaboomfabric.extras.modules.block.BlockIterator;
|
||||
|
||||
public abstract class CommandSpidey {
|
||||
|
@ -29,7 +30,7 @@ public abstract class CommandSpidey {
|
|||
final ServerCommandSource source = context.getSource();
|
||||
final Entity entity = source.getEntityOrThrow();
|
||||
final ServerWorld world = source.getWorld();
|
||||
|
||||
/*
|
||||
final Vec3d start = entity.getEyePos();
|
||||
final Vec3d direction = Vec3d.fromPolar(entity.getYaw(), entity.getPitch());
|
||||
final int yOffset = 0;
|
||||
|
@ -37,15 +38,16 @@ public abstract class CommandSpidey {
|
|||
|
||||
final BlockIterator iterator = new BlockIterator(start, direction, yOffset, distance);
|
||||
|
||||
final BlockState cobweb = Registries.BLOCK.get(new Identifier("minecraft", "cobweb")).getDefaultState();
|
||||
final BlockState cobweb = Registry.BLOCK.get(new Identifier("minecraft", "cobweb")).getDefaultState();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
BlockPos pos = iterator.next();
|
||||
if (!world.isInBuildLimit(pos) || !world.getBlockState(pos).isAir()) break;
|
||||
if ((pos.getY() >= 0 && pos.getY() <= 255) || !world.getBlockState(pos).isAir()) break;
|
||||
|
||||
if (world.getBlockState(pos).hasBlockEntity()) world.removeBlockEntity(pos);
|
||||
Clearable.clear(world.getBlockEntity(pos));
|
||||
world.setBlockState(pos, cobweb);
|
||||
}
|
||||
*/
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
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 net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
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;
|
||||
|
||||
public interface CommandTellraw {
|
||||
static void register (CommandDispatcher dispatcher) {
|
||||
final LiteralCommandNode node = dispatcher.register(
|
||||
literal("broadcastraw")
|
||||
.requires(CommandTellraw::requirement)
|
||||
.then(
|
||||
argument("message", greedyString())
|
||||
.executes(CommandTellraw::tellrawCommand)
|
||||
)
|
||||
);
|
||||
|
||||
dispatcher.register(literal("bcraw").requires(CommandTellraw::requirement).executes(CommandTellraw::tellrawCommand).redirect(node));
|
||||
// No tellraw alias
|
||||
}
|
||||
|
||||
static int tellrawCommand (CommandContext<ServerCommandSource> context) {
|
||||
String string = getString(context, "message");
|
||||
Text text = Text.literal(Extras.parseEscapeSequences(string));
|
||||
|
||||
for (ServerPlayerEntity player : context.getSource().getServer().getPlayerManager().getPlayerList()) {
|
||||
player.sendMessage(text);
|
||||
}
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
static boolean requirement (ServerCommandSource source) {
|
||||
return source.hasPermissionLevel(2);
|
||||
}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
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.exceptions.SimpleCommandExceptionType;
|
||||
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
|
||||
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 com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.PlayerManager;
|
||||
import net.minecraft.network.packet.s2c.play.PlayerRemoveS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
|
||||
import land.chipmunk.kaboomfabric.extras.Extras;
|
||||
import land.chipmunk.kaboomfabric.extras.mixin.PlayerEntityAccessor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Collections;
|
||||
|
||||
public abstract class CommandUsername {
|
||||
private static final DynamicCommandExceptionType ALREADY_HAVE_USERNAME_EXCEPTION = new DynamicCommandExceptionType(name -> Text.literal("You already have the username \"").append(Text.literal((String)name)).append(Text.literal("\"")));
|
||||
private static final SimpleCommandExceptionType RATELIMIT_EXCEPTION = new SimpleCommandExceptionType(Text.literal("Please wait a few seconds before changing your username."));
|
||||
private static final SimpleCommandExceptionType ALREADY_LOGGED_IN_EXCEPTION = new SimpleCommandExceptionType(Text.literal("A player with that username is already logged in."));
|
||||
|
||||
public static final Map<ServerPlayerEntity, Long> lastUsedMillis = new HashMap<>();
|
||||
|
||||
public static void register (CommandDispatcher dispatcher) {
|
||||
dispatcher.register(
|
||||
literal("username")
|
||||
.requires(source -> source.hasPermissionLevel(2))
|
||||
.then(
|
||||
argument("username", greedyString())
|
||||
.executes(CommandUsername::usernameCommand)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static int usernameCommand (CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
final ServerCommandSource source = context.getSource();
|
||||
final ServerPlayerEntity player = source.getPlayerOrThrow();
|
||||
final PlayerManager playerManager = source.getServer().getPlayerManager();
|
||||
|
||||
final GameProfile oldProfile = player.getGameProfile();
|
||||
final PropertyMap oldProperties = oldProfile.getProperties();
|
||||
|
||||
final String nameColor = Extras.parseEscapeSequences(getString(context, "username"));
|
||||
final String name = nameColor.substring(0, Math.min(16, nameColor.length()));
|
||||
final long millis = lastUsedMillis.getOrDefault(player, 0L);
|
||||
final long millisDifference = System.currentTimeMillis() - millis;
|
||||
|
||||
if (name.equals(oldProfile.getName())) {
|
||||
throw ALREADY_HAVE_USERNAME_EXCEPTION.create(name);
|
||||
}
|
||||
|
||||
if (millisDifference <= 2000) {
|
||||
throw RATELIMIT_EXCEPTION.create();
|
||||
}
|
||||
|
||||
for (ServerPlayerEntity other : source.getServer().getPlayerManager().getPlayerList()) {
|
||||
if (!other.getGameProfile().getName().equalsIgnoreCase(name)) continue;
|
||||
|
||||
throw ALREADY_LOGGED_IN_EXCEPTION.create();
|
||||
}
|
||||
|
||||
final GameProfile newProfile = new GameProfile(oldProfile.getId(), name);
|
||||
final PropertyMap newProperties = newProfile.getProperties();
|
||||
for (final Property property : oldProperties.values()) newProperties.put(property.getName(), property);
|
||||
|
||||
((PlayerEntityAccessor)(Object)player).gameProfile(newProfile);
|
||||
lastUsedMillis.put(player, System.currentTimeMillis());
|
||||
|
||||
// Update the player's player list entry
|
||||
playerManager.sendToAll(new PlayerRemoveS2CPacket(Collections.singletonList(oldProfile.getId())));
|
||||
playerManager.sendToAll(PlayerListS2CPacket.entryFromPlayer(Collections.singleton(player)));
|
||||
|
||||
source.sendFeedback(
|
||||
Text.literal("Successfully set your username to \"")
|
||||
.append(Text.literal(name))
|
||||
.append(Text.literal("\""))
|
||||
, false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
}
|
|
@ -8,7 +8,6 @@ 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)
|
||||
|
@ -17,7 +16,7 @@ public abstract class CommandManagerMixin {
|
|||
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) {
|
||||
private void init (boolean isDedicatedServer, CallbackInfo info) {
|
||||
Extras.registerCommands(dispatcher);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 com.mojang.brigadier.CommandDispatcher;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
|
||||
@Mixin(net.minecraft.server.command.DebugDimCommand.class)
|
||||
public abstract class DebugDimCommandMixin {
|
||||
@Inject(at = @At("HEAD"), method = "register", cancellable = true)
|
||||
private static void register (CommandDispatcher<ServerCommandSource> dispatcher, CallbackInfo info) {
|
||||
info.cancel();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package land.chipmunk.kaboomfabric.extras.mixin;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
@Mixin(net.minecraft.entity.Entity.class)
|
||||
public interface EntityAccessor {
|
||||
@Invoker("destroy") void destroy ();
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package land.chipmunk.kaboomfabric.extras.mixin;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Mutable;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
@Mixin(net.minecraft.entity.player.PlayerEntity.class)
|
||||
public interface PlayerEntityAccessor {
|
||||
@Accessor("gameProfile") @Mutable void gameProfile (GameProfile profile);
|
||||
}
|
|
@ -3,14 +3,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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
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) {
|
||||
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;reload()V"), method = "method_13530", cancellable = true)
|
||||
private static void reload (CommandContext<ServerCommandSource> context, CallbackInfoReturnable<Integer> info) {
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package land.chipmunk.kaboomfabric.extras.mixin;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
@Mixin(net.minecraft.server.world.ServerWorld.class)
|
||||
public interface ServerWorldAccessor {
|
||||
@Accessor("entitiesById") Int2ObjectMap<Entity> entitiesById ();
|
||||
}
|
|
@ -219,9 +219,12 @@ public class BlockIterator implements Iterator<BlockPos> {
|
|||
return getPosition(direction.getZ(), position.getZ(), block.getZ());
|
||||
}
|
||||
|
||||
// TODO: Backport
|
||||
/*
|
||||
public BlockIterator(Entity entity, int maxDistance) {
|
||||
this(entity.getPos(), Vec3d.fromPolar(entity.getYaw(), entity.getPitch()), entity.getEyeHeight(entity.getPose()), maxDistance);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Constructs the BlockIterator.
|
||||
|
@ -231,9 +234,11 @@ public class BlockIterator implements Iterator<BlockPos> {
|
|||
* @param entity Information from the entity is used to set up the trace
|
||||
*/
|
||||
|
||||
/*
|
||||
public BlockIterator(Entity entity) {
|
||||
this(entity, 0);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns true if the iteration has more elements
|
||||
|
|
|
@ -11,7 +11,9 @@
|
|||
"ReloadCommandMixin",
|
||||
"OpCommandMixin",
|
||||
"EntitySelectorMixin",
|
||||
"PlayerEntityAccessor"
|
||||
"ServerWorldAccessor",
|
||||
"EntityAccessor",
|
||||
"DebugDimCommandMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
|
@ -33,10 +33,11 @@
|
|||
],
|
||||
|
||||
"depends": {
|
||||
"fabricloader": ">=0.14.17",
|
||||
"minecraft": "~1.19.4",
|
||||
"java": ">=17"
|
||||
"fabricloader": ">=0.15.11",
|
||||
"minecraft": "1.16-alpha.20.13.inf",
|
||||
"java": ">=8"
|
||||
},
|
||||
|
||||
"suggests": {
|
||||
"another-mod": "*"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue