diff --git a/build.gradle b/build.gradle index 9057129a..192c1603 100644 --- a/build.gradle +++ b/build.gradle @@ -38,7 +38,7 @@ allprojects { dependencies { // Fabric minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" + mappings loom.officialMojangMappings() modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" // Code Quality diff --git a/ec-core/src/main/java/dev/jpcode/eccore/config/Config.java b/ec-core/src/main/java/dev/jpcode/eccore/config/Config.java index ebb913c3..c1a75d4e 100644 --- a/ec-core/src/main/java/dev/jpcode/eccore/config/Config.java +++ b/ec-core/src/main/java/dev/jpcode/eccore/config/Config.java @@ -10,17 +10,15 @@ import java.util.List; import java.util.function.Consumer; import java.util.stream.Collectors; - +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.Style; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import net.minecraft.text.MutableText; -import net.minecraft.text.Style; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; - public abstract class Config> { static final Logger LOGGER = LogManager.getLogger("ec-core-config"); @@ -110,16 +108,16 @@ public void storeProperties() { } - static final Style DEFAULT_STYLE = Style.EMPTY.withFormatting(Formatting.GOLD); - static final Style ACCENT_STYLE = Style.EMPTY.withFormatting(Formatting.GREEN); + static final Style DEFAULT_STYLE = Style.EMPTY.applyFormat(ChatFormatting.GOLD); + static final Style ACCENT_STYLE = Style.EMPTY.applyFormat(ChatFormatting.GREEN); - public @NotNull Text stateAsText() { - var result = Text.empty(); + public @NotNull Component stateAsText() { + var result = Component.empty(); String newLine = "\n";//System.getProperty("line.separator"); - result.append(Text.literal(displayName + " {").setStyle(DEFAULT_STYLE)); + result.append(Component.literal(displayName + " {").setStyle(DEFAULT_STYLE)); result.append(newLine); - var propsText = Text.empty(); + var propsText = Component.empty(); result.append(propsText); //print field names paired with their values @@ -132,7 +130,7 @@ public void storeProperties() { ex.printStackTrace(); } } - result.append(Text.literal("}").setStyle(ACCENT_STYLE)); + result.append(Component.literal("}").setStyle(ACCENT_STYLE)); return result; @@ -159,14 +157,14 @@ public List getPublicFieldNames() { return publicFieldNames; } - private MutableText fieldAsText(Field field) throws IllegalAccessException { + private MutableComponent fieldAsText(Field field) throws IllegalAccessException { var value = (Option) field.get(this); - return Text.empty() - .append(Text.literal(field.getName() + ": ").setStyle(DEFAULT_STYLE)) - .append(Text.literal(value.getValue().toString())); + return Component.empty() + .append(Component.literal(field.getName() + ": ").setStyle(DEFAULT_STYLE)) + .append(Component.literal(value.getValue().toString())); } - public @Nullable MutableText getFieldValueAsText(String fieldName) throws NoSuchFieldException { + public @Nullable MutableComponent getFieldValueAsText(String fieldName) throws NoSuchFieldException { try { return fieldAsText(this.getClass().getField(fieldName)); } catch (IllegalAccessException e) { diff --git a/ec-core/src/main/java/dev/jpcode/eccore/config/ConfigUtil.java b/ec-core/src/main/java/dev/jpcode/eccore/config/ConfigUtil.java index b2afc7b5..b2b1836b 100644 --- a/ec-core/src/main/java/dev/jpcode/eccore/config/ConfigUtil.java +++ b/ec-core/src/main/java/dev/jpcode/eccore/config/ConfigUtil.java @@ -4,7 +4,10 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; - +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.Style; +import net.minecraft.util.GsonHelper; import com.google.gson.JsonNull; import com.google.gson.JsonSyntaxException; import org.apache.logging.log4j.Level; @@ -13,12 +16,6 @@ import org.jetbrains.annotations.Nullable; import com.mojang.serialization.JsonOps; - -import net.minecraft.text.Style; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.JsonHelper; - import dev.jpcode.eccore.util.TimeUtil; import static dev.jpcode.eccore.config.Config.LOGGER; @@ -53,16 +50,16 @@ public static Style parseStyleOrDefault(String styleStr, String defaultStyleStr) @Nullable public static Style parseStyle(String styleStr) { Style outStyle = null; - Formatting formatting = Formatting.byName(styleStr); + ChatFormatting formatting = ChatFormatting.getByName(styleStr); if (formatting != null) { - outStyle = Style.EMPTY.withFormatting(formatting); + outStyle = Style.EMPTY.applyFormat(formatting); } if (outStyle == null) { try { - outStyle = Style.Codecs.CODEC.parse( + outStyle = Style.Serializer.CODEC.parse( JsonOps.INSTANCE, - JsonHelper.deserialize(styleStr) + GsonHelper.parse(styleStr) ).result().orElse(null); } catch (JsonSyntaxException e) { LOGGER.log(Level.ERROR, String.format( @@ -74,8 +71,8 @@ public static Style parseStyle(String styleStr) { return outStyle; } - public static Text parseTextOrDefault(String textStr, String defaultTextStr) { - Text outText = null; + public static Component parseTextOrDefault(String textStr, String defaultTextStr) { + Component outText = null; if (textStr != null) { outText = parseText(textStr); } @@ -154,7 +151,7 @@ private static void logNumberParseError(String num, String type) { } public static String serializeStyle(Style style) { - return Style.Codecs.CODEC.encodeStart(JsonOps.INSTANCE, style).result().orElse(JsonNull.INSTANCE).toString(); + return Style.Serializer.CODEC.encodeStart(JsonOps.INSTANCE, style).result().orElse(JsonNull.INSTANCE).toString(); } public static int parseDurationToTicks(String str) { diff --git a/ec-core/src/main/java/dev/jpcode/eccore/util/StringToTextParser.java b/ec-core/src/main/java/dev/jpcode/eccore/util/StringToTextParser.java index 282191e6..f2c068de 100644 --- a/ec-core/src/main/java/dev/jpcode/eccore/util/StringToTextParser.java +++ b/ec-core/src/main/java/dev/jpcode/eccore/util/StringToTextParser.java @@ -1,9 +1,9 @@ package dev.jpcode.eccore.util; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; @FunctionalInterface public interface StringToTextParser { - Text parseText(String str); + Component parseText(String str); } diff --git a/ec-core/src/main/java/dev/jpcode/eccore/util/TextUtil.java b/ec-core/src/main/java/dev/jpcode/eccore/util/TextUtil.java index a2c7d59f..07fa19ad 100644 --- a/ec-core/src/main/java/dev/jpcode/eccore/util/TextUtil.java +++ b/ec-core/src/main/java/dev/jpcode/eccore/util/TextUtil.java @@ -13,20 +13,21 @@ import com.mojang.serialization.JsonOps; -import net.minecraft.text.*; +import net.minecraft.network.chat.*; +import net.minecraft.network.chat.contents.PlainTextContents; public final class TextUtil { private TextUtil() {} - public static MutableText concat(Text... arr) { - MutableText out = Text.empty(); - for (Text text : arr) { + public static MutableComponent concat(Component... arr) { + MutableComponent out = Component.empty(); + for (Component text : arr) { out.append(text); } return out; } - public static MutableText deepCopy(Text text) { + public static MutableComponent deepCopy(Component text) { if (text.getSiblings().isEmpty()) { return text.copy(); } @@ -41,8 +42,8 @@ public static MutableText deepCopy(Text text) { } /** - *

Joins the elements of the provided array into a single Text - * containing the provided list of elements.

+ * Joins the elements of the provided array into a single Text + * containing the provided list of elements. * *

No delimiter is added before or after the list. * Null objects or empty strings within the array are represented by @@ -62,26 +63,26 @@ public static MutableText deepCopy(Text text) { * @return the joined String, null if null array input * @since 2.0 */ - public static MutableText join(Text[] array, Text separator) { + public static MutableComponent join(Component[] array, Component separator) { if (array == null) { return null; } return join(array, separator, 0, array.length); } - public static MutableText join(Collection textCollection, Text separator) { + public static MutableComponent join(Collection textCollection, Component separator) { if (textCollection == null) { return null; } - return join(textCollection.toArray(new Text[0]), separator, 0, textCollection.size()); + return join(textCollection.toArray(new Component[0]), separator, 0, textCollection.size()); } - public static MutableText join(Collection stringCollection, Text separator, Style stringsFormatting) { + public static MutableComponent join(Collection stringCollection, Component separator, Style stringsFormatting) { if (stringCollection == null) { return null; } return join( - stringCollection.stream().map(str -> Text.literal(str).setStyle(stringsFormatting)).toArray(Text[]::new), + stringCollection.stream().map(str -> Component.literal(str).setStyle(stringsFormatting)).toArray(Component[]::new), separator, 0, stringCollection.size() ); } @@ -116,7 +117,7 @@ public static String joinStrings(String[] array, String separator, int startInde return buf.toString(); } - public static MutableText join(Text[] array, Text separator, int startIndex, int endIndex) { + public static MutableComponent join(Component[] array, Component separator, int startIndex, int endIndex) { if (array == null) { return null; } @@ -124,7 +125,7 @@ public static MutableText join(Text[] array, Text separator, int startIndex, int if (bufSize <= 0) { return null; } - MutableText buf = Text.empty(); + MutableComponent buf = Component.empty(); for (int i = startIndex; i < endIndex; i++) { if (i > startIndex) { buf.append(separator); @@ -136,9 +137,9 @@ public static MutableText join(Text[] array, Text separator, int startIndex, int return buf; } - public static MutableText spaceBetween(Text[] array, int totalWidth, int padding) { + public static MutableComponent spaceBetween(Component[] array, int totalWidth, int padding) { int totalTextSize = 0; - for (Text txt : array) { + for (Component txt : array) { String str = txt.getString(); totalTextSize += str.length(); } @@ -148,37 +149,37 @@ public static MutableText spaceBetween(Text[] array, int totalWidth, int padding return concat(array); } - MutableText outText = Text.empty(); + MutableComponent outText = Component.empty(); String lrPadStr = " ".repeat(padding); String spaceStr = " ".repeat((totalWidth - padding * 2 - totalTextSize) / (array.length - 1)); - outText.append(Text.literal(lrPadStr)); + outText.append(Component.literal(lrPadStr)); for (int i = 0; i < array.length; i++) { outText.append(array[i]); if (i != array.length - 1) { - outText.append(Text.literal(spaceStr)); + outText.append(Component.literal(spaceStr)); } } - outText.append(Text.literal(lrPadStr)); + outText.append(Component.literal(lrPadStr)); return outText; } - public static MutableText clickableTeleport(MutableText originalText, String destinationName, String commandBaseString) { + public static MutableComponent clickableTeleport(MutableComponent originalText, String destinationName, String commandBaseString) { String teleportCommand = String.format("%s %s", commandBaseString, destinationName); Style outStyle = originalText.getStyle() .withClickEvent(new ClickEvent.RunCommand(teleportCommand)) - .withHoverEvent(new HoverEvent.ShowText(Text.literal("Click to teleport to " + .withHoverEvent(new HoverEvent.ShowText(Component.literal("Click to teleport to " + destinationName + "."))); return originalText.setStyle(outStyle); } - public static String toJsonString(Text text) { - return TextCodecs.CODEC + public static String toJsonString(Component text) { + return ComponentSerialization.CODEC .encodeStart(JsonOps.INSTANCE, text) .getOrThrow() .toString(); @@ -194,12 +195,12 @@ public static void registerTextParser(StringToTextParser parser) { } static { - registerTextParser(str -> TextCodecs.CODEC.parse(JsonOps.INSTANCE, JsonParser.parseString(str)).getOrThrow()); + registerTextParser(str -> ComponentSerialization.CODEC.parse(JsonOps.INSTANCE, JsonParser.parseString(str)).getOrThrow()); registerTextParser(str -> TagParser.DEFAULT.parseText(str, ParserContext.of())); } - public static Text parseText(String textStr) { - Text outText = null; + public static Component parseText(String textStr) { + Component outText = null; for (StringToTextParser parser : TEXT_PARSERS) { try { outText = parser.parseText(textStr); @@ -215,20 +216,20 @@ public static Text parseText(String textStr) { throw new RuntimeException(String.format("Failed to parse string '%s' as MinecraftText using any parsing strategy", textStr)); } - public static Collector collect() { + public static Collector collect() { return new Collector<>() { @Override - public Supplier supplier() { - return Text::empty; + public Supplier supplier() { + return Component::empty; } @Override - public BiConsumer accumulator() { - return MutableText::append; + public BiConsumer accumulator() { + return MutableComponent::append; } @Override - public BinaryOperator combiner() { + public BinaryOperator combiner() { return (r1, r2) -> { r1.append(r2); return r1; @@ -236,7 +237,7 @@ public BinaryOperator combiner() { } @Override - public Function finisher() { + public Function finisher() { return (a) -> a; } @@ -252,17 +253,17 @@ public Set characteristics() { * * @return flattened text */ - public static List flattenRoot(Text text) { + public static List flattenRoot(Component text) { var siblings = text.getSiblings(); - if (text.getContent().equals(PlainTextContent.EMPTY) && siblings.size() == 1) { + if (text.getContents().equals(PlainTextContents.EMPTY) && siblings.size() == 1) { return siblings; } else if (siblings.size() == 0) { return List.of(text); } - List content = new ArrayList<>(siblings.size() + 1); - if (!text.getContent().equals(PlainTextContent.EMPTY)) { - content.add(text.copyContentOnly().setStyle(text.getStyle())); + List content = new ArrayList<>(siblings.size() + 1); + if (!text.getContents().equals(PlainTextContents.EMPTY)) { + content.add(text.plainCopy().setStyle(text.getStyle())); } content.addAll(siblings); diff --git a/ec-core/src/main/java/dev/jpcode/eccore/util/TimeUtil.java b/ec-core/src/main/java/dev/jpcode/eccore/util/TimeUtil.java index f4228e04..ed15e54c 100644 --- a/ec-core/src/main/java/dev/jpcode/eccore/util/TimeUtil.java +++ b/ec-core/src/main/java/dev/jpcode/eccore/util/TimeUtil.java @@ -17,7 +17,7 @@ public static void init(MinecraftServer server) { } public static int getTicks() { - return server.getTicks(); + return server.getTickCount(); } public static long ticksToMs(int ticks) { @@ -29,12 +29,12 @@ public static int msToTicks(long ms) { } public static long tickTimeToEpochMs(int ticks) { - return ticksToMs(ticks - server.getTicks()) + net.minecraft.util.Util.getEpochTimeMs(); + return ticksToMs(ticks - server.getTickCount()) + net.minecraft.util.Util.getEpochMillis(); } public static int epochTimeMsToTicks(long epochTimeMs) { - var msFromNow = epochTimeMs - net.minecraft.util.Util.getEpochTimeMs(); - return server.getTicks() + msToTicks(msFromNow); + var msFromNow = epochTimeMs - net.minecraft.util.Util.getEpochMillis(); + return server.getTickCount() + msToTicks(msFromNow); } public static int durationToTicks(Duration duration) { diff --git a/ec-core/src/test/java/dev/jpcode/eccore/config/ConfigUtilTest.java b/ec-core/src/test/java/dev/jpcode/eccore/config/ConfigUtilTest.java new file mode 100644 index 00000000..fd0bf35f --- /dev/null +++ b/ec-core/src/test/java/dev/jpcode/eccore/config/ConfigUtilTest.java @@ -0,0 +1,27 @@ +package dev.jpcode.eccore.config; + +import net.minecraft.ChatFormatting; +import net.minecraft.SharedConstants; +import net.minecraft.server.Bootstrap; +import net.minecraft.network.chat.Style; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class ConfigUtilTest { + @BeforeEach + void setUp() { + SharedConstants.tryDetectVersion(); + Bootstrap.bootStrap(); + } + + @Test + void testStyleParser() { + Style expected = Style.EMPTY.withColor(ChatFormatting.RED); + Style thing = ConfigUtil.parseStyle("{\"color\":\"red\"}"); + + assertEquals(thing, expected); + } +} diff --git a/ec-core/src/test/java/dev/jpcode/eccore/util/TextUtilTests.java b/ec-core/src/test/java/dev/jpcode/eccore/util/TextUtilTests.java index 43c5ff32..56895dbc 100644 --- a/ec-core/src/test/java/dev/jpcode/eccore/util/TextUtilTests.java +++ b/ec-core/src/test/java/dev/jpcode/eccore/util/TextUtilTests.java @@ -5,36 +5,36 @@ import com.mojang.serialization.JsonOps; -import net.minecraft.Bootstrap; +import net.minecraft.server.Bootstrap; import net.minecraft.SharedConstants; -import net.minecraft.registry.Registries; -import net.minecraft.text.Style; -import net.minecraft.text.Text; -import net.minecraft.text.TextCodecs; -import net.minecraft.util.Formatting; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.ComponentSerialization; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Style; import static org.junit.jupiter.api.Assertions.assertEquals; @DisplayName("TextUtil") public class TextUtilTests { static { - SharedConstants.createGameVersion(); - Bootstrap.initialize(); - Registries.bootstrap(); + SharedConstants.tryDetectVersion(); + Bootstrap.bootStrap(); + BuiltInRegistries.bootStrap(); } @Test @DisplayName("flattenRoot output is shaped correctly") void flattenRoot_flattensCorrectly() { - var baseStyle = Style.EMPTY.withColor(Formatting.AQUA); - var input = Text.literal("testing").setStyle(baseStyle) + var baseStyle = Style.EMPTY.withColor(ChatFormatting.AQUA); + var input = Component.literal("testing").setStyle(baseStyle) .append("token2") .append("token3"); var output = TextUtil.flattenRoot(input); - assertEquals(output.getFirst().getContent(), input.getContent()); + assertEquals(output.getFirst().getContents(), input.getContents()); assertEquals(output.getFirst().getStyle(), baseStyle); var inputSiblings = input.getSiblings(); @@ -42,7 +42,7 @@ void flattenRoot_flattensCorrectly() var inputToken = inputSiblings.get(i - 1); var outToken = output.get(i); - assertEquals(inputToken.getContent(), outToken.getContent()); + assertEquals(inputToken.getContents(), outToken.getContents()); assertEquals(inputToken.getStyle(), outToken.getStyle()); } } @@ -51,12 +51,12 @@ void flattenRoot_flattensCorrectly() @DisplayName("from-to json is remotely sane") void fromToJson_isSane() { - var originalText = Text.literal(" hi there! "); - var textAsJson = TextCodecs.CODEC.encodeStart(JsonOps.INSTANCE, originalText) + var originalText = Component.literal(" hi there! "); + var textAsJson = ComponentSerialization.CODEC.encodeStart(JsonOps.INSTANCE, originalText) .getOrThrow(); - var parsedText = TextCodecs.CODEC.parse(JsonOps.INSTANCE, textAsJson) + var parsedText = ComponentSerialization.CODEC.parse(JsonOps.INSTANCE, textAsJson) .getOrThrow(); - assertEquals(originalText.getContent(), parsedText.getContent()); + assertEquals(originalText.getContents(), parsedText.getContents()); assertEquals(originalText.getStyle(), parsedText.getStyle()); // I think both null? } } diff --git a/gradle.properties b/gradle.properties index b3a6cfb0..6d17e998 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,6 @@ org.gradle.jvmargs=-Xmx2048M # Fabric Properties # check these on https://fabricmc.net/develup minecraft_version=1.21.11 -yarn_mappings=1.21.11+build.1 loader_version=0.18.2 loom_version=1.13-SNAPSHOT diff --git a/src/main/java/com/fibermc/essentialcommands/ECPerms.java b/src/main/java/com/fibermc/essentialcommands/ECPerms.java index eb04b4da..7f2ff2ad 100644 --- a/src/main/java/com/fibermc/essentialcommands/ECPerms.java +++ b/src/main/java/com/fibermc/essentialcommands/ECPerms.java @@ -6,15 +6,12 @@ import java.util.stream.Stream; import me.lucko.fabric.api.permissions.v0.Permissions; - -import net.minecraft.command.permission.Permission; - -import net.minecraft.command.permission.PermissionLevel; - import org.jetbrains.annotations.NotNull; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.permissions.Permission; +import net.minecraft.server.permissions.PermissionLevel; import static com.fibermc.essentialcommands.EssentialCommands.CONFIG; @@ -116,37 +113,38 @@ static void init() { }); } - private static boolean isSuperAdmin(ServerCommandSource source) { - return source.getPermissions().hasPermission(new Permission.Level(PermissionLevel.OWNERS)); + private static boolean isSuperAdmin(CommandSourceStack source) { + return source.permissions().hasPermission(new Permission.HasCommandLevel(PermissionLevel.OWNERS)); } - public static @NotNull Predicate require(@NotNull String permission, int defaultRequireLevel) { + public static @NotNull Predicate require(@NotNull String permission, int defaultRequireLevel) { return player -> check(player, permission, defaultRequireLevel); } - public static @NotNull Predicate requireAny(@NotNull String[] permissions, int defaultRequireLevel) { + public static @NotNull Predicate requireAny(@NotNull String[] permissions, int defaultRequireLevel) { return player -> checkAny(player, permissions, defaultRequireLevel); } - public static boolean check(@NotNull ServerCommandSource source, @NotNull String permission, int defaultRequireLevel) { + public static boolean check(@NotNull CommandSourceStack source, @NotNull String permission, int defaultRequireLevel) { if (CONFIG.USE_PERMISSIONS_API) { try { // TODO: In the future, config option for granting ops all perms. - return Permissions.getPermissionValue(source, permission).orElse(source.getPermissions().hasPermission(new Permission.Level(PermissionLevel.fromLevel(Math.max(2, defaultRequireLevel))))); + return Permissions.getPermissionValue(source, permission).orElse(source.permissions() + .hasPermission(new Permission.HasCommandLevel(PermissionLevel.byId(Math.max(2, defaultRequireLevel))))); } catch (Exception e) { EssentialCommands.LOGGER.error(e); return false; } } else { - return source.getPermissions().hasPermission(new Permission.Level(PermissionLevel.fromLevel(defaultRequireLevel))); + return source.permissions().hasPermission(new Permission.HasCommandLevel(PermissionLevel.byId(defaultRequireLevel))); } } - public static boolean check(@NotNull ServerCommandSource source, @NotNull String permission) { + public static boolean check(@NotNull CommandSourceStack source, @NotNull String permission) { return check(source, permission, 4); } - public static boolean checkAny(@NotNull ServerCommandSource source, @NotNull String[] permissions, int defaultRequireLevel) { + public static boolean checkAny(@NotNull CommandSourceStack source, @NotNull String[] permissions, int defaultRequireLevel) { for (String permission : permissions) { if (check(source, permission, defaultRequireLevel)) { return true; @@ -159,7 +157,7 @@ private static int getNumericValue(String permission) { return Integer.parseInt(permission.substring(permission.lastIndexOf('.') + 1)); } - public static int getHighestNumericPermission(@NotNull ServerCommandSource source, @NotNull String[] permissionGroup) { + public static int getHighestNumericPermission(@NotNull CommandSourceStack source, @NotNull String[] permissionGroup) { // No effective numeric limits for ops. if (isSuperAdmin(source)) { return Integer.MAX_VALUE; @@ -198,10 +196,10 @@ public static String[] makeNumericPermissionGroup(String basePermission, Collect return numericValues.stream().map(el -> trueBasePermission.concat(el.toString())).toArray(String[]::new); } - public static Stream getGrantedStatefulPlayerAbilityPermissions(ServerPlayerEntity player) { + public static Stream getGrantedStatefulPlayerAbilityPermissions(ServerPlayer player) { var list = Arrays.stream(Registry.Group.stateful_player_abilities); - return player.getPermissions().hasPermission(new Permission.Level(PermissionLevel.GAMEMASTERS)) + return player.permissions().hasPermission(new Permission.HasCommandLevel(PermissionLevel.GAMEMASTERS)) ? list // TODO: this is hacky - : list.filter(permission -> check(player.getCommandSource(), permission)); + : list.filter(permission -> check(player.createCommandSourceStack(), permission)); } } diff --git a/src/main/java/com/fibermc/essentialcommands/ECPlaceholderRegistry.java b/src/main/java/com/fibermc/essentialcommands/ECPlaceholderRegistry.java index 03765d44..4856ccbc 100644 --- a/src/main/java/com/fibermc/essentialcommands/ECPlaceholderRegistry.java +++ b/src/main/java/com/fibermc/essentialcommands/ECPlaceholderRegistry.java @@ -4,7 +4,7 @@ import eu.pb4.placeholders.api.PlaceholderResult; import eu.pb4.placeholders.api.Placeholders; -import net.minecraft.util.Identifier; +import net.minecraft.resources.Identifier; final class ECPlaceholderRegistry { private ECPlaceholderRegistry() {} @@ -12,7 +12,7 @@ private ECPlaceholderRegistry() {} public static void register() { var namespace = EssentialCommands.MOD_ID; Placeholders.register( - Identifier.of(namespace, "nickname"), + Identifier.fromNamespaceAndPath(namespace, "nickname"), (ctx, arg) -> { if (ctx.hasPlayer()) { return PlaceholderResult.value( diff --git a/src/main/java/com/fibermc/essentialcommands/EssentialCommandRegistry.java b/src/main/java/com/fibermc/essentialcommands/EssentialCommandRegistry.java index cb3cf35d..523a27ab 100644 --- a/src/main/java/com/fibermc/essentialcommands/EssentialCommandRegistry.java +++ b/src/main/java/com/fibermc/essentialcommands/EssentialCommandRegistry.java @@ -17,11 +17,6 @@ import com.fibermc.essentialcommands.types.NamedMinecraftLocation; import com.fibermc.essentialcommands.util.EssentialsConvertor; import com.fibermc.essentialcommands.util.EssentialsXParser; - -import net.minecraft.command.permission.Permission; - -import net.minecraft.command.permission.PermissionLevel; - import org.apache.logging.log4j.Level; import org.spongepowered.asm.util.IConsumer; @@ -33,17 +28,19 @@ import com.mojang.brigadier.tree.LiteralCommandNode; import com.mojang.brigadier.tree.RootCommandNode; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.command.argument.EntityArgumentType; -import net.minecraft.command.argument.TextArgumentType; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.EntityArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.server.permissions.Permission; +import net.minecraft.server.permissions.PermissionLevel; import static com.fibermc.essentialcommands.EssentialCommands.BACKING_CONFIG; import static com.fibermc.essentialcommands.EssentialCommands.CONFIG; -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; +import static net.minecraft.commands.Commands.argument; +import static net.minecraft.commands.Commands.literal; /** * Primary registry class for EssentialCommands. @@ -54,19 +51,19 @@ public final class EssentialCommandRegistry { private EssentialCommandRegistry() {} public static void register( - CommandDispatcher dispatcher, - CommandRegistryAccess commandRegistryAccess, - CommandManager.RegistrationEnvironment registrationEnvironment + CommandDispatcher dispatcher, + CommandBuildContext commandRegistryAccess, + Commands.CommandSelection registrationEnvironment ) { - RootCommandNode rootNode = dispatcher.getRoot(); + RootCommandNode rootNode = dispatcher.getRoot(); - LiteralCommandNode essentialCommandsRootNode; + LiteralCommandNode essentialCommandsRootNode; { - LiteralCommandNode ecInfoNode = CommandManager.literal("info") + LiteralCommandNode ecInfoNode = Commands.literal("info") .executes(new ModInfoCommand()) .build(); - essentialCommandsRootNode = CommandManager.literal("essentialcommands") + essentialCommandsRootNode = Commands.literal("essentialcommands") .executes(ecInfoNode.getCommand()) .build(); @@ -74,7 +71,7 @@ public static void register( } var excludedTopLevelCommands = new HashSet<>(CONFIG.EXCLUDED_TOP_LEVEL_COMMANDS); - IConsumer> registerNode = CONFIG.REGISTER_TOP_LEVEL_COMMANDS + IConsumer> registerNode = CONFIG.REGISTER_TOP_LEVEL_COMMANDS ? (node) -> { if (excludedTopLevelCommands.contains(node.getLiteral())) { excludedTopLevelCommands.remove(node.getLiteral()); @@ -86,18 +83,18 @@ public static void register( : essentialCommandsRootNode::addChild; if (CONFIG.ENABLE_TPA) { - registerNode.accept(CommandManager.literal("tpa") + registerNode.accept(Commands.literal("tpa") .requires(ECPerms.require(ECPerms.Registry.tpa, 0)) .then(CommandUtil.targetPlayerArgument() .executes(new TeleportAskCommand())) .build()); - registerNode.accept(CommandManager.literal("tpcancel") + registerNode.accept(Commands.literal("tpcancel") .requires(ECPerms.require(ECPerms.Registry.tpa, 0)) .executes(new TeleportCancelCommand()) .build()); - registerNode.accept(CommandManager.literal("tpaccept") + registerNode.accept(Commands.literal("tpaccept") .requires(ECPerms.require(ECPerms.Registry.tpaccept, 0)) .executes(new TeleportAcceptCommand()::runDefault) .then(CommandUtil.targetPlayerArgument() @@ -105,7 +102,7 @@ public static void register( .executes(new TeleportAcceptCommand())) .build()); - registerNode.accept(CommandManager.literal("tpdeny") + registerNode.accept(Commands.literal("tpdeny") .requires(ECPerms.require(ECPerms.Registry.tpdeny, 0)) .executes(new TeleportDenyCommand()::runDefault) .then(CommandUtil.targetPlayerArgument() @@ -113,7 +110,7 @@ public static void register( .executes(new TeleportDenyCommand())) .build()); - registerNode.accept(CommandManager.literal("tpahere") + registerNode.accept(Commands.literal("tpahere") .requires(ECPerms.require(ECPerms.Registry.tpahere, 0)) .then(CommandUtil.targetPlayerArgument() .executes(new TeleportAskHereCommand())) @@ -121,15 +118,15 @@ public static void register( } if (CONFIG.ENABLE_HOME) { - LiteralArgumentBuilder homeBuilder = CommandManager.literal("home"); - LiteralArgumentBuilder homeSetBuilder = CommandManager.literal("set"); - LiteralArgumentBuilder homeTpBuilder = CommandManager.literal("tp"); - LiteralArgumentBuilder homeTpOtherBuilder = CommandManager.literal("tp_other"); - LiteralArgumentBuilder homeTpOfflineBuilder = CommandManager.literal("tp_offline"); - LiteralArgumentBuilder homeDeleteBuilder = CommandManager.literal("delete"); - LiteralArgumentBuilder homeListBuilder = CommandManager.literal("list"); - LiteralArgumentBuilder homeListOfflineBuilder = CommandManager.literal("list_offline"); - LiteralArgumentBuilder homeOverwriteBuilder = CommandManager.literal("overwritehome"); + LiteralArgumentBuilder homeBuilder = Commands.literal("home"); + LiteralArgumentBuilder homeSetBuilder = Commands.literal("set"); + LiteralArgumentBuilder homeTpBuilder = Commands.literal("tp"); + LiteralArgumentBuilder homeTpOtherBuilder = Commands.literal("tp_other"); + LiteralArgumentBuilder homeTpOfflineBuilder = Commands.literal("tp_offline"); + LiteralArgumentBuilder homeDeleteBuilder = Commands.literal("delete"); + LiteralArgumentBuilder homeListBuilder = Commands.literal("list"); + LiteralArgumentBuilder homeListOfflineBuilder = Commands.literal("list_offline"); + LiteralArgumentBuilder homeOverwriteBuilder = Commands.literal("overwritehome"); homeSetBuilder .requires(ECPerms.require(ECPerms.Registry.home_set, 0)) @@ -146,7 +143,7 @@ public static void register( homeTpOtherBuilder .requires(ECPerms.require(ECPerms.Registry.home_tp_others, 2)) - .then(argument("target_player", EntityArgumentType.player()) + .then(argument("target_player", EntityArgument.player()) .then(argument("home_name", StringArgumentType.word()) .suggests(HomeTeleportOtherCommand.Suggestion.LIST_SUGGESTION_PROVIDER) .executes(new HomeTeleportOtherCommand()))); @@ -180,7 +177,7 @@ public static void register( .then(argument("home_name", StringArgumentType.word()) .executes(new HomeOverwriteCommand())); - LiteralCommandNode homeNode = homeBuilder + LiteralCommandNode homeNode = homeBuilder .requires(ECPerms.requireAny(ECPerms.Registry.Group.home_group, 0)) .build(); homeNode.addChild(homeTpBuilder.build()); @@ -198,12 +195,12 @@ public static void register( //Back if (CONFIG.ENABLE_BACK) { - LiteralArgumentBuilder backBuilder = CommandManager.literal("back"); + LiteralArgumentBuilder backBuilder = Commands.literal("back"); backBuilder .requires(ECPerms.require(ECPerms.Registry.back, 0)) .executes(new BackCommand()); - LiteralCommandNode backNode = backBuilder.build(); + LiteralCommandNode backNode = backBuilder.build(); rootNode.addChild(backNode); essentialCommandsRootNode.addChild(backNode); @@ -211,12 +208,12 @@ public static void register( //Warp if (CONFIG.ENABLE_WARP) { - LiteralArgumentBuilder warpBuilder = CommandManager.literal("warp"); - LiteralArgumentBuilder warpSetBuilder = CommandManager.literal("set"); - LiteralArgumentBuilder warpTpBuilder = CommandManager.literal("tp"); - LiteralArgumentBuilder warpTpOtherBuilder = CommandManager.literal("tp_other"); - LiteralArgumentBuilder warpDeleteBuilder = CommandManager.literal("delete"); - LiteralArgumentBuilder warpListBuilder = CommandManager.literal("list"); + LiteralArgumentBuilder warpBuilder = Commands.literal("warp"); + LiteralArgumentBuilder warpSetBuilder = Commands.literal("set"); + LiteralArgumentBuilder warpTpBuilder = Commands.literal("tp"); + LiteralArgumentBuilder warpTpOtherBuilder = Commands.literal("tp_other"); + LiteralArgumentBuilder warpDeleteBuilder = Commands.literal("delete"); + LiteralArgumentBuilder warpListBuilder = Commands.literal("list"); warpSetBuilder .requires(ECPerms.require(ECPerms.Registry.warp_set, 4)) @@ -233,7 +230,7 @@ public static void register( warpTpOtherBuilder .requires(ECPerms.require(ECPerms.Registry.home_tp_others, 2)) - .then(argument("target_player", EntityArgumentType.player()) + .then(argument("target_player", EntityArgument.player()) .then(argument("warp_name", StringArgumentType.word()) .suggests(WarpSuggestion.STRING_SUGGESTIONS_PROVIDER) .executes(new WarpTpCommand()::runOther))); @@ -249,11 +246,11 @@ public static void register( .executes(ListCommandFactory.create( ECText.getInstance().getString("cmd.warp.list.start"), "warp tp", - (context) -> ManagerLocator.getInstance().getWorldDataManager().getAccessibleWarps(context.getSource().getPlayerOrThrow()).toList(), + (context) -> ManagerLocator.getInstance().getWorldDataManager().getAccessibleWarps(context.getSource().getPlayerOrException()).toList(), NamedMinecraftLocation::getName )); - LiteralCommandNode warpNode = warpBuilder + LiteralCommandNode warpNode = warpBuilder .requires(ECPerms.requireAny(ECPerms.Registry.Group.warp_group, 0)) .build(); warpNode.addChild(warpTpBuilder.build()); @@ -267,9 +264,9 @@ public static void register( //Spawn if (CONFIG.ENABLE_SPAWN) { - LiteralArgumentBuilder spawnBuilder = CommandManager.literal("spawn"); - LiteralArgumentBuilder spawnSetBuilder = CommandManager.literal("set"); - LiteralArgumentBuilder spawnTpBuilder = CommandManager.literal("tp"); + LiteralArgumentBuilder spawnBuilder = Commands.literal("spawn"); + LiteralArgumentBuilder spawnSetBuilder = Commands.literal("set"); + LiteralArgumentBuilder spawnTpBuilder = Commands.literal("tp"); spawnSetBuilder .requires(ECPerms.require(ECPerms.Registry.spawn_set, 4)) @@ -283,7 +280,7 @@ public static void register( .requires(ECPerms.require(ECPerms.Registry.spawn_tp, 0)) .executes(cmd); - LiteralCommandNode spawnNode = spawnBuilder.build(); + LiteralCommandNode spawnNode = spawnBuilder.build(); spawnNode.addChild(spawnSetBuilder.build()); spawnNode.addChild(spawnTpBuilder.build()); @@ -291,19 +288,19 @@ public static void register( } if (CONFIG.ENABLE_NICK) { - LiteralArgumentBuilder nickBuilder = CommandManager.literal("nickname"); - LiteralArgumentBuilder nickSetBuilder = CommandManager.literal("set"); - LiteralArgumentBuilder nickClearBuilder = CommandManager.literal("clear"); - LiteralArgumentBuilder nickRevealBuilder = CommandManager.literal("reveal"); + LiteralArgumentBuilder nickBuilder = Commands.literal("nickname"); + LiteralArgumentBuilder nickSetBuilder = Commands.literal("set"); + LiteralArgumentBuilder nickClearBuilder = Commands.literal("clear"); + LiteralArgumentBuilder nickRevealBuilder = Commands.literal("reveal"); - Predicate permissionSelf = ECPerms.require(ECPerms.Registry.nickname_self, 2); - Predicate permissionOther = ECPerms.require(ECPerms.Registry.nickname_others, 2); + Predicate permissionSelf = ECPerms.require(ECPerms.Registry.nickname_self, 2); + Predicate permissionOther = ECPerms.require(ECPerms.Registry.nickname_others, 2); nickSetBuilder.requires(permissionSelf) - .then(argument("nickname", TextArgumentType.text(commandRegistryAccess)) + .then(argument("nickname", ComponentArgument.textComponent(commandRegistryAccess)) .executes(new NicknameSetCommand()) ).then(CommandUtil.targetPlayerArgument() .requires(permissionOther) - .then(argument("nickname", TextArgumentType.text(commandRegistryAccess)) + .then(argument("nickname", ComponentArgument.textComponent(commandRegistryAccess)) .executes(new NicknameSetCommand()) ).then(argument("nickname_placeholder_api", StringArgumentType.greedyString()) .executes(NicknameSetCommand::runStringToText) @@ -327,7 +324,7 @@ public static void register( .executes(new RealNameCommand()) ); - LiteralCommandNode nickNode = nickBuilder + LiteralCommandNode nickNode = nickBuilder .requires(ECPerms.requireAny(ECPerms.Registry.Group.nickname_group, 2)) .build(); nickNode.addChild(nickSetBuilder.build()); @@ -338,12 +335,12 @@ public static void register( } if (CONFIG.ENABLE_RTP) { - registerNode.accept(CommandManager.literal("randomteleport") + registerNode.accept(Commands.literal("randomteleport") .requires(ECPerms.require(ECPerms.Registry.randomteleport, 2)) .executes(new RandomTeleportCommand()) .build()); - registerNode.accept(CommandManager.literal("rtp") + registerNode.accept(Commands.literal("rtp") .requires(ECPerms.require(ECPerms.Registry.randomteleport, 2)) .executes(new RandomTeleportCommand()) .build() @@ -351,11 +348,11 @@ public static void register( } if (CONFIG.ENABLE_FLY) { - LiteralArgumentBuilder flyBuilder = CommandManager.literal("fly"); - LiteralArgumentBuilder flySpeedBuilder = CommandManager.literal("speed"); + LiteralArgumentBuilder flyBuilder = Commands.literal("fly"); + LiteralArgumentBuilder flySpeedBuilder = Commands.literal("speed"); - Predicate permissionSelf = ECPerms.require(ECPerms.Registry.fly_self, 2); - Predicate permissionOther = ECPerms.require(ECPerms.Registry.fly_others, 2); + Predicate permissionSelf = ECPerms.require(ECPerms.Registry.fly_self, 2); + Predicate permissionOther = ECPerms.require(ECPerms.Registry.fly_others, 2); flyBuilder .requires(permissionSelf) @@ -369,18 +366,18 @@ public static void register( flySpeedBuilder .requires(permissionSelf) - .then(CommandManager.literal("reset") + .then(Commands.literal("reset") .executes(new FlySpeedCommand()::reset)) .then(argument("fly_speed", IntegerArgumentType.integer(0)) .executes(new FlySpeedCommand())) .then(CommandUtil.targetPlayerArgument() .requires(permissionOther) - .then(CommandManager.literal("reset") + .then(Commands.literal("reset") .executes(new FlySpeedCommand()::reset)) .then(argument("fly_speed", IntegerArgumentType.integer(0)) .executes(new FlySpeedCommand()))); - LiteralCommandNode flyNode = flyBuilder.build(); + LiteralCommandNode flyNode = flyBuilder.build(); flyNode.addChild(flySpeedBuilder.build()); registerNode.accept(flyNode); @@ -388,7 +385,7 @@ public static void register( if (CONFIG.ENABLE_INVULN) { registerNode.accept( - CommandManager.literal("invuln") + Commands.literal("invuln") .requires(ECPerms.require(ECPerms.Registry.invuln_self, 2)) .executes(new InvulnCommand()) .then(CommandUtil.targetPlayerArgument() @@ -399,79 +396,79 @@ public static void register( } if (CONFIG.ENABLE_WORKBENCH) { - registerNode.accept(CommandManager.literal("workbench") + registerNode.accept(Commands.literal("workbench") .requires(ECPerms.require(ECPerms.Registry.workbench, 0)) .executes(new WorkbenchCommand()) .build()); - registerNode.accept(CommandManager.literal("stonecutter") + registerNode.accept(Commands.literal("stonecutter") .requires(ECPerms.require(ECPerms.Registry.stonecutter, 0)) .executes(new StonecutterCommand()) .build()); - registerNode.accept(CommandManager.literal("grindstone") + registerNode.accept(Commands.literal("grindstone") .requires(ECPerms.require(ECPerms.Registry.grindstone, 0)) .executes(new GrindstoneCommand()) .build()); } if (CONFIG.ENABLE_ANVIL) { - registerNode.accept(CommandManager.literal("anvil") + registerNode.accept(Commands.literal("anvil") .requires(ECPerms.require(ECPerms.Registry.anvil, 0)) .executes(new AnvilCommand()) .build()); } if (CONFIG.ENABLE_ENDERCHEST) { - registerNode.accept(CommandManager.literal("enderchest") + registerNode.accept(Commands.literal("enderchest") .requires(ECPerms.require(ECPerms.Registry.enderchest, 0)) .executes(new EnderchestCommand()) .build()); } if (CONFIG.ENABLE_WASTEBIN) { - registerNode.accept(CommandManager.literal("wastebin") + registerNode.accept(Commands.literal("wastebin") .requires(ECPerms.require(ECPerms.Registry.wastebin, 0)) .executes(new WastebinCommand()) .build()); } if (CONFIG.ENABLE_TOP) { - registerNode.accept(CommandManager.literal("top") + registerNode.accept(Commands.literal("top") .requires(ECPerms.require(ECPerms.Registry.top, 2)) .executes(new TopCommand()) .build()); } if (CONFIG.ENABLE_GAMETIME) { - registerNode.accept(CommandManager.literal("gametime") + registerNode.accept(Commands.literal("gametime") .requires(ECPerms.require(ECPerms.Registry.gametime, 0)) .executes(new GametimeCommand()) .build()); } if (CONFIG.ENABLE_AFK) { - registerNode.accept(CommandManager.literal("afk") + registerNode.accept(Commands.literal("afk") .requires(ECPerms.require(ECPerms.Registry.afk, 0)) .executes(new AfkCommand()) .build()); } if (CONFIG.ENABLE_BED) { - registerNode.accept(CommandManager.literal("bed") + registerNode.accept(Commands.literal("bed") .requires(ECPerms.require(ECPerms.Registry.bed, 0)) .executes(new BedCommand()) .build()); } if (CONFIG.ENABLE_SLEEP) { - registerNode.accept(CommandManager.literal("sleep") + registerNode.accept(Commands.literal("sleep") .requires(ECPerms.require(ECPerms.Registry.sleep, 0)) .executes(new SleepCommand()) .build()); } - registerNode.accept(CommandManager.literal("lastPos") + registerNode.accept(Commands.literal("lastPos") .requires(ECPerms.require("essentialcommands.admin.lastpos", 2)) .then(argument("target_player", StringArgumentType.word()) .executes((context) -> { @@ -481,11 +478,11 @@ public static void register( .getOfflinePlayerByNameAsync(targetPlayerName) .whenComplete((playerEntity, err) -> { if (playerEntity == null) { - context.getSource().sendError(Text.of("No player with the specified name found.")); + context.getSource().sendFailure(Component.nullToEmpty("No player with the specified name found.")); return; } - context.getSource().sendFeedback(() -> - Text.of(playerEntity.getEntityPos().toString()), + context.getSource().sendSuccess(() -> + Component.nullToEmpty(playerEntity.position().toString()), EssentialCommands.CONFIG.BROADCAST_TO_OPS); }); return 1; @@ -493,14 +490,14 @@ public static void register( .build()); if (CONFIG.ENABLE_DAY) { - registerNode.accept(CommandManager.literal("day") + registerNode.accept(Commands.literal("day") .requires(ECPerms.require(ECPerms.Registry.time_set_day, 2)) .executes(new DayCommand()) .build()); } if (CONFIG.ENABLE_RULES) { - registerNode.accept(CommandManager.literal("rules") + registerNode.accept(Commands.literal("rules") .requires(ECPerms.require(ECPerms.Registry.rules, 0)) .executes(RulesCommand::run) .then(literal("reload") @@ -510,7 +507,7 @@ public static void register( } if (CONFIG.ENABLE_FEED) { - registerNode.accept(CommandManager.literal("feed") + registerNode.accept(Commands.literal("feed") .requires(ECPerms.require(ECPerms.Registry.feed_self, 2)) .executes(new FeedCommand()) .then(CommandUtil.targetPlayerArgument() @@ -520,7 +517,7 @@ public static void register( } if (CONFIG.ENABLE_HEAL) { - registerNode.accept(CommandManager.literal("heal") + registerNode.accept(Commands.literal("heal") .requires(ECPerms.require(ECPerms.Registry.heal_self, 2)) .executes(new HealCommand()) .then(CommandUtil.targetPlayerArgument() @@ -530,7 +527,7 @@ public static void register( } if (CONFIG.ENABLE_EXTINGUISH) { - LiteralCommandNode node = CommandManager.literal("extinguish") + LiteralCommandNode node = Commands.literal("extinguish") .requires(ECPerms.require(ECPerms.Registry.extinguish_self, 2)) .executes(new ExtinguishCommand()) .then(CommandUtil.targetPlayerArgument() @@ -539,25 +536,25 @@ public static void register( .build(); registerNode.accept(node); - registerNode.accept(CommandManager.literal("ext").redirect(node).build()); + registerNode.accept(Commands.literal("ext").redirect(node).build()); } if (CONFIG.ENABLE_SUICIDE) { - registerNode.accept(CommandManager.literal("suicide") + registerNode.accept(Commands.literal("suicide") .requires(ECPerms.require(ECPerms.Registry.suicide, 0)) .executes(new SuicideCommand()) .build()); } if (CONFIG.ENABLE_NIGHT) { - registerNode.accept(CommandManager.literal("night") + registerNode.accept(Commands.literal("night") .requires(ECPerms.require(ECPerms.Registry.time_set_night, 2)) .executes(new NightCommand()) .build()); } if (CONFIG.ENABLE_REPAIR) { - registerNode.accept(CommandManager.literal("repair") + registerNode.accept(Commands.literal("repair") .requires(ECPerms.require(ECPerms.Registry.repair_self, 2)) .executes(new RepairCommand()) .then(CommandUtil.targetPlayerArgument() @@ -567,7 +564,7 @@ public static void register( } if (CONFIG.ENABLE_NEAR) { - registerNode.accept(CommandManager.literal("near") + registerNode.accept(Commands.literal("near") .requires(ECPerms.require(ECPerms.Registry.near_self, 2)) .executes(new NearCommand()) .then(argument("range", IntegerArgumentType.integer()) @@ -579,7 +576,7 @@ public static void register( } if (CONFIG.ENABLE_MOTD) { - registerNode.accept(CommandManager.literal("motd") + registerNode.accept(Commands.literal("motd") .requires(ECPerms.require(ECPerms.Registry.motd, 0)) .executes(MotdCommand::run) .build()); @@ -588,14 +585,14 @@ public static void register( var profileNode = ProfileCommand.buildNode(); essentialCommandsRootNode.addChild(profileNode); - LiteralCommandNode configNode = CommandManager.literal("config") + LiteralCommandNode configNode = Commands.literal("config") .requires(ECPerms.requireAny(ECPerms.Registry.Group.config_group, 4)) - .then(CommandManager.literal("reload") + .then(Commands.literal("reload") .executes((context) -> { BACKING_CONFIG.loadOrCreateProperties(); var player = context.getSource().getPlayer(); var ecText = player != null ? ECText.access(player) : ECText.getInstance(); - context.getSource().sendFeedback(() -> + context.getSource().sendSuccess(() -> ecText.getText("cmd.config.reload"), true ); @@ -603,23 +600,23 @@ public static void register( }).requires( ECPerms.require(ECPerms.Registry.config_reload, 4) ).build()) - .then(CommandManager.literal("display") + .then(Commands.literal("display") .requires(ECPerms.require(ECPerms.Registry.config_reload, 4)) .executes((context) -> { BACKING_CONFIG.loadOrCreateProperties(); - context.getSource().sendFeedback( + context.getSource().sendSuccess( BACKING_CONFIG::stateAsText, false ); return 1; }) - .then(CommandManager.argument("config_property", StringArgumentType.word()) + .then(Commands.argument("config_property", StringArgumentType.word()) .suggests(ListSuggestion.of(BACKING_CONFIG::getPublicFieldNames)) .executes(context -> { try { - Text t = BACKING_CONFIG.getFieldValueAsText( + Component t = BACKING_CONFIG.getFieldValueAsText( StringArgumentType.getString(context, "config_property")); - context.getSource().sendFeedback(() -> t, false); + context.getSource().sendSuccess(() -> t, false); } catch (NoSuchFieldException e) { e.printStackTrace(); } @@ -632,40 +629,40 @@ public static void register( essentialCommandsRootNode.addChild(configNode); if (true) { - essentialCommandsRootNode.addChild(CommandManager.literal("deleteAllPlayerData") - .requires(source -> source.getPermissions().hasPermission(new Permission.Level(PermissionLevel.OWNERS))) + essentialCommandsRootNode.addChild(Commands.literal("deleteAllPlayerData") + .requires(source -> source.permissions().hasPermission(new Permission.HasCommandLevel(PermissionLevel.OWNERS))) .executes(new ClearPlayerDataCommand()) .build() ); } if (CONFIG.ENABLE_ESSENTIALSX_CONVERT) { - essentialCommandsRootNode.addChild(CommandManager.literal("convertEssentialsXPlayerHomes") - .requires(source -> source.getPermissions().hasPermission(new Permission.Level(PermissionLevel.OWNERS))) + essentialCommandsRootNode.addChild(Commands.literal("convertEssentialsXPlayerHomes") + .requires(source -> source.permissions().hasPermission(new Permission.HasCommandLevel(PermissionLevel.OWNERS))) .executes((source) -> { - Path mcDir = source.getSource().getServer().getRunDirectory(); + Path mcDir = source.getSource().getServer().getServerDirectory(); try { EssentialsXParser.convertPlayerDataDir( mcDir.resolve("plugins/Essentials/userdata").toFile(), mcDir.resolve("world/modplayerdata").toFile(), source.getSource().getServer() ); - source.getSource().sendFeedback(() -> Text.literal("Successfully converted data dirs."), CONFIG.BROADCAST_TO_OPS); + source.getSource().sendSuccess(() -> Component.literal("Successfully converted data dirs."), CONFIG.BROADCAST_TO_OPS); } catch (NotDirectoryException | FileNotFoundException e) { e.printStackTrace(); } return 0; }).build() ); - essentialCommandsRootNode.addChild(CommandManager.literal("convertEssentialsXWarps") - .requires(source -> source.getPermissions().hasPermission(new Permission.Level(PermissionLevel.OWNERS))) + essentialCommandsRootNode.addChild(Commands.literal("convertEssentialsXWarps") + .requires(source -> source.permissions().hasPermission(new Permission.HasCommandLevel(PermissionLevel.OWNERS))) .executes((source) -> { - Path mcDir = source.getSource().getServer().getRunDirectory(); + Path mcDir = source.getSource().getServer().getServerDirectory(); EssentialsConvertor.warpConvert( source.getSource().getServer(), mcDir.resolve("plugins/Essentials/warps").toFile() ); - source.getSource().sendFeedback(() -> Text.literal("Successfully converted warps."), CONFIG.BROADCAST_TO_OPS); + source.getSource().sendSuccess(() -> Component.literal("Successfully converted warps."), CONFIG.BROADCAST_TO_OPS); return 0; }).build() ); diff --git a/src/main/java/com/fibermc/essentialcommands/WorldData.java b/src/main/java/com/fibermc/essentialcommands/WorldData.java index d1056fe0..5703bf00 100644 --- a/src/main/java/com/fibermc/essentialcommands/WorldData.java +++ b/src/main/java/com/fibermc/essentialcommands/WorldData.java @@ -13,9 +13,9 @@ import com.mojang.serialization.Dynamic; import com.mojang.serialization.codecs.RecordCodecBuilder; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtElement; +import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtOps; +import net.minecraft.nbt.Tag; public class WorldData { private @Nullable MinecraftLocation spawnLocation; @@ -43,20 +43,20 @@ public void setSpawn(@Nullable MinecraftLocation spawn) { this.spawnLocation = spawn; } - public static WorldData fromNbt(NbtCompound nbt) { + public static WorldData fromNbt(CompoundTag nbt) { // Handle legacy "data" wrapper if present nbt = nbt.getCompound("data").orElse(nbt); nbt = WorldDataDataFixer.createDataFixer().build().fixer().update( WorldDataDataFixer.TYPE, - new Dynamic(NbtOps.INSTANCE, nbt), - nbt.getInt(SCHEMA_VERSION_KEY, 0), + new Dynamic(NbtOps.INSTANCE, nbt), + nbt.getIntOr(SCHEMA_VERSION_KEY, 0), WorldData.SCHEMA_VERSION ).getValue().asCompound().orElseThrow(); return CODEC.parse(NbtOps.INSTANCE, nbt).getOrThrow(); } - public NbtCompound toNbt() { + public CompoundTag toNbt() { var data = CODEC.encodeStart(NbtOps.INSTANCE, this).getOrThrow().asCompound().orElseThrow(); data.putInt(SCHEMA_VERSION_KEY, SCHEMA_VERSION); return data; diff --git a/src/main/java/com/fibermc/essentialcommands/WorldDataManager.java b/src/main/java/com/fibermc/essentialcommands/WorldDataManager.java index ef1a23c2..2d4e544f 100644 --- a/src/main/java/com/fibermc/essentialcommands/WorldDataManager.java +++ b/src/main/java/com/fibermc/essentialcommands/WorldDataManager.java @@ -18,18 +18,18 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtAccounter; import net.minecraft.nbt.NbtIo; -import net.minecraft.nbt.NbtSizeTracker; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.WorldSavePath; -import net.minecraft.world.PersistentState; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.level.saveddata.SavedData; +import net.minecraft.world.level.storage.LevelResource; import net.fabricmc.fabric.api.event.Event; import net.fabricmc.fabric.api.event.EventFactory; -public class WorldDataManager extends PersistentState { +public class WorldDataManager extends SavedData { private Path saveDir; private File worldDataFile; private WorldData data; @@ -46,7 +46,7 @@ public static WorldDataManager createForServer(MinecraftServer server) } public void onServerStart(MinecraftServer server) { - this.saveDir = server.getSavePath(WorldSavePath.ROOT).resolve("essentialcommands"); + this.saveDir = server.getWorldPath(LevelResource.ROOT).resolve("essentialcommands"); try { Files.createDirectories(saveDir); } catch (IOException e) { @@ -59,12 +59,12 @@ public void onServerStart(MinecraftServer server) { boolean fileExisted = !worldDataFile.createNewFile(); if (fileExisted && worldDataFile.length() > 0) { // if files was not JUST created, read data from it. - var tag = NbtIo.readCompressed(worldDataFile.toPath(), NbtSizeTracker.ofUnlimitedBytes()); + var tag = NbtIo.readCompressed(worldDataFile.toPath(), NbtAccounter.unlimitedHeap()); // `data` was the main obj key in old mc PersistentState schema this.data = WorldData.fromNbt(tag.getCompound("data").orElse(tag)); warpsLoadEvent.invoker().accept(this.data.warps()); } else { - this.markDirty(); + this.setDirty(); this.save(); } } catch (IOException e) { @@ -87,7 +87,7 @@ private File getDataFile() { public void save() { EssentialCommands.log(Level.INFO, "Saving world_data.dat (Spawn/Warps)..."); - NbtCompound data = this.data.toNbt(); + CompoundTag data = this.data.toNbt(); try { NbtIo.writeCompressed(data, this.worldDataFile.toPath()); } catch (IOException e) { @@ -103,13 +103,13 @@ public void setWarp(String warpName, MinecraftLocation location, boolean require requiresPermission ? warpName : null, warpName )); - this.markDirty(); + this.setDirty(); this.save(); } public boolean delWarp(String warpName) { MinecraftLocation prevValue = this.data.warps().remove(warpName); - this.markDirty(); + this.setDirty(); this.save(); return prevValue != null; } @@ -122,7 +122,7 @@ public List getWarpNames() { return this.data.warps().keySet().stream().toList(); } - public Stream getAccessibleWarps(ServerPlayerEntity player) { + public Stream getAccessibleWarps(ServerPlayer player) { var warpsStream = this.data.warps().values().stream(); return (EssentialCommands.CONFIG.USE_PERMISSIONS_API ? warpsStream.filter(loc -> loc.hasPermission(player)) @@ -135,7 +135,7 @@ public Set> getWarpEntries() { public void setSpawn(MinecraftLocation location) { this.data.setSpawn(location); - this.markDirty(); + this.setDirty(); this.save(); } diff --git a/src/main/java/com/fibermc/essentialcommands/codec/Codecs.java b/src/main/java/com/fibermc/essentialcommands/codec/Codecs.java index 4aae52a0..2f73d0bd 100644 --- a/src/main/java/com/fibermc/essentialcommands/codec/Codecs.java +++ b/src/main/java/com/fibermc/essentialcommands/codec/Codecs.java @@ -9,14 +9,14 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; -import net.minecraft.registry.RegistryKey; -import net.minecraft.registry.RegistryKeys; -import net.minecraft.world.World; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.Level; public final class Codecs { private Codecs() {} - public static final Codec> WORLD_KEY = RegistryKey.createCodec(RegistryKeys.WORLD); + public static final Codec> WORLD_KEY = ResourceKey.codec(Registries.DIMENSION); public static final Codec MINECRAFT_LOCATION = RecordCodecBuilder.create(instance -> instance.group( diff --git a/src/main/java/com/fibermc/essentialcommands/commands/AfkCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/AfkCommand.java index 73d59be2..28462868 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/AfkCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/AfkCommand.java @@ -6,15 +6,15 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.commands.CommandSourceStack; import static com.fibermc.essentialcommands.EssentialCommands.CONFIG; -public class AfkCommand implements Command { +public class AfkCommand implements Command { @Override - public int run(CommandContext context) throws CommandSyntaxException { + public int run(CommandContext context) throws CommandSyntaxException { var source = context.getSource(); - var player = source.getPlayerOrThrow(); + var player = source.getPlayerOrException(); var playerAccess = ((ServerPlayerEntityAccess) player); var playerData = playerAccess.ec$getPlayerData(); diff --git a/src/main/java/com/fibermc/essentialcommands/commands/BackCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/BackCommand.java index 03fced6b..37c0d917 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/BackCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/BackCommand.java @@ -10,17 +10,17 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.level.ServerPlayer; -public class BackCommand implements Command { +public class BackCommand implements Command { public BackCommand() {} @Override - public int run(CommandContext context) throws CommandSyntaxException { + public int run(CommandContext context) throws CommandSyntaxException { //Store command sender - ServerPlayerEntity player = context.getSource().getPlayerOrThrow(); + ServerPlayer player = context.getSource().getPlayerOrException(); PlayerData playerData = ((ServerPlayerEntityAccess) player).ec$getPlayerData(); //Get previous location diff --git a/src/main/java/com/fibermc/essentialcommands/commands/BedCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/BedCommand.java index 0c84da60..acd84a9b 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/BedCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/BedCommand.java @@ -12,22 +12,22 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.block.BedBlock; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.RespawnAnchorBlock; -import net.minecraft.entity.EntityType; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.Vec3d; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.attribute.EnvironmentAttributes; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.level.block.BedBlock; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.RespawnAnchorBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.Vec3; -public class BedCommand implements Command { +public class BedCommand implements Command { @Override - public int run(CommandContext context) throws CommandSyntaxException { + public int run(CommandContext context) throws CommandSyntaxException { var source = context.getSource(); - var player = source.getPlayerOrThrow(); + var player = source.getPlayerOrException(); var safeSpawnPos = getSafeSpawnPos(player); if (safeSpawnPos.isEmpty()) { @@ -50,40 +50,40 @@ public int run(CommandContext context) throws CommandSyntax * if a "safe" spawnpoint cannot be found, we'll return a point just above the respawn target * block) */ - private static Optional getSafeSpawnPos(ServerPlayerEntity player) { - var respawn = player.getRespawn(); + private static Optional getSafeSpawnPos(ServerPlayer player) { + var respawn = player.getRespawnConfig(); if (respawn == null) { return Optional.empty(); } var respawnPosData = respawn.respawnData().globalPos(); - ServerWorld world = player.getEntityWorld().getServer().getWorld(respawnPosData.dimension()); + ServerLevel world = player.level().getServer().getLevel(respawnPosData.dimension()); var spawnPos = respawnPosData.pos(); // Safe Position Calculation, based on the game respawn position calculation logic, // which was basically rewritten because the game code caused the state of the RespawnAnchorBlock to be refreshed. - Vec3d safeSpawnPos; + Vec3 safeSpawnPos; BlockState blockState = world.getBlockState(spawnPos); Block block = blockState.getBlock(); if (block instanceof RespawnAnchorBlock - && blockState.get(RespawnAnchorBlock.CHARGES) > 0 && RespawnAnchorBlock.isUsable(world, spawnPos) + && blockState.getValue(RespawnAnchorBlock.CHARGE) > 0 && RespawnAnchorBlock.canSetSpawn(world, spawnPos) ) { - Optional optional = RespawnAnchorBlock.findRespawnPosition(EntityType.PLAYER, world, spawnPos); - safeSpawnPos = optional.orElseGet(() -> new Vec3d((double) spawnPos.getX() + 0.5, (double) spawnPos.getY() + 1, (double) spawnPos.getZ() + 0.5)); - } else if (block instanceof BedBlock && world.getEnvironmentAttributes().getAttributeValue(EnvironmentAttributes.BED_RULE_GAMEPLAY, spawnPos).canSetSpawn(world)) { - Optional optional = BedBlock.findWakeUpPosition(EntityType.PLAYER, world, spawnPos, blockState.get(BedBlock.FACING), respawn.respawnData().pitch()); - safeSpawnPos = optional.orElseGet(() -> new Vec3d((double) spawnPos.getX() + 0.5, (double) spawnPos.getY() + 0.5625, (double) spawnPos.getZ() + 0.5)); + Optional optional = RespawnAnchorBlock.findStandUpPosition(EntityType.PLAYER, world, spawnPos); + safeSpawnPos = optional.orElseGet(() -> new Vec3((double) spawnPos.getX() + 0.5, (double) spawnPos.getY() + 1, (double) spawnPos.getZ() + 0.5)); + } else if (block instanceof BedBlock && world.environmentAttributes().getValue(EnvironmentAttributes.BED_RULE, spawnPos).canSetSpawn(world)) { + Optional optional = BedBlock.findStandUpPosition(EntityType.PLAYER, world, spawnPos, blockState.getValue(BedBlock.FACING), respawn.respawnData().pitch()); + safeSpawnPos = optional.orElseGet(() -> new Vec3((double) spawnPos.getX() + 0.5, (double) spawnPos.getY() + 0.5625, (double) spawnPos.getZ() + 0.5)); } else { - boolean bl = block.canMobSpawnInside(blockState); - BlockState blockState2 = world.getBlockState(spawnPos.up()); - boolean bl2 = blockState2.getBlock().canMobSpawnInside(blockState2); + boolean bl = block.isPossibleToRespawnInThis(blockState); + BlockState blockState2 = world.getBlockState(spawnPos.above()); + boolean bl2 = blockState2.getBlock().isPossibleToRespawnInThis(blockState2); if (bl && bl2) { - safeSpawnPos = new Vec3d((double) spawnPos.getX() + 0.5, (double) spawnPos.getY() + 0.1, (double) spawnPos.getZ() + 0.5); + safeSpawnPos = new Vec3((double) spawnPos.getX() + 0.5, (double) spawnPos.getY() + 0.1, (double) spawnPos.getZ() + 0.5); } else { - safeSpawnPos = Vec3d.ofBottomCenter(spawnPos); + safeSpawnPos = Vec3.atBottomCenterOf(spawnPos); } } - return Optional.of(new MinecraftLocation(respawnPosData.dimension(), safeSpawnPos.getX(), safeSpawnPos.getY(), safeSpawnPos.getZ())); + return Optional.of(new MinecraftLocation(respawnPosData.dimension(), safeSpawnPos.x(), safeSpawnPos.y(), safeSpawnPos.z())); } } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/ClearPlayerDataCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/ClearPlayerDataCommand.java index 62c11f6a..a399362f 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/ClearPlayerDataCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/ClearPlayerDataCommand.java @@ -12,12 +12,12 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; import static com.fibermc.essentialcommands.EssentialCommands.CONFIG; -public class ClearPlayerDataCommand implements Command { +public class ClearPlayerDataCommand implements Command { // divide by 2 to prevent overflow... static final int INITIAL_LAST_EXEC_TIME = Integer.MIN_VALUE / 2; static final int MAX_SECONDS_FOR_CONFIRM = 30; @@ -25,19 +25,19 @@ public class ClearPlayerDataCommand implements Command { static int lastConsoleExecTime = INITIAL_LAST_EXEC_TIME; @Override - public int run(CommandContext context) throws CommandSyntaxException { + public int run(CommandContext context) throws CommandSyntaxException { var source = context.getSource(); if (!CONFIG.ENABLE_DELETE_ALL_PLAYER_DATA) { - source.sendError(Text.literal("This command is not enabled")); + source.sendFailure(Component.literal("This command is not enabled")); return -1; } var server = source.getServer(); - int currentTicks = server.getTicks(); + int currentTicks = server.getTickCount(); int lastExecTime; - if (source.isExecutedByPlayer()) { - var playerId = source.getPlayerOrThrow().getUuid(); + if (source.isPlayer()) { + var playerId = source.getPlayerOrException().getUUID(); lastExecTime = LAST_EXEC_TIME_PER_PLAYER_MAP.getOrDefault(playerId, INITIAL_LAST_EXEC_TIME); LAST_EXEC_TIME_PER_PLAYER_MAP.put(playerId, currentTicks); } else { @@ -46,7 +46,7 @@ public int run(CommandContext context) throws CommandSyntax } if (currentTicks - lastExecTime > 20 * MAX_SECONDS_FOR_CONFIRM) { - source.sendFeedback(() -> Text.literal( + source.sendSuccess(() -> Component.literal( "Are you sure you want to disconnect all players and permanently delete ALL" + " Essential Commands player data?" + " This action is irreversible. Run the command again to confirm."), @@ -54,7 +54,7 @@ public int run(CommandContext context) throws CommandSyntax return 0; } - server.getPlayerManager().disconnectAllPlayers(); + server.getPlayerList().removeAll(); try { var playerDataDirPath = PlayerDataFactory.getPlayerDataDirectoryPath(server); diff --git a/src/main/java/com/fibermc/essentialcommands/commands/CommandUtil.java b/src/main/java/com/fibermc/essentialcommands/commands/CommandUtil.java index 474a71b5..99f67f75 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/CommandUtil.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/CommandUtil.java @@ -8,11 +8,11 @@ import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.mojang.brigadier.tree.CommandNode; -import net.minecraft.command.EntitySelector; -import net.minecraft.command.argument.EntityArgumentType; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.commands.arguments.EntityArgument; +import net.minecraft.commands.arguments.selector.EntitySelector; +import net.minecraft.server.level.ServerPlayer; import dev.jpcode.eccore.util.TextUtil; @@ -20,12 +20,12 @@ public final class CommandUtil { private CommandUtil() {} - public static RequiredArgumentBuilder targetPlayerArgument() { - return CommandManager.argument("target_player", EntityArgumentType.player()); + public static RequiredArgumentBuilder targetPlayerArgument() { + return Commands.argument("target_player", EntityArgument.player()); } - public static String getCommandString(ServerCommandSource source, CommandNode commandNode) { - CommandDispatcher dispatcher = source.getServer().getCommandManager().getDispatcher(); + public static String getCommandString(CommandSourceStack source, CommandNode commandNode) { + CommandDispatcher dispatcher = source.getServer().getCommands().getDispatcher(); return "/" + TextUtil.joinStrings( dispatcher.getPath(commandNode), @@ -37,9 +37,9 @@ public static CommandSyntaxException createSimpleException(Message msg) { return new CommandSyntaxException(new SimpleCommandExceptionType(msg), msg); } - public static ServerPlayerEntity getCommandTargetPlayer(CommandContext context) throws CommandSyntaxException { + public static ServerPlayer getCommandTargetPlayer(CommandContext context) throws CommandSyntaxException { try { - return EntityArgumentType.getPlayer(context, "target_player"); + return EntityArgument.getPlayer(context, "target_player"); } catch (IllegalArgumentException e) { return context.getSource().getPlayer(); } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/FlyCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/FlyCommand.java index c4705ffb..ee7788cd 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/FlyCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/FlyCommand.java @@ -13,19 +13,19 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.entity.player.PlayerAbilities; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.player.Abilities; -public class FlyCommand implements Command { +public class FlyCommand implements Command { public FlyCommand() { } @Override - public int run(CommandContext context) throws CommandSyntaxException { - ServerCommandSource source = context.getSource(); - ServerPlayerEntity targetPlayer = CommandUtil.getCommandTargetPlayer(context); + public int run(CommandContext context) throws CommandSyntaxException { + CommandSourceStack source = context.getSource(); + ServerPlayer targetPlayer = CommandUtil.getCommandTargetPlayer(context); boolean shouldEnableFly; try { @@ -38,7 +38,7 @@ public int run(CommandContext context) throws CommandSyntax .getTracker(targetPlayer).isGrantedBy(ECAbilitySources.FLY_COMMAND); } catch (NoClassDefFoundError ign) { // If PAL is not found, fall back to toggling the current vanilla flight state. - shouldEnableFly = !targetPlayer.getAbilities().allowFlying; + shouldEnableFly = !targetPlayer.getAbilities().mayfly; } } @@ -46,25 +46,25 @@ public int run(CommandContext context) throws CommandSyntax return 0; } - public static void exec(ServerCommandSource source, ServerPlayerEntity target, boolean shouldEnableFly) throws CommandSyntaxException { - PlayerAbilities playerAbilities = target.getAbilities(); + public static void exec(CommandSourceStack source, ServerPlayer target, boolean shouldEnableFly) throws CommandSyntaxException { + Abilities playerAbilities = target.getAbilities(); PlayerData playerData = ((ServerPlayerEntityAccess) target).ec$getPlayerData(); try { playerData.setFlight(shouldEnableFly); } catch (NoClassDefFoundError ign) { - playerAbilities.allowFlying = shouldEnableFly; + playerAbilities.mayfly = shouldEnableFly; if (!shouldEnableFly) { playerAbilities.flying = false; } } - target.sendAbilitiesUpdate(); + target.onUpdateAbilities(); // Label boolean values in suggestions, or switch to single state value (present or it's not) - var senderPlayer = source.getPlayerOrThrow(); + var senderPlayer = source.getPlayerOrException(); var senderPlayerData = PlayerData.access(senderPlayer); var ecTextTarget = ECText.access(target); String enabledString = ecTextTarget.getString(shouldEnableFly ? "generic.enabled" : "generic.disabled"); diff --git a/src/main/java/com/fibermc/essentialcommands/commands/FlySpeedCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/FlySpeedCommand.java index d87ca002..5c2ad73b 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/FlySpeedCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/FlySpeedCommand.java @@ -10,21 +10,21 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.level.ServerPlayer; import static com.fibermc.essentialcommands.EssentialCommands.CONFIG; -public class FlySpeedCommand implements Command { +public class FlySpeedCommand implements Command { static int speedMultiplier = 20; public FlySpeedCommand() { } @Override - public int run(CommandContext context) throws CommandSyntaxException { - ServerCommandSource source = context.getSource(); - ServerPlayerEntity targetPlayer = CommandUtil.getCommandTargetPlayer(context); + public int run(CommandContext context) throws CommandSyntaxException { + CommandSourceStack source = context.getSource(); + ServerPlayer targetPlayer = CommandUtil.getCommandTargetPlayer(context); int newSpeed = IntegerArgumentType.getInteger(context, "fly_speed"); @@ -32,15 +32,15 @@ public int run(CommandContext context) throws CommandSyntax return SINGLE_SUCCESS; } - public int reset(CommandContext context) throws CommandSyntaxException { - ServerCommandSource source = context.getSource(); - ServerPlayerEntity targetPlayer = CommandUtil.getCommandTargetPlayer(context); + public int reset(CommandContext context) throws CommandSyntaxException { + CommandSourceStack source = context.getSource(); + ServerPlayer targetPlayer = CommandUtil.getCommandTargetPlayer(context); exec(source, targetPlayer, 1); return SINGLE_SUCCESS; } - public static void exec(ServerCommandSource source, ServerPlayerEntity target, int flySpeed) throws CommandSyntaxException { + public static void exec(CommandSourceStack source, ServerPlayer target, int flySpeed) throws CommandSyntaxException { ECText ecTextTarget = ECText.access(target); if (flySpeed > CONFIG.FLY_MAX_SPEED) @@ -51,13 +51,13 @@ public static void exec(ServerCommandSource source, ServerPlayerEntity target, i ecTextTarget.accent(String.valueOf(CONFIG.FLY_MAX_SPEED)) )); - int oldFlySpeed = (int)(target.getAbilities().getFlySpeed() * speedMultiplier); - target.getAbilities().setFlySpeed((float)flySpeed / speedMultiplier); - target.sendAbilitiesUpdate(); + int oldFlySpeed = (int)(target.getAbilities().getFlyingSpeed() * speedMultiplier); + target.getAbilities().setFlyingSpeed((float)flySpeed / speedMultiplier); + target.onUpdateAbilities(); if (!Objects.equals(source.getPlayer(), target)) { ECText ecTextSource = ECText.access(source.getPlayer()); - source.sendFeedback(() -> + source.sendSuccess(() -> ecTextSource.getText( "cmd.fly.speed.feedback.update.other", ecTextSource.accent(String.valueOf(oldFlySpeed)), @@ -67,7 +67,7 @@ public static void exec(ServerCommandSource source, ServerPlayerEntity target, i CONFIG.BROADCAST_TO_OPS ); } - target.sendMessage( + target.sendSystemMessage( ecTextTarget.getText( "cmd.fly.speed.feedback.update", ecTextTarget.accent(String.valueOf(oldFlySpeed)), diff --git a/src/main/java/com/fibermc/essentialcommands/commands/HomeCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/HomeCommand.java index 4606ca90..9881d524 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/HomeCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/HomeCommand.java @@ -22,23 +22,23 @@ import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.mojang.brigadier.suggestion.SuggestionProvider; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; -public class HomeCommand implements Command { +public class HomeCommand implements Command { public HomeCommand() {} @Override - public int run(CommandContext context) throws CommandSyntaxException { - PlayerData senderPlayerData = ((ServerPlayerEntityAccess) context.getSource().getPlayerOrThrow()).ec$getPlayerData(); + public int run(CommandContext context) throws CommandSyntaxException { + PlayerData senderPlayerData = ((ServerPlayerEntityAccess) context.getSource().getPlayerOrException()).ec$getPlayerData(); String homeName = StringArgumentType.getString(context, "home_name"); return exec(senderPlayerData, homeName); } - private static PlayerData getTargetPlayerData(CommandContext context) throws CommandSyntaxException { - return ((ServerPlayerEntityAccess) context.getSource().getPlayerOrThrow()).ec$getPlayerData(); + private static PlayerData getTargetPlayerData(CommandContext context) throws CommandSyntaxException { + return ((ServerPlayerEntityAccess) context.getSource().getPlayerOrException()).ec$getPlayerData(); } // TODO: Ideally the styling here should come from a context, intead of from the player we're @@ -57,8 +57,8 @@ public static String getSoleHomeName(PlayerData playerData) throws CommandSyntax return homeNames.stream().findAny().get(); } - public int runDefault(CommandContext context) throws CommandSyntaxException { - PlayerData playerData = ((ServerPlayerEntityAccess) context.getSource().getPlayerOrThrow()).ec$getPlayerData(); + public int runDefault(CommandContext context) throws CommandSyntaxException { + PlayerData playerData = ((ServerPlayerEntityAccess) context.getSource().getPlayerOrException()).ec$getPlayerData(); return exec( playerData, @@ -78,7 +78,7 @@ public static int exec(PlayerData senderPlayerData, PlayerData targetPlayerData, Message msg = ecText.getText( "cmd.home.tp.error.not_found", TextFormatType.Error, - Text.literal(homeName)); + Component.literal(homeName)); throw new CommandSyntaxException(new SimpleCommandExceptionType(msg), msg); } @@ -94,20 +94,20 @@ public static int exec(PlayerData senderPlayerData, PlayerData targetPlayerData, public static class Suggestion { //Brigader Suggestions - public static final SuggestionProvider LIST_SUGGESTION_PROVIDER + public static final SuggestionProvider LIST_SUGGESTION_PROVIDER = ListSuggestion.ofContext(Suggestion::getSuggestionsList); /** * Gets a list of suggested strings to be used with Brigader */ - public static List getSuggestionsList(CommandContext context) throws CommandSyntaxException { + public static List getSuggestionsList(CommandContext context) throws CommandSyntaxException { return new ArrayList<>(HomeCommand.getTargetPlayerData(context).getHomeNames()); } /** * Gets a set of suggestion entries to be used with ListCommandFactory */ - public static Set> getSuggestionEntries(CommandContext context) throws CommandSyntaxException { + public static Set> getSuggestionEntries(CommandContext context) throws CommandSyntaxException { return HomeCommand.getTargetPlayerData(context).getHomeEntries(); } } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/HomeDeleteCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/HomeDeleteCommand.java index 7dac4eb1..1432ac9e 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/HomeDeleteCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/HomeDeleteCommand.java @@ -9,18 +9,18 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.level.ServerPlayer; -public class HomeDeleteCommand implements Command { +public class HomeDeleteCommand implements Command { public HomeDeleteCommand() {} @Override - public int run(CommandContext context) throws CommandSyntaxException { - ServerCommandSource source = context.getSource(); + public int run(CommandContext context) throws CommandSyntaxException { + CommandSourceStack source = context.getSource(); //Store command sender - ServerPlayerEntity senderPlayer = source.getPlayerOrThrow(); + ServerPlayer senderPlayer = source.getPlayerOrException(); PlayerData senderPlayerData = ((ServerPlayerEntityAccess) senderPlayer).ec$getPlayerData(); //Store home name String homeName = StringArgumentType.getString(context, "home_name"); diff --git a/src/main/java/com/fibermc/essentialcommands/commands/HomeOverwriteCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/HomeOverwriteCommand.java index 1197b76f..2e1863e6 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/HomeOverwriteCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/HomeOverwriteCommand.java @@ -10,17 +10,17 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.level.ServerPlayer; -public class HomeOverwriteCommand implements Command { +public class HomeOverwriteCommand implements Command { public HomeOverwriteCommand() {} @Override - public int run(CommandContext context) throws CommandSyntaxException { + public int run(CommandContext context) throws CommandSyntaxException { String homeName = StringArgumentType.getString(context, "home_name"); - ServerCommandSource source = context.getSource(); - ServerPlayerEntity senderPlayer = source.getPlayerOrThrow(); + CommandSourceStack source = context.getSource(); + ServerPlayer senderPlayer = source.getPlayerOrException(); PlayerData playerData = ((ServerPlayerEntityAccess) senderPlayer).ec$getPlayerData(); var homeNameText = ECText.access(senderPlayer).accent(homeName); diff --git a/src/main/java/com/fibermc/essentialcommands/commands/HomeSetCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/HomeSetCommand.java index a4e11970..cc49d150 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/HomeSetCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/HomeSetCommand.java @@ -11,27 +11,27 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.Text; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; -public class HomeSetCommand implements Command { +public class HomeSetCommand implements Command { public HomeSetCommand() {} @Override - public int run(CommandContext context) throws CommandSyntaxException { + public int run(CommandContext context) throws CommandSyntaxException { String homeName = StringArgumentType.getString(context, "home_name"); return exec(context, homeName); } - public int runDefault(CommandContext context) throws CommandSyntaxException { + public int runDefault(CommandContext context) throws CommandSyntaxException { return exec(context, "unnamed"); } - private static int exec(CommandContext context, String homeName) throws CommandSyntaxException { - ServerCommandSource source = context.getSource(); - ServerPlayerEntity senderPlayer = source.getPlayerOrThrow(); + private static int exec(CommandContext context, String homeName) throws CommandSyntaxException { + CommandSourceStack source = context.getSource(); + ServerPlayer senderPlayer = source.getPlayerOrException(); PlayerData playerData = ((ServerPlayerEntityAccess) senderPlayer).ec$getPlayerData(); if (playerData.existsHome(homeName)) { @@ -48,7 +48,7 @@ private static int exec(CommandContext context, String home playerEcText.accent("[" + ECText.getInstance().getString("generic.confirm") + "]") ).send(); } else { - Text homeNameText = ECText.access(senderPlayer).accent(homeName); + Component homeNameText = ECText.access(senderPlayer).accent(homeName); playerData.addHome(homeName, new MinecraftLocation(senderPlayer)); playerData.save(); diff --git a/src/main/java/com/fibermc/essentialcommands/commands/HomeTeleportOtherCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/HomeTeleportOtherCommand.java index 98717593..9c288d5b 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/HomeTeleportOtherCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/HomeTeleportOtherCommand.java @@ -20,27 +20,27 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.suggestion.SuggestionProvider; -import net.minecraft.command.argument.EntityArgumentType; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.EntityArgument; +import net.minecraft.network.chat.Component; import static com.fibermc.essentialcommands.EssentialCommands.CONFIG; -public class HomeTeleportOtherCommand extends HomeCommand implements Command { +public class HomeTeleportOtherCommand extends HomeCommand implements Command { @Override - public int run(CommandContext context) throws CommandSyntaxException { - PlayerData senderPlayerData = ((ServerPlayerEntityAccess) context.getSource().getPlayerOrThrow()).ec$getPlayerData(); + public int run(CommandContext context) throws CommandSyntaxException { + PlayerData senderPlayerData = ((ServerPlayerEntityAccess) context.getSource().getPlayerOrException()).ec$getPlayerData(); String homeName = StringArgumentType.getString(context, "home_name"); return HomeCommand.exec(senderPlayerData, getTargetPlayerData(context), homeName); } - private static PlayerData getTargetPlayerData(CommandContext context) throws CommandSyntaxException { - return ((ServerPlayerEntityAccess) EntityArgumentType.getPlayer(context, "target_player")).ec$getPlayerData(); + private static PlayerData getTargetPlayerData(CommandContext context) throws CommandSyntaxException { + return ((ServerPlayerEntityAccess) EntityArgument.getPlayer(context, "target_player")).ec$getPlayerData(); } - public int runDefault(CommandContext context) throws CommandSyntaxException { - var senderPlayerData = ((ServerPlayerEntityAccess) context.getSource().getPlayerOrThrow()).ec$getPlayerData(); + public int runDefault(CommandContext context) throws CommandSyntaxException { + var senderPlayerData = ((ServerPlayerEntityAccess) context.getSource().getPlayerOrException()).ec$getPlayerData(); var targetPlayerData = getTargetPlayerData(context); return HomeCommand.exec( @@ -50,8 +50,8 @@ public int runDefault(CommandContext context) throws Comman ); } - public int runOfflinePlayer(CommandContext context) throws CommandSyntaxException { - PlayerData senderPlayerData = ((ServerPlayerEntityAccess) context.getSource().getPlayerOrThrow()).ec$getPlayerData(); + public int runOfflinePlayer(CommandContext context) throws CommandSyntaxException { + PlayerData senderPlayerData = ((ServerPlayerEntityAccess) context.getSource().getPlayerOrException()).ec$getPlayerData(); String homeName = StringArgumentType.getString(context, "home_name"); var targetPlayerName = StringArgumentType.getString(context, "target_player"); @@ -60,7 +60,7 @@ public int runOfflinePlayer(CommandContext context) throws .getOfflinePlayerByNameAsync(targetPlayerName) .whenComplete((playerEntity, err) -> { if (playerEntity == null) { - context.getSource().sendError(Text.of("No player with the specified name found.")); + context.getSource().sendFailure(Component.nullToEmpty("No player with the specified name found.")); return; } @@ -73,14 +73,14 @@ public int runOfflinePlayer(CommandContext context) throws homeName ); } catch (CommandSyntaxException e) { - context.getSource().sendError(ECText.access(senderPlayerData.getPlayer()).error(e.getMessage())); + context.getSource().sendFailure(ECText.access(senderPlayerData.getPlayer()).error(e.getMessage())); } }); return SINGLE_SUCCESS; } - public static int runListOffline(CommandContext context) throws CommandSyntaxException { + public static int runListOffline(CommandContext context) throws CommandSyntaxException { var targetPlayerName = StringArgumentType.getString(context, "target_player"); var senderPlayerProfile = PlayerProfile.accessFromContextOrThrow(context); ManagerLocator.getInstance() @@ -88,7 +88,7 @@ public static int runListOffline(CommandContext context) th .getOfflinePlayerByNameAsync(targetPlayerName) .whenComplete((targetPlayerEntity, err) -> { if (targetPlayerEntity == null) { - context.getSource().sendError(Text.of("No player with the specified name found.")); + context.getSource().sendFailure(Component.nullToEmpty("No player with the specified name found.")); return; } @@ -101,7 +101,7 @@ public static int runListOffline(CommandContext context) th senderPlayerProfile ); - context.getSource().sendFeedback(() -> + context.getSource().sendSuccess(() -> suggestionText, CONFIG.BROADCAST_TO_OPS ); @@ -112,20 +112,20 @@ public static int runListOffline(CommandContext context) th public static class Suggestion { //Brigader Suggestions - public static final SuggestionProvider LIST_SUGGESTION_PROVIDER + public static final SuggestionProvider LIST_SUGGESTION_PROVIDER = ListSuggestion.ofContext(HomeTeleportOtherCommand.Suggestion::getSuggestionsList); /** * Gets a list of suggested strings to be used with Brigader */ - public static List getSuggestionsList(CommandContext context) throws CommandSyntaxException { + public static List getSuggestionsList(CommandContext context) throws CommandSyntaxException { return new ArrayList<>(HomeTeleportOtherCommand.getTargetPlayerData(context).getHomeNames()); } /** * Gets a set of suggestion entries to be used with ListCommandFactory */ - public static Set> getSuggestionEntries(CommandContext context) throws CommandSyntaxException { + public static Set> getSuggestionEntries(CommandContext context) throws CommandSyntaxException { return HomeTeleportOtherCommand.getTargetPlayerData(context).getHomeEntries(); } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/InvulnCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/InvulnCommand.java index ebe1ab76..017fb518 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/InvulnCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/InvulnCommand.java @@ -11,14 +11,14 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.level.ServerPlayer; -public class InvulnCommand implements Command { +public class InvulnCommand implements Command { @Override - public int run(CommandContext context) throws CommandSyntaxException { - ServerCommandSource source = context.getSource(); - ServerPlayerEntity targetPlayer = CommandUtil.getCommandTargetPlayer(context); + public int run(CommandContext context) throws CommandSyntaxException { + CommandSourceStack source = context.getSource(); + ServerPlayer targetPlayer = CommandUtil.getCommandTargetPlayer(context); boolean shouldEnableInvuln; try { @@ -33,7 +33,7 @@ public int run(CommandContext context) throws CommandSyntax // TODO Label boolean values in suggestions, or switch to single state value (present, or it's not) - var senderPlayerAccess = ((ServerPlayerEntityAccess) source.getPlayerOrThrow()); + var senderPlayerAccess = ((ServerPlayerEntityAccess) source.getPlayerOrException()); var enabledText = senderPlayerAccess.ec$getEcText().getText( shouldEnableInvuln ? "generic.enabled" : "generic.disabled", TextFormatType.Accent); @@ -47,12 +47,12 @@ public int run(CommandContext context) throws CommandSyntax return 0; } - public static void exec(ServerPlayerEntity target, boolean shouldEnableInvuln) { + public static void exec(ServerPlayer target, boolean shouldEnableInvuln) { if (shouldEnableInvuln) { Pal.grantAbility(target, VanillaAbilities.INVULNERABLE, ECAbilitySources.INVULN_COMMAND); } else { Pal.revokeAbility(target, VanillaAbilities.INVULNERABLE, ECAbilitySources.INVULN_COMMAND); } - target.sendAbilitiesUpdate(); + target.onUpdateAbilities(); } } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/ListCommandFactory.java b/src/main/java/com/fibermc/essentialcommands/commands/ListCommandFactory.java index 2ad2339c..44b77e10 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/ListCommandFactory.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/ListCommandFactory.java @@ -15,9 +15,9 @@ import com.mojang.brigadier.Command; import com.mojang.brigadier.context.CommandContext; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; import dev.jpcode.eccore.util.TextUtil; @@ -28,16 +28,16 @@ public final class ListCommandFactory { private ListCommandFactory() {} // Specify leading response text, and supplier of list of strings/Text - public static Command create( + public static Command create( String responsePreText, String commandExecText, SuggestionListProvider> suggestionsProvider) { - return (CommandContext context) -> { + return (CommandContext context) -> { var styleProvider = PlayerProfile.accessFromContextOrThrow(context); Collection> suggestionsList = suggestionsProvider.getSuggestionList(context); - context.getSource().sendFeedback(() -> + context.getSource().sendSuccess(() -> getSuggestionText(responsePreText, commandExecText, suggestionsList, Entry::getKey, styleProvider), CONFIG.BROADCAST_TO_OPS ); @@ -45,17 +45,17 @@ public static Command create( }; } - public static Command create( + public static Command create( String responsePreText, String commandExecText, SuggestionListProvider suggestionsProvider, Function nameAccessor) { - return (CommandContext context) -> { + return (CommandContext context) -> { var styleProvider = PlayerProfile.accessFromContextOrThrow(context); Collection suggestionsList = suggestionsProvider.getSuggestionList(context); - context.getSource().sendFeedback(() -> + context.getSource().sendSuccess(() -> getSuggestionText(responsePreText, commandExecText, suggestionsList, nameAccessor, styleProvider), CONFIG.BROADCAST_TO_OPS ); @@ -63,20 +63,20 @@ public static Command create( }; } - public static Text getSuggestionText( + public static Component getSuggestionText( String responsePreText, String commandExecText, Collection suggestionsList, Function nameAccessor, IStyleProvider styleProvider) { - MutableText responseText = Text.empty() - .append(Text.literal(responsePreText).setStyle(styleProvider.getStyle(TextFormatType.Default))); + MutableComponent responseText = Component.empty() + .append(Component.literal(responsePreText).setStyle(styleProvider.getStyle(TextFormatType.Default))); - List suggestionTextList = suggestionsList.stream() + List suggestionTextList = suggestionsList.stream() .map(nameAccessor) .map((name) -> clickableTeleport( - Text.literal(name).setStyle(styleProvider.getStyle(TextFormatType.Accent)), + Component.literal(name).setStyle(styleProvider.getStyle(TextFormatType.Accent)), name, String.format("/%s", commandExecText))) .collect(Collectors.toList()); @@ -84,7 +84,7 @@ public static Text getSuggestionText( if (suggestionTextList.size() > 0) { responseText.append(TextUtil.join( suggestionTextList, - Text.literal(", ").setStyle(styleProvider.getStyle(TextFormatType.Default)) + Component.literal(", ").setStyle(styleProvider.getStyle(TextFormatType.Default)) )); } else { responseText.append(ECText.getInstance().getText("cmd.list.feedback.empty", TextFormatType.Error, styleProvider)); diff --git a/src/main/java/com/fibermc/essentialcommands/commands/ModInfoCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/ModInfoCommand.java index 2d505328..12814eee 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/ModInfoCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/ModInfoCommand.java @@ -8,22 +8,22 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; import dev.jpcode.eccore.util.TextUtil; -public class ModInfoCommand implements Command { +public class ModInfoCommand implements Command { private final String modVersion = EssentialCommands.MOD_METADATA.getVersion().getFriendlyString(); @Override - public int run(CommandContext context) throws CommandSyntaxException { - var senderPlayer = context.getSource().getPlayerOrThrow(); + public int run(CommandContext context) throws CommandSyntaxException { + var senderPlayer = context.getSource().getPlayerOrException(); var ecText = ECText.access(senderPlayer); PlayerData.access(senderPlayer).sendCommandFeedback(TextUtil.concat( ecText.literal(EssentialCommands.MOD_METADATA.getName()), - Text.literal(" "), + Component.literal(" "), ecText.accent(modVersion) )); diff --git a/src/main/java/com/fibermc/essentialcommands/commands/MotdCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/MotdCommand.java index 553b578a..985dcd0a 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/MotdCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/MotdCommand.java @@ -9,8 +9,8 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.level.ServerPlayer; import static com.fibermc.essentialcommands.EssentialCommands.CONFIG; @@ -22,14 +22,14 @@ private MotdCommand() {} .add(TagParser.QUICK_TEXT_WITH_STF) .build(); - public static int run(CommandContext context) throws CommandSyntaxException { - var player = context.getSource().getPlayerOrThrow(); + public static int run(CommandContext context) throws CommandSyntaxException { + var player = context.getSource().getPlayerOrException(); exec(player); return 0; } - public static void exec(ServerPlayerEntity player) { - player.getCommandSource().sendFeedback( + public static void exec(ServerPlayer player) { + player.createCommandSourceStack().sendSuccess( () -> Placeholders.parseText( NODE_PARSER.parseNode(CONFIG.MOTD), PlaceholderContext.of(player) diff --git a/src/main/java/com/fibermc/essentialcommands/commands/NicknameClearCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/NicknameClearCommand.java index 0834ab89..9b9676fb 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/NicknameClearCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/NicknameClearCommand.java @@ -6,12 +6,12 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; -public class NicknameClearCommand implements Command { +public class NicknameClearCommand implements Command { @Override - public int run(CommandContext context) throws CommandSyntaxException { + public int run(CommandContext context) throws CommandSyntaxException { var senderPlayerData = PlayerData.accessFromContextOrThrow(context); var targetPlayer = CommandUtil.getCommandTargetPlayer(context); @@ -22,7 +22,7 @@ public int run(CommandContext context) throws CommandSyntax //inform command sender that the nickname has been set senderPlayerData.sendCommandFeedback( "cmd.nickname.set.feedback", - Text.literal(targetPlayer.getGameProfile().name()) + Component.literal(targetPlayer.getGameProfile().name()) ); return SINGLE_SUCCESS; diff --git a/src/main/java/com/fibermc/essentialcommands/commands/NicknameSetCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/NicknameSetCommand.java index ea5e7d6f..b42eeb1b 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/NicknameSetCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/NicknameSetCommand.java @@ -14,33 +14,33 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.command.argument.TextArgumentType; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import net.minecraft.text.Texts; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.ComponentUtils; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.server.level.ServerPlayer; import dev.jpcode.eccore.util.TextUtil; import static com.fibermc.essentialcommands.EssentialCommands.CONFIG; -public class NicknameSetCommand implements Command { +public class NicknameSetCommand implements Command { @Override - public int run(CommandContext context) throws CommandSyntaxException { - return exec(context, TextArgumentType.getTextArgument(context, "nickname")); + public int run(CommandContext context) throws CommandSyntaxException { + return exec(context, ComponentArgument.getRawComponent(context, "nickname")); } - public static int runStringToText(CommandContext context) throws CommandSyntaxException { + public static int runStringToText(CommandContext context) throws CommandSyntaxException { NicknameSetCommand.exec(context, TextUtil.parseText(StringArgumentType.getString(context, "nickname_placeholder_api"))); return SINGLE_SUCCESS; } - public static int exec(CommandContext context, Text rawNicknameText) throws CommandSyntaxException { - ServerPlayerEntity targetPlayer = CommandUtil.getCommandTargetPlayer(context); + public static int exec(CommandContext context, Component rawNicknameText) throws CommandSyntaxException { + ServerPlayer targetPlayer = CommandUtil.getCommandTargetPlayer(context); var nicknameWithContext = ECPerms.check(context.getSource(), ECPerms.Registry.nickname_selector_and_ctx, 2) - ? Texts.parse( + ? ComponentUtils.updateForEntity( context.getSource(), rawNicknameText, targetPlayer, @@ -61,10 +61,10 @@ public static int exec(CommandContext context, Text rawNick if (successCode >= 0) { senderFeedbackReceiver.sendCommandFeedback( "cmd.nickname.set.feedback", - nicknameText != null ? nicknameText : Text.literal(targetPlayer.getGameProfile().name()) + nicknameText != null ? nicknameText : Component.literal(targetPlayer.getGameProfile().name()) ); } else { - MutableText failReason = switch (successCode) { + MutableComponent failReason = switch (successCode) { case -1 -> ecText.getText("cmd.nickname.set.error.perms", TextFormatType.Error); case -2 -> ecText.getText( "cmd.nickname.set.error.length", TextFormatType.Error, diff --git a/src/main/java/com/fibermc/essentialcommands/commands/ProfileCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/ProfileCommand.java index 17e8e273..f9071d76 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/ProfileCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/ProfileCommand.java @@ -8,42 +8,42 @@ import com.mojang.brigadier.tree.LiteralCommandNode; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.network.chat.Component; import static com.fibermc.essentialcommands.EssentialCommands.CONFIG; -import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.commands.Commands.argument; public final class ProfileCommand { private ProfileCommand() {} - public static LiteralCommandNode buildNode() { - var root = CommandManager.literal("profile"); - var set = CommandManager.literal("set"); - var get = CommandManager.literal("get"); + public static LiteralCommandNode buildNode() { + var root = Commands.literal("profile"); + var set = Commands.literal("set"); + var get = Commands.literal("get"); for (Map.Entry> entry : PlayerProfile.OPTIONS.entrySet()) { var name = entry.getKey(); var option = entry.getValue(); - set.then(CommandManager.literal(name) + set.then(Commands.literal(name) .then(argument("value", option.argumentType()).executes((context) -> { - var player = context.getSource().getPlayerOrThrow(); + var player = context.getSource().getPlayerOrException(); var profile = ((ServerPlayerEntityAccess) player).ec$getProfile(); option.profileSetter().setValue(context, "value", profile); - profile.markDirty(); - profile.save(context.getSource().getServer().getRegistryManager()); + profile.setDirty(); + profile.save(context.getSource().getServer().registryAccess()); return 0; })) ); - get.then(CommandManager.literal(name) + get.then(Commands.literal(name) .executes((context) -> { - var player = context.getSource().getPlayerOrThrow(); + var player = context.getSource().getPlayerOrException(); var profile = ((ServerPlayerEntityAccess) player).ec$getProfile(); - context.getSource().sendFeedback(() -> - Text.literal(option.profileGetter().getValue(profile).map(Object::toString).orElse("")), + context.getSource().sendSuccess(() -> + Component.literal(option.profileGetter().getValue(profile).map(Object::toString).orElse("")), CONFIG.BROADCAST_TO_OPS); return 0; }) diff --git a/src/main/java/com/fibermc/essentialcommands/commands/RandomTeleportCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/RandomTeleportCommand.java index 0443058c..deb96413 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/RandomTeleportCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/RandomTeleportCommand.java @@ -24,16 +24,16 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.text.Text; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.util.math.Vec3i; -import net.minecraft.world.chunk.Chunk; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Vec3i; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.ChunkAccess; import dev.jpcode.eccore.util.TextUtil; @@ -48,7 +48,7 @@ * */ @SuppressWarnings("checkstyle:all") -public class RandomTeleportCommand implements Command { +public class RandomTeleportCommand implements Command { public RandomTeleportCommand() {} @@ -64,12 +64,12 @@ public RandomTeleportCommand() {} }); @Override - public int run(CommandContext context) throws CommandSyntaxException { - ServerPlayerEntity player = context.getSource().getPlayerOrThrow(); - ServerWorld world = context.getSource().getWorld(); + public int run(CommandContext context) throws CommandSyntaxException { + ServerPlayer player = context.getSource().getPlayerOrException(); + ServerLevel world = context.getSource().getLevel(); var ecText = ECText.access(player); - if (!CONFIG.RTP_ENABLED_WORLDS.contains(world.getRegistryKey())) { - var currentWorldAsText = Text.of(world.getRegistryKey().getValue().toString()); + if (!CONFIG.RTP_ENABLED_WORLDS.contains(world.dimension())) { + var currentWorldAsText = Component.nullToEmpty(world.dimension().identifier().toString()); PlayerData.access(player).sendCommandError(TextUtil.concat( ecText.getText("cmd.rtp.error.pre", TextFormatType.Error), ecText.getText("cmd.rtp.error.world_not_enabled", TextFormatType.Error, currentWorldAsText) @@ -78,7 +78,7 @@ public int run(CommandContext context) throws CommandSyntax } if (CONFIG.RTP_COOLDOWN > 0 && !ECPerms.check(context.getSource(), ECPerms.Registry.bypass_randomteleport_cooldown)) { - int curServerTickTime = context.getSource().getServer().getTicks(); + int curServerTickTime = context.getSource().getServer().getTickCount(); var playerData = PlayerData.access(player); var rtpCooldownEndTime = playerData.getTimeUsedRtp() + CONFIG.RTP_COOLDOWN * 20; var rtpCooldownRemaining = rtpCooldownEndTime - curServerTickTime; @@ -111,13 +111,13 @@ final static class ExecutionContext { public final int topY; public final int bottomY; - public ExecutionContext(ServerWorld world) { - this.topY = world.getTopYInclusive(); - this.bottomY = world.getBottomY(); + public ExecutionContext(ServerLevel world) { + this.topY = world.getMaxY(); + this.bottomY = world.getMinY(); } } - private static void exec(ServerPlayerEntity player, ServerWorld world) { + private static void exec(ServerPlayer player, ServerLevel world) { var centerOpt = getRtpCenter(player); if (centerOpt.isEmpty()) { return; @@ -125,7 +125,7 @@ private static void exec(ServerPlayerEntity player, ServerWorld world) { Vec3i center = centerOpt.get(); final var executionContext = new ExecutionContext(world); - final var heightFinder = HeightFindingStrategy.forWorld(world.getRegistryKey()); + final var heightFinder = HeightFindingStrategy.forWorld(world.dimension()); int timesRun = 0; Optional pos; @@ -141,12 +141,12 @@ private static void exec(ServerPlayerEntity player, ServerWorld world) { // Teleport the player PlayerTeleporter.requestTeleport( player, - new MinecraftLocation(world.getRegistryKey(), pos.get(), 0, 0), + new MinecraftLocation(world.dimension(), pos.get(), 0, 0), ECText.access(player).getText("cmd.rtp.location_name") ); } - private static Optional getRtpCenter(ServerPlayerEntity player) { + private static Optional getRtpCenter(ServerPlayer player) { var configuredRtpCenter = CONFIG.RTP_CENTER.getPosition(); if (configuredRtpCenter.isPresent()) { var pair = configuredRtpCenter.get(); @@ -172,12 +172,12 @@ private static Optional getRtpCenter(ServerPlayerEntity player) { return Optional.empty(); } - private static Optional findRtpPosition(ServerWorld world, Vec3i center, HeightFinder heightFinder, ExecutionContext ctx) { + private static Optional findRtpPosition(ServerLevel world, Vec3i center, HeightFinder heightFinder, ExecutionContext ctx) { // Search for a valid y-level (not in a block, underwater, out of the world, etc.) final BlockPos targetXZ = getRandomXZ(center); - final Chunk chunk = world.getChunk(targetXZ); + final ChunkAccess chunk = world.getChunk(targetXZ); - for (BlockPos.Mutable candidateBlock : getChunkCandidateBlocks(chunk.getPos())) { + for (BlockPos.MutableBlockPos candidateBlock : getChunkCandidateBlocks(chunk.getPos())) { final int x = candidateBlock.getX(); final int z = candidateBlock.getZ(); final OptionalInt yOpt = heightFinder.getY(chunk, x, z); @@ -213,8 +213,8 @@ private static BlockPos getRandomXZ(Vec3i center) { return new BlockPos(new_x, 0, new_z); } - private static boolean isSafePosition(Chunk chunk, BlockPos pos, ExecutionContext ctx) { - if (pos.getY() <= chunk.getBottomY()) { + private static boolean isSafePosition(ChunkAccess chunk, BlockPos pos, ExecutionContext ctx) { + if (pos.getY() <= chunk.getMinY()) { return false; } @@ -222,10 +222,10 @@ private static boolean isSafePosition(Chunk chunk, BlockPos pos, ExecutionContex return pos.getY() < ctx.topY && blockState.getFluidState().isEmpty() && blockState.getBlock() != Blocks.FIRE; } - public static Iterable getChunkCandidateBlocks(ChunkPos chunkPos) { + public static Iterable getChunkCandidateBlocks(ChunkPos chunkPos) { return () -> new Iterator<>() { private int _idx = -1; - private final BlockPos.Mutable _pos = new BlockPos.Mutable(); + private final BlockPos.MutableBlockPos _pos = new BlockPos.MutableBlockPos(); @Override public boolean hasNext() { @@ -233,14 +233,14 @@ public boolean hasNext() { } @Override - public BlockPos.Mutable next() { + public BlockPos.MutableBlockPos next() { _idx++; return switch (_idx) { - case 0 -> _pos.set(chunkPos.getStartX(), 0, chunkPos.getStartZ()); - case 1 -> _pos.set(chunkPos.getStartX(), 0, chunkPos.getEndZ()); - case 2 -> _pos.set(chunkPos.getEndX(), 0, chunkPos.getStartZ()); - case 3 -> _pos.set(chunkPos.getEndX(), 0, chunkPos.getEndZ()); - case 4 -> _pos.set(chunkPos.getCenterX(), 0, chunkPos.getCenterZ()); + case 0 -> _pos.set(chunkPos.getMinBlockX(), 0, chunkPos.getMinBlockZ()); + case 1 -> _pos.set(chunkPos.getMinBlockX(), 0, chunkPos.getMaxBlockZ()); + case 2 -> _pos.set(chunkPos.getMaxBlockX(), 0, chunkPos.getMinBlockZ()); + case 3 -> _pos.set(chunkPos.getMaxBlockX(), 0, chunkPos.getMaxBlockZ()); + case 4 -> _pos.set(chunkPos.getMiddleBlockX(), 0, chunkPos.getMiddleBlockZ()); default -> throw new IllegalStateException("Unexpected value: " + _idx); }; } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/RealNameCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/RealNameCommand.java index 72133466..dfc8f7b1 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/RealNameCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/RealNameCommand.java @@ -11,21 +11,21 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; import static com.fibermc.essentialcommands.EssentialCommands.CONFIG; -public class RealNameCommand implements Command { +public class RealNameCommand implements Command { @Override - public int run(CommandContext context) throws CommandSyntaxException { + public int run(CommandContext context) throws CommandSyntaxException { String nicknameStr = StringArgumentType.getString(context, "player_nickname"); List nicknamePlayers = PlayerDataManager.getInstance().getPlayerDataMatchingNickname(nicknameStr); - MutableText responseText = Text.empty(); + MutableComponent responseText = Component.empty(); - var ecText = ECText.access(context.getSource().getPlayerOrThrow()); + var ecText = ECText.access(context.getSource().getPlayerOrException()); var nicknameText = ecText.accent(nicknameStr); // If no players matched the provided nickname if (nicknamePlayers.size() == 0) { @@ -42,7 +42,7 @@ public int run(CommandContext context) throws CommandSyntax } } - context.getSource().sendFeedback(() -> responseText, CONFIG.BROADCAST_TO_OPS); + context.getSource().sendSuccess(() -> responseText, CONFIG.BROADCAST_TO_OPS); return 0; } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/RulesCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/RulesCommand.java index 13db013a..4f0908d1 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/RulesCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/RulesCommand.java @@ -10,9 +10,9 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; import dev.jpcode.eccore.util.TextUtil; @@ -20,14 +20,14 @@ public final class RulesCommand { private RulesCommand() {} - private static Text rulesText; + private static Component rulesText; - public static int run(CommandContext context) throws CommandSyntaxException { - context.getSource().sendFeedback(() -> rulesText, false); + public static int run(CommandContext context) throws CommandSyntaxException { + context.getSource().sendSuccess(() -> rulesText, false); return 0; } - public static int reloadCommand(CommandContext context) throws CommandSyntaxException { + public static int reloadCommand(CommandContext context) throws CommandSyntaxException { var playerData = PlayerData.accessFromContextOrThrow(context); try { @@ -42,7 +42,7 @@ public static int reloadCommand(CommandContext context) thr @SuppressWarnings("ResultOfMethodCallIgnored") public static void reload(MinecraftServer server) throws IOException { - Path mcDir = server.getRunDirectory(); + Path mcDir = server.getServerDirectory(); var rulesFile = mcDir.resolve("config/essentialcommands/rules.txt").toFile(); rulesFile.getParentFile().mkdirs(); if (rulesFile.createNewFile()) { diff --git a/src/main/java/com/fibermc/essentialcommands/commands/SleepCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/SleepCommand.java index d694fc09..a00e2b24 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/SleepCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/SleepCommand.java @@ -7,30 +7,30 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; import static com.fibermc.essentialcommands.EssentialCommands.CONFIG; -public class SleepCommand implements Command { +public class SleepCommand implements Command { @Override - public int run(CommandContext context) throws CommandSyntaxException { + public int run(CommandContext context) throws CommandSyntaxException { var source = context.getSource(); - var player = source.getPlayerOrThrow(); + var player = source.getPlayerOrException(); var playerData = PlayerData.access(player); - var pos = player.getBlockPos(); + var pos = player.blockPosition(); if (player.isSleeping()) { - player.wakeUp(); + player.stopSleeping(); return SINGLE_SUCCESS; } if (!CONFIG.SLEEP_NEAR_MONSTERS && PlayerUtilities.isNearAngryMonsters(player)) { - PlayerData.access(player).sendCommandError(Text.translatable("block.minecraft.bed.not_safe")); + PlayerData.access(player).sendCommandError(Component.translatable("block.minecraft.bed.not_safe")); return 0; } - player.sleep(pos); + player.startSleeping(pos); playerData.setIsSleepingFromCommand(true); return SINGLE_SUCCESS; diff --git a/src/main/java/com/fibermc/essentialcommands/commands/SpawnCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/SpawnCommand.java index 98eccd6c..95a4365d 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/SpawnCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/SpawnCommand.java @@ -10,14 +10,14 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.commands.CommandSourceStack; -public class SpawnCommand implements Command { +public class SpawnCommand implements Command { public SpawnCommand() {} @Override - public int run(CommandContext context) throws CommandSyntaxException { + public int run(CommandContext context) throws CommandSyntaxException { WorldDataManager worldDataManager = ManagerLocator.getInstance().getWorldDataManager(); var loc = worldDataManager.getSpawn(); @@ -27,7 +27,7 @@ public int run(CommandContext context) throws CommandSyntax return -2; } - var senderPlayer = context.getSource().getPlayerOrThrow(); + var senderPlayer = context.getSource().getPlayerOrException(); // Teleport & chat message var styledLocationName = ECText.access(senderPlayer).getText("cmd.spawn.location_name"); diff --git a/src/main/java/com/fibermc/essentialcommands/commands/SpawnSetCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/SpawnSetCommand.java index 13322b12..3efe4345 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/SpawnSetCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/SpawnSetCommand.java @@ -9,16 +9,16 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.commands.CommandSourceStack; -public class SpawnSetCommand implements Command { +public class SpawnSetCommand implements Command { public SpawnSetCommand() {} @Override - public int run(CommandContext context) throws CommandSyntaxException { + public int run(CommandContext context) throws CommandSyntaxException { var worldDataManager = ManagerLocator.getInstance().getWorldDataManager(); - var senderPlayer = context.getSource().getPlayerOrThrow(); + var senderPlayer = context.getSource().getPlayerOrException(); var playerData = PlayerData.access(senderPlayer); //Set spawn diff --git a/src/main/java/com/fibermc/essentialcommands/commands/TeleportAcceptCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/TeleportAcceptCommand.java index 74678f44..c4470629 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/TeleportAcceptCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/TeleportAcceptCommand.java @@ -8,11 +8,11 @@ import com.mojang.brigadier.context.CommandContext; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.level.ServerPlayer; public class TeleportAcceptCommand extends TeleportResponseCommand { - protected int exec(CommandContext context, ServerPlayerEntity respondingPlayer, ServerPlayerEntity requesterPlayer) { + protected int exec(CommandContext context, ServerPlayer respondingPlayer, ServerPlayer requesterPlayer) { var senderPlayerData = PlayerData.access(respondingPlayer); var targetPlayerData = ((ServerPlayerEntityAccess) requesterPlayer).ec$getPlayerData(); diff --git a/src/main/java/com/fibermc/essentialcommands/commands/TeleportAskCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/TeleportAskCommand.java index fbed6494..58f1215e 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/TeleportAskCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/TeleportAskCommand.java @@ -13,19 +13,19 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.command.argument.EntityArgumentType; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.EntityArgument; +import net.minecraft.server.level.ServerPlayer; -public class TeleportAskCommand implements Command { +public class TeleportAskCommand implements Command { public TeleportAskCommand() {} @Override - public int run(CommandContext context) throws CommandSyntaxException { + public int run(CommandContext context) throws CommandSyntaxException { TeleportManager tpMgr = ManagerLocator.getInstance().getTpManager(); - ServerPlayerEntity senderPlayer = context.getSource().getPlayerOrThrow(); - ServerPlayerEntity targetPlayer = EntityArgumentType.getPlayer(context, "target_player"); + ServerPlayer senderPlayer = context.getSource().getPlayerOrException(); + ServerPlayer targetPlayer = EntityArgument.getPlayer(context, "target_player"); var senderPlayerData = PlayerData.access(senderPlayer); var targetPlayerData = PlayerData.access(targetPlayer); @@ -46,7 +46,7 @@ public int run(CommandContext context) throws CommandSyntax var targetPlayerProfile = PlayerProfile.access(targetPlayer); targetPlayerData.sendMessage( "cmd.tpask.receive", - senderPlayer.getDisplayName().copy().fillStyle(targetPlayerProfile.getStyle(TextFormatType.Accent)) + senderPlayer.getDisplayName().copy().withStyle(targetPlayerProfile.getStyle(TextFormatType.Accent)) ); String senderName = senderPlayer.getGameProfile().name(); @@ -63,7 +63,7 @@ public int run(CommandContext context) throws CommandSyntax //inform command sender that request has been sent var senderPlayerProfile = PlayerProfile.access(senderPlayer); - var targetPlayerText = targetPlayer.getDisplayName().copy().fillStyle(senderPlayerProfile.getStyle(TextFormatType.Accent)); + var targetPlayerText = targetPlayer.getDisplayName().copy().withStyle(senderPlayerProfile.getStyle(TextFormatType.Accent)); senderPlayerData.sendCommandFeedback("cmd.tpask.send", targetPlayerText); return SINGLE_SUCCESS; diff --git a/src/main/java/com/fibermc/essentialcommands/commands/TeleportAskHereCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/TeleportAskHereCommand.java index 75f793c1..d6d51143 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/TeleportAskHereCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/TeleportAskHereCommand.java @@ -11,19 +11,19 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.command.argument.EntityArgumentType; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.EntityArgument; +import net.minecraft.server.level.ServerPlayer; -public class TeleportAskHereCommand implements Command { +public class TeleportAskHereCommand implements Command { public TeleportAskHereCommand() {} @Override - public int run(CommandContext context) throws CommandSyntaxException { + public int run(CommandContext context) throws CommandSyntaxException { TeleportManager tpMgr = ManagerLocator.getInstance().getTpManager(); - ServerPlayerEntity senderPlayer = context.getSource().getPlayerOrThrow(); - ServerPlayerEntity targetPlayer = EntityArgumentType.getPlayer(context, "target_player"); + ServerPlayer senderPlayer = context.getSource().getPlayerOrException(); + ServerPlayer targetPlayer = EntityArgument.getPlayer(context, "target_player"); var senderPlayerData = PlayerData.access(senderPlayer); var targetPlayerData = PlayerData.access(targetPlayer); @@ -43,7 +43,7 @@ public int run(CommandContext context) throws CommandSyntax var targetPlayerEcText = ECText.access(targetPlayer); targetPlayerData.sendMessage( "cmd.tpaskhere.receive", - targetPlayerEcText.accent(senderPlayer.getNameForScoreboard()) + targetPlayerEcText.accent(senderPlayer.getScoreboardName()) ); String senderName = senderPlayer.getGameProfile().name(); @@ -59,7 +59,7 @@ public int run(CommandContext context) throws CommandSyntax tpMgr.startTpRequest(senderPlayer, targetPlayer, TeleportRequest.Type.TPA_HERE); //inform command sender that request has been sent - var targetPlayerText = ECText.access(senderPlayer).accent(targetPlayer.getNameForScoreboard()); + var targetPlayerText = ECText.access(senderPlayer).accent(targetPlayer.getScoreboardName()); senderPlayerData.sendCommandFeedback("cmd.tpask.send", targetPlayerText); return SINGLE_SUCCESS; diff --git a/src/main/java/com/fibermc/essentialcommands/commands/TeleportCancelCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/TeleportCancelCommand.java index 176aafec..c0e4b95e 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/TeleportCancelCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/TeleportCancelCommand.java @@ -7,20 +7,20 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.Text; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; import dev.jpcode.eccore.util.TextUtil; -public class TeleportCancelCommand implements Command { +public class TeleportCancelCommand implements Command { public TeleportCancelCommand() {} @Override - public int run(CommandContext context) throws CommandSyntaxException { + public int run(CommandContext context) throws CommandSyntaxException { //Store command sender - ServerPlayerEntity senderPlayer = context.getSource().getPlayerOrThrow(); + ServerPlayer senderPlayer = context.getSource().getPlayerOrException(); var senderPlayerData = PlayerData.access(senderPlayer); var existingTeleportRequests = senderPlayerData.getSentTeleportRequests(); @@ -36,8 +36,8 @@ public int run(CommandContext context) throws CommandSyntax senderPlayerData.sendCommandFeedback( "cmd.tpcancel.feedback", TextUtil.join( - targetPlayers.stream().map(PlayerData::getPlayer).map(ServerPlayerEntity::getDisplayName).toList(), - Text.literal(", ")) + targetPlayers.stream().map(PlayerData::getPlayer).map(ServerPlayer::getDisplayName).toList(), + Component.literal(", ")) ); return SINGLE_SUCCESS; diff --git a/src/main/java/com/fibermc/essentialcommands/commands/TeleportDenyCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/TeleportDenyCommand.java index c242ab77..f9baf14e 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/TeleportDenyCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/TeleportDenyCommand.java @@ -7,11 +7,11 @@ import com.mojang.brigadier.context.CommandContext; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.level.ServerPlayer; public class TeleportDenyCommand extends TeleportResponseCommand { - protected int exec(CommandContext context, ServerPlayerEntity respondingPlayer, ServerPlayerEntity requesterPlayer) { + protected int exec(CommandContext context, ServerPlayer respondingPlayer, ServerPlayer requesterPlayer) { var targetPlayerData = PlayerData.access(requesterPlayer); var senderPlayerData = PlayerData.access(respondingPlayer); diff --git a/src/main/java/com/fibermc/essentialcommands/commands/TeleportResponseCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/TeleportResponseCommand.java index 5b79d909..a6cd0659 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/TeleportResponseCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/TeleportResponseCommand.java @@ -12,22 +12,22 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.command.argument.EntityArgumentType; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.EntityArgument; +import net.minecraft.server.level.ServerPlayer; -public abstract class TeleportResponseCommand implements Command { +public abstract class TeleportResponseCommand implements Command { - public int run(CommandContext context) throws CommandSyntaxException { + public int run(CommandContext context) throws CommandSyntaxException { return exec( context, context.getSource().getPlayer(), - EntityArgumentType.getPlayer(context, "target_player") + EntityArgument.getPlayer(context, "target_player") ); } - public int runDefault(CommandContext context) throws CommandSyntaxException { - var respondingPlayer = context.getSource().getPlayerOrThrow(); + public int runDefault(CommandContext context) throws CommandSyntaxException { + var respondingPlayer = context.getSource().getPlayerOrException(); var respondingPlayerData = PlayerData.access(respondingPlayer); var ecText = ECText.access(respondingPlayer); LinkedHashMap incomingTeleportRequests = respondingPlayerData.getIncomingTeleportRequests(); @@ -40,7 +40,7 @@ public int runDefault(CommandContext context) throws Comman ecText.getText("cmd.tpa_reply.error.shortcut_none_exist", TextFormatType.Error)); } - ServerPlayerEntity teleportRequestSender = incomingTeleportRequests.values().stream().findFirst().get().getSenderPlayer(); + ServerPlayer teleportRequestSender = incomingTeleportRequests.values().stream().findFirst().get().getSenderPlayer(); if (teleportRequestSender == null) { throw CommandUtil.createSimpleException( ecText.getText("cmd.tpa_reply.error.no_request_from_target", TextFormatType.Error)); @@ -49,6 +49,6 @@ public int runDefault(CommandContext context) throws Comman return exec(context, respondingPlayer, teleportRequestSender); } - abstract int exec(CommandContext context, ServerPlayerEntity respondingPlayer, ServerPlayerEntity requesterPlayer); + abstract int exec(CommandContext context, ServerPlayer respondingPlayer, ServerPlayer requesterPlayer); } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/WarpDeleteCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/WarpDeleteCommand.java index 35782169..7d9116f6 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/WarpDeleteCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/WarpDeleteCommand.java @@ -10,14 +10,14 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.commands.CommandSourceStack; -public class WarpDeleteCommand implements Command { +public class WarpDeleteCommand implements Command { public WarpDeleteCommand() {} @Override - public int run(CommandContext context) throws CommandSyntaxException { + public int run(CommandContext context) throws CommandSyntaxException { WorldDataManager worldDataManager = ManagerLocator.getInstance().getWorldDataManager(); var senderPlayerData = PlayerData.accessFromContextOrThrow(context); String warpName = StringArgumentType.getString(context, "warp_name"); diff --git a/src/main/java/com/fibermc/essentialcommands/commands/WarpSetCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/WarpSetCommand.java index 4dcb103f..b0710b46 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/WarpSetCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/WarpSetCommand.java @@ -12,16 +12,16 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.commands.CommandSourceStack; -public class WarpSetCommand implements Command { +public class WarpSetCommand implements Command { public WarpSetCommand() {} @Override - public int run(CommandContext context) throws CommandSyntaxException { + public int run(CommandContext context) throws CommandSyntaxException { WorldDataManager worldDataManager = ManagerLocator.getInstance().getWorldDataManager(); - var senderPlayer = context.getSource().getPlayerOrThrow(); + var senderPlayer = context.getSource().getPlayerOrException(); var senderPlayerData = PlayerData.access(senderPlayer); String warpName = StringArgumentType.getString(context, "warp_name"); diff --git a/src/main/java/com/fibermc/essentialcommands/commands/WarpTpCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/WarpTpCommand.java index 6cc2dbec..944ce037 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/WarpTpCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/WarpTpCommand.java @@ -11,28 +11,28 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.command.argument.EntityArgumentType; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.EntityArgument; +import net.minecraft.server.level.ServerPlayer; -public class WarpTpCommand implements Command { +public class WarpTpCommand implements Command { public WarpTpCommand() {} @Override - public int run(CommandContext context) throws CommandSyntaxException { - ServerPlayerEntity senderPlayer = context.getSource().getPlayer(); + public int run(CommandContext context) throws CommandSyntaxException { + ServerPlayer senderPlayer = context.getSource().getPlayer(); exec(context, senderPlayer); return SINGLE_SUCCESS; } private void exec( - CommandContext context, - ServerPlayerEntity targetPlayer) throws CommandSyntaxException + CommandContext context, + ServerPlayer targetPlayer) throws CommandSyntaxException { var worldDataManager = ManagerLocator.getInstance().getWorldDataManager(); - var senderPlayer = context.getSource().getPlayerOrThrow(); + var senderPlayer = context.getSource().getPlayerOrException(); var ecText = ECText.access(senderPlayer); String warpName = StringArgumentType.getString(context, "warp_name"); @@ -60,8 +60,8 @@ private void exec( ecText.getText("cmd.warp.location_name", warpNameText)); } - public int runOther(CommandContext context) throws CommandSyntaxException { - exec(context, EntityArgumentType.getPlayer(context, "target_player")); + public int runOther(CommandContext context) throws CommandSyntaxException { + exec(context, EntityArgument.getPlayer(context, "target_player")); return 0; } } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/bench/AnvilCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/bench/AnvilCommand.java index a91fb5ad..12ffda30 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/bench/AnvilCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/bench/AnvilCommand.java @@ -3,32 +3,32 @@ import com.fibermc.essentialcommands.screen.AnvilCommandScreenHandler; import org.jetbrains.annotations.NotNull; -import net.minecraft.screen.ScreenHandlerContext; -import net.minecraft.screen.ScreenHandlerFactory; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.stat.Stats; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.stats.Stats; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuConstructor; public class AnvilCommand extends SimpleScreenCommand { - private static final ScreenHandlerFactory SCREEN_HANDLER_FACTORY = (syncId, inventory, player) -> + private static final MenuConstructor SCREEN_HANDLER_FACTORY = (syncId, inventory, player) -> new AnvilCommandScreenHandler( syncId, inventory, - ScreenHandlerContext.create(player.getEntityWorld(), player.getBlockPos()) + ContainerLevelAccess.create(player.level(), player.blockPosition()) ); @Override - protected Text getScreenTitle() { - return Text.translatable("block.minecraft.anvil"); + protected Component getScreenTitle() { + return Component.translatable("block.minecraft.anvil"); } @Override - protected @NotNull ScreenHandlerFactory getScreenHandlerFactory() { + protected @NotNull MenuConstructor getScreenHandlerFactory() { return SCREEN_HANDLER_FACTORY; } @Override - protected void onOpen(ServerPlayerEntity player) { - player.incrementStat(Stats.INTERACT_WITH_ANVIL); + protected void onOpen(ServerPlayer player) { + player.awardStat(Stats.INTERACT_WITH_ANVIL); } } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/bench/EnderchestCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/bench/EnderchestCommand.java index c5382859..62b16547 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/bench/EnderchestCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/bench/EnderchestCommand.java @@ -2,30 +2,30 @@ import org.jetbrains.annotations.NotNull; -import net.minecraft.screen.GenericContainerScreenHandler; -import net.minecraft.screen.NamedScreenHandlerFactory; -import net.minecraft.screen.SimpleNamedScreenHandlerFactory; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.stat.Stats; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.stats.Stats; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.SimpleMenuProvider; +import net.minecraft.world.inventory.ChestMenu; public class EnderchestCommand extends SimpleScreenCommand { @Override - protected Text getScreenTitle() { - return Text.translatable("container.enderchest"); + protected Component getScreenTitle() { + return Component.translatable("container.enderchest"); } @Override - protected @NotNull NamedScreenHandlerFactory getScreenHandlerFactory() { - return new SimpleNamedScreenHandlerFactory( + protected @NotNull MenuProvider getScreenHandlerFactory() { + return new SimpleMenuProvider( (syncId, inventory, player) -> - GenericContainerScreenHandler.createGeneric9x3(syncId, inventory, player.getEnderChestInventory()), - Text.translatable("container.enderchest") + ChestMenu.threeRows(syncId, inventory, player.getEnderChestInventory()), + Component.translatable("container.enderchest") ); } @Override - protected void onOpen(ServerPlayerEntity player) { - player.incrementStat(Stats.OPEN_ENDERCHEST); + protected void onOpen(ServerPlayer player) { + player.awardStat(Stats.OPEN_ENDERCHEST); } } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/bench/GrindstoneCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/bench/GrindstoneCommand.java index ffb174df..66ac386e 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/bench/GrindstoneCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/bench/GrindstoneCommand.java @@ -3,32 +3,32 @@ import com.fibermc.essentialcommands.screen.GrindstoneCommandScreenHandler; import org.jetbrains.annotations.NotNull; -import net.minecraft.screen.ScreenHandlerContext; -import net.minecraft.screen.ScreenHandlerFactory; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.stat.Stats; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.stats.Stats; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuConstructor; public class GrindstoneCommand extends SimpleScreenCommand { - private static final ScreenHandlerFactory SCREEN_HANDLER_FACTORY = (syncId, inventory, player) -> + private static final MenuConstructor SCREEN_HANDLER_FACTORY = (syncId, inventory, player) -> new GrindstoneCommandScreenHandler( syncId, inventory, - ScreenHandlerContext.create(player.getEntityWorld(), player.getBlockPos()) + ContainerLevelAccess.create(player.level(), player.blockPosition()) ); @Override - protected Text getScreenTitle() { - return Text.translatable("block.minecraft.grindstone"); + protected Component getScreenTitle() { + return Component.translatable("block.minecraft.grindstone"); } @Override - protected @NotNull ScreenHandlerFactory getScreenHandlerFactory() { + protected @NotNull MenuConstructor getScreenHandlerFactory() { return SCREEN_HANDLER_FACTORY; } @Override - protected void onOpen(ServerPlayerEntity player) { - player.incrementStat(Stats.INTERACT_WITH_GRINDSTONE); + protected void onOpen(ServerPlayer player) { + player.awardStat(Stats.INTERACT_WITH_GRINDSTONE); } } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/bench/SimpleScreenCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/bench/SimpleScreenCommand.java index 0084ca93..e63e5f10 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/bench/SimpleScreenCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/bench/SimpleScreenCommand.java @@ -7,20 +7,20 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.screen.NamedScreenHandlerFactory; -import net.minecraft.screen.ScreenHandlerFactory; -import net.minecraft.screen.SimpleNamedScreenHandlerFactory; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.Text; - -public abstract class SimpleScreenCommand implements Command { +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.SimpleMenuProvider; +import net.minecraft.world.inventory.MenuConstructor; + +public abstract class SimpleScreenCommand implements Command { @Override - public int run(CommandContext context) throws CommandSyntaxException { - var senderPlayer = context.getSource().getPlayerOrThrow(); + public int run(CommandContext context) throws CommandSyntaxException { + var senderPlayer = context.getSource().getPlayerOrException(); var senderPlayerData = PlayerData.access(senderPlayer); - senderPlayer.openHandledScreen(createNamedScreenHandlerFactory()); + senderPlayer.openMenu(createNamedScreenHandlerFactory()); senderPlayerData.sendCommandFeedback("cmd.workbench.feedback", getScreenTitle()); @@ -29,13 +29,13 @@ public int run(CommandContext context) throws CommandSyntax return 0; } - protected NamedScreenHandlerFactory createNamedScreenHandlerFactory() { - return new SimpleNamedScreenHandlerFactory(getScreenHandlerFactory(), getScreenTitle()); + protected MenuProvider createNamedScreenHandlerFactory() { + return new SimpleMenuProvider(getScreenHandlerFactory(), getScreenTitle()); } - protected abstract Text getScreenTitle(); + protected abstract Component getScreenTitle(); - protected abstract @NotNull ScreenHandlerFactory getScreenHandlerFactory(); + protected abstract @NotNull MenuConstructor getScreenHandlerFactory(); - protected abstract void onOpen(ServerPlayerEntity player); + protected abstract void onOpen(ServerPlayer player); } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/bench/StonecutterCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/bench/StonecutterCommand.java index 48470d53..c4b32949 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/bench/StonecutterCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/bench/StonecutterCommand.java @@ -3,32 +3,32 @@ import com.fibermc.essentialcommands.screen.StonecutterCommandScreenHandler; import org.jetbrains.annotations.NotNull; -import net.minecraft.screen.ScreenHandlerContext; -import net.minecraft.screen.ScreenHandlerFactory; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.stat.Stats; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.stats.Stats; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuConstructor; public class StonecutterCommand extends SimpleScreenCommand { - private static final ScreenHandlerFactory SCREEN_HANDLER_FACTORY = (syncId, inventory, player) -> + private static final MenuConstructor SCREEN_HANDLER_FACTORY = (syncId, inventory, player) -> new StonecutterCommandScreenHandler( syncId, inventory, - ScreenHandlerContext.create(player.getEntityWorld(), player.getBlockPos()) + ContainerLevelAccess.create(player.level(), player.blockPosition()) ); @Override - protected Text getScreenTitle() { - return Text.translatable("block.minecraft.stonecutter"); + protected Component getScreenTitle() { + return Component.translatable("block.minecraft.stonecutter"); } @Override - protected @NotNull ScreenHandlerFactory getScreenHandlerFactory() { + protected @NotNull MenuConstructor getScreenHandlerFactory() { return SCREEN_HANDLER_FACTORY; } @Override - protected void onOpen(ServerPlayerEntity player) { - player.incrementStat(Stats.INTERACT_WITH_STONECUTTER); + protected void onOpen(ServerPlayer player) { + player.awardStat(Stats.INTERACT_WITH_STONECUTTER); } } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/bench/WastebinCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/bench/WastebinCommand.java index 5928c694..7b120277 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/bench/WastebinCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/bench/WastebinCommand.java @@ -4,28 +4,28 @@ import com.fibermc.essentialcommands.text.TextFormatType; import org.jetbrains.annotations.NotNull; -import net.minecraft.inventory.SimpleInventory; -import net.minecraft.screen.GenericContainerScreenHandler; -import net.minecraft.screen.ScreenHandlerFactory; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.inventory.ChestMenu; +import net.minecraft.world.inventory.MenuConstructor; public class WastebinCommand extends SimpleScreenCommand { - private static final ScreenHandlerFactory SCREEN_HANDLER_FACTORY = (syncId, inventory, player) -> - GenericContainerScreenHandler.createGeneric9x3(syncId, inventory, new SimpleInventory(27)); + private static final MenuConstructor SCREEN_HANDLER_FACTORY = (syncId, inventory, player) -> + ChestMenu.threeRows(syncId, inventory, new SimpleContainer(27)); @Override - protected Text getScreenTitle() { + protected Component getScreenTitle() { return ECText.getInstance().getText("cmd.wastebin.name", TextFormatType.Empty); } @Override - protected @NotNull ScreenHandlerFactory getScreenHandlerFactory() { + protected @NotNull MenuConstructor getScreenHandlerFactory() { return SCREEN_HANDLER_FACTORY; } @Override - protected void onOpen(ServerPlayerEntity player) { + protected void onOpen(ServerPlayer player) { } } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/bench/WorkbenchCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/bench/WorkbenchCommand.java index fa9f7598..75bf7557 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/bench/WorkbenchCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/bench/WorkbenchCommand.java @@ -3,32 +3,32 @@ import com.fibermc.essentialcommands.screen.CraftingCommandScreenHandler; import org.jetbrains.annotations.NotNull; -import net.minecraft.screen.ScreenHandlerContext; -import net.minecraft.screen.ScreenHandlerFactory; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.stat.Stats; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.stats.Stats; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuConstructor; public class WorkbenchCommand extends SimpleScreenCommand { - private static final ScreenHandlerFactory SCREEN_HANDLER_FACTORY = (syncId, inventory, player) -> + private static final MenuConstructor SCREEN_HANDLER_FACTORY = (syncId, inventory, player) -> new CraftingCommandScreenHandler( syncId, inventory, - ScreenHandlerContext.create(player.getEntityWorld(), player.getBlockPos()) + ContainerLevelAccess.create(player.level(), player.blockPosition()) ); @Override - protected Text getScreenTitle() { - return Text.translatable("block.minecraft.crafting_table"); + protected Component getScreenTitle() { + return Component.translatable("block.minecraft.crafting_table"); } @Override - protected @NotNull ScreenHandlerFactory getScreenHandlerFactory() { + protected @NotNull MenuConstructor getScreenHandlerFactory() { return SCREEN_HANDLER_FACTORY; } @Override - protected void onOpen(ServerPlayerEntity player) { - player.incrementStat(Stats.INTERACT_WITH_CRAFTING_TABLE); + protected void onOpen(ServerPlayer player) { + player.awardStat(Stats.INTERACT_WITH_CRAFTING_TABLE); } } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/helpers/FeedbackReceiver.java b/src/main/java/com/fibermc/essentialcommands/commands/helpers/FeedbackReceiver.java index 18e90c46..f19715b0 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/helpers/FeedbackReceiver.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/helpers/FeedbackReceiver.java @@ -4,20 +4,20 @@ import com.fibermc.essentialcommands.text.ECText; import com.fibermc.essentialcommands.text.TextFormatType; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; import static com.fibermc.essentialcommands.EssentialCommands.CONFIG; public final class FeedbackReceiver implements IFeedbackReceiver { - private final ServerCommandSource commandSource; + private final CommandSourceStack commandSource; - private FeedbackReceiver(ServerCommandSource commandSource) { + private FeedbackReceiver(CommandSourceStack commandSource) { this.commandSource = commandSource; } - public static IFeedbackReceiver ofSource(ServerCommandSource commandSource) { + public static IFeedbackReceiver ofSource(CommandSourceStack commandSource) { var player = commandSource.getPlayer(); return player != null ? PlayerData.access(player) @@ -25,21 +25,21 @@ public static IFeedbackReceiver ofSource(ServerCommandSource commandSource) { } @Override - public void sendCommandFeedback(Text text) { - commandSource.sendFeedback(() -> text, CONFIG.BROADCAST_TO_OPS); + public void sendCommandFeedback(Component text) { + commandSource.sendSuccess(() -> text, CONFIG.BROADCAST_TO_OPS); } @Override - public void sendCommandFeedback(String messageKey, Text... args) { + public void sendCommandFeedback(String messageKey, Component... args) { sendCommandFeedback(ECText.getInstance().getText(messageKey, TextFormatType.Default, args)); } - public void sendCommandError(Text text) { - commandSource.sendError(text); + public void sendCommandError(Component text) { + commandSource.sendFailure(text); } @Override - public void sendCommandError(String messageKey, Text... args) { + public void sendCommandError(String messageKey, Component... args) { sendCommandError(ECText.getInstance().getText(messageKey, TextFormatType.Error, args)); } } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/helpers/HeightFinder.java b/src/main/java/com/fibermc/essentialcommands/commands/helpers/HeightFinder.java index d54bc527..279e7214 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/helpers/HeightFinder.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/helpers/HeightFinder.java @@ -2,7 +2,7 @@ import java.util.OptionalInt; -import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.level.chunk.ChunkAccess; @FunctionalInterface public interface HeightFinder { @@ -11,6 +11,6 @@ public interface HeightFinder { * * @return A Y value corresponding to the player's feet pos */ - OptionalInt getY(Chunk chunk, int x, int z); + OptionalInt getY(ChunkAccess chunk, int x, int z); } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/helpers/HeightFindingStrategy.java b/src/main/java/com/fibermc/essentialcommands/commands/helpers/HeightFindingStrategy.java index 899899df..50935d31 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/helpers/HeightFindingStrategy.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/helpers/HeightFindingStrategy.java @@ -4,13 +4,13 @@ import com.fibermc.essentialcommands.commands.utility.TopCommand; -import net.minecraft.block.BlockState; -import net.minecraft.registry.RegistryKey; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.ChunkSectionPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.World; -import net.minecraft.world.chunk.Chunk; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.core.SectionPos; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.ChunkAccess; public enum HeightFindingStrategy implements HeightFinder { SKY_TO_SURFACE__FIRST_SOLID(TopCommand::getTop), @@ -24,11 +24,11 @@ public enum HeightFindingStrategy implements HeightFinder { this.heightFinder = heightFinder; } - public static HeightFindingStrategy forWorld(RegistryKey worldRegistryKey) { - if (worldRegistryKey == World.OVERWORLD || worldRegistryKey == World.END) { + public static HeightFindingStrategy forWorld(ResourceKey worldRegistryKey) { + if (worldRegistryKey == Level.OVERWORLD || worldRegistryKey == Level.END) { return HeightFindingStrategy.SKY_TO_SURFACE__FIRST_SOLID; } - if (worldRegistryKey == World.NETHER) { + if (worldRegistryKey == Level.NETHER) { return HeightFindingStrategy.BOTTOM_TO_SKY__FIRST_SAFE_AIR; } @@ -37,18 +37,18 @@ public static HeightFindingStrategy forWorld(RegistryKey worldRegistryKey } @Override - public OptionalInt getY(Chunk chunk, int x, int z) { + public OptionalInt getY(ChunkAccess chunk, int x, int z) { return heightFinder.getY(chunk, x, z); } - private static OptionalInt findYBottomUp(Chunk chunk, int x, int z) { + private static OptionalInt findYBottomUp(ChunkAccess chunk, int x, int z) { final int topY = getChunkHighestNonEmptySectionYOffsetOrTopY(chunk); - final int bottomY = chunk.getBottomY(); + final int bottomY = chunk.getMinY(); if (topY <= bottomY) { return OptionalInt.empty(); } - final BlockPos.Mutable mutablePos = new BlockPos.Mutable(x, bottomY, z); + final BlockPos.MutableBlockPos mutablePos = new BlockPos.MutableBlockPos(x, bottomY, z); BlockState bsFeet1 = chunk.getBlockState(mutablePos); // Block below feet BlockState bsBody2 = chunk.getBlockState(mutablePos.move(Direction.UP)); // Block at feet level BlockState bsHead3; // Block at head level @@ -66,8 +66,8 @@ private static OptionalInt findYBottomUp(Chunk chunk, int x, int z) { return OptionalInt.empty(); } - public static int getChunkHighestNonEmptySectionYOffsetOrTopY(Chunk chunk) { - int i = chunk.getHighestNonEmptySection(); - return i == chunk.getTopYInclusive() ? chunk.getBottomY() : ChunkSectionPos.getBlockCoord(chunk.sectionIndexToCoord(i)); + public static int getChunkHighestNonEmptySectionYOffsetOrTopY(ChunkAccess chunk) { + int i = chunk.getHighestFilledSectionIndex(); + return i == chunk.getMaxY() ? chunk.getMinY() : SectionPos.sectionToBlockCoord(chunk.getSectionYFromSectionIndex(i)); } } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/helpers/IFeedbackReceiver.java b/src/main/java/com/fibermc/essentialcommands/commands/helpers/IFeedbackReceiver.java index a902c5c1..fec9aa19 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/helpers/IFeedbackReceiver.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/helpers/IFeedbackReceiver.java @@ -1,13 +1,13 @@ package com.fibermc.essentialcommands.commands.helpers; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; public interface IFeedbackReceiver { - void sendCommandFeedback(Text text); + void sendCommandFeedback(Component text); - void sendCommandFeedback(String messageKey, Text... args); + void sendCommandFeedback(String messageKey, Component... args); - void sendCommandError(Text text); + void sendCommandError(Component text); - void sendCommandError(String messageKey, Text... args); + void sendCommandError(String messageKey, Component... args); } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/suggestions/ListSuggestion.java b/src/main/java/com/fibermc/essentialcommands/commands/suggestions/ListSuggestion.java index 3c94c587..343867d0 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/suggestions/ListSuggestion.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/suggestions/ListSuggestion.java @@ -13,7 +13,7 @@ import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; -import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.commands.CommandSourceStack; public final class ListSuggestion { private ListSuggestion() {} @@ -34,8 +34,8 @@ public static CompletableFuture buildSuggestions(SuggestionsBuilder } @Contract(pure = true) - public static @NotNull SuggestionProvider of(Supplier> suggestionCollection) { - return (CommandContext context, SuggestionsBuilder builder) + public static @NotNull SuggestionProvider of(Supplier> suggestionCollection) { + return (CommandContext context, SuggestionsBuilder builder) -> buildSuggestions(builder, suggestionCollection.get()); } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/suggestions/NicknamePlayersSuggestion.java b/src/main/java/com/fibermc/essentialcommands/commands/suggestions/NicknamePlayersSuggestion.java index 152fddd4..80d606cd 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/suggestions/NicknamePlayersSuggestion.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/suggestions/NicknamePlayersSuggestion.java @@ -7,20 +7,20 @@ import com.mojang.brigadier.suggestion.SuggestionProvider; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.MutableText; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.MutableComponent; public final class NicknamePlayersSuggestion { private NicknamePlayersSuggestion() {} //Brigader Suggestions - public static final SuggestionProvider STRING_SUGGESTIONS_PROVIDER = + public static final SuggestionProvider STRING_SUGGESTIONS_PROVIDER = ListSuggestion.ofContext(context -> PlayerDataManager.getInstance().getAllPlayerData().stream() .map(PlayerData::getNickname) .filter(Optional::isPresent) .map(Optional::get) - .map(MutableText::getString) + .map(MutableComponent::getString) .sorted(String.CASE_INSENSITIVE_ORDER) .toList() ); diff --git a/src/main/java/com/fibermc/essentialcommands/commands/suggestions/OfflinePlayerRepo.java b/src/main/java/com/fibermc/essentialcommands/commands/suggestions/OfflinePlayerRepo.java index e18ac478..aea35333 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/suggestions/OfflinePlayerRepo.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/suggestions/OfflinePlayerRepo.java @@ -9,10 +9,9 @@ import com.mojang.authlib.GameProfile; import com.mojang.authlib.yggdrasil.response.NameAndId; -import net.minecraft.network.packet.c2s.common.SyncedClientOptions; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.PlayerConfigEntry; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.level.ClientInformation; +import net.minecraft.server.level.ServerPlayer; public class OfflinePlayerRepo { @@ -23,19 +22,19 @@ public OfflinePlayerRepo(MinecraftServer server) { this.server = server; } - public CompletableFuture getOfflinePlayerByNameAsync(String playerName) { + public CompletableFuture getOfflinePlayerByNameAsync(String playerName) { return getGameProfile(playerName) .handle(((gameProfile, throwable) -> gameProfile.map(this::getOfflinePlayer).orElse(null))); } - public ServerPlayerEntity getOfflinePlayer(NameAndId playerProfile) { - var player = new ServerPlayerEntity( + public ServerPlayer getOfflinePlayer(NameAndId playerProfile) { + var player = new ServerPlayer( server, - server.getOverworld(), + server.overworld(), new GameProfile(playerProfile.id(), playerProfile.name()), - SyncedClientOptions.createDefault()); + ClientInformation.createDefault()); - server.getPlayerManager().loadPlayerData(new PlayerConfigEntry(playerProfile.id(), playerProfile.name())); + server.getPlayerList().loadPlayerData(new net.minecraft.server.players.NameAndId(playerProfile.id(), playerProfile.name())); return player; } @@ -58,7 +57,7 @@ private CompletableFuture> requestGameProfile(String playerN gameProfileExecutor.execute(() -> { try { - completable.complete(server.getApiServices().profileRepository().findProfileByName(playerName)); + completable.complete(server.services().profileRepository().findProfileByName(playerName)); } catch (Exception ex) { completable.completeExceptionally(ex); } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/suggestions/SuggestionListProvider.java b/src/main/java/com/fibermc/essentialcommands/commands/suggestions/SuggestionListProvider.java index f2317185..34ffacc5 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/suggestions/SuggestionListProvider.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/suggestions/SuggestionListProvider.java @@ -5,9 +5,9 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.commands.CommandSourceStack; @FunctionalInterface public interface SuggestionListProvider { - Collection getSuggestionList(CommandContext context) throws CommandSyntaxException; + Collection getSuggestionList(CommandContext context) throws CommandSyntaxException; } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/suggestions/TeleportResponseSuggestion.java b/src/main/java/com/fibermc/essentialcommands/commands/suggestions/TeleportResponseSuggestion.java index e6b11423..c2a68167 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/suggestions/TeleportResponseSuggestion.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/suggestions/TeleportResponseSuggestion.java @@ -7,14 +7,14 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.suggestion.SuggestionProvider; -import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.commands.CommandSourceStack; public final class TeleportResponseSuggestion { private TeleportResponseSuggestion() {} //Brigader Suggestions - public static final SuggestionProvider STRING_SUGGESTIONS_PROVIDER - = ListSuggestion.ofContext((CommandContext context) -> + public static final SuggestionProvider STRING_SUGGESTIONS_PROVIDER + = ListSuggestion.ofContext((CommandContext context) -> ((ServerPlayerEntityAccess) context.getSource().getPlayer()).ec$getPlayerData().getIncomingTeleportRequests().values() .stream().map((entry) -> entry.getSenderPlayer().getGameProfile().name()) .collect(Collectors.toList()) diff --git a/src/main/java/com/fibermc/essentialcommands/commands/suggestions/WarpSuggestion.java b/src/main/java/com/fibermc/essentialcommands/commands/suggestions/WarpSuggestion.java index db5ac8b0..d73c086d 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/suggestions/WarpSuggestion.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/suggestions/WarpSuggestion.java @@ -5,17 +5,17 @@ import com.mojang.brigadier.suggestion.SuggestionProvider; -import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.commands.CommandSourceStack; public final class WarpSuggestion { private WarpSuggestion() {} //Brigader Suggestions - public static final SuggestionProvider STRING_SUGGESTIONS_PROVIDER + public static final SuggestionProvider STRING_SUGGESTIONS_PROVIDER = ListSuggestion.ofContext( (ctx) -> ManagerLocator.getInstance() .getWorldDataManager() - .getAccessibleWarps(ctx.getSource().getPlayerOrThrow()) + .getAccessibleWarps(ctx.getSource().getPlayerOrException()) .map(WarpLocation::getName) .toList() ); diff --git a/src/main/java/com/fibermc/essentialcommands/commands/utility/DayCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/utility/DayCommand.java index 843f50b1..49179e97 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/utility/DayCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/utility/DayCommand.java @@ -6,23 +6,23 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.world.ServerWorld; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.level.ServerLevel; -public class DayCommand implements Command { +public class DayCommand implements Command { @Override - public int run(CommandContext context) throws CommandSyntaxException { - ServerCommandSource source = context.getSource(); + public int run(CommandContext context) throws CommandSyntaxException { + CommandSourceStack source = context.getSource(); PlayerData playerData = PlayerData.accessFromContextOrThrow(context); - ServerWorld world = source.getServer().getOverworld(); - if (world.isDay()) { + ServerLevel world = source.getServer().overworld(); + if (world.isBrightOutside()) { playerData.sendCommandFeedback("cmd.day.error.already_daytime"); return -1; } - long time = world.getTimeOfDay(); + long time = world.getDayTime(); long timeToDay = 24000L - time % 24000L; - world.setTimeOfDay(time + timeToDay); + world.setDayTime(time + timeToDay); playerData.sendCommandFeedback("cmd.day.feedback"); return 1; } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/utility/ExtinguishCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/utility/ExtinguishCommand.java index db63a3fe..1d1b7606 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/utility/ExtinguishCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/utility/ExtinguishCommand.java @@ -7,21 +7,21 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.level.ServerPlayer; -public class ExtinguishCommand implements Command { +public class ExtinguishCommand implements Command { @Override - public int run(CommandContext context) throws CommandSyntaxException { + public int run(CommandContext context) throws CommandSyntaxException { PlayerData senderPlayerData = PlayerData.accessFromContextOrThrow(context); - ServerPlayerEntity targetPlayer = CommandUtil.getCommandTargetPlayer(context); + ServerPlayer targetPlayer = CommandUtil.getCommandTargetPlayer(context); if (!targetPlayer.isOnFire()) { senderPlayerData.sendCommandError("cmd.extinguish.error.not_on_fire"); return 0; } - targetPlayer.setFireTicks(0); + targetPlayer.setRemainingFireTicks(0); senderPlayerData.sendCommandFeedback("cmd.extinguish.feedback"); diff --git a/src/main/java/com/fibermc/essentialcommands/commands/utility/FeedCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/utility/FeedCommand.java index 40255896..33eafd37 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/utility/FeedCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/utility/FeedCommand.java @@ -7,24 +7,24 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.entity.player.HungerManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.food.FoodData; -public class FeedCommand implements Command { +public class FeedCommand implements Command { @Override - public int run(CommandContext context) throws CommandSyntaxException { + public int run(CommandContext context) throws CommandSyntaxException { PlayerData senderPlayerData = PlayerData.accessFromContextOrThrow(context); - ServerPlayerEntity targetPlayer = CommandUtil.getCommandTargetPlayer(context); + ServerPlayer targetPlayer = CommandUtil.getCommandTargetPlayer(context); - HungerManager hungerManager = targetPlayer.getHungerManager(); - if (!hungerManager.isNotFull()) { + FoodData hungerManager = targetPlayer.getFoodData(); + if (!hungerManager.needsFood()) { senderPlayerData.sendCommandError("cmd.feed.error.full"); return 0; } hungerManager.setFoodLevel(20); - hungerManager.setSaturationLevel(5); + hungerManager.setSaturation(5); // hungerManager.setExhaustion(0); // idk, you ca only add to it now diff --git a/src/main/java/com/fibermc/essentialcommands/commands/utility/GametimeCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/utility/GametimeCommand.java index 5130aa48..bd63ca03 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/utility/GametimeCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/utility/GametimeCommand.java @@ -9,11 +9,11 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.HoverEvent; -import net.minecraft.text.Text; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.HoverEvent; -public class GametimeCommand implements Command { +public class GametimeCommand implements Command { private final String modVersion = EssentialCommands.MOD_METADATA.getVersion().getFriendlyString(); private static final int TICKS_PER_SECOND = 20; @@ -25,11 +25,11 @@ public class GametimeCommand implements Command { private static final int MINUTES_PER_DAY = HOURS_PER_DAY * MINUTES_PER_HOUR; @Override - public int run(CommandContext context) throws CommandSyntaxException { - Text t = getFormattedTime( - context.getSource().getWorld().getTimeOfDay(), + public int run(CommandContext context) throws CommandSyntaxException { + Component t = getFormattedTime( + context.getSource().getLevel().getDayTime(), PlayerProfile.accessFromContextOrThrow(context)); - context.getSource().sendFeedback(() -> t, false); + context.getSource().sendSuccess(() -> t, false); return 0; } @@ -46,12 +46,12 @@ private static String formatGameTimeOfDay(long tickTime) { ); } - private static Text getFormattedTime(long time, IStyleProvider styleProvider) { - return Text.translatable( + private static Component getFormattedTime(long time, IStyleProvider styleProvider) { + return Component.translatable( "commands.time.query", - Text.literal(formatGameTimeOfDay(time)).setStyle(styleProvider.getStyle(TextFormatType.Accent))) + Component.literal(formatGameTimeOfDay(time)).setStyle(styleProvider.getStyle(TextFormatType.Accent))) .setStyle(styleProvider.getStyle(TextFormatType.Default) .withHoverEvent( - new HoverEvent.ShowText(Text.literal(String.valueOf(time % 24000L))))); + new HoverEvent.ShowText(Component.literal(String.valueOf(time % 24000L))))); } } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/utility/HealCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/utility/HealCommand.java index a2ebed9d..3afa601c 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/utility/HealCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/utility/HealCommand.java @@ -7,14 +7,14 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.level.ServerPlayer; -public class HealCommand implements Command { +public class HealCommand implements Command { @Override - public int run(CommandContext context) throws CommandSyntaxException { + public int run(CommandContext context) throws CommandSyntaxException { PlayerData senderPlayerData = PlayerData.accessFromContextOrThrow(context); - ServerPlayerEntity targetPlayer = CommandUtil.getCommandTargetPlayer(context); + ServerPlayer targetPlayer = CommandUtil.getCommandTargetPlayer(context); float currentHealth = targetPlayer.getHealth(); float maxHealth = targetPlayer.getMaxHealth(); diff --git a/src/main/java/com/fibermc/essentialcommands/commands/utility/NearCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/utility/NearCommand.java index 8965c2a7..ccdf78eb 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/utility/NearCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/utility/NearCommand.java @@ -13,26 +13,26 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.Text; -import net.minecraft.util.math.Vec3d; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.phys.Vec3; import dev.jpcode.eccore.util.TextUtil; -public class NearCommand implements Command { +public class NearCommand implements Command { @Override - public int run(CommandContext context) throws CommandSyntaxException { + public int run(CommandContext context) throws CommandSyntaxException { PlayerData senderPlayerData = PlayerData.accessFromContextOrThrow(context); - ServerPlayerEntity targetPlayer = CommandUtil.getCommandTargetPlayer(context); + ServerPlayer targetPlayer = CommandUtil.getCommandTargetPlayer(context); return exec(senderPlayerData, targetPlayer, EssentialCommands.CONFIG.NEAR_COMMAND_DEFAULT_RADIUS); } - public static int withRange(CommandContext context) throws CommandSyntaxException { + public static int withRange(CommandContext context) throws CommandSyntaxException { PlayerData senderPlayerData = PlayerData.accessFromContextOrThrow(context); - ServerPlayerEntity targetPlayer = CommandUtil.getCommandTargetPlayer(context); + ServerPlayer targetPlayer = CommandUtil.getCommandTargetPlayer(context); int range = IntegerArgumentType.getInteger(context, "range"); @@ -46,20 +46,20 @@ public static int withRange(CommandContext context) throws return exec(senderPlayerData, targetPlayer, range); } - public static int exec(PlayerData senderPlayerData, ServerPlayerEntity targetPlayer, int range) { - Vec3d basePos = targetPlayer.getEntityPos(); + public static int exec(PlayerData senderPlayerData, ServerPlayer targetPlayer, int range) { + Vec3 basePos = targetPlayer.position(); - List players = targetPlayer.getEntityWorld().getPlayers().stream() + List players = targetPlayer.level().players().stream() .filter(player -> - targetPlayer.getUuid() != player.getUuid() - && basePos.isInRange(player.getEntityPos(), range) - && (!EssentialCommands.VANISH_PRESENT || VanishAPI.canSeePlayer((ServerPlayerEntity) player, senderPlayerData.getPlayer())) + targetPlayer.getUUID() != player.getUUID() + && basePos.closerThan(player.position(), range) + && (!EssentialCommands.VANISH_PRESENT || VanishAPI.canSeePlayer((ServerPlayer) player, senderPlayerData.getPlayer())) ) - .map(PlayerEntity::getDisplayName) + .map(Player::getDisplayName) .toList(); if (players.isEmpty()) senderPlayerData.sendCommandFeedback("cmd.near.feedback.empty"); - else senderPlayerData.sendCommandFeedback("cmd.near.feedback.list", TextUtil.join(players, Text.literal(", "))); + else senderPlayerData.sendCommandFeedback("cmd.near.feedback.list", TextUtil.join(players, Component.literal(", "))); return SINGLE_SUCCESS; } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/utility/NightCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/utility/NightCommand.java index 2ee25751..390bb49c 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/utility/NightCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/utility/NightCommand.java @@ -6,23 +6,23 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.world.ServerWorld; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.level.ServerLevel; -public class NightCommand implements Command { +public class NightCommand implements Command { @Override - public int run(CommandContext context) throws CommandSyntaxException { - ServerCommandSource source = context.getSource(); + public int run(CommandContext context) throws CommandSyntaxException { + CommandSourceStack source = context.getSource(); PlayerData playerData = PlayerData.accessFromContextOrThrow(context); - ServerWorld world = source.getServer().getOverworld(); - if (world.isNight()) { + ServerLevel world = source.getServer().overworld(); + if (world.isDarkOutside()) { playerData.sendCommandFeedback("cmd.night.error.already_nighttime"); return -1; } - long time = world.getTimeOfDay(); + long time = world.getDayTime(); long timeToNight = 13000L - time % 24000L; - world.setTimeOfDay(time + timeToNight); + world.setDayTime(time + timeToNight); playerData.sendCommandFeedback("cmd.night.feedback"); return 1; } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/utility/RepairCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/utility/RepairCommand.java index 0e74aa5d..4c1ced68 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/utility/RepairCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/utility/RepairCommand.java @@ -7,24 +7,24 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.item.ItemStack; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.ItemStack; -public class RepairCommand implements Command { +public class RepairCommand implements Command { @Override - public int run(CommandContext context) throws CommandSyntaxException { + public int run(CommandContext context) throws CommandSyntaxException { PlayerData senderPlayerData = PlayerData.accessFromContextOrThrow(context); - ServerPlayerEntity targetPlayer = CommandUtil.getCommandTargetPlayer(context); + ServerPlayer targetPlayer = CommandUtil.getCommandTargetPlayer(context); - ItemStack itemStack = targetPlayer.getMainHandStack(); + ItemStack itemStack = targetPlayer.getMainHandItem(); if (!itemStack.isDamaged()) { senderPlayerData.sendCommandError("cmd.repair.error.not_damaged"); return 0; } - itemStack.setDamage(0); + itemStack.setDamageValue(0); senderPlayerData.sendCommandFeedback("cmd.repair.feedback"); diff --git a/src/main/java/com/fibermc/essentialcommands/commands/utility/SuicideCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/utility/SuicideCommand.java index 333a82fd..bfee9c80 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/utility/SuicideCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/utility/SuicideCommand.java @@ -7,21 +7,21 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.level.ServerPlayer; -public class SuicideCommand implements Command { +public class SuicideCommand implements Command { @Override - public int run(CommandContext context) throws CommandSyntaxException { - ServerPlayerEntity player = context.getSource().getPlayer(); + public int run(CommandContext context) throws CommandSyntaxException { + ServerPlayer player = context.getSource().getPlayer(); PlayerData playerData = ((ServerPlayerEntityAccess) player).ec$getPlayerData(); - if (player.isDead()) { + if (player.isDeadOrDying()) { playerData.sendCommandError("cmd.suicide.error.already_dead"); return 0; } - player.kill(player.getEntityWorld()); + player.kill(player.level()); return SINGLE_SUCCESS; } diff --git a/src/main/java/com/fibermc/essentialcommands/commands/utility/TopCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/utility/TopCommand.java index 231f49a0..40db8747 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/utility/TopCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/utility/TopCommand.java @@ -10,22 +10,22 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.World; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.chunk.ChunkSection; - -public class TopCommand implements Command { +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.chunk.ChunkAccess; +import net.minecraft.world.level.chunk.LevelChunkSection; + +public class TopCommand implements Command { @SuppressWarnings("checkstyle:LocalVariableName") @Override - public int run(CommandContext context) throws CommandSyntaxException { - ServerCommandSource source = context.getSource(); - ServerPlayerEntity player = source.getPlayerOrThrow(); - World world = source.getWorld(); - BlockPos playerPos = player.getBlockPos(); + public int run(CommandContext context) throws CommandSyntaxException { + CommandSourceStack source = context.getSource(); + ServerPlayer player = source.getPlayerOrException(); + Level world = source.getLevel(); + BlockPos playerPos = player.blockPosition(); OptionalInt new_y; int new_x = playerPos.getX(); @@ -33,7 +33,7 @@ public int run(CommandContext context) throws CommandSyntax final BlockPos targetXZ = new BlockPos(new_x, 0, new_z); - Chunk chunk = world.getChunk(targetXZ); + ChunkAccess chunk = world.getChunk(targetXZ); new_y = getTop(chunk, new_x, new_z); if (new_y.isEmpty()) { @@ -43,21 +43,21 @@ public int run(CommandContext context) throws CommandSyntax // Teleport the player PlayerTeleporter.requestTeleport( player, - new MinecraftLocation(world.getRegistryKey(), new_x, new_y.getAsInt(), new_z, player.getHeadYaw(), player.getPitch()), + new MinecraftLocation(world.dimension(), new_x, new_y.getAsInt(), new_z, player.getYHeadRot(), player.getXRot()), ECText.access(player).getText("cmd.top.location_name") ); return 0; } - public static OptionalInt getTop(Chunk chunk, int x, int z) { + public static OptionalInt getTop(ChunkAccess chunk, int x, int z) { final int maxY = calculateMaxY(chunk); - final int bottomY = chunk.getBottomY(); + final int bottomY = chunk.getMinY(); if (maxY <= bottomY) { return OptionalInt.empty(); } - final BlockPos.Mutable mutablePos = new BlockPos.Mutable(x, maxY, z); + final BlockPos.MutableBlockPos mutablePos = new BlockPos.MutableBlockPos(x, maxY, z); boolean isAir1 = chunk.getBlockState(mutablePos).isAir(); // Block at head level boolean isAir2 = chunk.getBlockState(mutablePos.move(Direction.DOWN)).isAir(); // Block at feet level boolean isAir3; // Block below feet @@ -75,13 +75,13 @@ public static OptionalInt getTop(Chunk chunk, int x, int z) { return OptionalInt.empty(); } - private static int calculateMaxY(Chunk chunk) { - final int maxY = chunk.getTopYInclusive(); - ChunkSection[] sections = chunk.getSectionArray(); + private static int calculateMaxY(ChunkAccess chunk) { + final int maxY = chunk.getMaxY(); + LevelChunkSection[] sections = chunk.getSections(); int maxSectionIndex = Math.min(sections.length - 1, maxY >> 4); for (int index = maxSectionIndex; index >= 0; --index) { - if (!sections[index].isEmpty()) { + if (!sections[index].hasOnlyAir()) { return Math.min(index << 4 + 15, maxY); } } diff --git a/src/main/java/com/fibermc/essentialcommands/config/EssentialCommandsConfig.java b/src/main/java/com/fibermc/essentialcommands/config/EssentialCommandsConfig.java index ed500472..908542ed 100644 --- a/src/main/java/com/fibermc/essentialcommands/config/EssentialCommandsConfig.java +++ b/src/main/java/com/fibermc/essentialcommands/config/EssentialCommandsConfig.java @@ -6,7 +6,12 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; - +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.Style; +import net.minecraft.resources.Identifier; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.Level; import com.fibermc.essentialcommands.ECPerms; import com.fibermc.essentialcommands.EssentialCommands; import com.fibermc.essentialcommands.ManagerLocator; @@ -14,14 +19,6 @@ import com.fibermc.essentialcommands.types.RespawnCondition; import com.fibermc.essentialcommands.types.RtpCenter; import org.jetbrains.annotations.NotNull; - -import net.minecraft.registry.RegistryKey; -import net.minecraft.text.Style; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.Identifier; -import net.minecraft.world.World; - import dev.jpcode.eccore.config.Config; import dev.jpcode.eccore.config.ConfigOption; import dev.jpcode.eccore.config.ConfigUtil; @@ -41,7 +38,7 @@ public final class EssentialCommandsConfig extends Config FORMATTING_DEFAULT = new Option<>("formatting_default", parseStyle("gold"), ConfigUtil::parseStyle, ConfigUtil::serializeStyle); @ConfigOption public final Option