diff --git a/build.gradle.kts b/build.gradle.kts index 5488128a..e72f63c7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -105,3 +105,13 @@ publishing { } } } + +stonecutter { + replacements.string(current.parsed >= "1.21.11") { +// replace("player.level()", "player.serverLevel()") +// replace("sourcePlayer.serverLevel()", "sourcePlayer.level()") + replace("player.getServer()", "player.level().getServer()") + replace("sourcePlayer.getServer()", "sourcePlayer.level().getServer()") + replace("dimension().location()", "dimension().identifier()") + } +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 6e8b8034..45aa4fe6 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -20,7 +20,7 @@ plugins { stonecutter { create(rootProject) { - versions("1.20.1", "1.21.1", "1.21.4") + versions("1.20.1", "1.21.1", "1.21.4", "1.21.11") vcsVersion = "1.21.1" } } diff --git a/src/main/java/me/alexdevs/solstice/Solstice.java b/src/main/java/me/alexdevs/solstice/Solstice.java index ee187eeb..6f3bbf4a 100644 --- a/src/main/java/me/alexdevs/solstice/Solstice.java +++ b/src/main/java/me/alexdevs/solstice/Solstice.java @@ -10,13 +10,12 @@ import me.alexdevs.solstice.integrations.ConnectorIntegration; import me.alexdevs.solstice.integrations.LuckPermsIntegration; import me.alexdevs.solstice.locale.LocaleManager; -import me.alexdevs.solstice.api.utils.ResourceUtils; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.world.level.storage.LevelResource; import org.slf4j.Logger; @@ -29,7 +28,7 @@ public class Solstice implements ModInitializer { public static final String MOD_ID = "solstice"; public static final Logger LOGGER = LoggerFactory.getLogger(Solstice.class); - public static final ResourceLocation ID = ResourceUtils.location(MOD_ID, ""); + public static final SolsticeIdentifier ID = SolsticeIdentifier.of(MOD_ID, ""); public static final IConfigDataManager configManager = new ConfigDataManager(Paths.configDirectory.resolve("config.conf")); public static final LocaleManager localeManager = new LocaleManager(Paths.configDirectory.resolve("locale.json")); diff --git a/src/main/java/me/alexdevs/solstice/api/Raycast.java b/src/main/java/me/alexdevs/solstice/api/Raycast.java index ad0ae453..c3945e4e 100644 --- a/src/main/java/me/alexdevs/solstice/api/Raycast.java +++ b/src/main/java/me/alexdevs/solstice/api/Raycast.java @@ -8,7 +8,7 @@ public class Raycast { public static BlockHitResult cast(ServerPlayer player, double maxDistance) { - var world = player.serverLevel(); + var world = player.level(); var eyePos = player.getEyePosition(); var rotVec = player.getLookAngle(); diff --git a/src/main/java/me/alexdevs/solstice/api/ServerLocation.java b/src/main/java/me/alexdevs/solstice/api/ServerLocation.java index 563ed1e8..87bb39ba 100644 --- a/src/main/java/me/alexdevs/solstice/api/ServerLocation.java +++ b/src/main/java/me/alexdevs/solstice/api/ServerLocation.java @@ -2,7 +2,7 @@ import com.google.common.collect.ImmutableList; import me.alexdevs.solstice.modules.ModuleProvider; -import me.alexdevs.solstice.api.utils.ResourceUtils; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.core.BlockPos; import net.minecraft.core.Vec3i; import net.minecraft.core.registries.Registries; @@ -48,7 +48,7 @@ public ServerLocation(double x, double y, double z, float yaw, float pitch, Serv } public ServerLocation(ServerPlayer player) { - this(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot(), player.serverLevel().dimension().location().toString()); + this(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot(), player.level().dimension().location().toString()); } public ServerLocation(double x, double y, double z, float yaw, float pitch, String worldKey) { @@ -98,7 +98,7 @@ public void teleport(ServerPlayer player) { } public ResourceKey getWorldKey() { - return ResourceKey.create(Registries.DIMENSION, ResourceUtils.parse(this.getWorld())); + return ResourceKey.create(Registries.DIMENSION, SolsticeIdentifier.parse(this.getWorld()).get()); } public ServerLevel getWorld(MinecraftServer server) { diff --git a/src/main/java/me/alexdevs/solstice/api/command/LocalGameProfile.java b/src/main/java/me/alexdevs/solstice/api/command/LocalGameProfile.java index e2728a3d..abe744f7 100644 --- a/src/main/java/me/alexdevs/solstice/api/command/LocalGameProfile.java +++ b/src/main/java/me/alexdevs/solstice/api/command/LocalGameProfile.java @@ -14,16 +14,16 @@ import java.util.concurrent.CompletableFuture; public class LocalGameProfile { - public static GameProfile getGameProfile(CommandContext context, String name) throws CommandSyntaxException { - var profiles = GameProfileArgument.getGameProfiles(context, name); - if (profiles.size() > 1) { - throw EntityArgument.ERROR_NOT_SINGLE_PLAYER.create(); - } - - return profiles.iterator().next(); - } - - public static GameProfile getProfile(CommandContext context, String name) throws CommandSyntaxException { +// public static GameProfile getGameProfile(CommandContext context, String name) throws CommandSyntaxException { +// var profiles = GameProfileArgument.getGameProfiles(context, name); +// if (profiles.size() > 1) { +// throw EntityArgument.ERROR_NOT_SINGLE_PLAYER.create(); +// } +// +// return profiles.iterator().next(); +// } + + public static com.mojang.authlib.GameProfile getProfile(CommandContext context, String name) throws CommandSyntaxException { var profileName = StringArgumentType.getString(context, name); var profile = Solstice.getUserCache().getByName(profileName); if(profile.isEmpty()) diff --git a/src/main/java/me/alexdevs/solstice/api/config/ConfigDataManager.java b/src/main/java/me/alexdevs/solstice/api/config/ConfigDataManager.java index cdf074d6..9d233f9f 100644 --- a/src/main/java/me/alexdevs/solstice/api/config/ConfigDataManager.java +++ b/src/main/java/me/alexdevs/solstice/api/config/ConfigDataManager.java @@ -2,7 +2,7 @@ import me.alexdevs.solstice.Solstice; import me.alexdevs.solstice.api.config.serializers.DateSerializer; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import org.spongepowered.configurate.CommentedConfigurationNode; import org.spongepowered.configurate.ConfigurateException; import org.spongepowered.configurate.hocon.HoconConfigurationLoader; @@ -22,7 +22,7 @@ */ public class ConfigDataManager implements IConfigDataManager { public static final int CONFIG_VERSION = 2; - private final Map> classMap = new HashMap<>(); + private final Map> classMap = new HashMap<>(); private final Map, Supplier> defaultSuppliers = new HashMap<>(); private final Map, Object> dataMap = new HashMap<>(); @@ -48,7 +48,7 @@ public ConfigDataManager(Path filePath) { } @Override - public void registerData(ResourceLocation id, Class classOfConfig, Supplier creator) { + public void registerData(SolsticeIdentifier id, Class classOfConfig, Supplier creator) { if (classMap.containsKey(id) || defaultSuppliers.containsKey(classOfConfig)) { throw new IllegalArgumentException("Config with identifier " + id + " already registered"); } @@ -75,7 +75,7 @@ public T getData(Class classOfConfig) { return (T) data; } - private Map>>> getSections() { + private Map>>> getSections() { return classMap.entrySet().stream() .collect(Collectors .groupingBy(entry -> entry.getKey().getNamespace())); diff --git a/src/main/java/me/alexdevs/solstice/api/config/IConfigDataManager.java b/src/main/java/me/alexdevs/solstice/api/config/IConfigDataManager.java index b41e6f45..9f9b4629 100644 --- a/src/main/java/me/alexdevs/solstice/api/config/IConfigDataManager.java +++ b/src/main/java/me/alexdevs/solstice/api/config/IConfigDataManager.java @@ -1,6 +1,6 @@ package me.alexdevs.solstice.api.config; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import org.spongepowered.configurate.ConfigurateException; import org.spongepowered.configurate.objectmapping.ConfigSerializable; @@ -15,7 +15,7 @@ public interface IConfigDataManager { * @param creator Supplier of the config that contains the default values when creating the initial data. * @param Class of the config. */ - void registerData(ResourceLocation id, Class classOfConfig, Supplier creator); + void registerData(SolsticeIdentifier id, Class classOfConfig, Supplier creator); /** * Get the object of the configuration data. diff --git a/src/main/java/me/alexdevs/solstice/api/events/PlayerConnectionEvents.java b/src/main/java/me/alexdevs/solstice/api/events/PlayerConnectionEvents.java index d232d3d7..2f83f583 100644 --- a/src/main/java/me/alexdevs/solstice/api/events/PlayerConnectionEvents.java +++ b/src/main/java/me/alexdevs/solstice/api/events/PlayerConnectionEvents.java @@ -27,11 +27,11 @@ public class PlayerConnectionEvents { @FunctionalInterface public interface WhitelistBypass { - boolean bypassWhitelist(GameProfile profile); + boolean bypassWhitelist(com.mojang.authlib.GameProfile profile); } @FunctionalInterface public interface FullServerBypass { - boolean bypassFullServer(GameProfile profile); + boolean bypassFullServer(com.mojang.authlib.GameProfile profile); } } diff --git a/src/main/java/me/alexdevs/solstice/api/module/Debug.java b/src/main/java/me/alexdevs/solstice/api/module/Debug.java index 4ff42194..201de7aa 100644 --- a/src/main/java/me/alexdevs/solstice/api/module/Debug.java +++ b/src/main/java/me/alexdevs/solstice/api/module/Debug.java @@ -1,6 +1,6 @@ package me.alexdevs.solstice.api.module; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import java.util.HashSet; import java.util.List; @@ -9,7 +9,7 @@ public class Debug { public static final HashSet commandDebugList = new HashSet<>(); - public record CommandDebug(ResourceLocation module, String command, List commands, String permission) { + public record CommandDebug(SolsticeIdentifier module, String command, List commands, String permission) { @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/src/main/java/me/alexdevs/solstice/api/module/ModuleBase.java b/src/main/java/me/alexdevs/solstice/api/module/ModuleBase.java index 00911050..d7ac70d0 100644 --- a/src/main/java/me/alexdevs/solstice/api/module/ModuleBase.java +++ b/src/main/java/me/alexdevs/solstice/api/module/ModuleBase.java @@ -3,19 +3,19 @@ import me.alexdevs.solstice.Solstice; import me.alexdevs.solstice.core.ToggleableConfig; import me.alexdevs.solstice.locale.Locale; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import java.util.*; import java.util.function.Supplier; public abstract class ModuleBase implements Comparable { - protected final ResourceLocation id; + protected final SolsticeIdentifier id; protected final List> commands = new ArrayList<>(); protected Class configClass = null; protected Class playerDataClass = null; protected Class serverDataClass = null; - public ModuleBase(ResourceLocation id) { + public ModuleBase(SolsticeIdentifier id) { this.id = id; } @@ -30,7 +30,7 @@ public Collection> getCommands() { return commands; } - public ResourceLocation getId() { + public SolsticeIdentifier getId() { return id; } @@ -89,7 +89,7 @@ public int compareTo(ModuleBase o) { } public static abstract class Toggleable extends ModuleBase { - public Toggleable(ResourceLocation id) { + public Toggleable(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/api/text/Format.java b/src/main/java/me/alexdevs/solstice/api/text/Format.java index d8df761a..1552c1fa 100644 --- a/src/main/java/me/alexdevs/solstice/api/text/Format.java +++ b/src/main/java/me/alexdevs/solstice/api/text/Format.java @@ -1,12 +1,10 @@ package me.alexdevs.solstice.api.text; +import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.api.PlaceholderContext; import eu.pb4.placeholders.api.Placeholders; import eu.pb4.placeholders.api.node.TextNode; -import eu.pb4.placeholders.api.parsers.LegacyFormattingParser; -import eu.pb4.placeholders.api.parsers.NodeParser; -import eu.pb4.placeholders.api.parsers.PatternPlaceholderParser; -import eu.pb4.placeholders.api.parsers.TextParserV1; +import eu.pb4.placeholders.api.parsers.*; import me.alexdevs.solstice.api.text.tag.PhaseGradientTag; import net.minecraft.network.chat.Component; import java.util.Map; @@ -24,7 +22,7 @@ public class Format { } public static Component parse(String text) { - return PARSER.parseNode(text).toText(null, true); + return PARSER.parseNode(text).toText(); } public static Component parse(TextNode textNode, PlaceholderContext context, Map placeholders) { diff --git a/src/main/java/me/alexdevs/solstice/api/text/parser/CodeParser.java b/src/main/java/me/alexdevs/solstice/api/text/parser/CodeParser.java index 8d0597a3..5c047819 100644 --- a/src/main/java/me/alexdevs/solstice/api/text/parser/CodeParser.java +++ b/src/main/java/me/alexdevs/solstice/api/text/parser/CodeParser.java @@ -6,6 +6,8 @@ import eu.pb4.placeholders.api.parsers.NodeParser; import java.util.ArrayList; import java.util.regex.Pattern; + +import me.alexdevs.solstice.api.utils.ComponentUtils; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.Component; @@ -44,10 +46,8 @@ public TextNode[] parseNodes(TextNode node) { var text = Component.empty() .append(display) .setStyle(Style.EMPTY - .withHoverEvent( - new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover) - ) - .withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, content)) + .withHoverEvent(ComponentUtils.showTextHoverEvent(hover)) + .withClickEvent(ComponentUtils.clickCopyToClipboardEvent(content)) ); list.add(new DirectTextNode(text)); diff --git a/src/main/java/me/alexdevs/solstice/api/text/parser/LinkParser.java b/src/main/java/me/alexdevs/solstice/api/text/parser/LinkParser.java index ea7db7c0..13a9cb7d 100644 --- a/src/main/java/me/alexdevs/solstice/api/text/parser/LinkParser.java +++ b/src/main/java/me/alexdevs/solstice/api/text/parser/LinkParser.java @@ -5,6 +5,7 @@ import eu.pb4.placeholders.api.node.TextNode; import eu.pb4.placeholders.api.node.parent.ParentNode; import eu.pb4.placeholders.api.parsers.NodeParser; +import me.alexdevs.solstice.api.utils.ComponentUtils; import me.alexdevs.solstice.core.coreModule.CoreModule; import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.Component; @@ -64,10 +65,8 @@ public TextNode[] parseNodes(TextNode node) { var text = Component.empty() .append(display) .setStyle(Style.EMPTY - .withHoverEvent( - new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover) - ) - .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, link)) + .withHoverEvent(ComponentUtils.showTextHoverEvent(hover)) + .withClickEvent(ComponentUtils.openUrlClickEvent(link)) ); list.add(new DirectTextNode(text)); diff --git a/src/main/java/me/alexdevs/solstice/api/text/parser/MarkdownComponentParser.java b/src/main/java/me/alexdevs/solstice/api/text/parser/MarkdownComponentParser.java index 09b61381..f3061f91 100644 --- a/src/main/java/me/alexdevs/solstice/api/text/parser/MarkdownComponentParser.java +++ b/src/main/java/me/alexdevs/solstice/api/text/parser/MarkdownComponentParser.java @@ -17,7 +17,11 @@ public static TextNode spoilerFormatting(TextNode[] textNodes) { TextNode.array( new FormattingNode(TextNode.array(TextNode.of("\u258C".repeat(text.toText().getString().length()))), ChatFormatting.DARK_GRAY) ), - HoverNode.Action.TEXT, text); + //? >= 1.21.11 + //HoverNode.Action.TEXT_NODE, + //? < 1.21.11 + HoverNode.Action.TEXT, + text); } public static TextNode quoteFormatting(TextNode[] textNodes) { @@ -25,7 +29,11 @@ public static TextNode quoteFormatting(TextNode[] textNodes) { TextNode.array( new HoverNode<>( TextNode.array(new FormattingNode(textNodes, ChatFormatting.GRAY)), - HoverNode.Action.TEXT, TextNode.of("Click to copy")) + //? >= 1.21.11 + //HoverNode.Action.TEXT_NODE, + //? < 1.21.11 + HoverNode.Action.TEXT, + TextNode.of("Click to copy")) ), ClickEvent.Action.COPY_TO_CLIPBOARD, TextNode.asSingle(textNodes) ); @@ -46,7 +54,11 @@ public static TextNode urlFormatting(TextNode[] textNodes, TextNode url) { TextNode.convert(text) ), ClickEvent.Action.OPEN_URL, url)), - HoverNode.Action.TEXT, TextNode.convert(hover) + //? >= 1.21.11 + //HoverNode.Action.TEXT_NODE, + //? < 1.21.11 + HoverNode.Action.TEXT, + TextNode.convert(hover) ); } } diff --git a/src/main/java/me/alexdevs/solstice/api/utils/ComponentUtils.java b/src/main/java/me/alexdevs/solstice/api/utils/ComponentUtils.java new file mode 100644 index 00000000..cf07069a --- /dev/null +++ b/src/main/java/me/alexdevs/solstice/api/utils/ComponentUtils.java @@ -0,0 +1,31 @@ +package me.alexdevs.solstice.api.utils; + +import net.minecraft.network.chat.ClickEvent; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.HoverEvent; + +import java.net.URI; + +public class ComponentUtils { + + public static HoverEvent showTextHoverEvent(Component hover) { + //? < 1.21.11 + return new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover); + //? >= 1.21.11 + //return new HoverEvent.ShowText(hover); + } + + public static ClickEvent clickCopyToClipboardEvent(String content) { + //? < 1.21.11 + return new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, content); + //? >= 1.21.11 + //return new ClickEvent.CopyToClipboard(content); + } + + public static ClickEvent openUrlClickEvent(String link) { + //? < 1.21.11 + return new ClickEvent(ClickEvent.Action.OPEN_URL, link); + //? >= 1.21.11 + //return new ClickEvent.OpenUrl(URI.create(link)); + } +} diff --git a/src/main/java/me/alexdevs/solstice/api/utils/IdUtils.java b/src/main/java/me/alexdevs/solstice/api/utils/IdUtils.java new file mode 100644 index 00000000..79594775 --- /dev/null +++ b/src/main/java/me/alexdevs/solstice/api/utils/IdUtils.java @@ -0,0 +1,23 @@ +package me.alexdevs.solstice.api.utils; + +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.context.CommandContext; +import net.minecraft.commands.CommandSourceStack; + +public class IdUtils { + + + public static ArgumentType idArgument() { + //? < 1.21.11 + return net.minecraft.commands.arguments.ResourceLocationArgument.id(); + //? >= 1.21.11 + //return net.minecraft.commands.arguments.IdentifierArgument.id(); + } + + public static Object getIdArgument(CommandContext context, String name) { + //? < 1.21.11 + return net.minecraft.commands.arguments.ResourceLocationArgument.getId(context, name); + //? >= 1.21.11 + //return net.minecraft.commands.arguments.IdentifierArgument.getId(context, name); + } +} diff --git a/src/main/java/me/alexdevs/solstice/api/utils/ItemUtils.java b/src/main/java/me/alexdevs/solstice/api/utils/ItemUtils.java index 6734cc3a..67da05aa 100644 --- a/src/main/java/me/alexdevs/solstice/api/utils/ItemUtils.java +++ b/src/main/java/me/alexdevs/solstice/api/utils/ItemUtils.java @@ -7,13 +7,15 @@ import net.minecraft.world.item.component.ResolvableProfile; import java.util.Optional; //? } else { -/*import net.minecraft.nbt.ListTag; +/*import com.mojang.authlib.properties.PropertyMap; +import net.minecraft.nbt.ListTag; import net.minecraft.nbt.StringTag; import net.minecraft.world.item.PlayerHeadItem; *///? } import net.minecraft.network.chat.Component; import net.minecraft.world.item.ItemStack; import java.util.List; +import java.util.Optional; import java.util.UUID; public class ItemUtils { public static void setCustomName(ItemStack stack, Component name) { @@ -69,21 +71,14 @@ public static void setGlint(ItemStack stack, boolean value) { *///? } } public static void setProfileByName(ItemStack stack, String name) { + //? >= 1.21.11 + //var profile = ResolvableProfile.createUnresolved(name); + //? < 1.21.11 && >= 1.21.1 + var profile = new ResolvableProfile(Optional.of(name), Optional.empty(), new PropertyMap()); + //? >= 1.21.1 - stack.set(DataComponents.PROFILE,new ResolvableProfile(Optional.of(name), Optional.empty(), new PropertyMap())); + stack.set(DataComponents.PROFILE, profile); //? < 1.21.1 //stack.addTagElement(PlayerHeadItem.TAG_SKULL_OWNER, StringTag.valueOf(name)); } - public static void setProfileByUUID(ItemStack stack, UUID uuid) { - //? >= 1.21.1 - stack.set(DataComponents.PROFILE,new ResolvableProfile(Optional.empty(), Optional.of(uuid), new PropertyMap())); - //? < 1.21.1 - //stack.addTagElement(PlayerHeadItem.TAG_SKULL_OWNER, StringTag.valueOf(uuid.toString())); - } - public static void setProfile(ItemStack stack, GameProfile profile) { - //? >= 1.21.1 - stack.set(DataComponents.PROFILE, new ResolvableProfile(profile)); - //? < 1.21.1 - //stack.addTagElement(PlayerHeadItem.TAG_SKULL_OWNER, StringTag.valueOf(profile.getName())); - } } diff --git a/src/main/java/me/alexdevs/solstice/api/utils/PlayerUtils.java b/src/main/java/me/alexdevs/solstice/api/utils/PlayerUtils.java index cf6ee5c5..aec28bd3 100644 --- a/src/main/java/me/alexdevs/solstice/api/utils/PlayerUtils.java +++ b/src/main/java/me/alexdevs/solstice/api/utils/PlayerUtils.java @@ -2,10 +2,16 @@ import com.mojang.authlib.GameProfile; import me.alexdevs.solstice.Solstice; +import net.minecraft.server.MinecraftServer; //? if >= 1.21.1 { import net.minecraft.server.level.ClientInformation; //? } +import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.sounds.SoundEvent; +import org.jetbrains.annotations.UnknownNullability; + +import java.util.Optional; import java.util.UUID; public class PlayerUtils { @@ -14,17 +20,34 @@ public static boolean isOnline(UUID uuid) { } public static ServerPlayer loadOfflinePlayer(GameProfile profile) { - if (isOnline(profile.getId())) { + if (isOnline(PlayerUtils.getId(profile))) { return null; } var playerManager = Solstice.server.getPlayerList(); - var player = - //? >= 1.21.1 - playerManager.getPlayerForLogin(profile, ClientInformation.createDefault()); - //? < 1.21.1 - //playerManager.getPlayerForLogin(profile); + //? if >= 1.21.11 { + /*var player = new ServerPlayer(Solstice.server, Solstice.server.overworld(), profile, ClientInformation.createDefault()); + + var nameAndId = new net.minecraft.server.players.NameAndId(profile.id(),profile.name()); + playerManager.loadPlayerData(nameAndId).ifPresent(tag -> { + var input = net.minecraft.world.level.storage.TagValueInput.create( + net.minecraft.util.ProblemReporter.DISCARDING, + Solstice.server.registryAccess(), + tag + ); + player.load(input); + }); + *///? } else if >= 1.21.1 { + var player = playerManager.getPlayerForLogin(profile, ClientInformation.createDefault()); + //? } else { + /*var player = playerManager.getPlayerForLogin(profile); + *///? } + + + //? if >= 1.21.11 + //Solstice.server.playerDataStorage.load(new net.minecraft.server.players.NameAndId(profile.id(), profile.name())); + //? if < 1.21.11 playerManager.load(player); return player; } @@ -38,4 +61,56 @@ public static void saveOfflinePlayer(ServerPlayer player) { saveHandler.save(player); Solstice.server.getPlayerList().remove(player); } + + public static void playSound(@UnknownNullability ServerPlayer player, SoundEvent sound, float volume, float pitch) { + //? < 1.21.11 + player.playNotifySound(sound, net.minecraft.sounds.SoundSource.MASTER, volume, pitch); + //? >= 1.21.1 + player.playSound(sound, volume, pitch); + + } + + public static Optional getProfile(MinecraftServer server, String targetName) { + //? >= 1.21.11 + //return server.services().profileResolver().fetchByName(targetName); + //? < 1.21.11 + return server.getProfileCache().get(targetName); + } + public static Optional getProfile(MinecraftServer server, UUID id) { + //? >= 1.21.11 + //return server.services().profileResolver().fetchById(id); + //? < 1.21.11 + return server.getProfileCache().get(id); + } + + //? >= 1.21.11 { + /*public static UUID getId(net.minecraft.server.players.NameAndId nameAndId) { + return nameAndId.id(); + } + *///? } + public static UUID getId(GameProfile gameProfile) { + //? >= 1.21.11 + //return gameProfile.id(); + //? < 1.21.11 + return gameProfile.getId(); + } + + //? >= 1.21.11 { + /*public static String getName(net.minecraft.server.players.NameAndId nameAndId) { + return nameAndId.name(); + } + *///? } + public static String getName(GameProfile gameProfile) { + //? >= 1.21.11 + //return gameProfile.name(); + //? < 1.21.11 + return gameProfile.getName(); + } + + public static ServerLevel getLevel(ServerPlayer player) { + //? >= 1.21.11 + //return player.level(); + //? < 1.21.11 + return player.serverLevel(); + } } diff --git a/src/main/java/me/alexdevs/solstice/api/utils/ProfileOrNameAndId.java b/src/main/java/me/alexdevs/solstice/api/utils/ProfileOrNameAndId.java new file mode 100644 index 00000000..321613a3 --- /dev/null +++ b/src/main/java/me/alexdevs/solstice/api/utils/ProfileOrNameAndId.java @@ -0,0 +1,72 @@ +package me.alexdevs.solstice.api.utils; + +import com.mojang.authlib.GameProfile; + +import java.util.UUID; + +public class ProfileOrNameAndId { + + private com.mojang.authlib.GameProfile profile; + + //? if >= 1.21.11 + //private net.minecraft.server.players.NameAndId nameAndId; + //? if < 1.21.11 + private GameProfile nameAndId; + + public ProfileOrNameAndId(com.mojang.authlib.GameProfile profile) { + this.profile = profile; + //? if >= 1.21.11 + //this.nameAndId = new net.minecraft.server.players.NameAndId(profile.id(), profile.name()); + //? if < 1.21.11 + this.nameAndId = profile; + } + + //? if >= 1.21.11 { + /*public ProfileOrNameAndId(net.minecraft.server.players.NameAndId nameAndId) { + this.nameAndId = nameAndId; + this.profile = new com.mojang.authlib.GameProfile(nameAndId.id(), nameAndId.name()); + } + *///? } + + //? if >= 1.21.11 + //public net.minecraft.server.players.NameAndId getNameAndId() { + //? if < 1.21.11 + public GameProfile getNameAndId() { + return nameAndId; + } + public com.mojang.authlib.GameProfile getProfile() { + return profile; + } + + public String getName() { + if (profile != null) + //? if < 1.21.11 + return profile.getName(); + //? if >= 1.21.11 + //return profile.name(); + + if (nameAndId!=null) { + //? if < 1.21.11 + return nameAndId.getName(); + //? if >= 1.21.11 + //return nameAndId.name(); + } + return null; + } + + public UUID getId() { + if (profile != null) + //? if < 1.21.11 + return profile.getId(); + //? if >= 1.21.11 + //return profile.id(); + + if (nameAndId != null) { + //? if < 1.21.11 + return nameAndId.getId(); + //? if >= 1.21.11 + //return nameAndId.id(); + } + return null; + } +} diff --git a/src/main/java/me/alexdevs/solstice/api/utils/RegistryUtils.java b/src/main/java/me/alexdevs/solstice/api/utils/RegistryUtils.java index aa23fccc..c4a1e4ea 100644 --- a/src/main/java/me/alexdevs/solstice/api/utils/RegistryUtils.java +++ b/src/main/java/me/alexdevs/solstice/api/utils/RegistryUtils.java @@ -8,7 +8,7 @@ public class RegistryUtils { public static List getBiomes(HolderLookup.RegistryLookup registry, boolean includeTags) { - var biomes = new ArrayList<>(registry.listElementIds().map(q -> q.location().toString()).toList()); + var biomes = new ArrayList<>(registry.listElementIds().map(q -> ResourceUtils.identifier(q).toString()).toList()); if (includeTags) { biomes.addAll(registry.listTagIds().map(q -> '#' + q.location().toString()).toList()); } diff --git a/src/main/java/me/alexdevs/solstice/api/utils/ResourceUtils.java b/src/main/java/me/alexdevs/solstice/api/utils/ResourceUtils.java index d89c5457..32a55196 100644 --- a/src/main/java/me/alexdevs/solstice/api/utils/ResourceUtils.java +++ b/src/main/java/me/alexdevs/solstice/api/utils/ResourceUtils.java @@ -1,21 +1,15 @@ package me.alexdevs.solstice.api.utils; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.ResourceKey; public class ResourceUtils { - public static ResourceLocation location(String namespace, String path) { - //? if >= 1.21.1 - return ResourceLocation.fromNamespaceAndPath(namespace, path); - //? if < 1.21.1 - //return new ResourceLocation(namespace, path); - } - - public static ResourceLocation parse(String value) { - //? if >= 1.21.1 - return ResourceLocation.parse(value); - //? if < 1.21.1 - //return ResourceLocation.tryParse(value); + //? if >= 1.21.11 { + /*public static net.minecraft.resources.Identifier identifier(ResourceKey resourceKey) { + return resourceKey.identifier(); + *///? } else { + public static net.minecraft.resources.ResourceLocation identifier(ResourceKey resourceKey) { + return resourceKey.location(); + //? } } } - diff --git a/src/main/java/me/alexdevs/solstice/api/utils/SolsticeIdentifier.java b/src/main/java/me/alexdevs/solstice/api/utils/SolsticeIdentifier.java new file mode 100644 index 00000000..305dfb87 --- /dev/null +++ b/src/main/java/me/alexdevs/solstice/api/utils/SolsticeIdentifier.java @@ -0,0 +1,133 @@ +package me.alexdevs.solstice.api.utils; + + +import org.jetbrains.annotations.Nullable; + +import java.util.Objects; + +//? < 1.21.11 +import net.minecraft.resources.ResourceLocation; +//? >= 1.21.11 +//import net.minecraft.resources.Identifier; + +/** + * Version-agnostic wrapper around Minecraft's {@code ResourceLocation}. + *

+ * This is the only file in Solstice that imports + * {@code net.minecraft.resources.ResourceLocation} or contains Stonecutter + * conditionals for the MC resource-location API. When the underlying class + * moves or is renamed in a future MC version, only this file needs updating. + *

+ * Use {@link #get()} to pass the raw value to Minecraft APIs that are outside + * Solstice's control. + */ +public final class SolsticeIdentifier implements Comparable { + + //? < 1.21.11 + private final ResourceLocation location; + //? >= 1.21.11 + //private final Identifier location; + + //? < 1.21.11 + private SolsticeIdentifier(ResourceLocation location) { + //? >= 1.21.11 + //private SolsticeIdentifier(Identifier location) { + this.location = location; + } + + // ---- Factory methods -------------------------------------------------------- + + /** + * Creates an identifier from a namespace and path. + * Equivalent to {@code ResourceLocation.fromNamespaceAndPath} / {@code new ResourceLocation}. + */ + public static SolsticeIdentifier of(String namespace, String path) { + //? if >= 1.21.11 { + /*return new SolsticeIdentifier(Identifier.fromNamespaceAndPath(namespace, path)); + *///? } elif >= 1.21.1 { + return new SolsticeIdentifier(ResourceLocation.fromNamespaceAndPath(namespace, path)); + //? } elif < 1.21.1 { + /*return new SolsticeIdentifier(new ResourceLocation(namespace, path)); + *///? } + + } + + /** + * Parses a {@code namespace:path} string, throwing on invalid input. + */ + public static SolsticeIdentifier parse(String value) { + //? if >= 1.21.11 { + /*return new SolsticeIdentifier(Identifier.parse(value)); + *///? } elif >= 1.21.1 { + return new SolsticeIdentifier(ResourceLocation.parse(value)); + //? } elif < 1.21.1 { + /*var loc = ResourceLocation.tryParse(value); + if (loc == null) throw new IllegalArgumentException("Invalid resource location: " + value); + return new SolsticeIdentifier(loc); + *///? } + } + + /** + * Parses a {@code namespace:path} string, returning {@code null} on invalid input. + */ + public static @Nullable SolsticeIdentifier tryParse(String value) { + //? < 1.21.11 + var loc = ResourceLocation.tryParse(value); + //? >= 1.21.11 + //var loc = Identifier.tryParse(value); + return loc != null ? new SolsticeIdentifier(loc) : null; + } + + // ---- Delegation -------------------------------------------------------------- + + public String getNamespace() { + return location.getNamespace(); + } + + public String getPath() { + return location.getPath(); + } + + /** + * Returns a new {@code SolsticeIdentifier} with the same namespace but a different path. + */ + public SolsticeIdentifier withPath(String path) { + return new SolsticeIdentifier(location.withPath(path)); + } + + /** + * Returns the underlying Minecraft {@code ResourceLocation}. + * Only use this when passing to APIs outside Solstice's control. + */ + //? < 1.21.11 + public ResourceLocation get() { + //? >= 1.21.11 + //public Identifier get() { + return location; + } + + // ---- Object overrides -------------------------------------------------------- + + @Override + public String toString() { + return location.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof SolsticeIdentifier that)) return false; + return Objects.equals(location, that.location); + } + + @Override + public int hashCode() { + return Objects.hashCode(location); + } + + @Override + public int compareTo(SolsticeIdentifier o) { + return location.compareTo(o.location); + } +} + diff --git a/src/main/java/me/alexdevs/solstice/core/UserCache.java b/src/main/java/me/alexdevs/solstice/core/UserCache.java index eabacb09..7836e541 100644 --- a/src/main/java/me/alexdevs/solstice/core/UserCache.java +++ b/src/main/java/me/alexdevs/solstice/core/UserCache.java @@ -7,6 +7,7 @@ import com.google.gson.*; import com.mojang.authlib.GameProfile; import me.alexdevs.solstice.Solstice; +import me.alexdevs.solstice.api.utils.PlayerUtils; import java.io.File; import java.io.FileNotFoundException; @@ -49,7 +50,7 @@ private long incrementAndGetAccessCount() { return this.accessCount.incrementAndGet(); } - public Optional getByName(String name) { + public Optional getByName(String name) { name = name.toLowerCase(Locale.ROOT); var entry = byName.get(name); @@ -60,7 +61,7 @@ public Optional getByName(String name) { } } - public Optional getByUUID(UUID uuid) { + public Optional getByUUID(UUID uuid) { var entry = byUUID.get(uuid); if (entry == null) { return Optional.empty(); @@ -73,7 +74,7 @@ public List getAllNames() { return ImmutableList.copyOf(this.byName.keySet()); } - public void add(GameProfile profile) { + public void add(com.mojang.authlib.GameProfile profile) { var calendar = Calendar.getInstance(); calendar.setTime(new Date()); calendar.add(Calendar.MONTH, 1); @@ -84,14 +85,14 @@ public void add(GameProfile profile) { } private void add(Entry entry) { - var gameProfile = entry.getProfile(); + var profile = entry.getProfile(); entry.setLastAccessed(this.incrementAndGetAccessCount()); - var name = gameProfile.getName(); + var name = PlayerUtils.getName(profile); if (name != null) { this.byName.put(name.toLowerCase(Locale.ROOT), entry); } - var uuid = gameProfile.getId(); + var uuid = PlayerUtils.getId(profile); if (uuid != null) { byUUID.put(uuid, entry); } @@ -99,8 +100,8 @@ private void add(Entry entry) { private static JsonElement entryToJson(Entry entry, DateFormat dateFormat) { JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty("name", entry.getProfile().getName()); - UUID uUID = entry.getProfile().getId(); + jsonObject.addProperty("name", PlayerUtils.getName(entry.getProfile())); + UUID uUID = PlayerUtils.getId(entry.getProfile()); jsonObject.addProperty("uuid", uUID == null ? "" : uUID.toString()); jsonObject.addProperty("expiresOn", dateFormat.format(entry.getExpirationDate())); return jsonObject; @@ -136,7 +137,7 @@ private static Optional entryFromJson(JsonElement json, DateFormat dateFo return Optional.empty(); } - return Optional.of(new Entry(new GameProfile(uUID, name), date)); + return Optional.of(new Entry(new com.mojang.authlib.GameProfile(uUID, name), date)); } return Optional.empty(); } @@ -208,16 +209,16 @@ private static DateFormat getDateFormat() { } public static class Entry { - private final GameProfile profile; + private final com.mojang.authlib.GameProfile profile; final Date expirationDate; private volatile long lastAccessed; - Entry(GameProfile profile, Date expirationDate) { + Entry(com.mojang.authlib.GameProfile profile, Date expirationDate) { this.profile = profile; this.expirationDate = expirationDate; } - public GameProfile getProfile() { + public com.mojang.authlib.GameProfile getProfile() { return this.profile; } diff --git a/src/main/java/me/alexdevs/solstice/core/coreModule/CoreModule.java b/src/main/java/me/alexdevs/solstice/core/coreModule/CoreModule.java index 25928da1..65bbb99b 100644 --- a/src/main/java/me/alexdevs/solstice/core/coreModule/CoreModule.java +++ b/src/main/java/me/alexdevs/solstice/core/coreModule/CoreModule.java @@ -5,6 +5,7 @@ import me.alexdevs.solstice.api.events.SolsticeEvents; import me.alexdevs.solstice.api.events.WorldSaveCallback; import me.alexdevs.solstice.api.module.ModuleBase; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.core.coreModule.commands.PingCommand; import me.alexdevs.solstice.core.coreModule.commands.ServerStatCommand; import me.alexdevs.solstice.core.coreModule.commands.SolsticeCommand; @@ -12,14 +13,16 @@ import me.alexdevs.solstice.core.coreModule.data.CoreLocale; import me.alexdevs.solstice.core.coreModule.data.CorePlayerData; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; +import com.mojang.authlib.GameProfile; import net.minecraft.world.entity.Entity; + import java.util.Date; import java.util.UUID; import java.util.concurrent.TimeUnit; public class CoreModule extends ModuleBase { - public CoreModule(ResourceLocation id) { + public CoreModule(SolsticeIdentifier id) { super(id); } @@ -35,21 +38,26 @@ public void init() { commands.add(new PingCommand(this)); ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> { + //? < 1.21.11 Solstice.getUserCache().add(handler.getPlayer().getGameProfile()); + //? >= 1.21.11 + //Solstice.getUserCache().add(handler.getPlayer().getGameProfile()); + var player = handler.getPlayer(); var playerData = Solstice.playerData.get(player).getData(CorePlayerData.class); - playerData.username = player.getGameProfile().getName(); + var playerName = PlayerUtils.getName(player.getGameProfile()); + playerData.username = playerName; playerData.lastSeenDate = new Date(); playerData.ipAddress = handler.getPlayer().getIpAddress(); if (playerData.firstJoinedDate == null) { - Solstice.LOGGER.info("Player {} joined for the first time!", player.getGameProfile().getName()); + Solstice.LOGGER.info("Player {} joined for the first time!", playerName); playerData.firstJoinedDate = new Date(); SolsticeEvents.WELCOME.invoker().onWelcome(player, server); } - if (playerData.username != null && !playerData.username.equals(player.getGameProfile().getName())) { - Solstice.LOGGER.info("Player {} has changed their username from {}", player.getGameProfile().getName(), playerData.username); + if (playerData.username != null && !playerData.username.equals(playerName)) { + Solstice.LOGGER.info("Player {} has changed their username from {}", playerName, playerData.username); SolsticeEvents.USERNAME_CHANGE.invoker().onUsernameChange(player, playerData.username); } }); @@ -78,9 +86,15 @@ public static CorePlayerData getPlayerData(UUID uuid) { } public static String getUsername(UUID uuid) { + //? >= 1.21.11 + //var profile = Solstice.server.services().profileResolver().fetchById(uuid); + //? < 1.21.11 var profile = Solstice.server.getProfileCache().get(uuid); - if(profile.isPresent()) - return profile.get().getName(); + + + if (profile.isPresent()) { + return PlayerUtils.getName(profile.get()); + } return uuid.toString(); } diff --git a/src/main/java/me/alexdevs/solstice/core/coreModule/commands/SolsticeCommand.java b/src/main/java/me/alexdevs/solstice/core/coreModule/commands/SolsticeCommand.java index 195f1ce0..b55a9f91 100644 --- a/src/main/java/me/alexdevs/solstice/core/coreModule/commands/SolsticeCommand.java +++ b/src/main/java/me/alexdevs/solstice/core/coreModule/commands/SolsticeCommand.java @@ -10,6 +10,9 @@ import me.alexdevs.solstice.api.module.Debug; import me.alexdevs.solstice.api.module.ModCommand; import me.alexdevs.solstice.api.text.Format; +import me.alexdevs.solstice.api.utils.ComponentUtils; +import me.alexdevs.solstice.api.utils.PlayerUtils; +import me.alexdevs.solstice.api.utils.ResourceUtils; import me.alexdevs.solstice.core.coreModule.CoreModule; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.SharedConstants; @@ -89,9 +92,9 @@ public LiteralArgumentBuilder command(String name) { .executes(context -> { var profile = LocalGameProfile.getProfile(context, "player"); - context.getSource().sendSuccess(() -> Component.nullToEmpty("Force reloading player data for " + profile.getName()), true); + context.getSource().sendSuccess(() -> Component.nullToEmpty("Force reloading player data for " + PlayerUtils.getName(profile)), true); - Solstice.playerData.forceLoad(profile.getId()); + Solstice.playerData.forceLoad(PlayerUtils.getId(profile)); return 0; }))) .then(literal("debug") @@ -131,7 +134,7 @@ public LiteralArgumentBuilder command(String name) { var itemStack = player.getItemInHand(hand); var entry = itemStack.getItemHolder().unwrapKey().get(); - var entryString = String.format("Tags for [%s / %s]:", entry.registry(), entry.location()); + var entryString = String.format("Tags for [%s / %s]:", entry.registry(), ResourceUtils.identifier(entry)); var text = Component.empty(); text.append(Component.nullToEmpty(entryString)); @@ -142,8 +145,8 @@ public LiteralArgumentBuilder command(String name) { text.append( Component.literal(" #" + tag.location()) .setStyle(Style.EMPTY - .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.nullToEmpty("Click to copy"))) - .withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, "#" + tag.location())) + .withHoverEvent(ComponentUtils.showTextHoverEvent(Component.nullToEmpty("Click to copy"))) + .withClickEvent(ComponentUtils.clickCopyToClipboardEvent("#" + tag.location())) ) ); } diff --git a/src/main/java/me/alexdevs/solstice/data/PlayerData.java b/src/main/java/me/alexdevs/solstice/data/PlayerData.java index 7cb3c95b..120f2718 100644 --- a/src/main/java/me/alexdevs/solstice/data/PlayerData.java +++ b/src/main/java/me/alexdevs/solstice/data/PlayerData.java @@ -2,8 +2,11 @@ import com.google.gson.*; import me.alexdevs.solstice.Solstice; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; +//? < 1.21.11 import net.minecraft.Util; -import net.minecraft.resources.ResourceLocation; +//? >= 1.21.11 +//import net.minecraft.util.Util; import org.jetbrains.annotations.Nullable; import java.io.File; @@ -23,7 +26,7 @@ public class PlayerData { protected final Path filePath; protected final Path basePath; - protected final Map> classMap = new HashMap<>(); + protected final Map> classMap = new HashMap<>(); protected final Map, Object> data = new HashMap<>(); protected final Map, Supplier> providers = new HashMap<>(); protected final Gson gson = new GsonBuilder() @@ -34,7 +37,7 @@ public class PlayerData { .create(); protected JsonObject node; - public PlayerData(Path basePath, UUID uuid, Map> classMap, Map, Supplier> providers) { + public PlayerData(Path basePath, UUID uuid, Map> classMap, Map, Supplier> providers) { this.uuid = uuid; this.classMap.putAll(classMap); this.providers.putAll(providers); @@ -89,7 +92,7 @@ public void save() { } } - public void registerData(ResourceLocation id, Class clazz, Supplier creator) { + public void registerData(SolsticeIdentifier id, Class clazz, Supplier creator) { classMap.put(id, clazz); providers.put(clazz, creator); } diff --git a/src/main/java/me/alexdevs/solstice/data/PlayerDataManager.java b/src/main/java/me/alexdevs/solstice/data/PlayerDataManager.java index ea9e5435..a499d858 100644 --- a/src/main/java/me/alexdevs/solstice/data/PlayerDataManager.java +++ b/src/main/java/me/alexdevs/solstice/data/PlayerDataManager.java @@ -2,8 +2,10 @@ import com.mojang.authlib.GameProfile; import me.alexdevs.solstice.Solstice; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.PlayerUtils; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.server.level.ServerPlayer; + import java.nio.file.Path; import java.util.HashMap; import java.util.List; @@ -13,7 +15,7 @@ import java.util.function.Supplier; public class PlayerDataManager { - private final Map> classMap = new HashMap<>(); + private final Map> classMap = new HashMap<>(); private final Map, Supplier> providers = new HashMap<>(); private final Map playerData = new ConcurrentHashMap<>(); private Path basePath; @@ -34,7 +36,7 @@ public void setDataPath(Path basePath) { * @param creator Default values provider * @param Type of class of data */ - public void registerData(ResourceLocation id, Class clazz, Supplier creator) { + public void registerData(SolsticeIdentifier id, Class clazz, Supplier creator) { classMap.put(id, clazz); providers.put(clazz, creator); } @@ -68,8 +70,8 @@ public PlayerData get(ServerPlayer player) { * @param profile Player profile * @return player data */ - public PlayerData get(GameProfile profile) { - return get(profile.getId()); + public PlayerData get(com.mojang.authlib.GameProfile profile) { + return get(PlayerUtils.getId(profile)); } /** diff --git a/src/main/java/me/alexdevs/solstice/data/ServerData.java b/src/main/java/me/alexdevs/solstice/data/ServerData.java index 62ea9502..85cfc9ef 100644 --- a/src/main/java/me/alexdevs/solstice/data/ServerData.java +++ b/src/main/java/me/alexdevs/solstice/data/ServerData.java @@ -2,8 +2,11 @@ import com.google.gson.*; import me.alexdevs.solstice.Solstice; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; +//? < 1.21.11 import net.minecraft.Util; -import net.minecraft.resources.ResourceLocation; +//? >= 1.21.11 +//import net.minecraft.util.Util; import org.jetbrains.annotations.Nullable; import java.io.File; @@ -18,7 +21,7 @@ import java.util.function.Supplier; public class ServerData { - protected final Map> classMap = new HashMap<>(); + protected final Map> classMap = new HashMap<>(); protected final Map, Object> data = new HashMap<>(); protected final Map, Supplier> providers = new HashMap<>(); protected final Gson gson = new GsonBuilder() @@ -75,7 +78,7 @@ public void save() { } } - public void registerData(ResourceLocation id, Class clazz, Supplier creator) { + public void registerData(SolsticeIdentifier id, Class clazz, Supplier creator) { classMap.put(id, clazz); providers.put(clazz, creator); } diff --git a/src/main/java/me/alexdevs/solstice/locale/Locale.java b/src/main/java/me/alexdevs/solstice/locale/Locale.java index 552818aa..50f873fd 100644 --- a/src/main/java/me/alexdevs/solstice/locale/Locale.java +++ b/src/main/java/me/alexdevs/solstice/locale/Locale.java @@ -2,18 +2,18 @@ import eu.pb4.placeholders.api.PlaceholderContext; import me.alexdevs.solstice.api.text.Format; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; import java.util.Map; import java.util.function.Supplier; public class Locale { - public final ResourceLocation id; + public final SolsticeIdentifier id; private final Supplier> localeSupplier; - public Locale(ResourceLocation id, Supplier> localeSupplier) { + public Locale(SolsticeIdentifier id, Supplier> localeSupplier) { this.id = id; this.localeSupplier = localeSupplier; } diff --git a/src/main/java/me/alexdevs/solstice/locale/LocaleManager.java b/src/main/java/me/alexdevs/solstice/locale/LocaleManager.java index 97490bae..7ca7fbeb 100644 --- a/src/main/java/me/alexdevs/solstice/locale/LocaleManager.java +++ b/src/main/java/me/alexdevs/solstice/locale/LocaleManager.java @@ -5,7 +5,7 @@ import com.google.gson.JsonSyntaxException; import com.google.gson.reflect.TypeToken; import me.alexdevs.solstice.Solstice; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import org.jetbrains.annotations.Nullable; import java.io.BufferedReader; @@ -55,7 +55,7 @@ public LocaleManager(Path path) { return null; } - public Locale getLocale(ResourceLocation id) { + public Locale getLocale(SolsticeIdentifier id) { return new Locale(id, () -> localeMap); } @@ -63,7 +63,7 @@ public Locale getShared() { return new Locale(Solstice.ID.withPath("shared"), () -> localeMap); } - public void registerModule(ResourceLocation id, Map defaults) { + public void registerModule(SolsticeIdentifier id, Map defaults) { var key = id.toString().replace(":", "."); this.defaultMap.modules.put(key, new ConcurrentHashMap<>(defaults)); } diff --git a/src/main/java/me/alexdevs/solstice/mixin/modules/admin/ConnectionBypassMixin.java b/src/main/java/me/alexdevs/solstice/mixin/modules/admin/ConnectionBypassMixin.java index c97fe39f..063f7fb3 100644 --- a/src/main/java/me/alexdevs/solstice/mixin/modules/admin/ConnectionBypassMixin.java +++ b/src/main/java/me/alexdevs/solstice/mixin/modules/admin/ConnectionBypassMixin.java @@ -1,8 +1,9 @@ package me.alexdevs.solstice.mixin.modules.admin; -import com.mojang.authlib.GameProfile; import me.alexdevs.solstice.Solstice; import me.alexdevs.solstice.api.events.PlayerConnectionEvents; +import me.alexdevs.solstice.api.utils.PlayerUtils; +import me.alexdevs.solstice.api.utils.ProfileOrNameAndId; import net.minecraft.server.dedicated.DedicatedPlayerList; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -12,22 +13,28 @@ @Mixin(DedicatedPlayerList.class) public abstract class ConnectionBypassMixin { @Inject(method = "isWhiteListed", at = @At("HEAD"), cancellable = true) - public void solstice$bypassWhitelist(GameProfile profile, CallbackInfoReturnable cir) { + //? if < 1.21.11 + public void solstice$bypassWhitelist(com.mojang.authlib.GameProfile profile, CallbackInfoReturnable cir) { + //? if >= 1.21.11 + //public void solstice$bypassWhitelist(net.minecraft.server.players.NameAndId profile, CallbackInfoReturnable cir) { try { - if (PlayerConnectionEvents.WHITELIST_BYPASS.invoker().bypassWhitelist(profile)) + if (PlayerConnectionEvents.WHITELIST_BYPASS.invoker().bypassWhitelist(new ProfileOrNameAndId(profile).getProfile())) cir.setReturnValue(true); } catch (Exception e) { - Solstice.LOGGER.error("Error checking whitelist bypass for profile {}", profile.getId(), e); + Solstice.LOGGER.error("Error checking whitelist bypass for profile {}", PlayerUtils.getId(profile), e); } } @Inject(method = "canBypassPlayerLimit", at = @At("HEAD"), cancellable = true) - public void solstice$bypassPlayerLimit(GameProfile profile, CallbackInfoReturnable cir) { + //? if < 1.21.11 + public void solstice$bypassPlayerLimit(com.mojang.authlib.GameProfile profile, CallbackInfoReturnable cir) { + //? if >= 1.21.11 + //public void solstice$bypassPlayerLimit(net.minecraft.server.players.NameAndId profile, CallbackInfoReturnable cir) { try { - if (PlayerConnectionEvents.FULL_SERVER_BYPASS.invoker().bypassFullServer(profile)) + if (PlayerConnectionEvents.FULL_SERVER_BYPASS.invoker().bypassFullServer(new ProfileOrNameAndId(profile).getProfile())) cir.setReturnValue(true); } catch (Exception e) { - Solstice.LOGGER.error("Error checking full server bypass for profile {}", profile.getId(), e); + Solstice.LOGGER.error("Error checking full server bypass for profile {}", PlayerUtils.getId(profile), e); } } } diff --git a/src/main/java/me/alexdevs/solstice/mixin/modules/ban/CustomBanMessageMixin.java b/src/main/java/me/alexdevs/solstice/mixin/modules/ban/CustomBanMessageMixin.java index 15373f45..7fd7e5db 100644 --- a/src/main/java/me/alexdevs/solstice/mixin/modules/ban/CustomBanMessageMixin.java +++ b/src/main/java/me/alexdevs/solstice/mixin/modules/ban/CustomBanMessageMixin.java @@ -1,8 +1,8 @@ package me.alexdevs.solstice.mixin.modules.ban; import com.llamalad7.mixinextras.sugar.Local; -import com.mojang.authlib.GameProfile; import me.alexdevs.solstice.Solstice; +import me.alexdevs.solstice.api.utils.ProfileOrNameAndId; import me.alexdevs.solstice.modules.ban.formatters.BanMessageFormatter; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; @@ -18,9 +18,12 @@ @Mixin(PlayerList.class) public abstract class CustomBanMessageMixin { @Inject(method = "canPlayerLogin", at = @At(value = "RETURN", ordinal = 0), cancellable = true) - public void solstice$formatBanMessage(SocketAddress address, GameProfile profile, CallbackInfoReturnable cir, @Local UserBanListEntry bannedPlayerEntry, @Local MutableComponent mutableText) { + //? >= 1.21.11 + //public void solstice$formatBanMessage(SocketAddress address, net.minecraft.server.players.NameAndId profile, CallbackInfoReturnable cir, @Local UserBanListEntry bannedPlayerEntry, @Local MutableComponent mutableText) { + //? < 1.21.11 + public void solstice$formatBanMessage(SocketAddress address, com.mojang.authlib.GameProfile profile, CallbackInfoReturnable cir, @Local UserBanListEntry bannedPlayerEntry, @Local MutableComponent mutableText) { try { - var reasonText = BanMessageFormatter.format(profile, bannedPlayerEntry); + var reasonText = BanMessageFormatter.format(new ProfileOrNameAndId(profile), bannedPlayerEntry); cir.setReturnValue(reasonText); } catch (Exception ex) { Solstice.LOGGER.error("Something went wrong while formatting the ban message", ex); diff --git a/src/main/java/me/alexdevs/solstice/mixin/modules/spawn/OverrideNewPlayerSpawnPointMixin.java b/src/main/java/me/alexdevs/solstice/mixin/modules/spawn/OverrideNewPlayerSpawnPointMixin.java index 163d3ba3..8c521753 100644 --- a/src/main/java/me/alexdevs/solstice/mixin/modules/spawn/OverrideNewPlayerSpawnPointMixin.java +++ b/src/main/java/me/alexdevs/solstice/mixin/modules/spawn/OverrideNewPlayerSpawnPointMixin.java @@ -18,20 +18,23 @@ @Mixin(PlayerList.class) public abstract class OverrideNewPlayerSpawnPointMixin { - @Redirect( + //? if < 1.21.1 { + /*@Redirect( method = "placeNewPlayer", at = @At( value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getLevel(Lnet/minecraft/resources/ResourceKey;)Lnet/minecraft/server/level/ServerLevel;" ) ) - //? if >= 1.21.1 { + *///? } + //? if >= 1.21.1 && < 1.21.11 { public ServerLevel solstice$overrideWorld(MinecraftServer server, ResourceKey dimension, @Local Optional optional) { if (optional.isEmpty()) { - //? } else { + //? } else if < 1.21.1 { /*public ServerLevel solstice$overrideWorld(MinecraftServer server, ResourceKey dimension) { if (server.getLevel(dimension) == null) { *///? } + //? if < 1.21.11 { var spawn = ModuleProvider.SPAWN; var firstSpawn = spawn.getFirstSpawn(); if (firstSpawn != null) { @@ -41,4 +44,5 @@ public abstract class OverrideNewPlayerSpawnPointMixin { } return server.getLevel(dimension); } + //? } } diff --git a/src/main/java/me/alexdevs/solstice/mixin/modules/spawn/OverrideSpawnPointMixin.java b/src/main/java/me/alexdevs/solstice/mixin/modules/spawn/OverrideSpawnPointMixin.java index f94c7b7f..ce9095b0 100644 --- a/src/main/java/me/alexdevs/solstice/mixin/modules/spawn/OverrideSpawnPointMixin.java +++ b/src/main/java/me/alexdevs/solstice/mixin/modules/spawn/OverrideSpawnPointMixin.java @@ -30,7 +30,30 @@ //? < 1.21.1 //@Mixin(Player.class) public abstract class OverrideSpawnPointMixin { - //? if >= 1.21.4 { + //? if >= 1.21.11 { + /*@Shadow @Final public MinecraftServer server; + @Shadow private ServerPlayer.RespawnConfig respawnConfig; + @Inject(method = "findRespawnPositionAndUseSpawnBlock", at = @At("RETURN"), cancellable = true) + public void solstice$overrideRespawnTarget(boolean useCharge, TeleportTransition.PostTeleportTransition postTeleportTransition, CallbackInfoReturnable cir) { + var spawnModule = ModuleProvider.SPAWN; + var config = spawnModule.getConfig(); + var spawn = spawnModule.getGlobalSpawnPosition(); + var world = spawn.getWorld(this.server); + var pos = new Vec3(spawn.getX(), spawn.getY(), spawn.getZ()); + var transition = new TeleportTransition( + world, pos, Vec3.ZERO, + spawn.getYaw(), spawn.getPitch(), + TeleportTransition.DO_NOTHING + ); + if (config.globalSpawn.onRespawn) { + cir.setReturnValue(transition); + return; + } + if (config.globalSpawn.onRespawnSoft && respawnConfig == null) { + cir.setReturnValue(transition); + } + } + *///? } else if >= 1.21.4 { /*@Shadow @Final public MinecraftServer server; @Shadow private BlockPos respawnPosition; @Inject(method = "findRespawnPositionAndUseSpawnBlock", at = @At("RETURN"), cancellable = true) diff --git a/src/main/java/me/alexdevs/solstice/modules/ModuleProvider.java b/src/main/java/me/alexdevs/solstice/modules/ModuleProvider.java index bb4cad18..16765e6f 100644 --- a/src/main/java/me/alexdevs/solstice/modules/ModuleProvider.java +++ b/src/main/java/me/alexdevs/solstice/modules/ModuleProvider.java @@ -3,6 +3,7 @@ import me.alexdevs.solstice.Solstice; import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.api.module.ModuleEntrypoint; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import me.alexdevs.solstice.modules.admin.AdminModule; import me.alexdevs.solstice.modules.afk.AfkModule; import me.alexdevs.solstice.modules.announcement.AnnouncementModule; @@ -59,7 +60,6 @@ import me.alexdevs.solstice.modules.trash.TrashModule; import me.alexdevs.solstice.modules.utilities.UtilitiesModule; import me.alexdevs.solstice.modules.warp.WarpModule; -import net.minecraft.resources.ResourceLocation; import java.util.HashSet; import java.util.Set; @@ -124,7 +124,7 @@ public class ModuleProvider implements ModuleEntrypoint { public static final UtilitiesModule UTILITIES = add(new UtilitiesModule(path("utilities"))); public static final WarpModule WARP = add(new WarpModule(path("warp"))); - private static ResourceLocation path(String path) { + private static SolsticeIdentifier path(String path) { return Solstice.ID.withPath(path); } diff --git a/src/main/java/me/alexdevs/solstice/modules/admin/AdminModule.java b/src/main/java/me/alexdevs/solstice/modules/admin/AdminModule.java index 299253b3..fd3ffa72 100644 --- a/src/main/java/me/alexdevs/solstice/modules/admin/AdminModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/admin/AdminModule.java @@ -3,11 +3,12 @@ import me.alexdevs.solstice.Solstice; import me.alexdevs.solstice.api.events.PlayerConnectionEvents; import me.alexdevs.solstice.api.module.ModuleBase; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.lucko.fabric.api.permissions.v0.Permissions; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; public class AdminModule extends ModuleBase { - public AdminModule(ResourceLocation id) { + public AdminModule(SolsticeIdentifier id) { super(id); } @@ -17,7 +18,7 @@ public void init() { try { return Permissions.check(profile, getWhitelistBypassPermission(), false).get(); } catch (Exception e) { - Solstice.LOGGER.error("Error checking whitelist bypass for profile {}", profile.getId(), e); + Solstice.LOGGER.error("Error checking whitelist bypass for profile {}", PlayerUtils.getId(profile), e); } return false; }); @@ -26,7 +27,7 @@ public void init() { try { return Permissions.check(profile, getFullServerBypassPermission(), false).get(); } catch (Exception e) { - Solstice.LOGGER.error("Error checking full server bypass for profile {}", profile.getId(), e); + Solstice.LOGGER.error("Error checking full server bypass for profile {}", PlayerUtils.getId(profile), e); } return false; }); diff --git a/src/main/java/me/alexdevs/solstice/modules/afk/AfkModule.java b/src/main/java/me/alexdevs/solstice/modules/afk/AfkModule.java index 68be12b0..1ae889d8 100644 --- a/src/main/java/me/alexdevs/solstice/modules/afk/AfkModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/afk/AfkModule.java @@ -10,15 +10,15 @@ import me.alexdevs.solstice.api.events.SolsticeEvents; import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.api.text.Format; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.afk.commands.ActiveTimeCommand; import me.alexdevs.solstice.modules.afk.commands.AfkCommand; import me.alexdevs.solstice.modules.afk.data.*; -import me.alexdevs.solstice.api.utils.ResourceUtils; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.fabricmc.fabric.api.event.player.*; import net.fabricmc.fabric.api.message.v1.ServerMessageEvents; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; -import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionResult; @@ -41,7 +41,7 @@ public class AfkModule extends ModuleBase.Toggleable { public static final int LEADERBOARD_SIZE = 10; - public AfkModule(ResourceLocation id) { + public AfkModule(SolsticeIdentifier id) { super(id); } @@ -71,7 +71,7 @@ public void init() { this.commands.add(new AfkCommand(this)); this.commands.add(new ActiveTimeCommand(this)); - Placeholders.register(ResourceUtils.location(Solstice.MOD_ID, "afk"), (context, arg) -> { + Placeholders.register(SolsticeIdentifier.of(Solstice.MOD_ID, "afk").get(), (context, arg) -> { if (!context.hasPlayer()) return PlaceholderResult.invalid("No player!"); @@ -101,11 +101,11 @@ public void init() { PlayerActivityEvents.AFK.register((player) -> { var config = getConfig(); - if (player.serverLevel().canSleepThroughNights()) { - player.serverLevel().updateSleepingPlayerList(); + if (PlayerUtils.getLevel(player).canSleepThroughNights()) { + PlayerUtils.getLevel(player).updateSleepingPlayerList(); } - Solstice.LOGGER.info("{} is AFK. Active time: {} seconds.", player.getGameProfile().getName(), getActiveTime(player.getUUID())); + Solstice.LOGGER.info("{} is AFK. Active time: {} seconds.", PlayerUtils.getName(player.getGameProfile()), getActiveTime(player.getUUID())); if (!config.announce) return; @@ -117,11 +117,11 @@ public void init() { PlayerActivityEvents.AFK_RETURN.register((player, reason) -> { var config = getConfig(); - if (player.serverLevel().canSleepThroughNights()) { - player.serverLevel().updateSleepingPlayerList(); + if (PlayerUtils.getLevel(player).canSleepThroughNights()) { + PlayerUtils.getLevel(player).updateSleepingPlayerList(); } - Solstice.LOGGER.info("{} is no longer AFK due to {}. Active time: {} seconds.", player.getGameProfile().getName(), reason.name(), getActiveTime(player.getUUID())); + Solstice.LOGGER.info("{} is no longer AFK due to {}. Active time: {} seconds.", PlayerUtils.getName(player.getGameProfile()), reason.name(), getActiveTime(player.getUUID())); if (!config.announce) return; @@ -160,7 +160,7 @@ private void tryInsertLeaderboard(ServerPlayer player, int activeTime) { var entry = leaderboard.stream().filter(e -> e.uuid().equals(player.getUUID())).findFirst(); if (entry.isPresent()) { entry.get().activeTime(activeTime); - entry.get().name(player.getGameProfile().getName()); + entry.get().name(PlayerUtils.getName(player.getGameProfile())); leaderboard.sort((o1, o2) -> Integer.compare(o2.activeTime(), o1.activeTime())); return; } @@ -170,11 +170,11 @@ private void tryInsertLeaderboard(ServerPlayer player, int activeTime) { if (smallest.isPresent()) { if (smallest.get().activeTime() < activeTime) { leaderboard.remove(smallest.get()); - leaderboard.add(new LeaderboardEntry(player.getGameProfile().getName(), player.getUUID(), activeTime)); + leaderboard.add(new LeaderboardEntry(PlayerUtils.getName(player.getGameProfile()), player.getUUID(), activeTime)); leaderboard.sort((o1, o2) -> Integer.compare(o2.activeTime(), o1.activeTime())); } } else { - leaderboard.add(new LeaderboardEntry(player.getGameProfile().getName(), player.getUUID(), activeTime)); + leaderboard.add(new LeaderboardEntry(PlayerUtils.getName(player.getGameProfile()), player.getUUID(), activeTime)); } } @@ -266,13 +266,14 @@ private void calculateLeaderboard() { var userCache = Solstice.getUserCache(); var temp = new ArrayList(); for (var name : userCache.getAllNames()) { - var profile = userCache.getByName(name); - if (profile.isEmpty()) + var profileOptional = userCache.getByName(name); + if (profileOptional.isEmpty()) continue; - var playerData = Solstice.playerData.get(profile.get().getId()).getData(AfkPlayerData.class); + var profile = profileOptional.get(); + var playerData = Solstice.playerData.get(PlayerUtils.getId(profile)).getData(AfkPlayerData.class); if (playerData.activeTime > 0) { - var entry = new LeaderboardEntry(profile.get().getName(), profile.get().getId(), playerData.activeTime); + var entry = new LeaderboardEntry(PlayerUtils.getName(profile), PlayerUtils.getId(profile), playerData.activeTime); temp.add(entry); } } diff --git a/src/main/java/me/alexdevs/solstice/modules/afk/commands/ActiveTimeCommand.java b/src/main/java/me/alexdevs/solstice/modules/afk/commands/ActiveTimeCommand.java index 20d9b5c3..0e822ac1 100644 --- a/src/main/java/me/alexdevs/solstice/modules/afk/commands/ActiveTimeCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/afk/commands/ActiveTimeCommand.java @@ -5,6 +5,7 @@ import me.alexdevs.solstice.api.command.LocalGameProfile; import me.alexdevs.solstice.api.command.TimeSpan; import me.alexdevs.solstice.api.module.ModCommand; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.afk.AfkModule; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; @@ -48,7 +49,7 @@ public LiteralArgumentBuilder command(String name) { .suggests(LocalGameProfile::suggest) .executes(context -> { var profile = LocalGameProfile.getProfile(context, "player"); - var activeTime = module.getActiveTime(profile.getId()); + var activeTime = module.getActiveTime(PlayerUtils.getId(profile)); if (activeTime == 0) { context.getSource().sendSuccess(() -> module.locale().get("neverPlayed"), false); @@ -59,7 +60,7 @@ public LiteralArgumentBuilder command(String name) { var map = Map.of( "activeTime", Component.nullToEmpty(longSpan), - "player", Component.nullToEmpty(profile.getName()) + "player", Component.nullToEmpty(PlayerUtils.getName(profile)) ); context.getSource().sendSuccess(() -> module.locale().get("playerActiveTime", map), false); @@ -106,11 +107,11 @@ public LiteralArgumentBuilder command(String name) { var profile = LocalGameProfile.getProfile(context, "player"); var time = TimeSpan.getTimeSpan(context, "time"); - var data = module.getPlayerData(profile.getId()); + var data = module.getPlayerData(PlayerUtils.getId(profile)); data.activeTime = time; var map = Map.of( - "player", Component.nullToEmpty(profile.getName()), + "player", Component.nullToEmpty(PlayerUtils.getName(profile)), "time", Component.nullToEmpty(TimeSpan.toLongString(time)) ); context.getSource().sendSuccess(() -> module.locale().get("activeTimeSet", map), true); diff --git a/src/main/java/me/alexdevs/solstice/modules/announcement/AnnouncementModule.java b/src/main/java/me/alexdevs/solstice/modules/announcement/AnnouncementModule.java index 4ecdc331..3824e2d7 100644 --- a/src/main/java/me/alexdevs/solstice/modules/announcement/AnnouncementModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/announcement/AnnouncementModule.java @@ -7,7 +7,7 @@ import me.alexdevs.solstice.api.text.Format; import me.alexdevs.solstice.modules.announcement.data.AnnouncementConfig; import me.lucko.fabric.api.permissions.v0.Permissions; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import java.util.Random; import java.util.concurrent.ScheduledFuture; @@ -19,7 +19,7 @@ public class AnnouncementModule extends ModuleBase.Toggleable { private ScheduledFuture scheduledFuture = null; private int currentLine = 0; - public AnnouncementModule(ResourceLocation id) { + public AnnouncementModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/back/BackModule.java b/src/main/java/me/alexdevs/solstice/modules/back/BackModule.java index 35e0d44e..98e05c71 100644 --- a/src/main/java/me/alexdevs/solstice/modules/back/BackModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/back/BackModule.java @@ -10,7 +10,7 @@ import me.alexdevs.solstice.modules.back.data.BackPlayerData; import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.server.level.ServerPlayer; import org.jetbrains.annotations.Nullable; @@ -21,7 +21,7 @@ public class BackModule extends ModuleBase.Toggleable { - public BackModule(ResourceLocation id) { + public BackModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/ban/BanModule.java b/src/main/java/me/alexdevs/solstice/modules/ban/BanModule.java index 81d894a7..516afb5e 100644 --- a/src/main/java/me/alexdevs/solstice/modules/ban/BanModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/ban/BanModule.java @@ -5,10 +5,10 @@ import me.alexdevs.solstice.modules.ban.commands.TempBanCommand; import me.alexdevs.solstice.modules.ban.commands.UnbanCommand; import me.alexdevs.solstice.modules.ban.data.BanLocale; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; public class BanModule extends ModuleBase.Toggleable { - public BanModule(ResourceLocation id) { + public BanModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/ban/commands/BanCommand.java b/src/main/java/me/alexdevs/solstice/modules/ban/commands/BanCommand.java index e2d616b6..a2ec6be0 100644 --- a/src/main/java/me/alexdevs/solstice/modules/ban/commands/BanCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/ban/commands/BanCommand.java @@ -11,6 +11,8 @@ import me.alexdevs.solstice.api.module.ModCommand; import me.alexdevs.solstice.api.module.Utils; import me.alexdevs.solstice.api.text.Format; +import me.alexdevs.solstice.api.utils.PlayerUtils; +import me.alexdevs.solstice.api.utils.ProfileOrNameAndId; import me.alexdevs.solstice.modules.ban.BanModule; import me.alexdevs.solstice.modules.ban.formatters.BanMessageFormatter; import net.minecraft.commands.CommandBuildContext; @@ -35,28 +37,30 @@ public BanCommand(BanModule module) { super(module); } - static int execute(CommandContext context, Collection targets, @Nullable String reason, @Nullable Date expiryDate) throws CommandSyntaxException { + static int execute(CommandContext context, Collection targets, @Nullable String reason, @Nullable Date expiryDate) throws CommandSyntaxException { var source = context.getSource(); var server = source.getServer(); var banList = server.getPlayerList().getBans(); var banCounter = 0; - for (GameProfile target : targets) { - if (banList.isBanned(target)) { + for (var profile : targets) { + + if (banList.isBanned(profile.getNameAndId())) { continue; } - var banEntry = new UserBanListEntry(target, null, source.getTextName(), expiryDate, reason); + var banEntry = new UserBanListEntry(profile.getNameAndId(), null, source.getTextName(), expiryDate, reason); banList.add(banEntry); banCounter++; - var playerContext = PlaceholderContext.of(target, server); + var playerContext = PlaceholderContext.of(profile.getProfile(), server); + - source.sendSuccess(() -> Component.translatable("commands.ban.success", Component.nullToEmpty(target.getName()), Format.parse(banEntry.getReason(), playerContext)), true); + source.sendSuccess(() -> Component.translatable("commands.ban.success", Component.nullToEmpty(PlayerUtils.getName(profile.getProfile())), Format.parse(banEntry.getReason(), playerContext)), true); - var serverPlayerEntity = source.getServer().getPlayerList().getPlayer(target.getId()); + var serverPlayerEntity = source.getServer().getPlayerList().getPlayer(PlayerUtils.getId(profile.getProfile())); if (serverPlayerEntity != null) { - serverPlayerEntity.connection.disconnect(BanMessageFormatter.format(target, banEntry)); + serverPlayerEntity.connection.disconnect(BanMessageFormatter.format(profile, banEntry)); } } @@ -83,9 +87,9 @@ public LiteralArgumentBuilder command(String name) { return literal(name) .requires(require(3)) .then(argument("targets", GameProfileArgument.gameProfile()) - .executes(context -> execute(context, GameProfileArgument.getGameProfiles(context, "targets"), null, null)) + .executes(context -> execute(context, GameProfileArgument.getGameProfiles(context, "targets").stream().map(ProfileOrNameAndId::new).toList(), null, null)) .then(argument("reason", StringArgumentType.greedyString()) - .executes(context -> execute(context, GameProfileArgument.getGameProfiles(context, "targets"), StringArgumentType.getString(context, "reason"), null)))); + .executes(context -> execute(context, GameProfileArgument.getGameProfiles(context, "targets").stream().map(ProfileOrNameAndId::new).toList(), StringArgumentType.getString(context, "reason"), null)))); } } diff --git a/src/main/java/me/alexdevs/solstice/modules/ban/commands/TempBanCommand.java b/src/main/java/me/alexdevs/solstice/modules/ban/commands/TempBanCommand.java index 9493e228..682cde1d 100644 --- a/src/main/java/me/alexdevs/solstice/modules/ban/commands/TempBanCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/ban/commands/TempBanCommand.java @@ -1,12 +1,12 @@ package me.alexdevs.solstice.modules.ban.commands; -import com.mojang.authlib.GameProfile; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import me.alexdevs.solstice.api.command.TimeSpan; import me.alexdevs.solstice.api.module.ModCommand; +import me.alexdevs.solstice.api.utils.ProfileOrNameAndId; import me.alexdevs.solstice.modules.ban.BanModule; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.arguments.GameProfileArgument; @@ -44,13 +44,13 @@ public LiteralArgumentBuilder command(String name) { .then(argument("targets", GameProfileArgument.gameProfile()) .then(argument("duration", StringArgumentType.string()) .suggests(TimeSpan::suggest) - .executes(context -> execute(context, GameProfileArgument.getGameProfiles(context, "targets"), null, TimeSpan.getTimeSpan(context, "duration"))) + .executes(context -> execute(context, GameProfileArgument.getGameProfiles(context, "targets").stream().map(ProfileOrNameAndId::new).toList(), null, TimeSpan.getTimeSpan(context, "duration"))) .then(argument("reason", StringArgumentType.greedyString()) - .executes(context -> execute(context, GameProfileArgument.getGameProfiles(context, "targets"), StringArgumentType.getString(context, "reason"), TimeSpan.getTimeSpan(context, "duration")))))); + .executes(context -> execute(context, GameProfileArgument.getGameProfiles(context, "targets").stream().map(ProfileOrNameAndId::new).toList(), StringArgumentType.getString(context, "reason"), TimeSpan.getTimeSpan(context, "duration")))))); } - private int execute(CommandContext context, Collection targets, String reason, int duration) throws CommandSyntaxException { + private int execute(CommandContext context, Collection targets, String reason, int duration) throws CommandSyntaxException { var expiryDate = getDateFromNow(duration); return BanCommand.execute(context, targets, reason, expiryDate); diff --git a/src/main/java/me/alexdevs/solstice/modules/ban/commands/UnbanCommand.java b/src/main/java/me/alexdevs/solstice/modules/ban/commands/UnbanCommand.java index 51bac6a4..bcef0238 100644 --- a/src/main/java/me/alexdevs/solstice/modules/ban/commands/UnbanCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/ban/commands/UnbanCommand.java @@ -8,6 +8,7 @@ import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import me.alexdevs.solstice.api.module.ModCommand; import me.alexdevs.solstice.api.module.Utils; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.ban.BanModule; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; @@ -48,15 +49,18 @@ public LiteralArgumentBuilder command(String name) { .executes(context -> execute(context, GameProfileArgument.getGameProfiles(context, "targets")))); } + //? < 1.21.11 private int execute(CommandContext context, Collection targets) throws CommandSyntaxException { + //? >= 1.21.11 + //private int execute(CommandContext context, Collection targets) throws CommandSyntaxException { var banList = context.getSource().getServer().getPlayerList().getBans(); var source = context.getSource(); var pardonCount = 0; - for (GameProfile profile : targets) { + for (var profile : targets) { if (banList.isBanned(profile)) { banList.remove(profile); pardonCount++; - source.sendSuccess(() -> Component.translatable("commands.pardon.success", Component.nullToEmpty(profile.getName())), true); + source.sendSuccess(() -> Component.translatable("commands.pardon.success", Component.nullToEmpty(PlayerUtils.getName(profile))), true); } } diff --git a/src/main/java/me/alexdevs/solstice/modules/ban/formatters/BanMessageFormatter.java b/src/main/java/me/alexdevs/solstice/modules/ban/formatters/BanMessageFormatter.java index 625dfe97..11473a40 100644 --- a/src/main/java/me/alexdevs/solstice/modules/ban/formatters/BanMessageFormatter.java +++ b/src/main/java/me/alexdevs/solstice/modules/ban/formatters/BanMessageFormatter.java @@ -1,12 +1,11 @@ package me.alexdevs.solstice.modules.ban.formatters; -import com.mojang.authlib.GameProfile; import eu.pb4.placeholders.api.PlaceholderContext; import me.alexdevs.solstice.Solstice; import me.alexdevs.solstice.api.text.Format; +import me.alexdevs.solstice.api.utils.ProfileOrNameAndId; import me.alexdevs.solstice.core.coreModule.CoreModule; import me.alexdevs.solstice.modules.ModuleProvider; -import me.alexdevs.solstice.modules.ban.BanModule; import net.minecraft.network.chat.Component; import net.minecraft.server.players.UserBanListEntry; @@ -14,12 +13,11 @@ import java.util.Map; public class BanMessageFormatter { - public static Component format(GameProfile profile, UserBanListEntry entry) { + public static Component format(ProfileOrNameAndId profile, UserBanListEntry entry) { var locale = ModuleProvider.BAN.locale(); var coreConfig = CoreModule.getConfig(); var df = new SimpleDateFormat(coreConfig.dateTimeFormat); - - var context = PlaceholderContext.of(profile, Solstice.server); + var context = PlaceholderContext.of(profile.getProfile(), Solstice.server); var expiryDate = Component.nullToEmpty(entry.getExpires() != null ? df.format(entry.getExpires()) : "never"); Map placeholders = Map.of( "reason", Format.parse(entry.getReason(), context), diff --git a/src/main/java/me/alexdevs/solstice/modules/broadcast/BroadcastModule.java b/src/main/java/me/alexdevs/solstice/modules/broadcast/BroadcastModule.java index 9a0b4ec0..1edd156a 100644 --- a/src/main/java/me/alexdevs/solstice/modules/broadcast/BroadcastModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/broadcast/BroadcastModule.java @@ -5,11 +5,11 @@ import me.alexdevs.solstice.modules.broadcast.commands.BroadcastCommand; import me.alexdevs.solstice.modules.broadcast.commands.PlainBroadcastCommand; import me.alexdevs.solstice.modules.broadcast.data.BroadcastConfig; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; public class BroadcastModule extends ModuleBase.Toggleable { - public BroadcastModule(ResourceLocation id) { + public BroadcastModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/commandSpy/CommandSpyModule.java b/src/main/java/me/alexdevs/solstice/modules/commandSpy/CommandSpyModule.java index 75014b0d..1f3571d8 100644 --- a/src/main/java/me/alexdevs/solstice/modules/commandSpy/CommandSpyModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/commandSpy/CommandSpyModule.java @@ -3,18 +3,19 @@ import me.alexdevs.solstice.Solstice; import me.alexdevs.solstice.api.events.CommandEvents; import me.alexdevs.solstice.api.module.ModuleBase; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.commandSpy.data.CommandSpyConfig; import me.alexdevs.solstice.modules.commandSpy.data.CommandSpyLocale; import me.lucko.fabric.api.permissions.v0.Permissions; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import java.util.Map; public class CommandSpyModule extends ModuleBase.Toggleable { - public CommandSpyModule(ResourceLocation id) { + public CommandSpyModule(SolsticeIdentifier id) { super(id); } @@ -40,7 +41,7 @@ public void init() { var player = source.getPlayer(); var players = source.getServer().getPlayerList().getPlayers(); - var placeholders = Map.of("player", Component.nullToEmpty(player.getGameProfile().getName()), "command", Component.nullToEmpty(command)); + var placeholders = Map.of("player", Component.nullToEmpty(PlayerUtils.getName(player.getGameProfile())), "command", Component.nullToEmpty(command)); var message = locale().get("spyFormat", placeholders); for (var pl : players) { var commandSpyEnabled = Permissions.check(pl, this.getPermissionNode("base")); diff --git a/src/main/java/me/alexdevs/solstice/modules/cooldown/CooldownModule.java b/src/main/java/me/alexdevs/solstice/modules/cooldown/CooldownModule.java index 76d8602b..fd2990de 100644 --- a/src/main/java/me/alexdevs/solstice/modules/cooldown/CooldownModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/cooldown/CooldownModule.java @@ -12,7 +12,7 @@ import me.lucko.fabric.api.permissions.v0.Permissions; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.server.level.ServerPlayer; import java.util.*; @@ -28,7 +28,7 @@ public class CooldownModule extends ModuleBase.Toggleable { // This map is replaced every reload and at start. private Map nodesMap = Map.of(); - public CooldownModule(ResourceLocation id) { + public CooldownModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/customName/CustomNameModule.java b/src/main/java/me/alexdevs/solstice/modules/customName/CustomNameModule.java index a5a09f4f..19f83c21 100644 --- a/src/main/java/me/alexdevs/solstice/modules/customName/CustomNameModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/customName/CustomNameModule.java @@ -5,13 +5,15 @@ import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.api.text.Format; import me.alexdevs.solstice.api.text.RawPlaceholder; +import me.alexdevs.solstice.api.utils.PlayerUtils; +import me.alexdevs.solstice.api.utils.ProfileOrNameAndId; import me.alexdevs.solstice.integrations.LuckPermsIntegration; import me.alexdevs.solstice.modules.customName.commands.NicknameCommand; import me.alexdevs.solstice.modules.customName.data.CustomNameConfig; import me.alexdevs.solstice.modules.customName.data.CustomNameLocale; import me.alexdevs.solstice.modules.customName.data.CustomNamePlayerData; import net.minecraft.network.chat.MutableComponent; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.server.level.ServerPlayer; import org.jetbrains.annotations.Nullable; @@ -22,7 +24,7 @@ public class CustomNameModule extends ModuleBase.Toggleable { public static final Pattern BASIC_NICKNAME_FILTER = Pattern.compile("[^a-zA-Zà-üÀ-Ü_ ]"); - public CustomNameModule(ResourceLocation id) { + public CustomNameModule(SolsticeIdentifier id) { super(id); } @@ -46,7 +48,7 @@ public String fetchUsernameFormat(ServerPlayer player) { } } - var isOperator = player.getServer().getPlayerList().isOp(player.getGameProfile()); + var isOperator = player.getServer().getPlayerList().isOp(new ProfileOrNameAndId(player.getGameProfile()).getNameAndId()); if (format == null) { format = "${username}"; @@ -69,7 +71,7 @@ public String fetchUsernameFormat(ServerPlayer player) { public String getResolvedUsername(ServerPlayer player) { var format = fetchUsernameFormat(player); var playerData = Solstice.playerData.get(player).getData(CustomNamePlayerData.class); - var name = playerData.nickname == null ? player.getGameProfile().getName() : playerData.nickname; + var name = playerData.nickname == null ? PlayerUtils.getName(player.getGameProfile()) : playerData.nickname; var prefix = LuckPermsIntegration.getPrefix(player); var suffix = LuckPermsIntegration.getSuffix(player); diff --git a/src/main/java/me/alexdevs/solstice/modules/customName/commands/NicknameCommand.java b/src/main/java/me/alexdevs/solstice/modules/customName/commands/NicknameCommand.java index f3443b2f..1f86431e 100644 --- a/src/main/java/me/alexdevs/solstice/modules/customName/commands/NicknameCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/customName/commands/NicknameCommand.java @@ -6,6 +6,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import me.alexdevs.solstice.api.command.LocalGameProfile; import me.alexdevs.solstice.api.module.ModCommand; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.customName.CustomNameModule; import me.lucko.fabric.api.permissions.v0.Permissions; import net.minecraft.commands.CommandSourceStack; @@ -107,14 +108,14 @@ private int executeSetOthers(CommandContext context) throws } module.setCustomName( - profile.getId(), + PlayerUtils.getId(profile), nickname, hasAdvancedPermissionOthers(context.getSource()) ); var map = Map.of( - "player", Component.nullToEmpty(profile.getName()), - "nickname", Component.nullToEmpty(module.getCustomName(profile.getId())) + "player", Component.nullToEmpty(PlayerUtils.getName(profile)), + "nickname", Component.nullToEmpty(module.getCustomName(PlayerUtils.getId(profile))) ); context.getSource().sendSuccess(() -> module.locale().get("setOther", map), true); @@ -124,11 +125,11 @@ private int executeSetOthers(CommandContext context) throws private int executeClearOthers(CommandContext context) throws CommandSyntaxException { var profile = LocalGameProfile.getProfile(context, "player"); - module.clearCustomName(profile.getId()); + module.clearCustomName(PlayerUtils.getId(profile)); var map = Map.of( - "player", Component.nullToEmpty(profile.getName()), - "nickname", Component.nullToEmpty(module.getCustomName(profile.getId())) + "player", Component.nullToEmpty(PlayerUtils.getName(profile)), + "nickname", Component.nullToEmpty(module.getCustomName(PlayerUtils.getId(profile))) ); context.getSource().sendSuccess(() -> module.locale().get("clearedOther", map), true); diff --git a/src/main/java/me/alexdevs/solstice/modules/enderchest/EnderChestModule.java b/src/main/java/me/alexdevs/solstice/modules/enderchest/EnderChestModule.java index 30ae3915..ec575820 100644 --- a/src/main/java/me/alexdevs/solstice/modules/enderchest/EnderChestModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/enderchest/EnderChestModule.java @@ -4,11 +4,11 @@ import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.modules.enderchest.commands.EnderChestCommand; import me.alexdevs.solstice.modules.enderchest.data.EnderChestLocale; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; public class EnderChestModule extends ModuleBase.Toggleable { - public EnderChestModule(ResourceLocation id) { + public EnderChestModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/enderchest/commands/EnderChestCommand.java b/src/main/java/me/alexdevs/solstice/modules/enderchest/commands/EnderChestCommand.java index 3014fd51..6f872937 100644 --- a/src/main/java/me/alexdevs/solstice/modules/enderchest/commands/EnderChestCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/enderchest/commands/EnderChestCommand.java @@ -6,6 +6,7 @@ import me.alexdevs.solstice.api.command.LocalGameProfile; import me.alexdevs.solstice.api.module.ModCommand; import me.alexdevs.solstice.api.utils.PlayerUtils; +import me.alexdevs.solstice.api.utils.ProfileOrNameAndId; import me.alexdevs.solstice.modules.enderchest.EnderChestModule; import me.alexdevs.solstice.modules.inventorySee.ImmutableSlot; import me.lucko.fabric.api.permissions.v0.Permissions; @@ -60,7 +61,7 @@ public LiteralArgumentBuilder command(String name) { return; } - var isOnline = PlayerUtils.isOnline(profile.getId()); + var isOnline = PlayerUtils.isOnline(PlayerUtils.getId(profile)); if (!isOnline && !Permissions.check(player, getPermissionNode("offline"), 3)) { source.sendSuccess(() -> module.locale().get("offlineNotAllowed"), false); return; @@ -69,7 +70,7 @@ public LiteralArgumentBuilder command(String name) { ServerPlayer targetPlayer; if (isOnline) { - targetPlayer = source.getServer().getPlayerList().getPlayer(profile.getId()); + targetPlayer = source.getServer().getPlayerList().getPlayer(PlayerUtils.getId(profile)); } else { targetPlayer = PlayerUtils.loadOfflinePlayer(profile); } @@ -79,7 +80,7 @@ public LiteralArgumentBuilder command(String name) { var canEdit = Permissions.check(player, getPermissionNode("edit"), 3); var map = Map.of( - "player", Component.nullToEmpty(profile.getName()) + "player", Component.nullToEmpty(PlayerUtils.getName(profile)) ); var title = module.locale().get("title", map); diff --git a/src/main/java/me/alexdevs/solstice/modules/experiments/ExperimentsModule.java b/src/main/java/me/alexdevs/solstice/modules/experiments/ExperimentsModule.java index 213f3a3c..82d3e48b 100644 --- a/src/main/java/me/alexdevs/solstice/modules/experiments/ExperimentsModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/experiments/ExperimentsModule.java @@ -5,7 +5,7 @@ import me.alexdevs.solstice.modules.experiments.commands.FlagsCommand; import me.alexdevs.solstice.modules.experiments.commands.SafeTeleportCommand; import me.alexdevs.solstice.modules.experiments.commands.TimeSpanCommand; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import java.util.Collection; import java.util.List; @@ -13,7 +13,7 @@ public class ExperimentsModule extends ModuleBase { public static final boolean ENABLED = false; - public ExperimentsModule(ResourceLocation id) { + public ExperimentsModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/extinguish/ExtinguishModule.java b/src/main/java/me/alexdevs/solstice/modules/extinguish/ExtinguishModule.java index a3395c54..445ad3d6 100644 --- a/src/main/java/me/alexdevs/solstice/modules/extinguish/ExtinguishModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/extinguish/ExtinguishModule.java @@ -2,11 +2,11 @@ import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.modules.extinguish.commands.ExtinguishCommand; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; public class ExtinguishModule extends ModuleBase.Toggleable { - public ExtinguishModule(ResourceLocation id) { + public ExtinguishModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/feed/FeedModule.java b/src/main/java/me/alexdevs/solstice/modules/feed/FeedModule.java index 7b89dcb1..c5ef6296 100644 --- a/src/main/java/me/alexdevs/solstice/modules/feed/FeedModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/feed/FeedModule.java @@ -4,11 +4,11 @@ import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.modules.feed.commands.FeedCommand; import me.alexdevs.solstice.modules.feed.data.FeedLocale; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; public class FeedModule extends ModuleBase.Toggleable { - public FeedModule(ResourceLocation id) { + public FeedModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/fly/FlyModule.java b/src/main/java/me/alexdevs/solstice/modules/fly/FlyModule.java index 8dc3ed0e..0366e734 100644 --- a/src/main/java/me/alexdevs/solstice/modules/fly/FlyModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/fly/FlyModule.java @@ -6,11 +6,11 @@ import me.alexdevs.solstice.modules.fly.data.FlyLocale; import me.alexdevs.solstice.modules.fly.data.FlyPlayerData; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; public class FlyModule extends ModuleBase.Toggleable { - public FlyModule(ResourceLocation id) { + public FlyModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/god/GodModule.java b/src/main/java/me/alexdevs/solstice/modules/god/GodModule.java index 854a8b5a..2d57e9c9 100644 --- a/src/main/java/me/alexdevs/solstice/modules/god/GodModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/god/GodModule.java @@ -6,11 +6,11 @@ import me.alexdevs.solstice.modules.god.data.GodLocale; import me.alexdevs.solstice.modules.god.data.GodPlayerData; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; public class GodModule extends ModuleBase.Toggleable { - public GodModule(ResourceLocation id) { + public GodModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/hat/HatModule.java b/src/main/java/me/alexdevs/solstice/modules/hat/HatModule.java index 6ba8eb1d..f06f06e2 100644 --- a/src/main/java/me/alexdevs/solstice/modules/hat/HatModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/hat/HatModule.java @@ -5,7 +5,7 @@ import me.alexdevs.solstice.modules.hat.commands.HatCommand; import me.alexdevs.solstice.modules.hat.data.HatConfig; import me.alexdevs.solstice.modules.hat.data.HatLocale; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; @@ -14,7 +14,7 @@ public class HatModule extends ModuleBase.Toggleable { - public HatModule(ResourceLocation id) { + public HatModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/hat/commands/HatCommand.java b/src/main/java/me/alexdevs/solstice/modules/hat/commands/HatCommand.java index 8b606bb9..bc0cd74f 100644 --- a/src/main/java/me/alexdevs/solstice/modules/hat/commands/HatCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/hat/commands/HatCommand.java @@ -2,8 +2,12 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import me.alexdevs.solstice.api.module.ModCommand; +import me.alexdevs.solstice.api.utils.ResourceUtils; import me.alexdevs.solstice.modules.hat.HatModule; import net.minecraft.commands.CommandSourceStack; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.item.Item; import java.util.List; @@ -35,7 +39,7 @@ public LiteralArgumentBuilder command(String name) { var config = module.getConfig(); - var itemId = handStack.getItemHolder().unwrapKey().get().location().toString(); + var itemId = ResourceUtils.identifier(handStack.getItemHolder().unwrapKey().get()).toString(); var tags = handStack.getTags(); if (config.whitelistFilter) { if(!module.isInFilter(itemId) && !module.isInFilter(tags)) { @@ -52,9 +56,14 @@ public LiteralArgumentBuilder command(String name) { //handStack.streamTags().toList().get(0).id().toString(); var inventory = player.getInventory(); + + //? if < 1.21.11 { var oldHeadStack = inventory.armor.get(3); // head slot - inventory.setItem(inventory.selected, oldHeadStack.copyAndClear()); - inventory.armor.set(3, handStack.copyAndClear()); + //inventory.setItem(inventory.selected, oldHeadStack.copyAndClear()); + //? } else { + /*var oldHeadStack = player.getItemBySlot(EquipmentSlot.HEAD); + inventory.setItem(inventory.getSelectedSlot(), oldHeadStack.copyAndClear()); + *///? } context.getSource().sendSuccess(() -> module.locale().get("success"), false); diff --git a/src/main/java/me/alexdevs/solstice/modules/heal/HealModule.java b/src/main/java/me/alexdevs/solstice/modules/heal/HealModule.java index e7a72f13..0af7a1da 100644 --- a/src/main/java/me/alexdevs/solstice/modules/heal/HealModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/heal/HealModule.java @@ -2,11 +2,11 @@ import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.modules.heal.commands.HealCommand; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import me.alexdevs.solstice.modules.heal.data.HealLocale; public class HealModule extends ModuleBase.Toggleable { - public HealModule(ResourceLocation id) { + public HealModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/helpOp/HelpOpModule.java b/src/main/java/me/alexdevs/solstice/modules/helpOp/HelpOpModule.java index a04c1cc7..5d6affad 100644 --- a/src/main/java/me/alexdevs/solstice/modules/helpOp/HelpOpModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/helpOp/HelpOpModule.java @@ -4,10 +4,10 @@ import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.modules.helpOp.commands.HelpOpCommand; import me.alexdevs.solstice.modules.helpOp.data.HelpOpLocale; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; public class HelpOpModule extends ModuleBase.Toggleable { - public HelpOpModule(ResourceLocation id) { + public HelpOpModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/home/HomeModule.java b/src/main/java/me/alexdevs/solstice/modules/home/HomeModule.java index b555c758..1f2a9dc2 100644 --- a/src/main/java/me/alexdevs/solstice/modules/home/HomeModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/home/HomeModule.java @@ -6,13 +6,13 @@ import me.alexdevs.solstice.modules.home.data.HomeConfig; import me.alexdevs.solstice.modules.home.data.HomeLocale; import me.alexdevs.solstice.modules.home.data.HomePlayerData; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import java.util.UUID; public class HomeModule extends ModuleBase.Toggleable { - public HomeModule(ResourceLocation id) { + public HomeModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/home/commands/HomeOtherCommand.java b/src/main/java/me/alexdevs/solstice/modules/home/commands/HomeOtherCommand.java index 603cbe66..a6b75400 100644 --- a/src/main/java/me/alexdevs/solstice/modules/home/commands/HomeOtherCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/home/commands/HomeOtherCommand.java @@ -7,6 +7,7 @@ import eu.pb4.placeholders.api.PlaceholderContext; import me.alexdevs.solstice.api.command.LocalGameProfile; import me.alexdevs.solstice.api.module.ModCommand; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.home.HomeModule; import net.minecraft.commands.CommandSourceStack; import net.minecraft.network.chat.Component; @@ -44,11 +45,11 @@ private int execute(CommandContext context, String name) thr var playerContext = PlaceholderContext.of(context.getSource().getPlayer()); - var data = module.getData(profile.getId()); + var data = module.getData(PlayerUtils.getId(profile)); var placeholders = Map.of( "home", Component.nullToEmpty(name), - "owner", Component.nullToEmpty(profile.getName()) + "owner", Component.nullToEmpty(PlayerUtils.getName(profile)) ); if (!data.homes.containsKey(name)) { diff --git a/src/main/java/me/alexdevs/solstice/modules/home/commands/HomesCommand.java b/src/main/java/me/alexdevs/solstice/modules/home/commands/HomesCommand.java index a4b121e3..5ec9990a 100644 --- a/src/main/java/me/alexdevs/solstice/modules/home/commands/HomesCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/home/commands/HomesCommand.java @@ -8,6 +8,7 @@ import eu.pb4.placeholders.api.PlaceholderContext; import me.alexdevs.solstice.api.command.LocalGameProfile; import me.alexdevs.solstice.api.module.ModCommand; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.home.HomeModule; import net.minecraft.commands.CommandSourceStack; import net.minecraft.network.chat.Component; @@ -86,12 +87,12 @@ private int executeOthers(CommandContext context, GameProfil var player = context.getSource().getPlayerOrException(); var playerContext = PlaceholderContext.of(player); - var data = module.getData(profile.getId()); + var data = module.getData(PlayerUtils.getId(profile)); var homeList = data.homes.keySet().stream().sorted().toList(); if (homeList.isEmpty()) { var placeholders = Map.of( - "owner", Component.nullToEmpty(profile.getName()) + "owner", Component.nullToEmpty(PlayerUtils.getName(profile)) ); context.getSource().sendSuccess(() -> module.locale().get( "noHomesOther", @@ -109,7 +110,7 @@ private int executeOthers(CommandContext context, GameProfil } var placeholders = Map.of( "home", Component.nullToEmpty(homeList.get(i)), - "owner", Component.nullToEmpty(profile.getName()) + "owner", Component.nullToEmpty(PlayerUtils.getName(profile)) ); listText = listText.append(module.locale().get( @@ -121,7 +122,7 @@ private int executeOthers(CommandContext context, GameProfil var placeholders = Map.of( "homeList", listText, - "owner", Component.nullToEmpty(profile.getName()) + "owner", Component.nullToEmpty(PlayerUtils.getName(profile)) ); context.getSource().sendSuccess(() -> module.locale().get( "homeListOther", diff --git a/src/main/java/me/alexdevs/solstice/modules/ignite/IgniteModule.java b/src/main/java/me/alexdevs/solstice/modules/ignite/IgniteModule.java index b5e9a6ac..71485119 100644 --- a/src/main/java/me/alexdevs/solstice/modules/ignite/IgniteModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/ignite/IgniteModule.java @@ -2,11 +2,11 @@ import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.modules.ignite.commands.IgniteCommand; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; public class IgniteModule extends ModuleBase.Toggleable { - public IgniteModule(ResourceLocation id) { + public IgniteModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/ignore/IgnoreModule.java b/src/main/java/me/alexdevs/solstice/modules/ignore/IgnoreModule.java index 7f8b5676..b15fb60b 100644 --- a/src/main/java/me/alexdevs/solstice/modules/ignore/IgnoreModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/ignore/IgnoreModule.java @@ -8,14 +8,14 @@ import me.alexdevs.solstice.modules.ignore.data.IgnoreLocale; import me.alexdevs.solstice.modules.ignore.data.IgnorePlayerData; import me.lucko.fabric.api.permissions.v0.Permissions; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.server.level.ServerPlayer; import java.util.UUID; public class IgnoreModule extends ModuleBase.Toggleable { - public IgnoreModule(ResourceLocation id) { + public IgnoreModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/ignore/commands/IgnoreCommand.java b/src/main/java/me/alexdevs/solstice/modules/ignore/commands/IgnoreCommand.java index 27e869d1..97e40626 100644 --- a/src/main/java/me/alexdevs/solstice/modules/ignore/commands/IgnoreCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/ignore/commands/IgnoreCommand.java @@ -4,6 +4,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import eu.pb4.placeholders.api.PlaceholderContext; import me.alexdevs.solstice.api.module.ModCommand; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.ignore.IgnoreModule; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.SharedSuggestionProvider; @@ -34,46 +35,35 @@ public LiteralArgumentBuilder command(String name) { .suggests((context, builder) -> { var player = context.getSource().getPlayerOrException(); var playerManager = context.getSource().getServer().getPlayerList(); - return SharedSuggestionProvider.suggest(Arrays.stream(playerManager.getPlayerNamesArray()).filter(s -> !s.equals(player.getGameProfile().getName())), builder); + return SharedSuggestionProvider.suggest(Arrays.stream(playerManager.getPlayerNamesArray()).filter(s -> !s.equals(PlayerUtils.getName(player.getGameProfile()))), builder); }) .executes(context -> { var player = context.getSource().getPlayerOrException(); - var targetName = StringArgumentType.getString(context, "target"); + var profileOpt = PlayerUtils.getProfile(context.getSource().getServer(), targetName); + var playerContext = PlaceholderContext.of(player); - //? >= 1.21.1 - context.getSource().getServer().getProfileCache().getAsync(targetName).thenAcceptAsync(profileOpt -> { - //? < 1.21.1 - //context.getSource().getServer().getProfileCache().getAsync(targetName, profileOpt -> { - - var playerContext = PlaceholderContext.of(player); - - if (profileOpt.isEmpty()) { - context.getSource().sendSuccess(() -> module.locale().get("playerNotFound", playerContext), false); - return; - } + if (profileOpt.isEmpty()) { + context.getSource().sendSuccess(() -> module.locale().get("playerNotFound", playerContext), false); + } else { var profile = profileOpt.get(); - if (profile.getId().equals(player.getGameProfile().getId())) { + if (PlayerUtils.getId(profile).equals(PlayerUtils.getId(player.getGameProfile()))) { context.getSource().sendSuccess(() -> module.locale().get("targetIsSelf", playerContext), false); - return; - } - - var playerData = module.getPlayerData(player.getUUID()); - - var map = Map.of("targetName", Component.nullToEmpty(profile.getName())); - - if (playerData.ignoredPlayers.contains(profile.getId())) { - playerData.ignoredPlayers.remove(profile.getId()); - context.getSource().sendSuccess(() -> module.locale().get("unblockedPlayer", playerContext, map), false); - } else { - playerData.ignoredPlayers.add(profile.getId()); - context.getSource().sendSuccess(() -> module.locale().get("blockedPlayer", playerContext, map), false); + var playerData = module.getPlayerData(player.getUUID()); + var map = Map.of("targetName", Component.nullToEmpty(PlayerUtils.getName(profile))); + + if (playerData.ignoredPlayers.contains(PlayerUtils.getId(profile))) { + playerData.ignoredPlayers.remove(PlayerUtils.getId(profile)); + context.getSource().sendSuccess(() -> module.locale().get("unblockedPlayer", playerContext, map), false); + } else { + playerData.ignoredPlayers.add(PlayerUtils.getId(profile)); + context.getSource().sendSuccess(() -> module.locale().get("blockedPlayer", playerContext, map), false); + } } - }); - + } return 1; })); } diff --git a/src/main/java/me/alexdevs/solstice/modules/ignore/commands/IgnoreListCommand.java b/src/main/java/me/alexdevs/solstice/modules/ignore/commands/IgnoreListCommand.java index 7e9854fc..ab4c02e9 100644 --- a/src/main/java/me/alexdevs/solstice/modules/ignore/commands/IgnoreListCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/ignore/commands/IgnoreListCommand.java @@ -3,6 +3,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import eu.pb4.placeholders.api.PlaceholderContext; import me.alexdevs.solstice.api.module.ModCommand; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.ignore.IgnoreModule; import net.minecraft.commands.CommandSourceStack; import net.minecraft.network.chat.Component; @@ -47,9 +48,9 @@ public LiteralArgumentBuilder command(String name) { } String playerName; - var gameProfile = context.getSource().getServer().getProfileCache().get(ignoreList.get(i)); + var gameProfile = PlayerUtils.getProfile(context.getSource().getServer(),ignoreList.get(i)); if (gameProfile.isPresent()) { - playerName = gameProfile.get().getName(); + playerName = PlayerUtils.getName(gameProfile.get()); } else { playerName = ignoreList.get(i).toString(); } diff --git a/src/main/java/me/alexdevs/solstice/modules/info/InfoModule.java b/src/main/java/me/alexdevs/solstice/modules/info/InfoModule.java index f5795026..9707770f 100644 --- a/src/main/java/me/alexdevs/solstice/modules/info/InfoModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/info/InfoModule.java @@ -12,7 +12,7 @@ import me.alexdevs.solstice.modules.info.data.InfoLocale; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import org.jetbrains.annotations.Nullable; import java.io.IOException; @@ -32,7 +32,7 @@ public class InfoModule extends ModuleBase.Toggleable { public final String nameFilterRegex = "[^a-z0-9-]"; private final Path infoDir; - public InfoModule(ResourceLocation id) { + public InfoModule(SolsticeIdentifier id) { super(id); infoDir = Paths.configDirectory.resolve("info"); } diff --git a/src/main/java/me/alexdevs/solstice/modules/inventorySee/InventorySeeModule.java b/src/main/java/me/alexdevs/solstice/modules/inventorySee/InventorySeeModule.java index d12b50fc..59f70a85 100644 --- a/src/main/java/me/alexdevs/solstice/modules/inventorySee/InventorySeeModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/inventorySee/InventorySeeModule.java @@ -4,11 +4,11 @@ import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.modules.inventorySee.commands.InventorySeeCommand; import me.alexdevs.solstice.modules.inventorySee.data.InventorySeeLocale; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; public class InventorySeeModule extends ModuleBase.Toggleable { - public InventorySeeModule(ResourceLocation id) { + public InventorySeeModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/inventorySee/commands/InventorySeeCommand.java b/src/main/java/me/alexdevs/solstice/modules/inventorySee/commands/InventorySeeCommand.java index f1e7bca5..ad008f82 100644 --- a/src/main/java/me/alexdevs/solstice/modules/inventorySee/commands/InventorySeeCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/inventorySee/commands/InventorySeeCommand.java @@ -65,8 +65,8 @@ public LiteralArgumentBuilder command(String name) { .executes(context -> { var source = context.getSource(); var player = source.getPlayerOrException(); - var targetProfile = LocalGameProfile.getProfile(context, "player"); - var targetOnline = PlayerUtils.isOnline(targetProfile.getId()); + var profile = LocalGameProfile.getProfile(context, "player"); + var targetOnline = PlayerUtils.isOnline(PlayerUtils.getId(profile)); if (!targetOnline && !Permissions.check(player, getPermissionNode("offline"), 3)) { source.sendSuccess(() -> module.locale().get("offlineNotAllowed"), false); @@ -75,14 +75,14 @@ public LiteralArgumentBuilder command(String name) { ServerPlayer target; if (targetOnline) { - target = context.getSource().getServer().getPlayerList().getPlayer(targetProfile.getId()); + target = context.getSource().getServer().getPlayerList().getPlayer(PlayerUtils.getId(profile)); if (Permissions.check(target, getPermissionNode("exempt"), 3)) { source.sendSuccess(() -> module.locale().get("exempt"), false); return 0; } } else { - target = PlayerUtils.loadOfflinePlayer(targetProfile); - if (Permissions.check(targetProfile, getPermissionNode("exempt"), 3, source.getServer()).getNow(false)) { + target = PlayerUtils.loadOfflinePlayer(profile); + if (Permissions.check(profile, getPermissionNode("exempt"), 3, source.getServer()).getNow(false)) { source.sendSuccess(() -> module.locale().get("exempt"), false); return 0; } @@ -121,7 +121,7 @@ public void onClose() { container.open(); var map = Map.of( - "user", Component.nullToEmpty(target.getGameProfile().getName()) + "user", Component.nullToEmpty(PlayerUtils.getName(target.getGameProfile())) ); source.sendSuccess(() -> module.locale().get("openedInventory", map), true); @@ -131,8 +131,8 @@ public void onClose() { .executes(context -> { var source = context.getSource(); var player = source.getPlayerOrException(); - var targetProfile = LocalGameProfile.getProfile(context, "player"); - var targetOnline = PlayerUtils.isOnline(targetProfile.getId()); + var profile = LocalGameProfile.getProfile(context, "player"); + var targetOnline = PlayerUtils.isOnline(PlayerUtils.getId(profile)); if (!targetOnline && !Permissions.check(player, getPermissionNode("offline"), 3)) { source.sendSuccess(() -> module.locale().get("offlineNotAllowed"), false); @@ -141,14 +141,14 @@ public void onClose() { ServerPlayer target; if (targetOnline) { - target = context.getSource().getServer().getPlayerList().getPlayer(targetProfile.getId()); + target = context.getSource().getServer().getPlayerList().getPlayer(PlayerUtils.getId(profile)); if (Permissions.check(target, getPermissionNode("exempt"), 3)) { source.sendSuccess(() -> module.locale().get("exempt"), false); return 0; } } else { - target = PlayerUtils.loadOfflinePlayer(targetProfile); - if (Permissions.check(targetProfile, getPermissionNode("exempt"), 3, source.getServer()).getNow(false)) { + target = PlayerUtils.loadOfflinePlayer(profile); + if (Permissions.check(profile, getPermissionNode("exempt"), 3, source.getServer()).getNow(false)) { source.sendSuccess(() -> module.locale().get("exempt"), false); return 0; } @@ -209,7 +209,7 @@ public void onClose() { container.open(); var map = Map.of( - "user", Component.nullToEmpty(target.getGameProfile().getName()) + "user", Component.nullToEmpty(PlayerUtils.getName(target.getGameProfile())) ); source.sendSuccess(() -> module.locale().get("openedTrinkets", map), true); diff --git a/src/main/java/me/alexdevs/solstice/modules/item/ItemModule.java b/src/main/java/me/alexdevs/solstice/modules/item/ItemModule.java index a99a4969..72ac41dd 100644 --- a/src/main/java/me/alexdevs/solstice/modules/item/ItemModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/item/ItemModule.java @@ -7,10 +7,10 @@ import me.alexdevs.solstice.modules.item.commands.MoreCommand; import me.alexdevs.solstice.modules.item.commands.RepairCommand; import me.alexdevs.solstice.modules.item.data.ItemLocale; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; public class ItemModule extends ModuleBase.Toggleable { - public ItemModule(ResourceLocation id) { + public ItemModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/jail/JailModule.java b/src/main/java/me/alexdevs/solstice/modules/jail/JailModule.java index 8ac0b549..700c491b 100644 --- a/src/main/java/me/alexdevs/solstice/modules/jail/JailModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/jail/JailModule.java @@ -20,7 +20,7 @@ import net.fabricmc.fabric.api.message.v1.ServerMessageEvents; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; @@ -35,7 +35,7 @@ public class JailModule extends ModuleBase.Toggleable { - public JailModule(ResourceLocation id) { + public JailModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/jail/commands/CheckJailCommand.java b/src/main/java/me/alexdevs/solstice/modules/jail/commands/CheckJailCommand.java index 005e07a1..65b4ce4c 100644 --- a/src/main/java/me/alexdevs/solstice/modules/jail/commands/CheckJailCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/jail/commands/CheckJailCommand.java @@ -6,6 +6,7 @@ import me.alexdevs.solstice.api.command.LocalGameProfile; import me.alexdevs.solstice.api.command.TimeSpan; import me.alexdevs.solstice.api.module.ModCommand; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.core.coreModule.data.CoreConfig; import me.alexdevs.solstice.modules.jail.JailModule; import net.minecraft.commands.CommandSourceStack; @@ -35,8 +36,8 @@ public LiteralArgumentBuilder command(String name) { .then(Commands.argument("user", StringArgumentType.word()) .suggests(LocalGameProfile::suggest) .executes(context -> { - var user = LocalGameProfile.getProfile(context, "user"); - var data = module.getPlayer(user.getId()); + var profile = LocalGameProfile.getProfile(context, "user"); + var data = module.getPlayer(PlayerUtils.getId(profile)); if (!data.jailed) { context.getSource().sendSuccess(() -> module.locale().get("notJailed"), false); @@ -47,9 +48,9 @@ public LiteralArgumentBuilder command(String name) { if (new UUID(0, 0).equals(data.jailedBy)) { operator = "Server"; } else { - var opProfile = context.getSource().getServer().getProfileCache().get(data.jailedBy); + var opProfile = PlayerUtils.getProfile(context.getSource().getServer(), data.jailedBy); if (opProfile.isPresent()) { - operator = opProfile.get().getName(); + operator = PlayerUtils.getName(opProfile.get()); } else { operator = data.jailedBy != null ? data.jailedBy.toString() : "Unknown"; } @@ -73,7 +74,7 @@ public LiteralArgumentBuilder command(String name) { var df = new SimpleDateFormat(coreConfig.dateTimeFormat); var map = Map.of( - "player", Component.nullToEmpty(user.getName()), + "player", Component.nullToEmpty(PlayerUtils.getName(profile)), "jail", Component.nullToEmpty(data.jailName), "operator", Component.nullToEmpty(operator), "reason", Component.nullToEmpty(reason), diff --git a/src/main/java/me/alexdevs/solstice/modules/jail/commands/JailCommand.java b/src/main/java/me/alexdevs/solstice/modules/jail/commands/JailCommand.java index ca7159e2..93cc7287 100644 --- a/src/main/java/me/alexdevs/solstice/modules/jail/commands/JailCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/jail/commands/JailCommand.java @@ -11,6 +11,7 @@ import me.alexdevs.solstice.api.command.LocalGameProfile; import me.alexdevs.solstice.api.command.TimeSpan; import me.alexdevs.solstice.api.module.ModCommand; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.core.coreModule.data.CorePlayerData; import me.alexdevs.solstice.modules.jail.JailModule; import me.lucko.fabric.api.permissions.v0.Permissions; @@ -60,8 +61,8 @@ private int execute(CommandContext context, int seconds, @Nu var source = context.getSource(); var profile = LocalGameProfile.getProfile(context, "user"); - var data = module.getPlayer(profile.getId()); - var coreData = Solstice.playerData.get(profile.getId()).getData(CorePlayerData.class); + var data = module.getPlayer(PlayerUtils.getId(profile)); + var coreData = Solstice.playerData.get(PlayerUtils.getId(profile)).getData(CorePlayerData.class); if (data.jailed) { source.sendSuccess(() -> module.locale().get("alreadyJailed"), false); @@ -82,7 +83,7 @@ private int execute(CommandContext context, int seconds, @Nu return; } - var player = source.getServer().getPlayerList().getPlayer(profile.getId()); + var player = source.getServer().getPlayerList().getPlayer(PlayerUtils.getId(profile)); data.jailed = true; data.jailedBy = source.isPlayer() ? source.getPlayer().getUUID() : new UUID(0L, 0L); @@ -98,7 +99,7 @@ private int execute(CommandContext context, int seconds, @Nu } var map = Map.of( - "player", Component.nullToEmpty(profile.getName()), + "player", Component.nullToEmpty(PlayerUtils.getName(profile)), "jail", Component.nullToEmpty(jailName), "duration", Component.nullToEmpty(TimeSpan.toLongString(seconds)), "reason", Component.nullToEmpty(reason) diff --git a/src/main/java/me/alexdevs/solstice/modules/jail/commands/UnjailCommand.java b/src/main/java/me/alexdevs/solstice/modules/jail/commands/UnjailCommand.java index 5a64ea69..6297d626 100644 --- a/src/main/java/me/alexdevs/solstice/modules/jail/commands/UnjailCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/jail/commands/UnjailCommand.java @@ -4,6 +4,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import me.alexdevs.solstice.api.command.LocalGameProfile; import me.alexdevs.solstice.api.module.ModCommand; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.jail.JailModule; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; @@ -31,17 +32,17 @@ public LiteralArgumentBuilder command(String name) { .executes(context -> { var profile = LocalGameProfile.getProfile(context, "user"); - var data = module.getPlayer(profile.getId()); + var data = module.getPlayer(PlayerUtils.getId(profile)); if (!data.jailed) { context.getSource().sendSuccess(() -> module.locale().get("notJailed"), false); return 0; } - module.unjailPlayer(profile.getId()); + module.unjailPlayer(PlayerUtils.getId(profile)); var map = Map.of( - "player", Component.nullToEmpty(profile.getName()) + "player", Component.nullToEmpty(PlayerUtils.getName(profile)) ); context.getSource().sendSuccess(() -> module.locale().get("unjailed", map), false); diff --git a/src/main/java/me/alexdevs/solstice/modules/kick/KickModule.java b/src/main/java/me/alexdevs/solstice/modules/kick/KickModule.java index ff4bfca2..2fbd9f7a 100644 --- a/src/main/java/me/alexdevs/solstice/modules/kick/KickModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/kick/KickModule.java @@ -2,11 +2,11 @@ import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.modules.kick.commands.KickCommand; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; public class KickModule extends ModuleBase.Toggleable { - public KickModule(ResourceLocation id) { + public KickModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/kit/KitModule.java b/src/main/java/me/alexdevs/solstice/modules/kit/KitModule.java index 12c4b38e..b22ced57 100644 --- a/src/main/java/me/alexdevs/solstice/modules/kit/KitModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/kit/KitModule.java @@ -7,7 +7,7 @@ import me.alexdevs.solstice.modules.kit.commands.KitsCommand; import me.alexdevs.solstice.modules.kit.data.*; import me.lucko.fabric.api.permissions.v0.Permissions; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.item.ItemStack; @@ -17,7 +17,7 @@ public class KitModule extends ModuleBase.Toggleable { - public KitModule(ResourceLocation id) { + public KitModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/kit/Utils.java b/src/main/java/me/alexdevs/solstice/modules/kit/Utils.java index 95e8da06..17af8514 100644 --- a/src/main/java/me/alexdevs/solstice/modules/kit/Utils.java +++ b/src/main/java/me/alexdevs/solstice/modules/kit/Utils.java @@ -8,7 +8,10 @@ //? if >= 1.21.1 { import me.alexdevs.solstice.Solstice; //? } +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtOps; import net.minecraft.nbt.TagParser; +import net.minecraft.resources.RegistryOps; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; @@ -16,19 +19,31 @@ import java.util.List; public class Utils { + + + + public static String serializeItemStack(ItemStack itemStack) { //? if >= 1.21.1 { var registry = Solstice.server.registryAccess(); - var nbt = itemStack.save(registry); - //? } else { + var registryOps = RegistryOps.create(NbtOps.INSTANCE, registry); + return ItemStack.CODEC.encodeStart(registryOps, itemStack).getOrThrow().toString(); + //? } elif >= 1.21.1 { + /*var registry = Solstice.server.registryAccess(); + return itemStack.save(registry).getAsString(); + *///? } else { /*var nbt = new CompoundTag(); - itemStack.save(nbt); + return itemStack.save(nbt).getAsString(); *///? } - return nbt.getAsString(); } public static ItemStack deserializeItemStack(String string) throws CommandSyntaxException { - //? if >= 1.21.1 { + //? if >= 1.21.11 { + /*var registry = Solstice.server.registryAccess(); + var registryOps = RegistryOps.create(NbtOps.INSTANCE, registry); + var tag = TagParser.parseCompoundFully(string); + return ItemStack.OPTIONAL_CODEC.parse(registryOps, tag).getOrThrow(); + *///? } elif >= 1.21.1 { var registry = Solstice.server.registryAccess(); return ItemStack.parseOptional(registry, TagParser.parseTag(string)); //? } else { diff --git a/src/main/java/me/alexdevs/solstice/modules/mail/MailModule.java b/src/main/java/me/alexdevs/solstice/modules/mail/MailModule.java index a0d34ecc..1c20517e 100644 --- a/src/main/java/me/alexdevs/solstice/modules/mail/MailModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/mail/MailModule.java @@ -9,7 +9,7 @@ import me.alexdevs.solstice.modules.mail.data.MailLocale; import me.alexdevs.solstice.modules.mail.data.MailPlayerData; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import java.util.List; import java.util.UUID; @@ -17,7 +17,7 @@ public class MailModule extends ModuleBase.Toggleable { - public MailModule(ResourceLocation id) { + public MailModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/mail/commands/MailCommand.java b/src/main/java/me/alexdevs/solstice/modules/mail/commands/MailCommand.java index 828acdc8..f27d6aaf 100644 --- a/src/main/java/me/alexdevs/solstice/modules/mail/commands/MailCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/mail/commands/MailCommand.java @@ -6,6 +6,7 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import eu.pb4.placeholders.api.PlaceholderContext; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.mail.data.PlayerMail; import me.alexdevs.solstice.api.command.LocalGameProfile; import me.alexdevs.solstice.api.module.ModCommand; @@ -158,20 +159,20 @@ private int deleteMail(CommandContext context) throws Comman private int sendMail(CommandContext context) throws CommandSyntaxException { var sender = context.getSource().getPlayerOrException(); - var recipient = LocalGameProfile.getProfile(context, "recipient"); + var profile = LocalGameProfile.getProfile(context, "recipient"); var message = StringArgumentType.getString(context, "message"); var server = context.getSource().getServer(); var mail = new PlayerMail(message, sender.getUUID()); - var actuallySent = module.sendMail(recipient.getId(), mail); + var actuallySent = module.sendMail(PlayerUtils.getId(profile), mail); var senderContext = PlaceholderContext.of(sender); context.getSource().sendSuccess(() -> module.locale().get("mailSent", senderContext), false); if (actuallySent) { - var recPlayer = server.getPlayerList().getPlayer(recipient.getId()); + var recPlayer = server.getPlayerList().getPlayer(PlayerUtils.getId(profile)); if (recPlayer == null) { return 1; } diff --git a/src/main/java/me/alexdevs/solstice/modules/miscellaneous/MiscellaneousModule.java b/src/main/java/me/alexdevs/solstice/modules/miscellaneous/MiscellaneousModule.java index 92b819e0..854f3d92 100644 --- a/src/main/java/me/alexdevs/solstice/modules/miscellaneous/MiscellaneousModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/miscellaneous/MiscellaneousModule.java @@ -1,11 +1,12 @@ package me.alexdevs.solstice.modules.miscellaneous; import me.alexdevs.solstice.api.module.ModuleBase; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.miscellaneous.commands.*; import me.alexdevs.solstice.modules.miscellaneous.data.MiscellaneousLocale; import net.fabricmc.fabric.api.entity.event.v1.EntitySleepEvents; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.LivingEntity; @@ -18,7 +19,7 @@ public class MiscellaneousModule extends ModuleBase.Toggleable { private final Map commandSleeping = new ConcurrentHashMap<>(); - public MiscellaneousModule(ResourceLocation id) { + public MiscellaneousModule(SolsticeIdentifier id) { super(id); } @@ -37,16 +38,11 @@ public void init() { ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> commandSleeping.remove(handler.getPlayer().getUUID())); EntitySleepEvents.STOP_SLEEPING.register((entity, pos) -> commandSleeping.remove(entity.getUUID())); - EntitySleepEvents.ALLOW_SLEEP_TIME.register((player, pos, vanillaResult) -> { - if (commandSleeping.getOrDefault(player.getUUID(), false)) { - return InteractionResult.SUCCESS; - } - - return InteractionResult.PASS; - }); - EntitySleepEvents.ALLOW_RESETTING_TIME.register(player -> { if (commandSleeping.getOrDefault(player.getUUID(), false)) { + //? >= 1.21.11 + //return !(!player.level().dimensionType().hasFixedTime() && player.level().getSkyDarken() < 4); + //? < 1.21.11 return !player.level().isDay(); } @@ -69,7 +65,7 @@ public void putToSleep(LivingEntity entity) { commandSleeping.put(entity.getUUID(), true); entity.startSleeping(entity.blockPosition()); if (entity instanceof ServerPlayer player) { - player.serverLevel().updateSleepingPlayerList(); + PlayerUtils.getLevel(player).updateSleepingPlayerList(); } } } diff --git a/src/main/java/me/alexdevs/solstice/modules/miscellaneous/commands/KittyCannonCommand.java b/src/main/java/me/alexdevs/solstice/modules/miscellaneous/commands/KittyCannonCommand.java index 0c7449d4..cc16d972 100644 --- a/src/main/java/me/alexdevs/solstice/modules/miscellaneous/commands/KittyCannonCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/miscellaneous/commands/KittyCannonCommand.java @@ -4,6 +4,7 @@ import me.alexdevs.solstice.Solstice; import me.alexdevs.solstice.api.module.ModCommand; import me.alexdevs.solstice.api.utils.EntityUtils; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.miscellaneous.DummyExplosion; import me.alexdevs.solstice.modules.miscellaneous.MiscellaneousModule; import net.minecraft.commands.CommandSourceStack; @@ -33,7 +34,7 @@ public LiteralArgumentBuilder command(String name) { .executes(context -> { final var player = context.getSource().getPlayerOrException(); - final var world = player.serverLevel(); + final var world = PlayerUtils.getLevel(player); EntityUtils.createWithCommand(BALL, world, entity -> { entity.setDeltaMovement(player.getLookAngle().scale(3.5)); diff --git a/src/main/java/me/alexdevs/solstice/modules/miscellaneous/commands/NudgeCommand.java b/src/main/java/me/alexdevs/solstice/modules/miscellaneous/commands/NudgeCommand.java index fdeef465..66aa76e6 100644 --- a/src/main/java/me/alexdevs/solstice/modules/miscellaneous/commands/NudgeCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/miscellaneous/commands/NudgeCommand.java @@ -6,6 +6,7 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import me.alexdevs.solstice.api.module.ModCommand; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.miscellaneous.MiscellaneousModule; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; @@ -59,7 +60,7 @@ private int execute(CommandContext context, float power, boo if (!quiet) { if (entity instanceof ServerPlayer player) { var pitch = (float) (Math.sin(random.nextDouble() * Math.PI * 2) / 10 + 1); - player.playNotifySound(SoundEvents.PLAYER_ATTACK_NODAMAGE, SoundSource.MASTER, 1f, pitch); + PlayerUtils.playSound(player, SoundEvents.PLAYER_ATTACK_NODAMAGE, 1f, pitch); } } } diff --git a/src/main/java/me/alexdevs/solstice/modules/miscellaneous/commands/RocketCommand.java b/src/main/java/me/alexdevs/solstice/modules/miscellaneous/commands/RocketCommand.java index b2ce096f..8ba68494 100644 --- a/src/main/java/me/alexdevs/solstice/modules/miscellaneous/commands/RocketCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/miscellaneous/commands/RocketCommand.java @@ -55,11 +55,11 @@ private int execute(CommandContext context, String flags) th } var count = 0; - for (var target : targets) { + for (var player : targets) { count++; if (explode) { - var world = (ServerLevel) target.level(); - var pos = target.position(); + var world = (ServerLevel) player.level(); + var pos = player.position(); DummyExplosion.spawn(world, pos, power * 2); world.playSound(null, pos.x, pos.y, pos.z, @@ -67,8 +67,8 @@ private int execute(CommandContext context, String flags) th 2, 1); } - target.push(0, power, 0); - target.hurtMarked = true; + player.push(0, power, 0); + player.hurtMarked = true; } diff --git a/src/main/java/me/alexdevs/solstice/modules/miscellaneous/commands/SpeedCommand.java b/src/main/java/me/alexdevs/solstice/modules/miscellaneous/commands/SpeedCommand.java index fb2915ac..938fb308 100644 --- a/src/main/java/me/alexdevs/solstice/modules/miscellaneous/commands/SpeedCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/miscellaneous/commands/SpeedCommand.java @@ -75,14 +75,14 @@ private int setWalkingSpeed(CommandContext context, float sp if (speedMultiplier == 1) { //? >= 1.21.1 - instance.removeModifier(id); + instance.removeModifier(id.get()); //? < 1.21.1 //instance.getModifiers().stream().filter(x -> x.getName().equals(id.toString())).findFirst().ifPresent(instance::removeModifier); context.getSource().sendSuccess(() -> module.locale().get("walkSpeedReset", map), true); } else { //? if >= 1.21.1 { - var modifier = new AttributeModifier(id, speedMultiplier, AttributeModifier.Operation.ADD_MULTIPLIED_BASE); + var modifier = new AttributeModifier(id.get(), speedMultiplier, AttributeModifier.Operation.ADD_MULTIPLIED_BASE); instance.addOrUpdateTransientModifier(modifier); //? } else { /*var res = instance.getModifiers().stream().filter(x -> x.getName().equals(id.toString())).findFirst(); diff --git a/src/main/java/me/alexdevs/solstice/modules/miscellaneous/commands/TopCommand.java b/src/main/java/me/alexdevs/solstice/modules/miscellaneous/commands/TopCommand.java index 1d040b4f..fa9a9bdc 100644 --- a/src/main/java/me/alexdevs/solstice/modules/miscellaneous/commands/TopCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/miscellaneous/commands/TopCommand.java @@ -26,7 +26,7 @@ public LiteralArgumentBuilder command(String name) { .executes(context -> { var player = context.getSource().getPlayerOrException(); - var world = player.serverLevel(); + var world = player.level(); var top = world.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, player.blockPosition()); var pos = top.getCenter(); diff --git a/src/main/java/me/alexdevs/solstice/modules/mute/MuteModule.java b/src/main/java/me/alexdevs/solstice/modules/mute/MuteModule.java index 3b227b6f..62b41d89 100644 --- a/src/main/java/me/alexdevs/solstice/modules/mute/MuteModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/mute/MuteModule.java @@ -7,7 +7,7 @@ import me.alexdevs.solstice.modules.mute.data.MuteLocale; import me.alexdevs.solstice.modules.mute.data.MutePlayerData; import net.fabricmc.fabric.api.message.v1.ServerMessageEvents; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import java.util.Date; import java.util.UUID; @@ -15,7 +15,7 @@ public class MuteModule extends ModuleBase.Toggleable { - public MuteModule(ResourceLocation id) { + public MuteModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/mute/commands/MuteCommand.java b/src/main/java/me/alexdevs/solstice/modules/mute/commands/MuteCommand.java index 20e745bf..07049a9c 100644 --- a/src/main/java/me/alexdevs/solstice/modules/mute/commands/MuteCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/mute/commands/MuteCommand.java @@ -7,6 +7,7 @@ import me.alexdevs.solstice.Solstice; import me.alexdevs.solstice.api.command.TimeSpan; import me.alexdevs.solstice.api.module.ModCommand; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.mute.MuteModule; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.arguments.GameProfileArgument; @@ -49,7 +50,7 @@ private int execute(CommandContext context, int timespan) th var date = calendar.getTime(); targets.forEach(profile -> { - var playerData = module.getPlayerData(profile.getId()); + var playerData = module.getPlayerData(PlayerUtils.getId(profile)); playerData.muted = true; if (timespan != 0) { playerData.mutedUntil = date; @@ -76,7 +77,7 @@ private int execute(CommandContext context, int timespan) th var placeholders = Map.of( "count", Component.nullToEmpty(String.valueOf(targets.size())), - "player", Component.nullToEmpty(targets.stream().findFirst().get().getName()), + "player", Component.nullToEmpty(PlayerUtils.getName(targets.stream().findFirst().get())), "timespan", Component.nullToEmpty(TimeSpan.toLongString(timespan)) ); diff --git a/src/main/java/me/alexdevs/solstice/modules/mute/commands/UnmuteCommand.java b/src/main/java/me/alexdevs/solstice/modules/mute/commands/UnmuteCommand.java index 7d145ca3..59929945 100644 --- a/src/main/java/me/alexdevs/solstice/modules/mute/commands/UnmuteCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/mute/commands/UnmuteCommand.java @@ -3,6 +3,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import me.alexdevs.solstice.Solstice; import me.alexdevs.solstice.api.module.ModCommand; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.mute.MuteModule; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.arguments.GameProfileArgument; @@ -33,7 +34,7 @@ public LiteralArgumentBuilder command(String name) { var targets = GameProfileArgument.getGameProfiles(context, "targets"); targets.forEach(profile -> { - var playerData = module.getPlayerData(profile.getId()); + var playerData = module.getPlayerData(PlayerUtils.getId(profile)); playerData.muted = false; playerData.mutedUntil = null; }); @@ -49,7 +50,10 @@ public LiteralArgumentBuilder command(String name) { var placeholders = Map.of( "count", Component.nullToEmpty(String.valueOf(targets.size())), + //? < 1.21.11 "player", Component.nullToEmpty(targets.stream().findFirst().get().getName()) + //? >= 1.21.11 + //"player", Component.nullToEmpty(targets.stream().findFirst().get().name()) ); context.getSource().sendSuccess(() -> module.locale().get(localeKey, placeholders), true); diff --git a/src/main/java/me/alexdevs/solstice/modules/near/NearModule.java b/src/main/java/me/alexdevs/solstice/modules/near/NearModule.java index e14b3ad2..1613fc85 100644 --- a/src/main/java/me/alexdevs/solstice/modules/near/NearModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/near/NearModule.java @@ -5,11 +5,11 @@ import me.alexdevs.solstice.modules.near.commands.NearCommand; import me.alexdevs.solstice.modules.near.data.NearConfig; import me.alexdevs.solstice.modules.near.data.NearLocale; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; public class NearModule extends ModuleBase.Toggleable { - public NearModule(ResourceLocation id) { + public NearModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/near/commands/NearCommand.java b/src/main/java/me/alexdevs/solstice/modules/near/commands/NearCommand.java index 73684051..ffca7eff 100644 --- a/src/main/java/me/alexdevs/solstice/modules/near/commands/NearCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/near/commands/NearCommand.java @@ -6,6 +6,7 @@ import eu.pb4.placeholders.api.PlaceholderContext; import me.alexdevs.solstice.Solstice; import me.alexdevs.solstice.api.module.ModCommand; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.near.NearModule; import me.alexdevs.solstice.modules.near.data.NearConfig; import net.minecraft.commands.CommandSourceStack; @@ -44,7 +45,7 @@ private int execute(CommandContext context, int range, Serve var list = new ArrayList(); var sourcePos = sourcePlayer.position(); - sourcePlayer.serverLevel().players().forEach(targetPlayer -> { + PlayerUtils.getLevel(sourcePlayer).players().forEach(targetPlayer -> { var targetPos = targetPlayer.position(); if (!sourcePlayer.getUUID().equals(targetPlayer.getUUID()) && sourcePos.closerThan(targetPos, range)) { var distance = sourcePos.distanceTo(targetPos); diff --git a/src/main/java/me/alexdevs/solstice/modules/note/NoteModule.java b/src/main/java/me/alexdevs/solstice/modules/note/NoteModule.java index 4e94c01a..56b37f92 100644 --- a/src/main/java/me/alexdevs/solstice/modules/note/NoteModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/note/NoteModule.java @@ -4,6 +4,7 @@ import me.alexdevs.solstice.Solstice; import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.api.text.Components; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.note.commands.NotesCommand; import me.alexdevs.solstice.modules.note.data.Note; import me.alexdevs.solstice.modules.note.data.NoteConfig; @@ -12,7 +13,7 @@ import me.lucko.fabric.api.permissions.v0.Permissions; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import java.util.List; import java.util.Map; @@ -20,7 +21,7 @@ public class NoteModule extends ModuleBase.Toggleable { - public NoteModule(ResourceLocation id) { + public NoteModule(SolsticeIdentifier id) { super(id); } @@ -48,10 +49,10 @@ public void init() { var checkButton = Components.button( locale().raw("checkButton"), locale().raw("hoverCheck"), - "/notes " + player.getGameProfile().getName() + "/notes " + PlayerUtils.getName(player.getGameProfile()) ); final var text = locale().get("loginInfo", context, Map.of( - "user", Component.nullToEmpty(player.getGameProfile().getName()), + "user", Component.nullToEmpty(PlayerUtils.getName(player.getGameProfile())), "notes", Component.nullToEmpty(String.valueOf(notes.size())), "checkButton", checkButton )); diff --git a/src/main/java/me/alexdevs/solstice/modules/note/commands/NotesCommand.java b/src/main/java/me/alexdevs/solstice/modules/note/commands/NotesCommand.java index 26f3893a..002969f6 100644 --- a/src/main/java/me/alexdevs/solstice/modules/note/commands/NotesCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/note/commands/NotesCommand.java @@ -9,6 +9,7 @@ import me.alexdevs.solstice.api.module.ModCommand; import me.alexdevs.solstice.api.text.Components; import me.alexdevs.solstice.api.text.Format; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.core.coreModule.CoreModule; import me.alexdevs.solstice.modules.note.NoteModule; import me.alexdevs.solstice.modules.note.data.Note; @@ -61,8 +62,8 @@ public LiteralArgumentBuilder command(String name) { } private int listNotes(CommandContext context) throws CommandSyntaxException { - var user = LocalGameProfile.getProfile(context, "user"); - var notes = module.getNotes(user.getId()); + var profile = LocalGameProfile.getProfile(context, "user"); + var notes = module.getNotes(PlayerUtils.getId(profile)); if (notes.isEmpty()) { context.getSource().sendSuccess(() -> module.locale().get("emptyNotes"), false); @@ -71,7 +72,7 @@ private int listNotes(CommandContext context) throws Command var output = Component.empty() .append(module.locale().get("noteListHeader", Map.of( - "user", Component.nullToEmpty(user.getName()) + "user", Component.nullToEmpty(PlayerUtils.getName(profile)) ))) .append(Component.nullToEmpty("\n")); @@ -84,7 +85,7 @@ private int listNotes(CommandContext context) throws Command var checkButton = Components.button( module.locale().raw("checkButton"), module.locale().raw("hoverCheck"), - "/notes " + user.getName() + " check " + i + "/notes " + PlayerUtils.getName(profile) + " check " + i ); var senderName = CoreModule.getUsername(note.createdBy); @@ -108,7 +109,7 @@ private int listNotes(CommandContext context) throws Command private int checkNote(CommandContext context) throws CommandSyntaxException { var user = LocalGameProfile.getProfile(context, "user"); - var notes = module.getNotes(user.getId()); + var notes = module.getNotes(PlayerUtils.getId(user)); var index = IntegerArgumentType.getInteger(context, "index"); if (index < 0 || index >= notes.size()) { @@ -121,7 +122,7 @@ private int checkNote(CommandContext context) throws Command var deleteButton = Components.button( module.locale().raw("deleteButton"), module.locale().raw("hoverDelete"), - "/note " + user.getName() + " delete " + index + "/note " + PlayerUtils.getName(user) + " delete " + index ); var operator = CoreModule.getUsername(note.createdBy); @@ -140,7 +141,7 @@ private int checkNote(CommandContext context) throws Command private int deleteNote(CommandContext context) throws CommandSyntaxException { var user = LocalGameProfile.getProfile(context, "user"); - var notes = module.getNotes(user.getId()); + var notes = module.getNotes(PlayerUtils.getId(user)); var index = IntegerArgumentType.getInteger(context, "index"); if (index < notes.size()) { @@ -164,7 +165,7 @@ private int addNote(CommandContext context) throws CommandSy var message = StringArgumentType.getString(context, "message"); var note = new Note(message, operatorId); - var notes = module.getNotes(user.getId()); + var notes = module.getNotes(PlayerUtils.getId(user)); notes.add(note); var index = notes.size() - 1; @@ -174,11 +175,11 @@ private int addNote(CommandContext context) throws CommandSy var checkButton = Components.button( module.locale().raw("checkButton"), module.locale().raw("hoverCheck"), - "/notes " + user.getName() + " check " + index + "/notes " + PlayerUtils.getName(user) + " check " + index ); final var text = module.locale().get("addedNotification", Map.of( "operator", context.getSource().getDisplayName(), - "user", Component.nullToEmpty(user.getName()), + "user", Component.nullToEmpty(PlayerUtils.getName(user)), "checkButton", checkButton )); @@ -194,11 +195,11 @@ private int addNote(CommandContext context) throws CommandSy private int clearNotes(CommandContext context) throws CommandSyntaxException { var user = LocalGameProfile.getProfile(context, "user"); - var notes = module.getNotes(user.getId()); + var notes = module.getNotes(PlayerUtils.getId(user)); notes.clear(); context.getSource().sendSuccess(() -> module.locale().get("notesCleared", Map.of( - "user", Component.nullToEmpty(user.getName()) + "user", Component.nullToEmpty(PlayerUtils.getName(user)) )), true); return 1; diff --git a/src/main/java/me/alexdevs/solstice/modules/notifications/NotificationsModule.java b/src/main/java/me/alexdevs/solstice/modules/notifications/NotificationsModule.java index 9f1b44a2..1c2bf97a 100644 --- a/src/main/java/me/alexdevs/solstice/modules/notifications/NotificationsModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/notifications/NotificationsModule.java @@ -2,6 +2,7 @@ import me.alexdevs.solstice.Solstice; import me.alexdevs.solstice.api.module.ModuleBase; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.ModuleProvider; import me.alexdevs.solstice.modules.afk.AfkModule; import me.alexdevs.solstice.modules.notifications.commands.NotificationsCommand; @@ -10,14 +11,14 @@ import me.alexdevs.solstice.modules.notifications.data.NotificationsPlayerData; import me.alexdevs.solstice.modules.notifications.data.PlayerNotificationSettings; import net.fabricmc.fabric.api.message.v1.ServerMessageEvents; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundSource; public class NotificationsModule extends ModuleBase.Toggleable { private static NotificationsModule instance; - public NotificationsModule(ResourceLocation id) { + public NotificationsModule(SolsticeIdentifier id) { super(id); instance = this; } @@ -30,15 +31,15 @@ public void init() { commands.add(new NotificationsCommand(this)); - ServerMessageEvents.CHAT_MESSAGE.register((message, sender, parameters) -> { + ServerMessageEvents.CHAT_MESSAGE.register((message, sourcePlayer, parameters) -> { var content = message.decoratedContent().getString().toLowerCase(); - sender.getServer().getPlayerList().getPlayers().forEach(player -> { - if (player.equals(sender)) { + sourcePlayer.getServer().getPlayerList().getPlayers().forEach(player -> { + if (player.equals(sourcePlayer)) { return; } - var playerName = player.getGameProfile().getName().toLowerCase(); + var playerName = PlayerUtils.getName(player.getGameProfile()).toLowerCase(); if (content.contains(playerName)) { var settings = getPlayerSettings(player); if (settings.onChat()) { @@ -100,11 +101,11 @@ public void notifyPlayer(ServerPlayer player) { return; var settings = getPlayerSettings(player); - var id = ResourceLocation.tryParse(settings.soundId()); + var id = SolsticeIdentifier.tryParse(settings.soundId()); if (id == null) { return; } - player.playNotifySound(SoundEvent.createVariableRangeEvent(id), SoundSource.MASTER, settings.volume(), settings.pitch()); + PlayerUtils.playSound(player,SoundEvent.createVariableRangeEvent(id.get()),settings.volume(),settings.pitch()); } } diff --git a/src/main/java/me/alexdevs/solstice/modules/notifications/commands/NotificationsCommand.java b/src/main/java/me/alexdevs/solstice/modules/notifications/commands/NotificationsCommand.java index 158d9f23..d04d6303 100644 --- a/src/main/java/me/alexdevs/solstice/modules/notifications/commands/NotificationsCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/notifications/commands/NotificationsCommand.java @@ -7,10 +7,10 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import me.alexdevs.solstice.api.module.ModCommand; +import me.alexdevs.solstice.api.utils.IdUtils; import me.alexdevs.solstice.modules.notifications.NotificationsModule; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; -import net.minecraft.commands.arguments.ResourceLocationArgument; import net.minecraft.commands.synchronization.SuggestionProviders; import net.minecraft.network.chat.Component; @@ -34,7 +34,10 @@ public LiteralArgumentBuilder command(String name) { .requires(require(true)) .then(Commands.literal("set") .then(Commands.literal("sound") - .then(Commands.argument("sound", ResourceLocationArgument.id()) + .then(Commands.argument("sound", IdUtils.idArgument()) + //? >= 1.21.11 + //.suggests(SuggestionProviders.cast(SuggestionProviders.AVAILABLE_SOUNDS)) + //? < 1.21.11 .suggests(SuggestionProviders.AVAILABLE_SOUNDS) .executes(this::setSound) ) @@ -70,7 +73,7 @@ public LiteralArgumentBuilder command(String name) { private int setSound(CommandContext context) throws CommandSyntaxException { var player = context.getSource().getPlayerOrException(); - var soundId = ResourceLocationArgument.getId(context, "sound"); + var soundId = IdUtils.getIdArgument(context, "sound"); var data = module.getPlayerData(player); data.soundId = soundId.toString(); diff --git a/src/main/java/me/alexdevs/solstice/modules/placeholders/PlaceholdersModule.java b/src/main/java/me/alexdevs/solstice/modules/placeholders/PlaceholdersModule.java index e10dfe59..77a91c46 100644 --- a/src/main/java/me/alexdevs/solstice/modules/placeholders/PlaceholdersModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/placeholders/PlaceholdersModule.java @@ -3,20 +3,19 @@ import eu.pb4.placeholders.api.PlaceholderResult; import eu.pb4.placeholders.api.Placeholders; import me.alexdevs.solstice.api.module.ModuleBase; -import me.alexdevs.solstice.api.utils.ResourceUtils; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; public class PlaceholdersModule extends ModuleBase.Toggleable { - + public static final String ENTITY = "entity"; - public PlaceholdersModule(ResourceLocation id) { + public PlaceholdersModule(SolsticeIdentifier id) { super(id); } @Override public void init() { - Placeholders.register(ResourceUtils.location(ENTITY, "name"), (context, str) -> { + Placeholders.register(SolsticeIdentifier.of(ENTITY, "name").get(), (context, str) -> { if (!context.hasEntity()) { return PlaceholderResult.invalid("No entity!"); } @@ -24,7 +23,7 @@ public void init() { return PlaceholderResult.value(entity.getName()); }); - Placeholders.register(ResourceUtils.location(ENTITY, "displayname"), (context, str) -> { + Placeholders.register(SolsticeIdentifier.of(ENTITY, "displayname").get(), (context, str) -> { if (!context.hasEntity()) { return PlaceholderResult.invalid("No entity!"); } @@ -32,7 +31,7 @@ public void init() { return PlaceholderResult.value(entity.getDisplayName()); }); - Placeholders.register(ResourceUtils.location(ENTITY, "uuid"), (context, str) -> { + Placeholders.register(SolsticeIdentifier.of(ENTITY, "uuid").get(), (context, str) -> { if (!context.hasEntity()) { return PlaceholderResult.invalid("No entity!"); } diff --git a/src/main/java/me/alexdevs/solstice/modules/powertool/PowerToolModule.java b/src/main/java/me/alexdevs/solstice/modules/powertool/PowerToolModule.java index 2bfdf906..80d2fb75 100644 --- a/src/main/java/me/alexdevs/solstice/modules/powertool/PowerToolModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/powertool/PowerToolModule.java @@ -6,6 +6,7 @@ import eu.pb4.placeholders.api.Placeholders; import me.alexdevs.solstice.Solstice; import me.alexdevs.solstice.api.module.ModuleBase; +import me.alexdevs.solstice.api.utils.ResourceUtils; import me.alexdevs.solstice.modules.powertool.commands.PowerToolCommand; import me.alexdevs.solstice.modules.powertool.data.PowerToolLocale; import me.alexdevs.solstice.modules.powertool.data.PowerToolPlayerData; @@ -13,7 +14,7 @@ import net.fabricmc.fabric.api.event.player.*; import net.minecraft.commands.CommandSourceStack; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; @@ -32,7 +33,7 @@ public class PowerToolModule extends ModuleBase.Toggleable { private CommandDispatcher dispatcher; - public PowerToolModule(ResourceLocation id) { + public PowerToolModule(SolsticeIdentifier id) { super(id); } @@ -169,7 +170,7 @@ private String resolveCommand(String command, PlaceholderContext context) { } public String getStackId(ItemStack stack) { - return stack.getItemHolder().unwrapKey().get().location().toString(); + return ResourceUtils.identifier(stack.getItemHolder().unwrapKey().get()).toString(); } public PowerToolPlayerData getData(UUID uuid) { diff --git a/src/main/java/me/alexdevs/solstice/modules/restart/RestartModule.java b/src/main/java/me/alexdevs/solstice/modules/restart/RestartModule.java index 523b6bbb..ae323fe3 100644 --- a/src/main/java/me/alexdevs/solstice/modules/restart/RestartModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/restart/RestartModule.java @@ -5,6 +5,7 @@ import me.alexdevs.solstice.api.events.SolsticeEvents; import me.alexdevs.solstice.api.events.TimeBarEvents; import me.alexdevs.solstice.api.module.ModuleBase; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.integrations.ConnectorIntegration; import me.alexdevs.solstice.modules.ModuleProvider; import me.alexdevs.solstice.modules.restart.commands.RestartCommand; @@ -12,7 +13,7 @@ import me.alexdevs.solstice.modules.restart.data.RestartLocale; import me.alexdevs.solstice.modules.timeBar.TimeBar; import me.alexdevs.solstice.modules.timeBar.TimeBarModule; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.server.MinecraftServer; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvents; @@ -35,7 +36,7 @@ public class RestartModule extends ModuleBase.Toggleable { private SoundEvent sound; private ScheduledFuture currentSchedule = null; - public RestartModule(ResourceLocation id) { + public RestartModule(SolsticeIdentifier id) { super(id); } @@ -128,12 +129,12 @@ public void restart() { private void setup() { var soundName = getConfig().restartSound; - var id = ResourceLocation.tryParse(soundName); + var id = SolsticeIdentifier.tryParse(soundName); if (id == null) { Solstice.LOGGER.error("Invalid restart notification sound name {}", soundName); sound = SoundEvents.NOTE_BLOCK_BELL.value(); } else { - sound = SoundEvent.createVariableRangeEvent(id); + sound = SoundEvent.createVariableRangeEvent(id.get()); } } @@ -183,7 +184,7 @@ private void notifyRestart(MinecraftServer server, TimeBar bar) { solstice.broadcast(text); var pitch = getConfig().restartSoundPitch; - server.getPlayerList().getPlayers().forEach(player -> player.playNotifySound(sound, SoundSource.MASTER, 1f, pitch)); + server.getPlayerList().getPlayers().forEach(player -> PlayerUtils.playSound(player,sound, 1f, pitch)); } @Nullable diff --git a/src/main/java/me/alexdevs/solstice/modules/rtp/RTPModule.java b/src/main/java/me/alexdevs/solstice/modules/rtp/RTPModule.java index d91bc369..b1d131dc 100644 --- a/src/main/java/me/alexdevs/solstice/modules/rtp/RTPModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/rtp/RTPModule.java @@ -2,13 +2,14 @@ import me.alexdevs.solstice.Solstice; import me.alexdevs.solstice.api.module.ModuleBase; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.rtp.commands.RTPCommand; import me.alexdevs.solstice.modules.rtp.core.Locator; import me.alexdevs.solstice.modules.rtp.data.RTPConfig; import me.alexdevs.solstice.modules.rtp.data.RTPLocale; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.level.biome.Biome; @@ -18,7 +19,7 @@ public class RTPModule extends ModuleBase.Toggleable { private final ArrayList locators = new ArrayList<>(); - public RTPModule(ResourceLocation id) { + public RTPModule(SolsticeIdentifier id) { super(id); } @@ -37,13 +38,13 @@ public RTPConfig getConfig() { } public Locator createLocator(ServerPlayer player) { - var locator = new Locator(player, player.serverLevel(), getConfig()); + var locator = new Locator(player, PlayerUtils.getLevel(player), getConfig()); locators.add(locator); return locator; } public Locator createLocatorWithBiome(ServerPlayer player, ResourceKey biome) { - var locator = new Locator(player, player.serverLevel(), getConfig(), biome); + var locator = new Locator(player, PlayerUtils.getLevel(player), getConfig(), biome); locators.add(locator); return locator; } diff --git a/src/main/java/me/alexdevs/solstice/modules/rtp/commands/RTPCommand.java b/src/main/java/me/alexdevs/solstice/modules/rtp/commands/RTPCommand.java index 750d5e36..e11b35fa 100644 --- a/src/main/java/me/alexdevs/solstice/modules/rtp/commands/RTPCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/rtp/commands/RTPCommand.java @@ -8,6 +8,7 @@ //? if >= 1.21.1 { import me.alexdevs.solstice.api.utils.RegistryUtils; //? } +import me.alexdevs.solstice.api.utils.ResourceUtils; import me.alexdevs.solstice.modules.rtp.RTPModule; import me.alexdevs.solstice.modules.rtp.core.Locator; import me.lucko.fabric.api.permissions.v0.Permissions; @@ -51,7 +52,7 @@ public LiteralArgumentBuilder command(String name) { var biomes = RegistryUtils.getBiomes(biomeRegistry.get(), false); //? } else { /*var biomeRegistry = this.commandRegistry.holderLookup(Registries.BIOME); - var biomes = biomeRegistry.listElements().map(r -> r.unwrapKey().get().location().toString()).toList(); + var biomes = biomeRegistry.listElements().map(r -> ResourceUtils.identifier(r.unwrapKey().get()).toString()).toList(); *///? } return SharedSuggestionProvider.suggest(biomes, builder); } @@ -68,7 +69,7 @@ private int execute(CommandContext context, boolean withBiom var config = module.getConfig(); if (config.requireWorldPermission) { - var worldName = player.serverLevel().dimension().location().toString(); + var worldName = player.level().dimension().location().toString(); if (!Permissions.check(context.getSource(), getPermissionNode("worlds." + worldName), 2)) { context.getSource().sendSuccess(() -> module.locale().get("noWorldPermission", Map.of("world", Component.nullToEmpty(worldName))), false); return 0; @@ -82,7 +83,7 @@ private int execute(CommandContext context, boolean withBiom if (biomeEntry.unwrapKey().isPresent()) { if (!Permissions.check(context.getSource(), getPermissionNode("exempt.biome"), 2)) { - var biomeId = biome.location().toString(); + var biomeId = ResourceUtils.identifier(biome).toString(); var allowedBiomes = getAllowedBiomes(context.getSource(), context.getSource().getLevel()); if (!allowedBiomes.contains(biomeId)) { context.getSource().sendSuccess(() -> module.locale().get("noBiomePermission"), false); diff --git a/src/main/java/me/alexdevs/solstice/modules/rtp/core/Locator.java b/src/main/java/me/alexdevs/solstice/modules/rtp/core/Locator.java index b6dee08d..b297bbfc 100644 --- a/src/main/java/me/alexdevs/solstice/modules/rtp/core/Locator.java +++ b/src/main/java/me/alexdevs/solstice/modules/rtp/core/Locator.java @@ -7,6 +7,8 @@ import me.alexdevs.solstice.modules.rtp.data.RTPConfig; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.ChunkHolder; import net.minecraft.server.level.ServerLevel; @@ -27,8 +29,11 @@ import java.util.function.Consumer; public class Locator { - + //? < 1.21.11 public static final TicketType RTP_TICKET = TicketType.create("rtp", Comparator.comparingLong(ChunkPos::asLong), 300); + //? >= 1.21.11 + //public static final TicketType RTP_TICKET = Registry.register(BuiltInRegistries.TICKET_TYPE, "RTP", new TicketType(300, TicketType.FLAG_LOADING)); + public final ServerPlayer player; public final ServerLevel world; @@ -174,6 +179,9 @@ private void findValidPlacement() { } private void load() { + //? >= 1.21.11 + //world.getChunkSource().addTicketWithRadius(RTP_TICKET, new ChunkPos(attemptPos),0); + //? < 1.21.11 world.getChunkSource().addRegionTicket(RTP_TICKET, new ChunkPos(attemptPos), 0, attemptPos); } diff --git a/src/main/java/me/alexdevs/solstice/modules/rtp/data/RTPConfig.java b/src/main/java/me/alexdevs/solstice/modules/rtp/data/RTPConfig.java index 847054d7..8df51f97 100644 --- a/src/main/java/me/alexdevs/solstice/modules/rtp/data/RTPConfig.java +++ b/src/main/java/me/alexdevs/solstice/modules/rtp/data/RTPConfig.java @@ -1,6 +1,6 @@ package me.alexdevs.solstice.modules.rtp.data; -import me.alexdevs.solstice.api.utils.ResourceUtils; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; import net.minecraft.world.level.biome.Biome; @@ -68,7 +68,7 @@ public class RTPConfig { public List> parseBiomes() { return prohibitedBiomes.stream() - .map(biomeId -> ResourceKey.create(Registries.BIOME, ResourceUtils.parse(biomeId))) + .map(biomeId -> ResourceKey.create(Registries.BIOME, SolsticeIdentifier.parse(biomeId).get())) .toList(); } } diff --git a/src/main/java/me/alexdevs/solstice/modules/seen/SeenModule.java b/src/main/java/me/alexdevs/solstice/modules/seen/SeenModule.java index 9a988aa0..d53aabd6 100644 --- a/src/main/java/me/alexdevs/solstice/modules/seen/SeenModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/seen/SeenModule.java @@ -4,11 +4,11 @@ import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.modules.seen.commands.SeenCommand; import me.alexdevs.solstice.modules.seen.data.SeenLocale; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; public class SeenModule extends ModuleBase.Toggleable { - public SeenModule(ResourceLocation id) { + public SeenModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/seen/commands/SeenCommand.java b/src/main/java/me/alexdevs/solstice/modules/seen/commands/SeenCommand.java index 8173b9f6..67cde2c6 100644 --- a/src/main/java/me/alexdevs/solstice/modules/seen/commands/SeenCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/seen/commands/SeenCommand.java @@ -7,6 +7,7 @@ import me.alexdevs.solstice.api.command.LocalGameProfile; import me.alexdevs.solstice.api.module.ModCommand; import me.alexdevs.solstice.api.text.Format; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.core.coreModule.CoreModule; import me.alexdevs.solstice.modules.seen.SeenModule; import me.lucko.fabric.api.permissions.v0.Permissions; @@ -59,8 +60,8 @@ public LiteralArgumentBuilder command(String name) { var config = CoreModule.getConfig(); var dateFormatter = new SimpleDateFormat(config.dateTimeFormat); - var player = source.getServer().getPlayerList().getPlayer(profile.getId()); - var playerData = CoreModule.getPlayerData(profile.getId()); + var player = source.getServer().getPlayerList().getPlayer(PlayerUtils.getId(profile)); + var playerData = CoreModule.getPlayerData(PlayerUtils.getId(profile)); if(playerData.firstJoinedDate == null) { source.sendSuccess(() -> module.locale().get("playerNotFound"), false); @@ -79,8 +80,8 @@ public LiteralArgumentBuilder command(String name) { var ipAddress = playerData.ipAddress != null ? playerData.ipAddress : module.locale().raw("unknown"); Map map = Map.of( - "username", Component.nullToEmpty(profile.getName()), - "uuid", Component.nullToEmpty(profile.getId().toString()), + "username", Component.nullToEmpty(PlayerUtils.getName(profile)), + "uuid", Component.nullToEmpty(PlayerUtils.getId(profile).toString()), "firstSeenDate", Component.nullToEmpty(firstSeenDate), "lastSeenDate", Component.nullToEmpty(player != null ? module.locale().raw("online") : lastSeenDate), "ipAddress", Component.nullToEmpty(ipAddress), diff --git a/src/main/java/me/alexdevs/solstice/modules/sign/SignModule.java b/src/main/java/me/alexdevs/solstice/modules/sign/SignModule.java index cd36f661..0575a58b 100644 --- a/src/main/java/me/alexdevs/solstice/modules/sign/SignModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/sign/SignModule.java @@ -3,7 +3,7 @@ import eu.pb4.placeholders.api.parsers.LegacyFormattingParser; import me.alexdevs.solstice.api.module.ModuleBase; import me.lucko.fabric.api.permissions.v0.Permissions; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.server.network.FilteredText; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.block.entity.SignText; @@ -11,7 +11,7 @@ public class SignModule extends ModuleBase.Toggleable { - public SignModule(ResourceLocation id) { + public SignModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/skull/SkullModule.java b/src/main/java/me/alexdevs/solstice/modules/skull/SkullModule.java index 8746c8c9..262a7183 100644 --- a/src/main/java/me/alexdevs/solstice/modules/skull/SkullModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/skull/SkullModule.java @@ -1,18 +1,16 @@ package me.alexdevs.solstice.modules.skull; -import com.mojang.authlib.GameProfile; import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.api.utils.ItemUtils; import me.alexdevs.solstice.modules.skull.commands.SkullCommand; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import java.util.UUID; public class SkullModule extends ModuleBase.Toggleable { - public SkullModule(ResourceLocation id) { + public SkullModule(SolsticeIdentifier id) { super(id); } @@ -20,21 +18,11 @@ public SkullModule(ResourceLocation id) { public void init() { commands.add(new SkullCommand(this)); } + public ItemStack createSkull(String name) { var skull = Items.PLAYER_HEAD.getDefaultInstance(); name = name.substring(0, Math.min(name.length(), 16)); ItemUtils.setProfileByName(skull, name); return skull; } - public ItemStack createSkull(UUID uuid) { - var skull = Items.PLAYER_HEAD.getDefaultInstance(); - ItemUtils.setProfileByUUID(skull, uuid); - return skull; - } - - public ItemStack createSkull(GameProfile profile) { - var skull = Items.PLAYER_HEAD.getDefaultInstance(); - ItemUtils.setProfile(skull, profile); - return skull; - } } diff --git a/src/main/java/me/alexdevs/solstice/modules/skull/commands/SkullCommand.java b/src/main/java/me/alexdevs/solstice/modules/skull/commands/SkullCommand.java index eb90544c..4f0bd28f 100644 --- a/src/main/java/me/alexdevs/solstice/modules/skull/commands/SkullCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/skull/commands/SkullCommand.java @@ -5,6 +5,7 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import me.alexdevs.solstice.api.module.ModCommand; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.skull.SkullModule; import net.minecraft.commands.CommandSourceStack; @@ -27,7 +28,7 @@ public List getNames() { public LiteralArgumentBuilder command(String name) { return literal(name) .requires(require(2)) - .executes(context -> execute(context, context.getSource().getPlayerOrException().getGameProfile().getName())) + .executes(context -> execute(context, PlayerUtils.getName(context.getSource().getPlayerOrException().getGameProfile()))) .then(argument("name", StringArgumentType.word()) .executes(context -> execute(context, StringArgumentType.getString(context, "name")))); } diff --git a/src/main/java/me/alexdevs/solstice/modules/smite/SmiteModule.java b/src/main/java/me/alexdevs/solstice/modules/smite/SmiteModule.java index 3ed32e41..1d47cc5e 100644 --- a/src/main/java/me/alexdevs/solstice/modules/smite/SmiteModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/smite/SmiteModule.java @@ -2,11 +2,11 @@ import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.modules.smite.commands.SmiteCommand; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; public class SmiteModule extends ModuleBase.Toggleable { - public SmiteModule(ResourceLocation id) { + public SmiteModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/smite/commands/SmiteCommand.java b/src/main/java/me/alexdevs/solstice/modules/smite/commands/SmiteCommand.java index 785c3f54..34184a25 100644 --- a/src/main/java/me/alexdevs/solstice/modules/smite/commands/SmiteCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/smite/commands/SmiteCommand.java @@ -7,6 +7,7 @@ import me.alexdevs.solstice.api.Raycast; import me.alexdevs.solstice.api.module.ModCommand; import me.alexdevs.solstice.api.utils.EntityUtils; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.smite.SmiteModule; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.arguments.EntityArgument; @@ -57,7 +58,7 @@ private int executePos(CommandContext context) throws Comman return 0; } - summon(player.serverLevel(), result.getBlockPos().above()); + summon(PlayerUtils.getLevel(player), result.getBlockPos().above()); return 1; } @@ -73,7 +74,7 @@ private int execute(CommandContext context, int times) throw } for (var i = 0; i < times; i++) { targets.forEach(target -> - summon(player.serverLevel(), target.blockPosition()) + summon(PlayerUtils.getLevel(player), target.blockPosition()) ); } diff --git a/src/main/java/me/alexdevs/solstice/modules/spawn/SpawnModule.java b/src/main/java/me/alexdevs/solstice/modules/spawn/SpawnModule.java index e5197192..8891b42b 100644 --- a/src/main/java/me/alexdevs/solstice/modules/spawn/SpawnModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/spawn/SpawnModule.java @@ -11,21 +11,22 @@ import me.alexdevs.solstice.modules.spawn.data.SpawnConfig; import me.alexdevs.solstice.modules.spawn.data.SpawnLocale; import me.alexdevs.solstice.modules.spawn.data.SpawnServerData; -import me.alexdevs.solstice.api.utils.ResourceUtils; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.minecraft.core.BlockPos; +import net.minecraft.core.GlobalPos; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.level.Level; +import net.minecraft.world.level.storage.LevelData; import org.jetbrains.annotations.Nullable; public class SpawnModule extends ModuleBase.Toggleable { - public SpawnModule(ResourceLocation id) { + public SpawnModule(SolsticeIdentifier id) { super(id); } @@ -68,28 +69,19 @@ public void init() { if (spawnData.spawn != null) { var legacy = spawnData.spawn; var world = legacy.getWorld(server); + //? >= 1.21.11 + //world.setRespawnData(new LevelData.RespawnData(new GlobalPos(world.dimension(),new BlockPos((int) legacy.getX(), (int) legacy.getY(), (int) legacy.getZ())), legacy.getYaw(), legacy.getPitch())); + //? < 1.21.11 world.setDefaultSpawnPos(new BlockPos((int) legacy.getX(), (int) legacy.getY(), (int) legacy.getZ()), legacy.getYaw()); spawnData.spawn = null; } }); } - @Deprecated - public ServerLocation getSpawn() { - var serverData = getServerData(); - var spawnPosition = serverData.spawn; - if (spawnPosition == null) { - var server = Solstice.server; - var spawnPos = server.overworld().getSharedSpawnPos(); - spawnPosition = new ServerLocation(spawnPos.getX(), spawnPos.getY(), spawnPos.getZ(), 0, 0, server.overworld()); - } - return spawnPosition; - } - public ServerLevel getGlobalSpawnWorld() { var targetWorld = getConfig().globalSpawn.targetSpawnWorld; - var key = ResourceKey.create(Registries.DIMENSION, ResourceUtils.parse(targetWorld)); + var key = ResourceKey.create(Registries.DIMENSION, SolsticeIdentifier.parse(targetWorld).get()); return Solstice.server.getLevel(key); } @@ -98,8 +90,14 @@ public ServerLocation getGlobalSpawnPosition() { } public ServerLocation getWorldSpawn(ServerLevel world) { + + //? if >= 1.21.11 { + /*var worldSpawnPosition = world.getRespawnData().pos().getCenter(); + var worldSpawnYaw = world.getRespawnData().yaw(); + *///? } else { var worldSpawnPosition = world.getSharedSpawnPos().getCenter(); var worldSpawnYaw = world.getSharedSpawnAngle(); + //? } var worldName = world.dimension().location().toString(); if (world.dimension() != Level.OVERWORLD) { @@ -123,10 +121,6 @@ public SpawnServerData getServerData() { return Solstice.serverData.getData(SpawnServerData.class); } - public void sendToSpawn(ServerPlayer player) { - sendToSpawn(player, player.serverLevel()); - } - public void sendToSpawn(ServerPlayer player, ServerLevel world) { var pos = getWorldSpawn(world); pos.teleport(player); diff --git a/src/main/java/me/alexdevs/solstice/modules/spawn/commands/SetSpawnCommand.java b/src/main/java/me/alexdevs/solstice/modules/spawn/commands/SetSpawnCommand.java index 089b49e9..d165e09e 100644 --- a/src/main/java/me/alexdevs/solstice/modules/spawn/commands/SetSpawnCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/spawn/commands/SetSpawnCommand.java @@ -3,10 +3,14 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import me.alexdevs.solstice.api.ServerLocation; import me.alexdevs.solstice.api.module.ModCommand; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.spawn.SpawnModule; import net.minecraft.commands.CommandSourceStack; +import net.minecraft.core.BlockPos; +import net.minecraft.core.GlobalPos; import net.minecraft.network.chat.Component; import net.minecraft.world.level.Level; +import net.minecraft.world.level.storage.LevelData; import java.util.List; import java.util.Map; @@ -30,14 +34,14 @@ public LiteralArgumentBuilder command(String name) { .executes(context -> { var player = context.getSource().getPlayerOrException(); var location = new ServerLocation(player); - var world = player.serverLevel(); + var world = PlayerUtils.getLevel(player); // world spawn point is ignored on non-overworld levels if(world.dimension() == Level.OVERWORLD) { - world.setDefaultSpawnPos( - location.getBlockPos(), - location.getYaw() - ); + //? >= 1.21.11 + //world.setRespawnData(new LevelData.RespawnData(new GlobalPos(location.getWorldKey(),new BlockPos(location.getBlockPos().getX(), location.getBlockPos().getY(), location.getBlockPos().getZ())), location.getYaw(), location.getPitch())); + //? < 1.21.11 + world.setDefaultSpawnPos(location.getBlockPos(), location.getYaw()); } else { module.getServerData().spawnPoints.put(location.getWorld(), location); } diff --git a/src/main/java/me/alexdevs/solstice/modules/staffChat/StaffChatModule.java b/src/main/java/me/alexdevs/solstice/modules/staffChat/StaffChatModule.java index f1736af5..71abf752 100644 --- a/src/main/java/me/alexdevs/solstice/modules/staffChat/StaffChatModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/staffChat/StaffChatModule.java @@ -9,7 +9,7 @@ import me.lucko.fabric.api.permissions.v0.Permissions; import net.fabricmc.fabric.api.message.v1.ServerMessageEvents; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.server.level.ServerPlayer; import java.util.Map; @@ -19,7 +19,7 @@ public class StaffChatModule extends ModuleBase.Toggleable { private final ConcurrentHashMap stickyStaffChat = new ConcurrentHashMap<>(); - public StaffChatModule(ResourceLocation id) { + public StaffChatModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/styling/CustomPlayerTeam.java b/src/main/java/me/alexdevs/solstice/modules/styling/CustomPlayerTeam.java index 2c08fe3f..fb47cfe3 100644 --- a/src/main/java/me/alexdevs/solstice/modules/styling/CustomPlayerTeam.java +++ b/src/main/java/me/alexdevs/solstice/modules/styling/CustomPlayerTeam.java @@ -1,4 +1,5 @@ package me.alexdevs.solstice.modules.styling; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.ModuleProvider; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; @@ -23,9 +24,9 @@ public class CustomPlayerTeam extends PlayerTeam { private final ServerPlayer player; public CustomPlayerTeam(Scoreboard scoreboard, ServerPlayer player) { - super(scoreboard, "sol_" + player.getGameProfile().getName()); + super(scoreboard, "sol_" + PlayerUtils.getName(player.getGameProfile())); this.player = player; - super.getPlayers().add(player.getGameProfile().getName()); + super.getPlayers().add(PlayerUtils.getName(player.getGameProfile())); } //? if >= 1.21.1 { @@ -74,6 +75,6 @@ public Component getPlayerSuffix() { @Override public Collection getPlayers() { - return List.of(player.getGameProfile().getName()); + return List.of(PlayerUtils.getName(player.getGameProfile())); } } \ No newline at end of file diff --git a/src/main/java/me/alexdevs/solstice/modules/styling/StylingModule.java b/src/main/java/me/alexdevs/solstice/modules/styling/StylingModule.java index a1e7ca8b..3b039d7a 100644 --- a/src/main/java/me/alexdevs/solstice/modules/styling/StylingModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/styling/StylingModule.java @@ -10,7 +10,7 @@ import me.lucko.fabric.api.permissions.v0.Permissions; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.players.PlayerList; @@ -32,7 +32,7 @@ public class StylingModule extends ModuleBase.Toggleable { //? < 1.21.1 //private static final StylingConfig.NameplateFormat DEFAULT_NAMEPLATE = new StylingConfig.NameplateFormat("", "", "WHITE"); - public StylingModule(ResourceLocation id) { + public StylingModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/sudo/SudoModule.java b/src/main/java/me/alexdevs/solstice/modules/sudo/SudoModule.java index d0a9993f..a5daa6a7 100644 --- a/src/main/java/me/alexdevs/solstice/modules/sudo/SudoModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/sudo/SudoModule.java @@ -3,10 +3,10 @@ import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.modules.sudo.commands.DoAsCommand; import me.alexdevs.solstice.modules.sudo.commands.SudoCommand; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; public class SudoModule extends ModuleBase.Toggleable { - public SudoModule(ResourceLocation id) { + public SudoModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/sudo/commands/DoAsCommand.java b/src/main/java/me/alexdevs/solstice/modules/sudo/commands/DoAsCommand.java index f8afd7b4..b0549ab0 100644 --- a/src/main/java/me/alexdevs/solstice/modules/sudo/commands/DoAsCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/sudo/commands/DoAsCommand.java @@ -4,6 +4,7 @@ import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import me.alexdevs.solstice.api.module.ModCommand; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.sudo.SudoModule; import net.minecraft.commands.CommandSource; import net.minecraft.commands.CommandSourceStack; @@ -42,16 +43,26 @@ public static CommandSource getCommandOutput(CommandSourceStack source) { public static CommandSourceStack buildPlayerSource(CommandSource commandOutput, MinecraftServer server, ServerPlayer player) { var opList = server.getPlayerList().getOps(); + //? < 1.21.11 var operator = opList.get(player.getGameProfile()); + //? >= 1.21.11 + //var operator = opList.get(new net.minecraft.server.players.NameAndId(player.getGameProfile())); + //? < 1.21.11 int opLevel = 0; + //? >= 1.21.11 + //var opLevel = net.minecraft.server.permissions.LevelBasedPermissionSet.ALL; + if (operator != null) { + //? < 1.21.11 opLevel = operator.getLevel(); + //? >= 1.21.11 + //opLevel = operator.permissions(); } return new CommandSourceStack( commandOutput, player.position(), player.getRotationVector(), - player.serverLevel(), + PlayerUtils.getLevel(player), opLevel, player.getScoreboardName(), player.getDisplayName(), diff --git a/src/main/java/me/alexdevs/solstice/modules/sudo/commands/SudoCommand.java b/src/main/java/me/alexdevs/solstice/modules/sudo/commands/SudoCommand.java index b1c73b05..6664fa15 100644 --- a/src/main/java/me/alexdevs/solstice/modules/sudo/commands/SudoCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/sudo/commands/SudoCommand.java @@ -4,6 +4,7 @@ import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import me.alexdevs.solstice.api.module.ModCommand; +import me.alexdevs.solstice.api.utils.ComponentUtils; import me.alexdevs.solstice.modules.sudo.SudoModule; import me.lucko.fabric.api.permissions.v0.Permissions; import net.minecraft.commands.CommandSource; @@ -43,7 +44,7 @@ public LiteralArgumentBuilder command(String name) { .executes(context -> { if (!Permissions.check(context.getSource(), getPermissionNode("sudo"), 4)) { context.getSource().sendFailure(Component.literal(String.format("%s is not in the sudoers file. This incident will be reported.", context.getSource().getTextName())) - .setStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://xkcd.com/838/")))); + .setStyle(Style.EMPTY.withClickEvent(ComponentUtils.openUrlClickEvent( "https://xkcd.com/838/")))); return 1; } var command = StringArgumentType.getString(context, "command"); @@ -64,9 +65,15 @@ public LiteralArgumentBuilder command(String name) { public CommandSourceStack buildServerSource(CommandSource commandOutput, MinecraftServer server) { return new CommandSourceStack( commandOutput, + //? >= 1.21.11 + //server.overworld().getRespawnData().pos().getCenter(), + //? < 1.21.11 server.overworld().getSharedSpawnPos().getCenter(), Vec2.ZERO, server.overworld(), + //? >= 1.21.11 + //net.minecraft.server.permissions.PermissionSet.ALL_PERMISSIONS, + //? < 1.21.11 4, "Server", Component.nullToEmpty("Server"), diff --git a/src/main/java/me/alexdevs/solstice/modules/suicide/SuicideModule.java b/src/main/java/me/alexdevs/solstice/modules/suicide/SuicideModule.java index 48653970..ff051938 100644 --- a/src/main/java/me/alexdevs/solstice/modules/suicide/SuicideModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/suicide/SuicideModule.java @@ -2,12 +2,12 @@ import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.modules.suicide.commands.SuicideCommand; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; public class SuicideModule extends ModuleBase.Toggleable { - public SuicideModule(ResourceLocation id) { + public SuicideModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/suicide/commands/SuicideCommand.java b/src/main/java/me/alexdevs/solstice/modules/suicide/commands/SuicideCommand.java index 9916902d..53564425 100644 --- a/src/main/java/me/alexdevs/solstice/modules/suicide/commands/SuicideCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/suicide/commands/SuicideCommand.java @@ -2,6 +2,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import me.alexdevs.solstice.api.module.ModCommand; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.suicide.SuicideModule; import net.minecraft.commands.CommandSourceStack; @@ -27,7 +28,7 @@ public LiteralArgumentBuilder command(String name) { var player = context.getSource().getPlayerOrException(); //? >= 1.21.4 - //player.kill(player.serverLevel()); + //player.kill(PlayerUtils.getLevel(player)); //? < 1.21.4 player.kill(); diff --git a/src/main/java/me/alexdevs/solstice/modules/tablist/TabListModule.java b/src/main/java/me/alexdevs/solstice/modules/tablist/TabListModule.java index f201e4ba..3e380d02 100644 --- a/src/main/java/me/alexdevs/solstice/modules/tablist/TabListModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/tablist/TabListModule.java @@ -11,7 +11,7 @@ import me.alexdevs.solstice.modules.tablist.data.TabListConfig; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.minecraft.network.protocol.game.ClientboundTabListPacket; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; @@ -23,7 +23,7 @@ public class TabListModule extends ModuleBase.Toggleable { private MinecraftServer server; private ScheduledFuture scheduledFuture = null; - public TabListModule(ResourceLocation id) { + public TabListModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/teleportHere/TeleportHereModule.java b/src/main/java/me/alexdevs/solstice/modules/teleportHere/TeleportHereModule.java index 3e54a0a7..9828ff72 100644 --- a/src/main/java/me/alexdevs/solstice/modules/teleportHere/TeleportHereModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/teleportHere/TeleportHereModule.java @@ -2,12 +2,12 @@ import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.modules.teleportHere.commands.TeleportHereCommand; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; public class TeleportHereModule extends ModuleBase.Toggleable { - public TeleportHereModule(ResourceLocation id) { + public TeleportHereModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/teleportHere/commands/TeleportHereCommand.java b/src/main/java/me/alexdevs/solstice/modules/teleportHere/commands/TeleportHereCommand.java index 9ca260f4..7c171669 100644 --- a/src/main/java/me/alexdevs/solstice/modules/teleportHere/commands/TeleportHereCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/teleportHere/commands/TeleportHereCommand.java @@ -2,6 +2,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import me.alexdevs.solstice.api.module.ModCommand; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.teleportHere.TeleportHereModule; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.arguments.EntityArgument; @@ -31,7 +32,7 @@ public LiteralArgumentBuilder command(String name) { .executes(context -> { var source = context.getSource(); var player = source.getPlayerOrException(); - var world = player.serverLevel(); + var world = PlayerUtils.getLevel(player); var vec3d = player.position(); var yaw = player.getYRot(); var pitch = player.getXRot(); diff --git a/src/main/java/me/alexdevs/solstice/modules/teleportOffline/TeleportOfflineModule.java b/src/main/java/me/alexdevs/solstice/modules/teleportOffline/TeleportOfflineModule.java index e12953f5..a9dd32bf 100644 --- a/src/main/java/me/alexdevs/solstice/modules/teleportOffline/TeleportOfflineModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/teleportOffline/TeleportOfflineModule.java @@ -2,12 +2,12 @@ import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.modules.teleportOffline.commands.TeleportOfflineCommand; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; public class TeleportOfflineModule extends ModuleBase.Toggleable { - public TeleportOfflineModule(ResourceLocation id) { + public TeleportOfflineModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/teleportOffline/commands/TeleportOfflineCommand.java b/src/main/java/me/alexdevs/solstice/modules/teleportOffline/commands/TeleportOfflineCommand.java index 457aad30..8eec1bc1 100644 --- a/src/main/java/me/alexdevs/solstice/modules/teleportOffline/commands/TeleportOfflineCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/teleportOffline/commands/TeleportOfflineCommand.java @@ -5,6 +5,7 @@ import me.alexdevs.solstice.Solstice; import me.alexdevs.solstice.api.command.LocalGameProfile; import me.alexdevs.solstice.api.module.ModCommand; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.core.coreModule.data.CorePlayerData; import me.alexdevs.solstice.modules.teleportOffline.TeleportOfflineModule; import net.minecraft.commands.CommandSourceStack; @@ -43,7 +44,7 @@ public LiteralArgumentBuilder command(String name) { return 0; } - source.sendSuccess(() -> Component.translatable("commands.teleport.success.entity.single", player.getDisplayName(), Component.nullToEmpty(gameProfile.getName())), true); + source.sendSuccess(() -> Component.translatable("commands.teleport.success.entity.single", player.getDisplayName(), Component.nullToEmpty(PlayerUtils.getName(gameProfile))), true); targetData.logoffPosition.teleport(player, true); return 1; diff --git a/src/main/java/me/alexdevs/solstice/modules/teleportPosition/TeleportPositionModule.java b/src/main/java/me/alexdevs/solstice/modules/teleportPosition/TeleportPositionModule.java index f24501d3..8a02a57f 100644 --- a/src/main/java/me/alexdevs/solstice/modules/teleportPosition/TeleportPositionModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/teleportPosition/TeleportPositionModule.java @@ -2,11 +2,11 @@ import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.modules.teleportPosition.commands.TeleportPositionCommand; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; public class TeleportPositionModule extends ModuleBase.Toggleable { - public TeleportPositionModule(ResourceLocation id) { + public TeleportPositionModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/teleportRequest/TeleportRequestModule.java b/src/main/java/me/alexdevs/solstice/modules/teleportRequest/TeleportRequestModule.java index 4e81d498..d01c35e9 100644 --- a/src/main/java/me/alexdevs/solstice/modules/teleportRequest/TeleportRequestModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/teleportRequest/TeleportRequestModule.java @@ -5,6 +5,7 @@ import me.alexdevs.solstice.api.ServerLocation; import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.api.text.Components; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.notifications.NotificationsModule; import me.alexdevs.solstice.modules.teleportRequest.commands.TeleportAcceptCommand; import me.alexdevs.solstice.modules.teleportRequest.commands.TeleportAskCommand; @@ -14,7 +15,7 @@ import me.alexdevs.solstice.modules.teleportRequest.data.TeleportConfig; import me.alexdevs.solstice.modules.teleportRequest.data.TeleportLocale; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.server.level.ServerPlayer; import java.util.Map; @@ -28,7 +29,7 @@ public class TeleportRequestModule extends ModuleBase.Toggleable { private final Map> requests = new ConcurrentHashMap<>(); - public TeleportRequestModule(ResourceLocation id) { + public TeleportRequestModule(SolsticeIdentifier id) { super(id); } @@ -119,11 +120,11 @@ public void requestTo(ServerPlayer source, ServerPlayer target) { "acceptButton", Components.button( locale().raw("~accept"), locale().raw("~accept.hover"), - "/tpaccept " + source.getGameProfile().getName()), + "/tpaccept " + PlayerUtils.getName(source.getGameProfile())), "refuseButton", Components.button( locale().raw("~refuse"), locale().raw("~refuse.hover"), - "/tpdeny " + source.getGameProfile().getName()) + "/tpdeny " + PlayerUtils.getName(source.getGameProfile())) ); target.sendSystemMessage(locale().get( @@ -151,11 +152,11 @@ public void requestToHere(ServerPlayer source, ServerPlayer target) { "acceptButton", Components.button( locale().raw("~accept"), locale().raw("~accept.hover"), - "/tpaccept " + source.getGameProfile().getName()), + "/tpaccept " + PlayerUtils.getName(source.getGameProfile())), "refuseButton", Components.button( locale().raw("~refuse"), locale().raw("~refuse.hover"), - "/tpdeny " + source.getGameProfile().getName()) + "/tpdeny " + PlayerUtils.getName(source.getGameProfile())) ); target.sendSystemMessage(locale().get( diff --git a/src/main/java/me/alexdevs/solstice/modules/tell/TellModule.java b/src/main/java/me/alexdevs/solstice/modules/tell/TellModule.java index f379ab3d..817ad8bc 100644 --- a/src/main/java/me/alexdevs/solstice/modules/tell/TellModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/tell/TellModule.java @@ -4,6 +4,7 @@ import me.alexdevs.solstice.Solstice; import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.api.text.Components; +import me.alexdevs.solstice.api.utils.PlayerUtils; import me.alexdevs.solstice.modules.ModuleProvider; import me.alexdevs.solstice.modules.ignore.IgnoreModule; import me.alexdevs.solstice.modules.notifications.NotificationsModule; @@ -13,7 +14,7 @@ import me.lucko.fabric.api.permissions.v0.Permissions; import net.minecraft.commands.CommandSourceStack; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.server.level.ServerPlayer; import java.util.HashMap; @@ -23,7 +24,7 @@ public class TellModule extends ModuleBase.Toggleable { public final HashMap lastSender = new HashMap<>(); - public TellModule(ResourceLocation id) { + public TellModule(SolsticeIdentifier id) { super(id); } @@ -131,7 +132,7 @@ public void sendDirectMessage(String targetName, CommandSourceStack source, Stri } source.getServer().getPlayerList().getPlayers().forEach(player -> { - var playerName = player.getGameProfile().getName(); + var playerName = PlayerUtils.getName(player.getGameProfile()); if (playerName.equals(targetName) || playerName.equals(source.getTextName())) { return; } diff --git a/src/main/java/me/alexdevs/solstice/modules/timeBar/TimeBar.java b/src/main/java/me/alexdevs/solstice/modules/timeBar/TimeBar.java index 2cb4200a..3ed2f747 100644 --- a/src/main/java/me/alexdevs/solstice/modules/timeBar/TimeBar.java +++ b/src/main/java/me/alexdevs/solstice/modules/timeBar/TimeBar.java @@ -5,7 +5,7 @@ import me.alexdevs.solstice.api.command.TimeSpan; import me.alexdevs.solstice.api.text.Format; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.server.bossevents.CustomBossEvent; import net.minecraft.world.BossEvent; @@ -21,7 +21,7 @@ public class TimeBar { private int elapsedSeconds = 0; public TimeBar(String label, int time, boolean countdown, BossEvent.BossBarColor color, BossEvent.BossBarOverlay style) { - this.bossBar = new CustomBossEvent(ResourceLocation.tryBuild(Solstice.MOD_ID, uuid.toString()), Component.nullToEmpty(label)); + this.bossBar = new CustomBossEvent(SolsticeIdentifier.of(Solstice.MOD_ID, uuid.toString()).get(), Component.nullToEmpty(label)); this.bossBar.setColor(color); this.bossBar.setOverlay(style); this.label = label; diff --git a/src/main/java/me/alexdevs/solstice/modules/timeBar/TimeBarModule.java b/src/main/java/me/alexdevs/solstice/modules/timeBar/TimeBarModule.java index e1a812b4..0726c0c1 100644 --- a/src/main/java/me/alexdevs/solstice/modules/timeBar/TimeBarModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/timeBar/TimeBarModule.java @@ -4,7 +4,7 @@ import me.alexdevs.solstice.api.events.TimeBarEvents; import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.modules.timeBar.commands.TimeBarCommand; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.BossEvent; @@ -17,7 +17,7 @@ public class TimeBarModule extends ModuleBase.Toggleable { private static final ConcurrentLinkedDeque timeBars = new ConcurrentLinkedDeque<>(); - public TimeBarModule(ResourceLocation id) { + public TimeBarModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/timeBar/commands/TimeBarCommand.java b/src/main/java/me/alexdevs/solstice/modules/timeBar/commands/TimeBarCommand.java index b49c793a..c8a0d923 100644 --- a/src/main/java/me/alexdevs/solstice/modules/timeBar/commands/TimeBarCommand.java +++ b/src/main/java/me/alexdevs/solstice/modules/timeBar/commands/TimeBarCommand.java @@ -9,6 +9,7 @@ import me.alexdevs.solstice.api.command.TimeSpan; import me.alexdevs.solstice.api.events.TimeBarEvents; import me.alexdevs.solstice.api.module.ModCommand; +import me.alexdevs.solstice.api.utils.ComponentUtils; import me.alexdevs.solstice.modules.timeBar.TimeBarModule; import net.minecraft.ChatFormatting; import net.minecraft.commands.CommandSourceStack; @@ -107,8 +108,8 @@ private int execute(CommandContext context) throws CommandSy context.getSource().sendSuccess(() -> Component .literal("New time bar created with UUID ") .append(Component.literal(bar.getUuid().toString()).setStyle(Style.EMPTY - .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.nullToEmpty("Click to copy"))) - .withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, bar.getUuid().toString())))), true); + .withHoverEvent(ComponentUtils.showTextHoverEvent(Component.nullToEmpty("Click to copy"))) + .withClickEvent(ComponentUtils.clickCopyToClipboardEvent(bar.getUuid().toString())))), true); return 1; } diff --git a/src/main/java/me/alexdevs/solstice/modules/trash/TrashModule.java b/src/main/java/me/alexdevs/solstice/modules/trash/TrashModule.java index e460b1e4..f2d2e300 100644 --- a/src/main/java/me/alexdevs/solstice/modules/trash/TrashModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/trash/TrashModule.java @@ -4,12 +4,12 @@ import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.modules.trash.commands.TrashCommand; import me.alexdevs.solstice.modules.trash.data.TrashLocale; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; public class TrashModule extends ModuleBase.Toggleable { - public TrashModule(ResourceLocation id) { + public TrashModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/utilities/UtilitiesModule.java b/src/main/java/me/alexdevs/solstice/modules/utilities/UtilitiesModule.java index 418acb1b..f7f35252 100644 --- a/src/main/java/me/alexdevs/solstice/modules/utilities/UtilitiesModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/utilities/UtilitiesModule.java @@ -2,10 +2,10 @@ import me.alexdevs.solstice.api.module.ModuleBase; import me.alexdevs.solstice.modules.utilities.commands.*; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; public class UtilitiesModule extends ModuleBase.Toggleable { - public UtilitiesModule(ResourceLocation id) { + public UtilitiesModule(SolsticeIdentifier id) { super(id); } diff --git a/src/main/java/me/alexdevs/solstice/modules/warp/WarpModule.java b/src/main/java/me/alexdevs/solstice/modules/warp/WarpModule.java index 6d275ff0..8e309038 100644 --- a/src/main/java/me/alexdevs/solstice/modules/warp/WarpModule.java +++ b/src/main/java/me/alexdevs/solstice/modules/warp/WarpModule.java @@ -9,13 +9,13 @@ import me.alexdevs.solstice.modules.warp.data.WarpLocale; import me.alexdevs.solstice.modules.warp.data.WarpServerData; import me.lucko.fabric.api.permissions.v0.Permissions; -import net.minecraft.resources.ResourceLocation; +import me.alexdevs.solstice.api.utils.SolsticeIdentifier; import net.minecraft.server.level.ServerPlayer; public class WarpModule extends ModuleBase.Toggleable { - public WarpModule(ResourceLocation id) { + public WarpModule(SolsticeIdentifier id) { super(id); } diff --git a/versions/1.21.11/gradle.properties b/versions/1.21.11/gradle.properties new file mode 100644 index 00000000..6cd28eca --- /dev/null +++ b/versions/1.21.11/gradle.properties @@ -0,0 +1,16 @@ +org.gradle.jvmargs=-Xmx3G + +minecraft_version=1.21.11 +loader_version=0.18.4 +java_version=21 +minecraft_constraint=~1.21.11 +parchment_mappings=2025.12.20 + +fabric_version=0.141.3+1.21.11 +configurate_version=4.1.2 +permissions_api_version=0.6.1 +placeholderapi_version=2.8.2+1.21.10 +sgui_version=1.12.0+1.21.11 +commoneconomy_version=2.0.0 +trinkets_version=3.10.0 +