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
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "fabric-loom" version "1.11.+"
id "fabric-loom" version "1.14-SNAPSHOT"
}

version = project.mod_version
Expand All @@ -20,7 +20,7 @@ repositories {
dependencies {
//to change the versions see the gradle.properties file
minecraft("com.mojang:minecraft:${project.minecraft_version}")
mappings("net.fabricmc:yarn:${project.yarn_mappings}:v2")
mappings(loom.officialMojangMappings())
modImplementation("net.fabricmc:fabric-loader:${project.loader_version}")

modImplementation("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}")
Expand Down
14 changes: 8 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.21.9
yarn_mappings=1.21.9+build.1
loader_version=0.17.2
minecraft_version=1.21.11
loader_version=0.18.2

# Mod Properties
mod_version=1.2.0
mod_version=1.2.1
maven_group=us.potatoboy
archives_base_name=htm

# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.133.14+1.21.9
fabric_version=0.139.4+1.21.11
translation_version=2.5.2+1.21.9-pre3
permissions_api_version=0.4.1
permissions_api_version=0.6.1
protection_api_version=1.0.0
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
38 changes: 21 additions & 17 deletions src/main/java/com/github/fabricservertools/htm/HTM.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.github.fabricservertools.htm;

import com.github.fabricservertools.htm.api.Lock;
import com.github.fabricservertools.htm.command.HTMCommand;
import com.github.fabricservertools.htm.command.subcommands.*;
import com.github.fabricservertools.htm.config.HTMConfig;
import com.github.fabricservertools.htm.interactions.InteractionManager;
import com.github.fabricservertools.htm.listeners.PlayerEventListener;
import com.github.fabricservertools.htm.listeners.WorldEventListener;
import com.github.fabricservertools.htm.listeners.LevelEventListener;
import com.mojang.brigadier.CommandDispatcher;
import eu.pb4.common.protection.api.CommonProtection;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.Identifier;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.resources.Identifier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -20,25 +21,28 @@ public class HTM implements ModInitializer {

@Override
public void onInitialize() {
// For some reason, the Lock class has to be loaded before the HTMConfig class for the codecs to be initialised properly
// Calling a method of the class loads it. Removing the line below results in an NPE when launching Minecraft
Lock.bootstrap();
HTMConfig.load();

CommandRegistrationCallback.EVENT.register(((dispatcher, environment, registryAccess) -> registerCommands(dispatcher)));
CommonProtection.register(Identifier.of("htm", "containers"), new InteractionManager());
CommonProtection.register(Identifier.fromNamespaceAndPath("htm", "containers"), new InteractionManager());

PlayerEventListener.init();
WorldEventListener.init();
LevelEventListener.init();
}

private void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher) {
HTMCommand.register(dispatcher);
HTMCommand.registerSubCommand(new SetCommand().build());
HTMCommand.registerSubCommand(new RemoveCommand().build());
HTMCommand.registerSubCommand(new TrustCommand().build());
HTMCommand.registerSubCommand(new UntrustCommand().build());
HTMCommand.registerSubCommand(new InfoCommand().build());
HTMCommand.registerSubCommand(new TransferCommand().build());
HTMCommand.registerSubCommand(new FlagCommand().build());
HTMCommand.registerSubCommand(new PersistCommand().build());
HTMCommand.registerSubCommand(new QuietCommand().build());
}
private void registerCommands(CommandDispatcher<CommandSourceStack> dispatcher) {
HTMCommand.registerSubCommand(new SetCommand());
HTMCommand.registerSubCommand(new RemoveCommand());
HTMCommand.registerSubCommand(new TrustCommand());
HTMCommand.registerSubCommand(new UntrustCommand());
HTMCommand.registerSubCommand(new InfoCommand());
HTMCommand.registerSubCommand(new TransferCommand());
HTMCommand.registerSubCommand(new FlagCommand());
HTMCommand.registerSubCommand(new PersistCommand());
HTMCommand.registerSubCommand(new QuietCommand());
HTMCommand.register(dispatcher);
}
}
87 changes: 87 additions & 0 deletions src/main/java/com/github/fabricservertools/htm/HTMComponents.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.github.fabricservertools.htm;

import java.util.function.UnaryOperator;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;

public final class HTMComponents {
private static final String PREFIX = "text.htm.";

public static final Component NOT_LOCKABLE = error("error.unlockable");
public static final Component NOT_LOCKED = error("error.no_lock");
public static final Component NOT_OWNER = error("error.not_owner");
public static final Component ALREADY_LOCKED = error("error.already_locked");
public static final Component INVALID_LOCK_TYPE = error("error.lock_type");
public static final Component INVALID_FLAG_TYPE = error("error.flag_type");
public static final Component CANNOT_TRUST_SELF = error("error.trust_self");
public static final TranslatableComponentBuilder ALREADY_TRUSTED = errorBuilder("error.already_trusted");
public static final TranslatableComponentBuilder PLAYER_NOT_TRUSTED = errorBuilder("error.not_trusted");
public static final Component CONTAINER_LOCKED = error("locked");
public static final Component OVERRIDING = error("overriding");

public static final Component CLICK_TO_SELECT = info("select");
public static final Component DIVIDER = info("divider");
public static final TranslatableComponentBuilder CONTAINER_LOCK_TYPE = infoBuilder("type");
public static final TranslatableComponentBuilder CONTAINER_OWNER = infoBuilder("owner");
public static final TranslatableComponentBuilder CONTAINER_TRUSTED = infoBuilder("trusted");
public static final TranslatableComponentBuilder TRUSTED_GLOBALLY = infoBuilder("trusted.global");
public static final TranslatableComponentBuilder TRUST = infoBuilder("trust");
public static final TranslatableComponentBuilder UNTRUST = infoBuilder("untrust");
public static final Component GLOBAL = info("global").withStyle(ChatFormatting.BOLD);
public static final TranslatableComponentBuilder CONTAINER_TRANSFER = infoBuilder("transfer");
public static final Component CONTAINER_UNLOCKED = info("unlocked");
public static final TranslatableComponentBuilder CONTAINER_KEY = infoBuilder("key");
public static final TranslatableComponentBuilder CONTAINER_SET = infoBuilder("set");
public static final TranslatableComponentBuilder CONTAINER_KEY_SET = infoBuilder("key_set");
public static final TranslatableComponentBuilder CONTAINER_OVERRIDE = infoBuilder("override").andThen(text -> text.append(CommonComponents.space()).append(OVERRIDING));
public static final TranslatableComponentBuilder CONTAINER_FLAG_SET = infoBuilder("set_flag");
public static final TranslatableComponentBuilder CONTAINER_FLAG_RESET = infoBuilder("reset_flag");
public static final TranslatableComponentBuilder CONTAINER_FLAG = infoBuilder("flag");
public static final Component ON = translatable("on")
.withStyle(ChatFormatting.GREEN, ChatFormatting.BOLD);
public static final Component OFF = translatable("off")
.withStyle(ChatFormatting.RED, ChatFormatting.BOLD);
public static final Component TOGGLE_PERSIST_ON = info("persist").append(CommonComponents.SPACE).append(ON);
public static final Component TOGGLE_PERSIST_OFF = info("persist").append(CommonComponents.SPACE).append(OFF);
public static final Component TOGGLE_NO_MSG_ON = info("no_msg").append(CommonComponents.SPACE).append(ON);
public static final Component TOGGLE_NO_MSG_OFF = info("no_msg").append(CommonComponents.SPACE).append(OFF);

private static MutableComponent error(String key) {
return errorBuilder(key).apply();
}

private static TranslatableComponentBuilder errorBuilder(String key) {
return builder(key, style -> style.withColor(ChatFormatting.RED));
}

private static MutableComponent info(String key) {
return infoBuilder(key).apply();
}

private static TranslatableComponentBuilder infoBuilder(String key) {
return builder(key, style -> style.withColor(ChatFormatting.AQUA));
}

private static TranslatableComponentBuilder builder(String key, UnaryOperator<Style> style) {
return args -> translatable(key, args).withStyle(style);
}

private static MutableComponent translatable(String translation, Object... args) {
return Component.translatable(PREFIX + translation, args);
}

@FunctionalInterface
public interface TranslatableComponentBuilder {

MutableComponent apply(Object... arg);

default TranslatableComponentBuilder andThen(UnaryOperator<MutableComponent> operator) {
return args -> operator.apply(apply(args));
}
}

private HTMComponents() {}
}
88 changes: 0 additions & 88 deletions src/main/java/com/github/fabricservertools/htm/HTMTexts.java

This file was deleted.

31 changes: 15 additions & 16 deletions src/main/java/com/github/fabricservertools/htm/Utility.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
package com.github.fabricservertools.htm;

import com.github.fabricservertools.htm.interactions.InteractionManager;
import com.github.fabricservertools.htm.world.data.GlobalTrustState;
import net.minecraft.entity.player.PlayerEntity;
import com.github.fabricservertools.htm.world.data.GlobalTrustData;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PlayerConfigEntry;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

import net.minecraft.server.players.NameAndId;
import net.minecraft.world.entity.player.Player;
import java.util.UUID;

public class Utility {

public static String getNameFromUUID(UUID uuid, MinecraftServer server) {
return server.getApiServices().nameToIdCache().getByUuid(uuid)
.map(PlayerConfigEntry::name)
return server.services().nameToIdCache().get(uuid)
.map(NameAndId::name)
.orElse("unknown");
}

public static Text getFormattedNameFromUUID(UUID uuid, MinecraftServer server) {
return Text.literal(getNameFromUUID(uuid, server)).formatted(Formatting.WHITE);
public static Component getFormattedNameFromUUID(UUID uuid, MinecraftServer server) {
return Component.literal(getNameFromUUID(uuid, server)).withStyle(ChatFormatting.WHITE);
}

public static GlobalTrustState getGlobalTrustState(MinecraftServer server) {
return server.getOverworld().getPersistentStateManager().getOrCreate(GlobalTrustState.TYPE);
public static GlobalTrustData getGlobalTrustData(MinecraftServer server) {
return server.overworld().getDataStorage().computeIfAbsent(GlobalTrustData.TYPE);
}

public static void sendMessage(PlayerEntity player, Text message) {
public static void sendMessage(Player player, Component message) {
sendMessage(player, message, false);
}

public static void sendMessage(PlayerEntity player, Text message, boolean actionBar) {
if (!InteractionManager.noMessage.contains(player.getUuid())) {
player.sendMessage(message, actionBar);
public static void sendMessage(Player player, Component message, boolean actionBar) {
if (!InteractionManager.noMessage.contains(player.getUUID())) {
player.displayClientMessage(message, actionBar);
}
}
}
19 changes: 10 additions & 9 deletions src/main/java/com/github/fabricservertools/htm/api/FlagType.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.github.fabricservertools.htm.api;

import com.mojang.serialization.Codec;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.StringIdentifiable;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.util.StringRepresentable;
import org.jspecify.annotations.Nullable;

public enum FlagType implements StringIdentifiable {
public enum FlagType implements StringRepresentable {
HOPPERS("hoppers", true),
COPPER_GOLEMS("copper_golems", true);

public static final Codec<FlagType> CODEC = StringIdentifiable.createCodec(FlagType::values);
public static final Codec<FlagType> CODEC = StringRepresentable.fromEnum(FlagType::values);

private final String id;
private final boolean defaultValue;
Expand All @@ -20,19 +21,19 @@ public enum FlagType implements StringIdentifiable {
}

@Override
public String asString() {
public String getSerializedName() {
return id;
}

public boolean defaultValue() {
return defaultValue;
}

public Text displayName() {
return Text.literal(id.toUpperCase()).formatted(Formatting.WHITE);
public Component displayName() {
return Component.literal(id.toUpperCase()).withStyle(ChatFormatting.WHITE);
}

public static FlagType fromString(String flag) {
public static @Nullable FlagType fromString(String flag) {
for (FlagType type : values()) {
if (type.id.equals(flag.toLowerCase())) {
return type;
Expand Down
Loading