2018-07-21 18:47:46 +00:00
|
|
|
package me.zeroeightsix.kami;
|
|
|
|
|
2018-10-14 14:33:27 +00:00
|
|
|
import com.google.common.base.Converter;
|
|
|
|
import com.google.gson.JsonElement;
|
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
import com.google.gson.JsonPrimitive;
|
2018-10-02 18:46:43 +00:00
|
|
|
import me.zero.alpine.EventBus;
|
|
|
|
import me.zero.alpine.EventManager;
|
2018-10-14 14:33:27 +00:00
|
|
|
import me.zeroeightsix.kami.command.Command;
|
2018-07-21 18:47:46 +00:00
|
|
|
import me.zeroeightsix.kami.command.CommandManager;
|
|
|
|
import me.zeroeightsix.kami.event.ForgeEventProcessor;
|
|
|
|
import me.zeroeightsix.kami.gui.kami.KamiGUI;
|
2018-10-14 14:33:27 +00:00
|
|
|
import me.zeroeightsix.kami.gui.rgui.component.AlignedComponent;
|
|
|
|
import me.zeroeightsix.kami.gui.rgui.component.Component;
|
|
|
|
import me.zeroeightsix.kami.gui.rgui.component.container.use.Frame;
|
|
|
|
import me.zeroeightsix.kami.gui.rgui.util.ContainerHelper;
|
|
|
|
import me.zeroeightsix.kami.gui.rgui.util.Docking;
|
2018-07-21 18:47:46 +00:00
|
|
|
import me.zeroeightsix.kami.module.Module;
|
|
|
|
import me.zeroeightsix.kami.module.ModuleManager;
|
2019-12-15 23:14:30 +00:00
|
|
|
import me.zeroeightsix.kami.module.modules.bewwawho.capes.Capes;
|
|
|
|
import me.zeroeightsix.kami.module.modules.bewwawho.misc.BlueDiscordRPC;
|
2019-12-16 15:57:56 +00:00
|
|
|
import me.zeroeightsix.kami.module.modules.bewwawho.util.Donator;
|
2018-10-14 14:33:27 +00:00
|
|
|
import me.zeroeightsix.kami.setting.Setting;
|
|
|
|
import me.zeroeightsix.kami.setting.Settings;
|
|
|
|
import me.zeroeightsix.kami.setting.SettingsRegister;
|
2018-10-13 23:31:30 +00:00
|
|
|
import me.zeroeightsix.kami.setting.config.Configuration;
|
2018-08-08 19:06:42 +00:00
|
|
|
import me.zeroeightsix.kami.util.Friends;
|
2018-07-21 18:47:46 +00:00
|
|
|
import me.zeroeightsix.kami.util.LagCompensator;
|
|
|
|
import me.zeroeightsix.kami.util.Wrapper;
|
2019-12-15 23:14:30 +00:00
|
|
|
import net.minecraft.client.Minecraft;
|
2018-07-21 18:47:46 +00:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.fml.common.Mod;
|
|
|
|
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
2019-12-15 23:14:30 +00:00
|
|
|
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
2018-07-21 18:47:46 +00:00
|
|
|
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
|
2019-12-13 03:59:59 +00:00
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.BufferedWriter;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2019-01-22 23:25:54 +00:00
|
|
|
import java.nio.file.Files;
|
2019-08-06 15:15:08 +00:00
|
|
|
import java.nio.file.NoSuchFileException;
|
2019-01-22 23:25:54 +00:00
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.nio.file.Paths;
|
2018-10-14 14:33:27 +00:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Optional;
|
2018-07-21 18:47:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by 086 on 7/11/2017.
|
2019-12-16 15:57:56 +00:00
|
|
|
* Updated by S-B99 on 16/12/19
|
2018-07-21 18:47:46 +00:00
|
|
|
*/
|
2019-12-13 02:45:22 +00:00
|
|
|
@Mod(
|
|
|
|
modid = KamiMod.MODID,
|
|
|
|
name = KamiMod.MODNAME,
|
|
|
|
version = KamiMod.MODVER,
|
|
|
|
updateJSON = KamiMod.UPDATE_JSON
|
|
|
|
)
|
2018-07-21 18:47:46 +00:00
|
|
|
public class KamiMod {
|
|
|
|
|
2019-12-15 05:24:26 +00:00
|
|
|
public static final String MODID = "kamiblue";
|
2019-10-25 12:47:00 +00:00
|
|
|
public static final String MODNAME = "KAMI Blue";
|
2019-12-15 23:55:35 +00:00
|
|
|
public static final String MODVER = "v1.1.1";
|
2019-12-13 02:45:22 +00:00
|
|
|
public static final String UPDATE_JSON = "https://raw.githubusercontent.com/S-B99/KAMI/features-master/assets/updateChecker.json";
|
2018-07-21 18:47:46 +00:00
|
|
|
|
|
|
|
public static final String KAMI_HIRAGANA = "\u304B\u307F";
|
|
|
|
public static final String KAMI_KATAKANA = "\u30AB\u30DF";
|
2019-12-13 02:45:22 +00:00
|
|
|
public static final String KAMI_KANJI = "\u30ab\u30df\u30d6\u30eb"; //\u30ab\u30df\u30d6\u30eb //\u795E
|
2019-11-07 01:26:36 +00:00
|
|
|
public static final String KAMI_BLUE = "\u1d0b\u1d00\u1d0d\u026a \u0299\u029f\u1d1c\u1d07";
|
2018-07-21 18:47:46 +00:00
|
|
|
|
2019-12-15 05:24:26 +00:00
|
|
|
private static final String KAMI_CONFIG_NAME_DEFAULT = "KAMIBlueConfig.json";
|
2018-10-14 13:21:16 +00:00
|
|
|
|
2019-12-15 05:24:26 +00:00
|
|
|
public static final Logger log = LogManager.getLogger("KAMI Blue");
|
2018-07-21 18:47:46 +00:00
|
|
|
|
|
|
|
public static final EventBus EVENT_BUS = new EventManager();
|
|
|
|
|
|
|
|
@Mod.Instance
|
|
|
|
private static KamiMod INSTANCE;
|
|
|
|
|
|
|
|
public KamiGUI guiManager;
|
|
|
|
public CommandManager commandManager;
|
2018-10-14 14:33:27 +00:00
|
|
|
private Setting<JsonObject> guiStateSetting = Settings.custom("gui", new JsonObject(), new Converter<JsonObject, JsonObject>() {
|
|
|
|
@Override
|
|
|
|
protected JsonObject doForward(JsonObject jsonObject) {
|
|
|
|
return jsonObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected JsonObject doBackward(JsonObject jsonObject) {
|
|
|
|
return jsonObject;
|
|
|
|
}
|
|
|
|
}).buildAndRegister("");
|
2018-07-21 18:47:46 +00:00
|
|
|
|
|
|
|
@Mod.EventHandler
|
|
|
|
public void preInit(FMLPreInitializationEvent event) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-12-15 23:14:30 +00:00
|
|
|
@Mod.EventHandler
|
|
|
|
public void postInit(FMLPostInitializationEvent event) {
|
2019-12-16 15:57:56 +00:00
|
|
|
for (Donator.DonatorUser user : Donator.INSTANCE.donatorUsers) {
|
2019-12-15 23:14:30 +00:00
|
|
|
if (user.uuid.equalsIgnoreCase(Minecraft.getMinecraft().session.getProfile().getId().toString())) {
|
|
|
|
DiscordPresence.presence.smallImageKey = "donator2";
|
|
|
|
DiscordPresence.presence.smallImageText = "donator uwu";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-21 18:47:46 +00:00
|
|
|
@Mod.EventHandler
|
|
|
|
public void init(FMLInitializationEvent event) {
|
|
|
|
KamiMod.log.info("\n\nInitializing KAMI " + MODVER);
|
|
|
|
|
|
|
|
ModuleManager.initialize();
|
|
|
|
|
|
|
|
ModuleManager.getModules().stream().filter(module -> module.alwaysListening).forEach(EVENT_BUS::subscribe);
|
|
|
|
MinecraftForge.EVENT_BUS.register(new ForgeEventProcessor());
|
|
|
|
LagCompensator.INSTANCE = new LagCompensator();
|
|
|
|
|
|
|
|
Wrapper.init();
|
|
|
|
|
|
|
|
guiManager = new KamiGUI();
|
|
|
|
guiManager.initializeGUI();
|
|
|
|
|
|
|
|
commandManager = new CommandManager();
|
|
|
|
|
2018-10-13 23:31:30 +00:00
|
|
|
Friends.initFriends();
|
2018-10-14 14:33:27 +00:00
|
|
|
SettingsRegister.register("commandPrefix", Command.commandPrefix);
|
|
|
|
loadConfiguration();
|
2018-07-21 18:47:46 +00:00
|
|
|
KamiMod.log.info("Settings loaded");
|
|
|
|
|
2019-12-17 15:32:16 +00:00
|
|
|
// custom names aren't known at compile-time
|
|
|
|
//ModuleManager.updateLookup(); // generate the lookup table after settings are loaded to make custom module names work
|
2019-01-20 16:45:46 +00:00
|
|
|
|
2019-12-15 23:14:30 +00:00
|
|
|
new Capes();
|
|
|
|
KamiMod.log.info("Capes init!\n");
|
|
|
|
|
2019-12-16 16:15:14 +00:00
|
|
|
new Donator();
|
|
|
|
KamiMod.log.info("Donators init!\n");
|
|
|
|
|
2018-07-21 18:47:46 +00:00
|
|
|
// After settings loaded, we want to let the enabled modules know they've been enabled (since the setting is done through reflection)
|
|
|
|
ModuleManager.getModules().stream().filter(Module::isEnabled).forEach(Module::enable);
|
|
|
|
|
2019-12-15 23:14:30 +00:00
|
|
|
|
2019-12-13 16:47:31 +00:00
|
|
|
try { // load modules that are on by default
|
|
|
|
ModuleManager.getModuleByName("InfoOverlay").setEnabled(true);
|
2019-12-15 23:14:30 +00:00
|
|
|
if (((BlueDiscordRPC) ModuleManager.getModuleByName("DiscordRPC")).startupGlobal.getValue()) {
|
|
|
|
ModuleManager.getModuleByName("DiscordRPC").setEnabled(true);
|
|
|
|
}
|
2019-12-13 16:47:31 +00:00
|
|
|
}
|
|
|
|
catch (NullPointerException e) {
|
|
|
|
KamiMod.log.info("NPE in loading always enabled modules\n");
|
|
|
|
}
|
|
|
|
|
2018-10-14 13:21:16 +00:00
|
|
|
KamiMod.log.info("KAMI Mod initialized!\n");
|
|
|
|
}
|
|
|
|
|
2018-10-14 15:24:30 +00:00
|
|
|
public static String getConfigName() {
|
2019-12-15 05:58:19 +00:00
|
|
|
Path config = Paths.get("KAMIBlueLastConfig.txt");
|
2018-10-14 13:21:16 +00:00
|
|
|
String kamiConfigName = KAMI_CONFIG_NAME_DEFAULT;
|
2019-12-13 03:59:59 +00:00
|
|
|
try (BufferedReader reader = Files.newBufferedReader(config)) {
|
2018-10-14 13:21:16 +00:00
|
|
|
kamiConfigName = reader.readLine();
|
|
|
|
if (!isFilenameValid(kamiConfigName)) kamiConfigName = KAMI_CONFIG_NAME_DEFAULT;
|
2019-08-06 15:15:08 +00:00
|
|
|
} catch (NoSuchFileException e) {
|
2019-12-13 03:59:59 +00:00
|
|
|
try (BufferedWriter writer = Files.newBufferedWriter(config)) {
|
2018-10-14 13:21:16 +00:00
|
|
|
writer.write(KAMI_CONFIG_NAME_DEFAULT);
|
|
|
|
} catch (IOException e1) {
|
|
|
|
e1.printStackTrace();
|
2018-10-11 18:25:17 +00:00
|
|
|
}
|
2018-10-14 13:21:16 +00:00
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return kamiConfigName;
|
|
|
|
}
|
2018-10-11 18:25:17 +00:00
|
|
|
|
2018-10-14 13:21:16 +00:00
|
|
|
public static void loadConfiguration() {
|
|
|
|
try {
|
|
|
|
loadConfigurationUnsafe();
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void loadConfigurationUnsafe() throws IOException {
|
|
|
|
String kamiConfigName = getConfigName();
|
2019-01-22 23:25:54 +00:00
|
|
|
Path kamiConfig = Paths.get(kamiConfigName);
|
|
|
|
if (!Files.exists(kamiConfig)) return;
|
2018-10-14 13:21:16 +00:00
|
|
|
Configuration.loadConfiguration(kamiConfig);
|
2018-10-14 14:33:27 +00:00
|
|
|
|
|
|
|
JsonObject gui = KamiMod.INSTANCE.guiStateSetting.getValue();
|
|
|
|
for (Map.Entry<String, JsonElement> entry : gui.entrySet()) {
|
|
|
|
Optional<Component> optional = KamiMod.INSTANCE.guiManager.getChildren().stream().filter(component -> component instanceof Frame).filter(component -> ((Frame) component).getTitle().equals(entry.getKey())).findFirst();
|
|
|
|
if (optional.isPresent()) {
|
|
|
|
JsonObject object = entry.getValue().getAsJsonObject();
|
|
|
|
Frame frame = (Frame) optional.get();
|
|
|
|
frame.setX(object.get("x").getAsInt());
|
|
|
|
frame.setY(object.get("y").getAsInt());
|
|
|
|
Docking docking = Docking.values()[object.get("docking").getAsInt()];
|
|
|
|
if (docking.isLeft()) ContainerHelper.setAlignment(frame, AlignedComponent.Alignment.LEFT);
|
|
|
|
else if (docking.isRight()) ContainerHelper.setAlignment(frame, AlignedComponent.Alignment.RIGHT);
|
2019-12-13 03:59:59 +00:00
|
|
|
else if (docking.isCenterVertical())
|
|
|
|
ContainerHelper.setAlignment(frame, AlignedComponent.Alignment.CENTER);
|
2018-10-14 14:33:27 +00:00
|
|
|
frame.setDocking(docking);
|
|
|
|
frame.setMinimized(object.get("minimized").getAsBoolean());
|
|
|
|
frame.setPinned(object.get("pinned").getAsBoolean());
|
|
|
|
} else {
|
|
|
|
System.err.println("Found GUI config entry for " + entry.getKey() + ", but found no frame with that name");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
KamiMod.getInstance().getGuiManager().getChildren().stream().filter(component -> (component instanceof Frame) && (((Frame) component).isPinneable()) && component.isVisible()).forEach(component -> component.setOpacity(0f));
|
2018-10-14 13:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void saveConfiguration() {
|
|
|
|
try {
|
|
|
|
saveConfigurationUnsafe();
|
2019-12-13 03:59:59 +00:00
|
|
|
} catch (IOException e) {
|
2018-10-14 13:21:16 +00:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void saveConfigurationUnsafe() throws IOException {
|
2018-10-14 14:33:27 +00:00
|
|
|
JsonObject object = new JsonObject();
|
|
|
|
KamiMod.INSTANCE.guiManager.getChildren().stream().filter(component -> component instanceof Frame).map(component -> (Frame) component).forEach(frame -> {
|
|
|
|
JsonObject frameObject = new JsonObject();
|
|
|
|
frameObject.add("x", new JsonPrimitive(frame.getX()));
|
|
|
|
frameObject.add("y", new JsonPrimitive(frame.getY()));
|
|
|
|
frameObject.add("docking", new JsonPrimitive(Arrays.asList(Docking.values()).indexOf(frame.getDocking())));
|
|
|
|
frameObject.add("minimized", new JsonPrimitive(frame.isMinimized()));
|
|
|
|
frameObject.add("pinned", new JsonPrimitive(frame.isPinned()));
|
|
|
|
object.add(frame.getTitle(), frameObject);
|
|
|
|
});
|
|
|
|
KamiMod.INSTANCE.guiStateSetting.setValue(object);
|
|
|
|
|
2019-01-22 23:25:54 +00:00
|
|
|
Path outputFile = Paths.get(getConfigName());
|
|
|
|
if (!Files.exists(outputFile))
|
|
|
|
Files.createFile(outputFile);
|
2018-10-14 13:21:16 +00:00
|
|
|
Configuration.saveConfiguration(outputFile);
|
|
|
|
ModuleManager.getModules().forEach(Module::destroy);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isFilenameValid(String file) {
|
|
|
|
File f = new File(file);
|
|
|
|
try {
|
|
|
|
f.getCanonicalPath();
|
|
|
|
return true;
|
|
|
|
} catch (IOException e) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-21 18:47:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static KamiMod getInstance() {
|
|
|
|
return INSTANCE;
|
|
|
|
}
|
|
|
|
|
|
|
|
public KamiGUI getGuiManager() {
|
|
|
|
return guiManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
public CommandManager getCommandManager() {
|
|
|
|
return commandManager;
|
|
|
|
}
|
|
|
|
}
|