Skip to content

Commit

Permalink
I lied with the previous version... The mod works now
Browse files Browse the repository at this point in the history
  • Loading branch information
MrFrydae committed Feb 19, 2021
1 parent 1be9af0 commit 2e1d6d9
Show file tree
Hide file tree
Showing 20 changed files with 112 additions and 97 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ loader_version=0.11.1
fabric_version=0.29.3+1.16

# Mod Properties
mod_version = 1.3.0
mod_version = 1.3.2
maven_group = coffee.waffle
archives_base_name = empire-minecraft-utilities

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package coffee.waffle.emcutils;
package dev.frydae.emcutils;

import coffee.waffle.emcutils.callbacks.CommandExecutionCallback;
import coffee.waffle.emcutils.features.UsableItems;
import coffee.waffle.emcutils.features.VisitResidenceHandler;
import coffee.waffle.emcutils.utils.Config;
import coffee.waffle.emcutils.utils.Util;
import dev.frydae.emcutils.callbacks.CommandExecutionCallback;
import dev.frydae.emcutils.features.UsableItems;
import dev.frydae.emcutils.features.VisitResidenceHandler;
import dev.frydae.emcutils.utils.Config;
import dev.frydae.emcutils.utils.Util;
import lombok.Getter;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
Expand All @@ -24,7 +24,7 @@ public void onInitialize() {
logger = LogManager.getLogger("EMC Utils");
Util.getOnJoinCommandQueue();

Config.initConfig();
Config.getInstance().load();

registerListeners();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package coffee.waffle.emcutils.callbacks;
package dev.frydae.emcutils.callbacks;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package coffee.waffle.emcutils.callbacks;
package dev.frydae.emcutils.callbacks;

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package coffee.waffle.emcutils.features;
package dev.frydae.emcutils.features;

import coffee.waffle.emcutils.utils.Util;
import dev.frydae.emcutils.utils.Util;
import lombok.AllArgsConstructor;
import lombok.Getter;
import net.minecraft.client.MinecraftClient;
Expand All @@ -9,7 +9,6 @@
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.LiteralText;
import net.minecraft.util.Formatting;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package coffee.waffle.emcutils.features;
package dev.frydae.emcutils.features;

import coffee.waffle.emcutils.utils.Config;
import coffee.waffle.emcutils.utils.EmpireServer;
import coffee.waffle.emcutils.utils.Util;
import dev.frydae.emcutils.utils.Config;
import dev.frydae.emcutils.utils.ModMenuIntegration;
import dev.frydae.emcutils.utils.EmpireServer;
import dev.frydae.emcutils.utils.Util;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import net.minecraft.client.network.PlayerListEntry;
Expand Down Expand Up @@ -33,20 +34,20 @@ public static List<PlayerListEntry> sortPlayers(List<PlayerListEntry> original)
}
}

if (!Config.getConfigValues().isTabListShowAllServers()) {
if (!Config.getInstance().isTabListShowAllServers()) {
enhanced = enhanced.stream().filter(e -> e.server == Util.getCurrentServer()).collect(Collectors.toList());
}

// This ensures that the names are in alphabetical order before any other sort.
enhanced.sort(Config.TabListSortType.NAME_ASCENDING::compare);
currentServer.sort(Config.TabListSortType.NAME_ASCENDING::compare);
enhanced.sort(ModMenuIntegration.TabListSortType.NAME_ASCENDING::compare);
currentServer.sort(ModMenuIntegration.TabListSortType.NAME_ASCENDING::compare);

// This sorts based on what config option you have set
enhanced.sort(Config.getConfigValues().getTabListSortType()::compare);
enhanced.sort(Config.getInstance().getTabListSortType()::compare);

List<EnhancedTabListEntry> sorted = Lists.newArrayList();

switch (Config.getConfigValues().getTabListCurrentServerPlacement()) {
switch (Config.getInstance().getTabListCurrentServerPlacement()) {
case TOP:
enhanced.removeAll(currentServer);
sorted.addAll(currentServer);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package coffee.waffle.emcutils.features;
package dev.frydae.emcutils.features;

import coffee.waffle.emcutils.utils.Util;
import dev.frydae.emcutils.utils.Util;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package coffee.waffle.emcutils.features;
package dev.frydae.emcutils.features;

import coffee.waffle.emcutils.utils.EmpireServer;
import coffee.waffle.emcutils.utils.Log;
import coffee.waffle.emcutils.utils.Util;
import dev.frydae.emcutils.utils.EmpireServer;
import dev.frydae.emcutils.utils.Log;
import dev.frydae.emcutils.utils.Util;
import com.google.common.collect.Lists;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package coffee.waffle.emcutils.mixins;
package dev.frydae.emcutils.mixins;

import coffee.waffle.emcutils.features.ChatChannels;
import dev.frydae.emcutils.features.ChatChannels;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.util.math.MatrixStack;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package coffee.waffle.emcutils.mixins;
package dev.frydae.emcutils.mixins;

import coffee.waffle.emcutils.callbacks.ChatCallback;
import coffee.waffle.emcutils.callbacks.CommandExecutionCallback;
import dev.frydae.emcutils.callbacks.ChatCallback;
import dev.frydae.emcutils.callbacks.CommandExecutionCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.util.ActionResult;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package coffee.waffle.emcutils.mixins;
package dev.frydae.emcutils.mixins;

import coffee.waffle.emcutils.callbacks.ChatCallback;
import coffee.waffle.emcutils.features.ChatChannels;
import coffee.waffle.emcutils.features.VisitResidenceHandler;
import coffee.waffle.emcutils.utils.Util;
import dev.frydae.emcutils.callbacks.ChatCallback;
import dev.frydae.emcutils.features.ChatChannels;
import dev.frydae.emcutils.features.VisitResidenceHandler;
import dev.frydae.emcutils.utils.Util;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package coffee.waffle.emcutils.mixins;
package dev.frydae.emcutils.mixins;

import coffee.waffle.emcutils.utils.Util;
import dev.frydae.emcutils.utils.Util;
import net.minecraft.client.gui.screen.ConnectScreen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package coffee.waffle.emcutils.mixins;
package dev.frydae.emcutils.mixins;

import coffee.waffle.emcutils.features.TabListOrganizer;
import dev.frydae.emcutils.features.TabListOrganizer;
import net.minecraft.client.gui.hud.PlayerListHud;
import net.minecraft.client.network.PlayerListEntry;
import org.spongepowered.asm.mixin.Mixin;
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/dev/frydae/emcutils/utils/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package dev.frydae.emcutils.utils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lombok.Getter;
import lombok.Setter;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Config {
@Getter @Setter private boolean tabListShowAllServers;
@Getter @Setter private ModMenuIntegration.TabListSortType tabListSortType;
@Getter @Setter private ModMenuIntegration.TabListCurrentServerPlacement tabListCurrentServerPlacement;

private static volatile Config singleton;

private Config() {
this.tabListShowAllServers = true;
this.tabListSortType = ModMenuIntegration.TabListSortType.SERVER_ASCENDING;
this.tabListCurrentServerPlacement = ModMenuIntegration.TabListCurrentServerPlacement.TOP;
}

public static synchronized Config getInstance() {
if (singleton == null) {
singleton = new Config();
}

return singleton;
}

public void load() {
try (FileReader reader = new FileReader("config/emc_utils.json")) {
Gson gson = new Gson();

singleton = gson.fromJson(reader, Config.class);
} catch (IOException e) {
Log.exception(e);
}
}

public void save() {
try (FileWriter writer = new FileWriter("config/emc_utils.json")) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();

gson.toJson(singleton, writer);
} catch (IOException e) {
Log.exception(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package coffee.waffle.emcutils.utils;
package dev.frydae.emcutils.utils;

import lombok.Getter;
import net.minecraft.client.MinecraftClient;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package coffee.waffle.emcutils.utils;
package dev.frydae.emcutils.utils;

import coffee.waffle.emcutils.EmpireMinecraftUtilities;
import dev.frydae.emcutils.EmpireMinecraftUtilities;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.logging.log4j.Logger;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,103 +1,68 @@
package coffee.waffle.emcutils.utils;
package dev.frydae.emcutils.utils;

import coffee.waffle.emcutils.features.TabListOrganizer;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import dev.frydae.emcutils.features.TabListOrganizer;
import io.github.prospector.modmenu.api.ConfigScreenFactory;
import io.github.prospector.modmenu.api.ModMenuApi;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import me.shedaniel.clothconfig2.api.ConfigBuilder;
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.TranslatableText;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

@Environment(EnvType.CLIENT)
public class Config implements ModMenuApi {
@Getter private static ConfigValues configValues;

public static void initConfig() {
try (FileReader reader = new FileReader("config/emc_utils.json")) {
Gson gson = new Gson();

configValues = gson.fromJson(reader, ConfigValues.class);
} catch (IOException e) {
Log.exception(e);
}
}

@Getter @Setter
public static class ConfigValues {
public boolean tabListShowAllServers = true;
public TabListSortType tabListSortType = TabListSortType.SERVER_ASCENDING;
public TabListCurrentServerPlacement tabListCurrentServerPlacement = TabListCurrentServerPlacement.TOP;
}
public class ModMenuIntegration implements ModMenuApi {

@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return Config::genConfig;
return ModMenuIntegration::genConfig;
}

private static Screen genConfig(Screen parent) {
ConfigBuilder builder = ConfigBuilder.create()
.setParentScreen(parent)
.setTitle(new TranslatableText("emc_utils.config"))
.setSavingRunnable(Config::save);
.setSavingRunnable(Config.getInstance()::save);
ConfigEntryBuilder entryBuilder = builder.entryBuilder();

builder.getOrCreateCategory(new TranslatableText("emc_utils.config.tablist.category"))
.addEntry(entryBuilder
.startBooleanToggle(
new TranslatableText("emc_utils.config.tablist.showAllServers"),
configValues.isTabListShowAllServers()
Config.getInstance().isTabListShowAllServers()
)
.setDefaultValue(true)
.setSaveConsumer(configValues::setTabListShowAllServers)
.setSaveConsumer(Config.getInstance()::setTabListShowAllServers)
.build()
)
.addEntry(entryBuilder
.startEnumSelector(
new TranslatableText("emc_utils.config.tablist.sort.type"),
TabListSortType.class,
configValues.getTabListSortType()
Config.getInstance().getTabListSortType()
)
.setDefaultValue(TabListSortType.NAME_ASCENDING)
.setEnumNameProvider(type -> ((TabListSortType) type).getDescription())
.setSaveConsumer(configValues::setTabListSortType)
.setSaveConsumer(Config.getInstance()::setTabListSortType)
.build()
)
.addEntry(entryBuilder
.startEnumSelector(
new TranslatableText("emc_utils.config.tablist.placement"),
TabListCurrentServerPlacement.class,
configValues.getTabListCurrentServerPlacement()
Config.getInstance().getTabListCurrentServerPlacement()
)
.setDefaultValue(TabListCurrentServerPlacement.TOP)
.setEnumNameProvider(placement -> ((TabListCurrentServerPlacement) placement).getDescription())
.setSaveConsumer(configValues::setTabListCurrentServerPlacement)
.setSaveConsumer(Config.getInstance()::setTabListCurrentServerPlacement)
.build()
);

return builder.build();
}

private static void save() {
try (FileWriter writer = new FileWriter("config/emc_utils.json")) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();

gson.toJson(configValues, writer);
} catch (IOException e) {
Log.exception(e);
}
}

@AllArgsConstructor
public enum TabListCurrentServerPlacement {
TOP(new TranslatableText("emc_utils.config.tablist.placement.top")),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package coffee.waffle.emcutils.utils;
package dev.frydae.emcutils.utils;

import coffee.waffle.emcutils.features.VisitResidenceHandler;
import com.google.common.collect.Queues;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
Expand Down Expand Up @@ -55,7 +54,6 @@ public static int getUserGroup(String name) {
public static void handleServerPlayConnect(ClientPlayNetworkHandler handler, MinecraftClient client) {
String playerName = handler.getProfile().getName();

VisitResidenceHandler.loadResidences();
setPlayerGroupId(playerName);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/emcutils.mixins.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"required": true,
"minVersion": "0.8",
"package": "coffee.waffle.emcutils.mixins",
"package": "dev.frydae.emcutils.mixins",
"compatibilityLevel": "JAVA_8",
"mixins": [
"ClientEntityPlayerMixin",
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
"environment": "*",
"entrypoints": {
"main": [
"coffee.waffle.emcutils.EmpireMinecraftUtilities"
"dev.frydae.emcutils.EmpireMinecraftUtilities"
],
"modmenu": [
"coffee.waffle.emcutils.utils.Config"
"dev.frydae.emcutils.utils.ModMenuIntegration"
]
},
"mixins": [
Expand Down

0 comments on commit 2e1d6d9

Please sign in to comment.