Added customizable config messages & feature toggles
This commit is contained in:
25
README.md
25
README.md
@ -11,17 +11,28 @@ As a challenge I'm trying to make it as user-friendly as possible. (It ain't the
|
|||||||
- Tab list dimension indicator
|
- Tab list dimension indicator
|
||||||
|
|
||||||
### Commands
|
### Commands
|
||||||
- /spectator | Essentially server-side freecam, you get put in spectator and are able to fly around, once you use the command again you get put back to where you were.
|
- /spectator | Essentially server-side free-cam, you get put in spectator and are able to fly around, once you use the command again you get put back to where you were.
|
||||||
|
|
||||||
|
## Currently working on
|
||||||
|
|
||||||
|
### Features
|
||||||
|
- Config
|
||||||
|
- [x] Configurable messages
|
||||||
|
- [x] Feature toggle
|
||||||
|
- [ ] Shared Ender Chest
|
||||||
|
- [ ] Access control
|
||||||
|
|
||||||
|
|
||||||
|
### Misc
|
||||||
|
- [x] Updated icon
|
||||||
|
|
||||||
## Features to come
|
## Features to come
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
- Config
|
|
||||||
- [ ] Configurable messages
|
|
||||||
- [ ] Configurable players for Ender Chest
|
|
||||||
- Vein miner
|
- Vein miner
|
||||||
- Telekinesis
|
- Telekinesis
|
||||||
- Shared Ender Chest
|
|
||||||
- [ ] Shared for all
|
### Commands
|
||||||
- [ ] Shared per team
|
|
||||||
|
- /slimechunk (/sc) | See if you're currently in a slimechunk
|
@ -9,7 +9,7 @@ yarn_mappings=1.21.4+build.8
|
|||||||
loader_version=0.16.10
|
loader_version=0.16.10
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version=1.2.0
|
mod_version=1.2.1
|
||||||
maven_group=wtf.hak.survivalfabric
|
maven_group=wtf.hak.survivalfabric
|
||||||
archives_base_name=survivalfabric
|
archives_base_name=survivalfabric
|
||||||
|
|
||||||
|
26
src/main/java/wtf/hak/survivalfabric/config/Config.java
Normal file
26
src/main/java/wtf/hak/survivalfabric/config/Config.java
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package wtf.hak.survivalfabric.config;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Config {
|
||||||
|
|
||||||
|
public boolean joinMessageEnabled = true;
|
||||||
|
public String joinMessage = "§8[§a+§8] §7%s";
|
||||||
|
|
||||||
|
public boolean quitMessageEnabled = true;
|
||||||
|
public String quitMessage = "§8[§c-§8] §7%s";
|
||||||
|
|
||||||
|
public boolean chatMessageEnabled = true;
|
||||||
|
public String chatMessage = "§7%s§8:§f %s";
|
||||||
|
|
||||||
|
public boolean dimensionIndicatorEnabled = true;
|
||||||
|
public String overworldPrefix = "§8[§aOverworld§8] ";
|
||||||
|
public String netherPrefix = "§8[§cNether§8] ";
|
||||||
|
public String endPrefix = "§8[§dEnd§8] ";
|
||||||
|
public String spectatorPrefix = "§8[§eSpectator§8] ";
|
||||||
|
public String unknownPrefix = "§8[§7Unknown§8] ";
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package wtf.hak.survivalfabric.config;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class ConfigManager {
|
||||||
|
|
||||||
|
private static final File CONFIG_FILE = FabricLoader.getInstance().getConfigDir().resolve("survivalfabric.json").toFile();
|
||||||
|
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||||
|
|
||||||
|
private static Config INSTANCE;
|
||||||
|
|
||||||
|
public static Config getConfig() {
|
||||||
|
if (INSTANCE == null) {
|
||||||
|
return load();
|
||||||
|
}else
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Config load() {
|
||||||
|
try(FileReader reader = new FileReader(CONFIG_FILE)) {
|
||||||
|
return GSON.fromJson(reader, Config.class);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Config config = new Config();
|
||||||
|
save(config);
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void save(Config config) {
|
||||||
|
try(FileWriter writer = new FileWriter(CONFIG_FILE)) {
|
||||||
|
GSON.toJson(config, writer);
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error saving config: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -14,7 +14,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
|||||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
import wtf.hak.survivalfabric.commands.SpectatorCommand;
|
import wtf.hak.survivalfabric.commands.SpectatorCommand;
|
||||||
import wtf.hak.survivalfabric.utils.Messages;
|
import wtf.hak.survivalfabric.config.ConfigManager;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -24,14 +24,19 @@ public abstract class PlayerManagerMixin {
|
|||||||
|
|
||||||
@Inject(method = {"onPlayerConnect"}, at = {@At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V")})
|
@Inject(method = {"onPlayerConnect"}, at = {@At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V")})
|
||||||
public void onPlayerConnect(ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData, CallbackInfo ci) {
|
public void onPlayerConnect(ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData, CallbackInfo ci) {
|
||||||
Text text = Text.literal(String.format(Messages.JOIN_MESSAGE, player.getName().getString()));
|
if(ConfigManager.getConfig().joinMessageEnabled) {
|
||||||
|
Text text = Text.literal(String.format(ConfigManager.getConfig().joinMessage, player.getName().getString()));
|
||||||
player.sendMessage(text, false);
|
player.sendMessage(text, false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ModifyArg(method = {"onPlayerConnect"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V"))
|
@ModifyArg(method = {"onPlayerConnect"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V"))
|
||||||
private Text onPlayerConnect(Text text) {
|
private Text onPlayerConnect(Text text) {
|
||||||
|
if(ConfigManager.getConfig().joinMessageEnabled) {
|
||||||
String name = text.getString().split(" ")[0];
|
String name = text.getString().split(" ")[0];
|
||||||
return Text.literal(String.format(Messages.JOIN_MESSAGE, name));
|
return Text.literal(String.format(ConfigManager.getConfig().joinMessage, name));
|
||||||
|
} else
|
||||||
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = {"remove"}, at = {@At("HEAD")})
|
@Inject(method = {"remove"}, at = {@At("HEAD")})
|
||||||
@ -45,8 +50,8 @@ public abstract class PlayerManagerMixin {
|
|||||||
|
|
||||||
@Inject(method = {"broadcast(Lnet/minecraft/network/message/SignedMessage;Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/network/message/MessageType$Parameters;)V"}, at = {@At("HEAD")}, cancellable = true)
|
@Inject(method = {"broadcast(Lnet/minecraft/network/message/SignedMessage;Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/network/message/MessageType$Parameters;)V"}, at = {@At("HEAD")}, cancellable = true)
|
||||||
private void onBroadcast(SignedMessage message, ServerPlayerEntity sender, MessageType.Parameters parameters, CallbackInfo ci) {
|
private void onBroadcast(SignedMessage message, ServerPlayerEntity sender, MessageType.Parameters parameters, CallbackInfo ci) {
|
||||||
if(sender != null) {
|
if(sender != null && ConfigManager.getConfig().chatMessageEnabled) {
|
||||||
Text text = Text.literal(String.format(Messages.CHAT_FORMAT, sender.getName().getString(), message.getContent().getString()));
|
Text text = Text.literal(String.format(ConfigManager.getConfig().chatMessage, sender.getName().getString(), message.getContent().getString()));
|
||||||
Objects.requireNonNull(sender.getServer()).getPlayerManager().broadcast(text, false);
|
Objects.requireNonNull(sender.getServer()).getPlayerManager().broadcast(text, false);
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
}
|
}
|
||||||
|
@ -5,15 +5,18 @@ import net.minecraft.text.Text;
|
|||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||||
import wtf.hak.survivalfabric.utils.Messages;
|
import wtf.hak.survivalfabric.config.ConfigManager;
|
||||||
|
|
||||||
@Mixin(ServerPlayNetworkHandler.class)
|
@Mixin(ServerPlayNetworkHandler.class)
|
||||||
public abstract class ServerPlayNetworkHandlerMixin {
|
public abstract class ServerPlayNetworkHandlerMixin {
|
||||||
|
|
||||||
@ModifyArg(method = {"cleanUp"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V"))
|
@ModifyArg(method = {"cleanUp"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V"))
|
||||||
private Text quitMessage(Text text) {
|
private Text quitMessage(Text text) {
|
||||||
|
if(ConfigManager.getConfig().quitMessageEnabled) {
|
||||||
String name = text.getString().split(" ")[0];
|
String name = text.getString().split(" ")[0];
|
||||||
return Text.literal(String.format(Messages.QUIT_MESSAGE, name));
|
return Text.literal(String.format(ConfigManager.getConfig().quitMessage, name));
|
||||||
|
}
|
||||||
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,28 +7,30 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
import wtf.hak.survivalfabric.commands.SpectatorCommand;
|
import wtf.hak.survivalfabric.commands.SpectatorCommand;
|
||||||
import wtf.hak.survivalfabric.utils.Messages;
|
import wtf.hak.survivalfabric.config.ConfigManager;
|
||||||
|
|
||||||
@Mixin(ServerPlayerEntity.class)
|
@Mixin(ServerPlayerEntity.class)
|
||||||
public abstract class ServerPlayerEntityMixin {
|
public abstract class ServerPlayerEntityMixin {
|
||||||
|
|
||||||
@Inject(method = "getPlayerListName", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "getPlayerListName", at = @At("HEAD"), cancellable = true)
|
||||||
private void changePlayerListName(CallbackInfoReturnable<Text> cir) {
|
private void changePlayerListName(CallbackInfoReturnable<Text> cir) {
|
||||||
|
if(ConfigManager.getConfig().dimensionIndicatorEnabled) {
|
||||||
ServerPlayerEntity p = (ServerPlayerEntity) (Object) this;
|
ServerPlayerEntity p = (ServerPlayerEntity) (Object) this;
|
||||||
String world = p.getServerWorld().getRegistryKey().getValue().toTranslationKey();
|
String world = p.getServerWorld().getRegistryKey().getValue().toTranslationKey();
|
||||||
String finalName;
|
String finalName;
|
||||||
if (!SpectatorCommand.spectating.containsKey(p)) {
|
if (!SpectatorCommand.spectating.containsKey(p)) {
|
||||||
finalName = switch (world) {
|
finalName = switch (world) {
|
||||||
case "minecraft.overworld" -> Messages.OVERWORLD_PREFIX;
|
case "minecraft.overworld" -> ConfigManager.getConfig().overworldPrefix;
|
||||||
case "minecraft.the_nether" -> Messages.NETHER_PREFIX;
|
case "minecraft.the_nether" -> ConfigManager.getConfig().netherPrefix;
|
||||||
case "minecraft.the_end" -> Messages.END_PREFIX;
|
case "minecraft.the_end" -> ConfigManager.getConfig().endPrefix;
|
||||||
default -> Messages.UNKNOWN_PREFIX;
|
default -> ConfigManager.getConfig().unknownPrefix;
|
||||||
};
|
};
|
||||||
} else
|
} else
|
||||||
finalName = Messages.SPECTATOR_PREFIX;
|
finalName = ConfigManager.getConfig().spectatorPrefix;
|
||||||
|
|
||||||
finalName += "§7" + p.getName().getString();
|
finalName += "§7" + p.getName().getString();
|
||||||
|
|
||||||
cir.setReturnValue(Text.of(finalName));
|
cir.setReturnValue(Text.of(finalName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
package wtf.hak.survivalfabric.utils;
|
|
||||||
|
|
||||||
public class Messages {
|
|
||||||
public static final String JOIN_MESSAGE = "§8[§a+§8] §7%s";
|
|
||||||
|
|
||||||
public static final String QUIT_MESSAGE = "§8[§c-§8] §7%s";
|
|
||||||
|
|
||||||
public static final String CHAT_FORMAT = "§7%s§8:§f %s";
|
|
||||||
|
|
||||||
public static final String OVERWORLD_PREFIX = "§8[§aOverworld§8] ";
|
|
||||||
public static final String NETHER_PREFIX = "§8[§cNether§8] ";
|
|
||||||
public static final String END_PREFIX = "§8[§dEnd§8] ";
|
|
||||||
public static final String SPECTATOR_PREFIX = "§8[§eSpectator§8] ";
|
|
||||||
public static final String UNKNOWN_PREFIX = "§8[§7Unknown§8] ";
|
|
||||||
|
|
||||||
}
|
|
Reference in New Issue
Block a user