Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Commit

Permalink
All the Configs updated to Spongepowered Configurate
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsEeleeya committed Feb 5, 2020
1 parent b078d5e commit d115276
Show file tree
Hide file tree
Showing 32 changed files with 159 additions and 122 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 KiloCraft
Copyright (c) 2019-2020 KiloCraft

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ dependencies {

compile "org.spongepowered:configurate-hocon:${project.configurate_version}"
shadow "org.spongepowered:configurate-hocon:${project.configurate_version}"
compile group: 'com.electronwill.night-config', name: 'yaml', version: "${project.night_config_version}"
shadow group: 'com.electronwill.night-config', name: 'yaml', version: "${project.night_config_version}"
compile group: 'org.fusesource.jansi', name: 'jansi', version: '1.17.1'
shadow group: 'org.fusesource.jansi', name: 'jansi', version: '1.17.1'
compile group: 'com.google.inject', name: 'guice', version: '4.0'
Expand Down
2 changes: 0 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ mod_version = 1.8.0-valentains-configurate_pending
# Dependencies
# A set of annotations used for code inspection support and code documentation.
jetbrains_annotations = 17.0.0
#NightConfig yaml
night_config_version = 3.6.0
#Sponge Powered Configurate
configurate_version = 3.6.1
#Cfg4j
Expand Down
27 changes: 10 additions & 17 deletions src/main/java/org/kilocraft/essentials/KiloEssentialsImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import org.kilocraft.essentials.chat.channels.GlobalChat;
import org.kilocraft.essentials.chat.channels.StaffChat;
import org.kilocraft.essentials.commands.CommandHelper;
import org.kilocraft.essentials.commands.misc.DiscordCommand;
import org.kilocraft.essentials.commands.misc.VoteCommand;
import org.kilocraft.essentials.config.KiloConfig;
import org.kilocraft.essentials.events.server.ServerScheduledUpdateEventImpl;
import org.kilocraft.essentials.extensions.betterchairs.PlayerSitManager;
Expand Down Expand Up @@ -71,7 +69,7 @@ public class KiloEssentialsImpl implements KiloEssentials {
private List<FeatureType<SingleInstanceConfigurableFeature>> singleInstanceConfigurationRegistry = new ArrayList<>();
private Map<FeatureType<? extends SingleInstanceConfigurableFeature>, SingleInstanceConfigurableFeature> proxySingleInstanceFeatures = new HashMap<>();

public KiloEssentialsImpl(KiloEvents events, KiloConfig config) {
public KiloEssentialsImpl(final KiloEvents events, final KiloConfig config) {
instance = this;
logger.info("Running KiloEssentials version " + ModConstants.getVersion());
minecraftServer = KiloServer.getServer().getVanillaServer();
Expand Down Expand Up @@ -129,12 +127,12 @@ public KiloEssentialsImpl(KiloEvents events, KiloConfig config) {
getServer().getChatManager().register(new BuilderChat());

ConfigurableFeatures features = new ConfigurableFeatures();
features.tryToRegister(new UserHomeHandler(), "PlayerHomes");
features.tryToRegister(new WarpManager(), "ServerWideWarps");
features.tryToRegister(new PlayerSitManager(), "BetterChairs");
features.tryToRegister(new DiscordCommand(), "DiscordCommand");
features.tryToRegister(new VoteCommand(), "VoteCommand");
features.tryToRegister(new ParticleAnimationManager(), "MagicalParticles");
features.tryToRegister(new UserHomeHandler(), "playerHomes");
features.tryToRegister(new WarpManager(), "serverWideWarps");
features.tryToRegister(new PlayerSitManager(), "betterChairs");
//features.tryToRegister(new DiscordCommand(), "DiscordCommand");
//features.tryToRegister(new VoteCommand(), "VoteCommand");
features.tryToRegister(new ParticleAnimationManager(), "magicalParticles");

if (KiloConfig.main().startupScript().enabled)
new StartupScript();
Expand Down Expand Up @@ -199,10 +197,10 @@ public MessageUtil getMessageUtil() {
}

public static KiloEssentialsImpl getInstance() {
if (instance == null)
throw new RuntimeException("Its too early to get a static instance of KiloEssentials!");
if (instance != null)
return instance;

return instance;
throw new RuntimeException("Its too early to get a static instance of KiloEssentials!");
}

private static String featureEntry(String name) {
Expand All @@ -213,11 +211,6 @@ public Server getServer() {
return KiloServer.getServer();
}

@Override
public ModConstants getConstants() {
return constants;
}

@Override
public KiloCommands getCommandHandler() {
return this.commands;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import net.fabricmc.api.DedicatedServerModInitializer;
import net.minecraft.SharedConstants;
import org.kilocraft.essentials.api.KiloEssentials;
import org.kilocraft.essentials.chat.channels.GlobalChat;
import org.kilocraft.essentials.config.KiloConfig;

import java.io.File;
Expand All @@ -14,12 +13,10 @@ public void onInitializeServer() {
File debugFile = new File(KiloEssentials.getWorkingDirectory() + "/kiloessentials.debug");
if (debugFile.exists()) {
KiloEssentials.getServer().getLogger().warn("**** SERVER IS RUNNING IN DEBUG/DEVELOPMENT MODE!");
KiloEssentials.getServer().getLogger().warn("To change this simply remove the \"kiloessentials.debug\" file");
SharedConstants.isDevelopment = true;
}

new KiloEssentialsImpl(new KiloEvents(), new KiloConfig());

String template = KiloConfig.getMainNode().getNode("chat").getNode("channelsMeta").getNode(GlobalChat.getChannelId() + "Chat").getString();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ static boolean hasPermissionNode(ServerCommandSource source, EssentialPermission

MessageUtil getMessageUtil();

ModConstants getConstants();

KiloCommands getCommandHandler();

CompletableFuture<Optional<User>> getUserThenAcceptAsync(ServerCommandSource requester, String username, Consumer<? super User> action);
Expand Down Expand Up @@ -102,6 +100,6 @@ static String getEssentialsDirectory() {
}

static String getDataDirectory() {
return getEssentialsDirectory() + "/data/";
return getEssentialsDirectory() + "data/";
}
}
10 changes: 5 additions & 5 deletions src/main/java/org/kilocraft/essentials/api/chat/TextFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private static String[] list() {
}

public static final char COLOR_CHAR = '\u00A7';
private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf(COLOR_CHAR) + "[0-9A-FK-OR]");
private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + COLOR_CHAR + "[0-9A-FK-OR]");

private final int intCode;
private final char code;
Expand All @@ -126,7 +126,7 @@ private static String[] list() {
private static final Map<Integer, TextFormat> BY_ID = Maps.newHashMap();
private static final Map<Character, TextFormat> BY_CHAR = Maps.newHashMap();

private TextFormat(char code, int intCode, Formatting formatting, boolean isFormat, String ansi) {
TextFormat(char code, int intCode, Formatting formatting, boolean isFormat, String ansi) {
this.code = code;
this.intCode = intCode;
this.isFormat = isFormat;
Expand All @@ -135,15 +135,15 @@ private TextFormat(char code, int intCode, Formatting formatting, boolean isForm
this.ansi = ansi;
}

private TextFormat(char code, int intCode, Formatting formatting, String ansi) {
TextFormat(char code, int intCode, Formatting formatting, String ansi) {
this(code, intCode, formatting, false, ansi);
}

private TextFormat(char code, int intCode, Formatting formatting) {
TextFormat(char code, int intCode, Formatting formatting) {
this(code, intCode, formatting, false);
}

private TextFormat(char code, int intCode, Formatting formatting, boolean isFormat) {
TextFormat(char code, int intCode, Formatting formatting, boolean isFormat) {
this(code, intCode, formatting, isFormat, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import org.kilocraft.essentials.api.user.OnlineUser;
import org.kilocraft.essentials.api.user.User;
import org.kilocraft.essentials.chat.KiloChat;
import org.kilocraft.essentials.config.KiloConfig;
import org.kilocraft.essentials.config.main.Config;
import org.kilocraft.essentials.config.messages.Messages;

import java.util.Optional;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -223,4 +226,8 @@ public RequiredArgumentBuilder<ServerCommandSource, String> getUserArgument(Stri
public String tl(String key, Object... objects) {
return ModConstants.translation(key, objects);
}

public Config config = KiloConfig.main();

public Messages messages = KiloConfig.messages();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public ConfigurableFeatures() {

public <F extends ConfigurableFeature> F tryToRegister(F feature, String configID) {
try {
if (KiloConfig.getMainNode().getNode("features." + configID).getBoolean()) {
if (KiloConfig.getMainNode().getNode("features").getNode(configID).getBoolean()) {
if (SharedConstants.isDevelopment)
KiloEssentialsImpl.getLogger().info("Initialing \"" + feature.getClass().getName() + "\"");

Expand Down
11 changes: 8 additions & 3 deletions src/main/java/org/kilocraft/essentials/chat/ChatMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import org.kilocraft.essentials.api.chat.TextFormat;
import org.kilocraft.essentials.api.user.OnlineUser;
import org.kilocraft.essentials.api.user.User;
import org.kilocraft.essentials.config.ConfigVariableFactory;

Expand All @@ -22,9 +23,13 @@ public ChatMessage(String message, boolean formatText) {
public ChatMessage(String message, User user) {
this.original = ConfigVariableFactory.replaceUserVariables(message, user);
this.formatText = true;
this.formatted = formatText ?
TextFormat.translateAlternateColorCodes('&', message) :
TextFormat.removeAlternateColorCodes('&', message);
this.formatted = TextFormat.translateAlternateColorCodes('&', original);
}

public ChatMessage(String message, OnlineUser user) {
this.original = ConfigVariableFactory.replaceOnlineUserVariables(message, user);
this.formatText = true;
this.formatted = TextFormat.translateAlternateColorCodes('&', message);
}

public String getFormattedMessage() {
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/org/kilocraft/essentials/chat/ServerChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ public class ServerChat {
private static boolean pingEnabled = config.ping().enabled;

public static void send(OnlineUser sender, String rawMessage, ChatChannel channel) {
// String template = config.getStringSafely(ConfigCache.valueOf(
// ("chat.channels.formats." + channel.getId()).replaceAll("\\.", "_").toUpperCase()),
// "&r[&r%USER_DISPLAYNAME%&r]:&r %MESSAGE%");
String template = KiloConfig.getMainNode().getNode("chat").getNode("channelsMeta").getNode(channel.getId() + "Chat").getString();
ServerPlayerEntity player = sender.getPlayer();

Expand Down Expand Up @@ -79,7 +76,7 @@ public static void send(OnlineUser sender, String rawMessage, ChatChannel channe
KiloChat.sendMessageTo(sender.getPlayer(), new LiteralText(e.getMessage()));
}

message.setMessage(ConfigVariableFactory.replaceUserVariables(message.getFormattedMessage(), sender)
message.setMessage(ConfigVariableFactory.replaceUserVariables(template, sender)
.replace("%USER_RANKED_DISPLAYNAME%", sender.getRankedDisplayName().asFormattedString())
.replace("%MESSAGE%", message.getFormattedMessage()), true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private int setSelf(CommandContext<ServerCommandSource> ctx) throws CommandSynta

User user = KiloServer.getServer().getUserManager().getOnline(self);

KiloServer.getServer().getCommandSourceUser(source).sendMessage(new ChatMessage(KiloConfig.getMessage("commands.nickname.setSelf")
KiloServer.getServer().getCommandSourceUser(source).sendMessage(new ChatMessage(messages.commands().nickname().setSelf
.replace("{NICK}", user.getNickname().isPresent() ? user.getNickname().get() : user.getDisplayName())
.replace("{NICK_NEW}", nickname)
, true));
Expand Down Expand Up @@ -129,7 +129,7 @@ private int setOther(CommandContext<ServerCommandSource> ctx) throws CommandSynt

essentials.getUserThenAcceptAsync(source, getUserArgumentInput(ctx, "user"), (user) -> {
String formattedNickname = TextFormat.translateAlternateColorCodes('&', nickname);
KiloServer.getServer().getCommandSourceUser(source).sendMessage(new ChatMessage(KiloConfig.getMessage("commands.nickname.setOthers")
KiloServer.getServer().getCommandSourceUser(source).sendMessage(new ChatMessage(messages.commands().nickname().setOthers
.replace("{NICK}", user.getNickname().isPresent() ? user.getNickname().get() : user.getDisplayName())
.replace("{NICK_NEW}", nickname)
.replace("{TARGET_TAG}", user.getNameTag())
Expand Down Expand Up @@ -157,21 +157,24 @@ private int setOther(CommandContext<ServerCommandSource> ctx) throws CommandSynt
private int resetSelf(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
ServerPlayerEntity player = ctx.getSource().getPlayer();
User user = KiloServer.getServer().getUserManager().getOnline(player);
user.clearNickname();
// This is an Optional.ofNullable, so the DataTracker will just reset the name without any other magic since TrackedData is always and automatically synchronized with the client.
user.clearNickname(); /* This is an Optional.ofNullable, so the DataTracker will
just reset the name without any other magic since TrackedData
is always and automatically synchronized with the client. */

player.setCustomName(null);

KiloServer.getServer().getCommandSourceUser(ctx.getSource()).sendConfigMessage("commands.nickname.resetSelf");
KiloServer.getServer().getCommandSourceUser(ctx.getSource()).sendMessage(messages.commands().nickname().resetSelf);
return 1;
}

private int resetOther(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
CommandSourceUser source = getServerUser(ctx);

essentials.getUserThenAcceptAsync(source, getUserArgumentInput(ctx, "user"), (user) -> {
user.clearNickname(); // This is an Optional.ofNullable, so the DataTracker will
// just reset the name without any other magic since TrackedData
// is always and automatically synchronized with the client.
user.clearNickname(); /* This is an Optional.ofNullable, so the DataTracker will
just reset the name without any other magic since TrackedData
is always and automatically synchronized with the client. */

if (user.isOnline())
((OnlineUser) user).getPlayer().setCustomName(new LiteralText(""));
else {
Expand All @@ -182,7 +185,7 @@ private int resetOther(CommandContext<ServerCommandSource> ctx) throws CommandSy
dataModifier.save();
}

KiloServer.getServer().getCommandSourceUser(ctx.getSource()).sendMessage(new ChatMessage(KiloConfig.getMessage("commands.nickname.resetOthers")
KiloServer.getServer().getCommandSourceUser(ctx.getSource()).sendMessage(new ChatMessage(messages.commands().nickname().resetOthers
.replace("{TARGET_TAG}", user.getNameTag())
, true));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ static void teleportRandomly(ServerCommandSource source, ServerPlayerEntity targ

//Check if the target is in the correct dimension or has permission to perform the command in other dimensions
if (!target.dimension.equals(DimensionType.OVERWORLD) && !PERMISSION_CHECK_OTHER_DIMENSIONS.test(source)) {
targetUser.sendConfigMessage("commands.rtp.dimension_exception");
targetUser.sendConfigMessage("commands.rtp.dimensionException");
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.kilocraft.essentials.config;

public class ConfigObjectReplacerUtil {
private boolean isLocal;
private String prefix;
private String text;

public ConfigObjectReplacerUtil(String prefix, String str) {
this.prefix = prefix;
this.text = str;
}

public ConfigObjectReplacerUtil(String prefix, String str, boolean isLocal) {
this.prefix = prefix;
this.text = str;
this.isLocal = isLocal;
}

public String toVar(String key) {
String s = prefix.toUpperCase() + "_" + key.toUpperCase();
return isLocal ? "{" + s + "}" : "%" + s + "%";
}

public ConfigObjectReplacerUtil append(String key, Object value) {
this.text = text.replace(toVar(key), String.valueOf(value));
return this;
}

public String toString() {
String s = this.text;
this.text = null;
this.prefix = null;
return s;
}
}
Loading

0 comments on commit d115276

Please sign in to comment.