Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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()")
}
}
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/me/alexdevs/solstice/Solstice.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/alexdevs/solstice/api/Raycast.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/me/alexdevs/solstice/api/ServerLocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -98,7 +98,7 @@ public void teleport(ServerPlayer player) {
}

public ResourceKey<Level> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
import java.util.concurrent.CompletableFuture;

public class LocalGameProfile {
public static GameProfile getGameProfile(CommandContext<CommandSourceStack> 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<CommandSourceStack> context, String name) throws CommandSyntaxException {
// public static GameProfile getGameProfile(CommandContext<CommandSourceStack> 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<CommandSourceStack> context, String name) throws CommandSyntaxException {
var profileName = StringArgumentType.getString(context, name);
var profile = Solstice.getUserCache().getByName(profileName);
if(profile.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,7 +22,7 @@
*/
public class ConfigDataManager implements IConfigDataManager {
public static final int CONFIG_VERSION = 2;
private final Map<ResourceLocation, Class<?>> classMap = new HashMap<>();
private final Map<SolsticeIdentifier, Class<?>> classMap = new HashMap<>();
private final Map<Class<?>, Supplier<?>> defaultSuppliers = new HashMap<>();
private final Map<Class<?>, Object> dataMap = new HashMap<>();

Expand All @@ -48,7 +48,7 @@ public ConfigDataManager(Path filePath) {
}

@Override
public <T> void registerData(ResourceLocation id, Class<T> classOfConfig, Supplier<T> creator) {
public <T> void registerData(SolsticeIdentifier id, Class<T> classOfConfig, Supplier<T> creator) {
if (classMap.containsKey(id) || defaultSuppliers.containsKey(classOfConfig)) {
throw new IllegalArgumentException("Config with identifier " + id + " already registered");
}
Expand All @@ -75,7 +75,7 @@ public <T> T getData(Class<T> classOfConfig) {
return (T) data;
}

private Map<String, List<Map.Entry<ResourceLocation, Class<?>>>> getSections() {
private Map<String, List<Map.Entry<SolsticeIdentifier, Class<?>>>> getSections() {
return classMap.entrySet().stream()
.collect(Collectors
.groupingBy(entry -> entry.getKey().getNamespace()));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -15,7 +15,7 @@ public interface IConfigDataManager {
* @param creator Supplier of the config that contains the default values when creating the initial data.
* @param <T> Class of the config.
*/
<T> void registerData(ResourceLocation id, Class<T> classOfConfig, Supplier<T> creator);
<T> void registerData(SolsticeIdentifier id, Class<T> classOfConfig, Supplier<T> creator);

/**
* Get the object of the configuration data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions src/main/java/me/alexdevs/solstice/api/module/Debug.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,7 +9,7 @@
public class Debug {
public static final HashSet<CommandDebug> commandDebugList = new HashSet<>();

public record CommandDebug(ResourceLocation module, String command, List<String> commands, String permission) {
public record CommandDebug(SolsticeIdentifier module, String command, List<String> commands, String permission) {
@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/me/alexdevs/solstice/api/module/ModuleBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ModuleBase> {
protected final ResourceLocation id;
protected final SolsticeIdentifier id;
protected final List<ModCommand<?>> 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;
}

Expand All @@ -30,7 +30,7 @@ public Collection<? extends ModCommand<?>> getCommands() {
return commands;
}

public ResourceLocation getId() {
public SolsticeIdentifier getId() {
return id;
}

Expand Down Expand Up @@ -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);
}

Expand Down
8 changes: 3 additions & 5 deletions src/main/java/me/alexdevs/solstice/api/text/Format.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String, Component> placeholders) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,23 @@ 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) {
return new ClickActionNode(
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)
);
Expand All @@ -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)
);
}
}
31 changes: 31 additions & 0 deletions src/main/java/me/alexdevs/solstice/api/utils/ComponentUtils.java
Original file line number Diff line number Diff line change
@@ -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));
}
}
23 changes: 23 additions & 0 deletions src/main/java/me/alexdevs/solstice/api/utils/IdUtils.java
Original file line number Diff line number Diff line change
@@ -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<CommandSourceStack> 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);
}
}
Loading
Loading