just a copy of petroleum right now
This commit is contained in:
		
						commit
						183c81258a
					
				
					 88 changed files with 7405 additions and 0 deletions
				
			
		
							
								
								
									
										59
									
								
								remappedSrc/pm/j4/petroleum/util/config/Config.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								remappedSrc/pm/j4/petroleum/util/config/Config.java
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,59 @@ | |||
| package pm.j4.petroleum.util.config; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| import pm.j4.petroleum.PetroleumMod; | ||||
| import pm.j4.petroleum.util.module.ModuleBase; | ||||
| 
 | ||||
| /** | ||||
|  * The type Config. | ||||
|  */ | ||||
| public abstract class Config { | ||||
| 	/** | ||||
| 	 * The Enabled modules. | ||||
| 	 */ | ||||
| 	public List<String> enabledModules = new ArrayList<>(); | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Is enabled boolean. | ||||
| 	 * | ||||
| 	 * @param mod the mod | ||||
| 	 * @return the boolean | ||||
| 	 */ | ||||
| 	public boolean isEnabled(String mod) { | ||||
| 		return enabledModules.contains(mod); | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Disable module. | ||||
| 	 * | ||||
| 	 * @param mod the mod | ||||
| 	 */ | ||||
| 	public void disableModule(String mod) { | ||||
| 		if (isEnabled(mod) && PetroleumMod.isActive(mod) && PetroleumMod.getMod(mod).isPresent()) { | ||||
| 			ModuleBase moduleInfo = PetroleumMod.getMod(mod).get(); | ||||
| 			if (moduleInfo.isActivatable()) { | ||||
| 				enabledModules.remove(mod); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Toggle module. | ||||
| 	 * | ||||
| 	 * @param mod the mod | ||||
| 	 */ | ||||
| 	public void toggleModule(String mod) { | ||||
| 		if (PetroleumMod.isActive(mod) && PetroleumMod.getMod(mod).isPresent()) { | ||||
| 			ModuleBase moduleInfo = PetroleumMod.getMod(mod).get(); | ||||
| 			if (moduleInfo.isActivatable()) { | ||||
| 				if (isEnabled(mod)) { | ||||
| 					enabledModules.remove(mod); | ||||
| 				} else { | ||||
| 					enabledModules.add(mod); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										102
									
								
								remappedSrc/pm/j4/petroleum/util/config/ConfigHolder.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										102
									
								
								remappedSrc/pm/j4/petroleum/util/config/ConfigHolder.java
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,102 @@ | |||
| package pm.j4.petroleum.util.config; | ||||
| 
 | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import java.util.stream.Collectors; | ||||
| import pm.j4.petroleum.PetroleumMod; | ||||
| import pm.j4.petroleum.util.module.ModuleBase; | ||||
| 
 | ||||
| /** | ||||
|  * The type Config holder. | ||||
|  */ | ||||
| public class ConfigHolder { | ||||
| 	/** | ||||
| 	 * The Global config. | ||||
| 	 */ | ||||
| 	public GlobalConfig globalConfig; | ||||
| 	/** | ||||
| 	 * The Server configs. | ||||
| 	 */ | ||||
| 	public Map<String, ServerConfig> serverConfigs; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Is module enabled boolean. | ||||
| 	 * | ||||
| 	 * @param module the module | ||||
| 	 * @return the boolean | ||||
| 	 */ | ||||
| 	public boolean isModuleEnabled(String module) { | ||||
| 
 | ||||
| 		if (!PetroleumMod.isActive(module)) { | ||||
| 			return false; | ||||
| 		} | ||||
| 		if (globalConfig.isEnabled(module)) { | ||||
| 			return true; | ||||
| 		} | ||||
| 		String server = this.getServer(); | ||||
| 		if (serverConfigs.containsKey(server)) { | ||||
| 			return serverConfigs.get(server).isEnabled(module); | ||||
| 		} | ||||
| 		return false; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Gets enabled modules. | ||||
| 	 * | ||||
| 	 * @return the enabled modules | ||||
| 	 */ | ||||
| 	public List<ModuleBase> getEnabledModules() { | ||||
| 		List<ModuleBase> modules = PetroleumMod.getActiveMods(); | ||||
| 		return modules.stream().filter(module -> | ||||
| 				isModuleEnabled(module.getModuleName()) | ||||
| 		).collect(Collectors.toList()); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Gets server. | ||||
| 	 * | ||||
| 	 * @return the server | ||||
| 	 */ | ||||
| 	public String getServer() { | ||||
| 		return PetroleumMod.getServerAddress(); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Toggle module. | ||||
| 	 * | ||||
| 	 * @param module the module | ||||
| 	 */ | ||||
| 	public void toggleModule(String module) { | ||||
| 		String server = this.getServer(); | ||||
| 		if (serverConfigs.containsKey(server)) { | ||||
| 			System.out.println("Toggling module " + module + " on server " + server); | ||||
| 			serverConfigs.get(server).toggleModule(module); | ||||
| 		} else { | ||||
| 			globalConfig.toggleModule(module); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Disable module. | ||||
| 	 * | ||||
| 	 * @param module the module | ||||
| 	 */ | ||||
| 	public void disableModule(String module) { | ||||
| 		String server = this.getServer(); | ||||
| 		if (serverConfigs.containsKey(server)) { | ||||
| 			System.out.println("disabling module " + module + " on server " + server); | ||||
| 			serverConfigs.get(server).disableModule(module); | ||||
| 		} else { | ||||
| 			globalConfig.disableModule(module); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Save module. | ||||
| 	 * | ||||
| 	 * @param module the module | ||||
| 	 */ | ||||
| 	public static void saveModule(ModuleBase module) { | ||||
| 
 | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										270
									
								
								remappedSrc/pm/j4/petroleum/util/config/ConfigManager.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										270
									
								
								remappedSrc/pm/j4/petroleum/util/config/ConfigManager.java
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,270 @@ | |||
| package pm.j4.petroleum.util.config; | ||||
| 
 | ||||
| import com.google.common.reflect.TypeToken; | ||||
| import com.google.gson.*; | ||||
| import java.io.*; | ||||
| import java.lang.reflect.Type; | ||||
| import java.util.*; | ||||
| import net.fabricmc.loader.api.FabricLoader; | ||||
| import pm.j4.petroleum.PetroleumMod; | ||||
| import pm.j4.petroleum.modules.bindings.BindingInfo; | ||||
| import pm.j4.petroleum.modules.menu.ModMenu; | ||||
| import pm.j4.petroleum.util.data.ButtonInformation; | ||||
| import pm.j4.petroleum.util.data.ModuleConfig; | ||||
| import pm.j4.petroleum.util.data.OptionSerializiable; | ||||
| import pm.j4.petroleum.util.module.ModuleBase; | ||||
| 
 | ||||
| /** | ||||
|  * The type Config manager. | ||||
|  */ | ||||
| public class ConfigManager { | ||||
| 	/** | ||||
| 	 * The constant GSON. | ||||
| 	 */ | ||||
| 	public static final Gson GSON = new GsonBuilder() | ||||
| 			.registerTypeAdapter(GlobalConfig.class, SerializationHelper.getGlobalSerializer()) | ||||
| 			.registerTypeAdapter(GlobalConfig.class, SerializationHelper.getGlobalDeserializer()) | ||||
| 			.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).setPrettyPrinting().create(); | ||||
| 	/** | ||||
| 	 * The constant config. | ||||
| 	 */ | ||||
| 	private static ConfigHolder config; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Prepare config file. | ||||
| 	 * | ||||
| 	 * @param path     the path | ||||
| 	 * @param filename the filename | ||||
| 	 * @return the file | ||||
| 	 */ | ||||
| 	private static File prepareConfigFile(String path, String filename) { | ||||
| 		if (path != "") { | ||||
| 			File directory = new File(FabricLoader.getInstance().getConfigDir().toString(), path); | ||||
| 			if (!directory.exists()) directory.mkdir(); | ||||
| 		} | ||||
| 		return new File(FabricLoader.getInstance().getConfigDir().toString(), path + filename); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Init config. | ||||
| 	 */ | ||||
| 	public static void initConfig() { | ||||
| 		if (config != null) { | ||||
| 			return; | ||||
| 		} | ||||
| 
 | ||||
| 		config = new ConfigHolder(); | ||||
| 		config.globalConfig = new DefaultConfig(); | ||||
| 		config.serverConfigs = new HashMap<>(); | ||||
| 
 | ||||
| 		config = load("petroleum/", "petroleum.json", ConfigHolder.class); | ||||
| 		initModules(); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Init modules. | ||||
| 	 */ | ||||
| 	public static void initModules() { | ||||
| 		PetroleumMod.getActiveMods().forEach(module -> { | ||||
| 			ModuleConfig options = load("petroleum/modules/", module.getModuleName() + ".json", ModuleConfig.class); | ||||
| 			if (options != null && options.options != null) { | ||||
| 				options.options.forEach((key, option) -> { | ||||
| 					if (module.hasOption(option.key)) { | ||||
| 						module.setConfigOption(option.key, option.value); | ||||
| 					} | ||||
| 				}); | ||||
| 			} | ||||
| 		}); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Load. | ||||
| 	 * | ||||
| 	 * @param <T>      the type parameter | ||||
| 	 * @param path     the path | ||||
| 	 * @param filename the filename | ||||
| 	 * @param tClass   the t class | ||||
| 	 * @return the t | ||||
| 	 */ | ||||
| 	private static <T> T load(String path, String filename, Class<T> tClass) { | ||||
| 		File file = prepareConfigFile(path, filename); | ||||
| 
 | ||||
| 		try { | ||||
| 			if (!file.exists()) { | ||||
| 				save(path, filename, tClass.newInstance()); | ||||
| 			} | ||||
| 			if (file.exists()) { | ||||
| 				BufferedReader reader = new BufferedReader(new FileReader(file)); | ||||
| 				T parsedConfig = null; | ||||
| 				try { | ||||
| 					parsedConfig = GSON.fromJson(reader, tClass); | ||||
| 				} catch (Exception e) { | ||||
| 					System.out.println("Couldn't parse config file"); | ||||
| 					e.printStackTrace(); | ||||
| 				} | ||||
| 				if (parsedConfig != null) { | ||||
| 					return parsedConfig; | ||||
| 				} | ||||
| 			} | ||||
| 		} catch (FileNotFoundException | InstantiationException | IllegalAccessException e) { | ||||
| 			System.out.println("Couldn't load configuration file at " + path); | ||||
| 			e.printStackTrace(); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Deserialize element t. | ||||
| 	 * | ||||
| 	 * @param <T>     the type parameter | ||||
| 	 * @param element the element | ||||
| 	 * @param tClass  the t class | ||||
| 	 * @return the t | ||||
| 	 */ | ||||
| 	public static <T> T deserializeElement(JsonElement element, Class<T> tClass) { | ||||
| 		return GSON.fromJson(element, tClass); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Save. | ||||
| 	 * | ||||
| 	 * @param <T>      the type parameter | ||||
| 	 * @param path     the path | ||||
| 	 * @param filename the filename | ||||
| 	 * @param data     the data | ||||
| 	 */ | ||||
| 	private static <T> void save(String path, String filename, T data) { | ||||
| 		File file = prepareConfigFile(path, filename); | ||||
| 
 | ||||
| 		String json = GSON.toJson(data); | ||||
| 		try (FileWriter fileWriter = new FileWriter(file)) { | ||||
| 			fileWriter.write(json); | ||||
| 		} catch (IOException e) { | ||||
| 			System.out.println("Couldn't save configuration file at " + path); | ||||
| 			e.printStackTrace(); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Save module. | ||||
| 	 * | ||||
| 	 * @param b the b | ||||
| 	 */ | ||||
| 	public static void saveModule(ModuleBase b) { | ||||
| 		ModuleConfig c = new ModuleConfig(); | ||||
| 		c.options = GlobalConfig.serializeModuleConfiguration(b); | ||||
| 		save("petroleum/modules/", b.getModuleName() + ".json", c); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Save all modules. | ||||
| 	 */ | ||||
| 	public static void saveAllModules() { | ||||
| 		List<ModuleBase> mods = PetroleumMod.getActiveMods(); | ||||
| 		mods.forEach(ConfigManager::saveModule); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Save global config. | ||||
| 	 */ | ||||
| 	public static void saveGlobalConfig() { | ||||
| 		save("petroleum/", "petroleum.json", config); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Gets config. | ||||
| 	 * | ||||
| 	 * @return the config | ||||
| 	 */ | ||||
| 	public static Optional<ConfigHolder> getConfig() { | ||||
| 		if (config == null) { | ||||
| 			return Optional.empty(); | ||||
| 		} | ||||
| 		return Optional.of(config); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * The type Serialization helper. | ||||
|  */ | ||||
| class SerializationHelper { | ||||
| 
 | ||||
| 	/** | ||||
| 	 * The constant s. | ||||
| 	 */ | ||||
| 	private static final JsonSerializer<GlobalConfig> GLOBAL_CONFIG_JSON_SERIALIZER = (src, typeOfSrc, ctx) -> { | ||||
| 		JsonObject jsonConfig = new JsonObject(); | ||||
| 
 | ||||
| 		JsonArray bindings = ctx.serialize(src.serializeBindings()).getAsJsonArray(); | ||||
| 		jsonConfig.add("bindings", bindings); | ||||
| 
 | ||||
| 		JsonArray modules = ctx.serialize(src.enabledModules).getAsJsonArray(); | ||||
| 		jsonConfig.add("enabled_modules", modules); | ||||
| 
 | ||||
| 		JsonObject tabCoordinates = new JsonObject(); | ||||
| 		ModMenu.getButtons().forEach((category, coordinates) -> { | ||||
| 			tabCoordinates.add(category, ctx.serialize(coordinates)); | ||||
| 		}); | ||||
| 		jsonConfig.add("button_coordinates", tabCoordinates); | ||||
| 
 | ||||
| 		return jsonConfig; | ||||
| 	}; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * The constant ds. | ||||
| 	 */ | ||||
| 	private static final JsonDeserializer<GlobalConfig> GLOBAL_CONFIG_JSON_DESERIALIZER = ((json, typeOfT, ctx) -> { | ||||
| 		JsonObject obj = json.getAsJsonObject(); | ||||
| 
 | ||||
| 		List<BindingInfo> bindings = new ArrayList<>(); | ||||
| 		if (obj.has("bindings")) { | ||||
| 			obj.get("bindings").getAsJsonArray().forEach(b -> bindings.add(ctx.deserialize(b, BindingInfo.class))); | ||||
| 		} | ||||
| 		List<String> modules = new ArrayList<>(); | ||||
| 		if (obj.has("enabled_modules")) { | ||||
| 			obj.get("enabled_modules").getAsJsonArray().forEach(m -> modules.add(m.getAsString())); | ||||
| 		} | ||||
| 		GlobalConfig cfg = new GlobalConfig(); | ||||
| 		Map<String, List<OptionSerializiable>> options; | ||||
| 		Type type = new TypeToken<Map<String, List<OptionSerializiable>>>() { | ||||
| 		}.getType(); | ||||
| 		if (obj.has("module_configuration")) { | ||||
| 			options = ctx.deserialize(obj.get("module_configuration"), type); | ||||
| 		} else { | ||||
| 			options = new HashMap<>(); | ||||
| 		} | ||||
| 		if (obj.has("button_coordinates")) { | ||||
| 			obj.get("button_coordinates").getAsJsonObject().entrySet().forEach( | ||||
| 					value -> { | ||||
| 						cfg.setButton(value.getKey(), ctx.deserialize(value.getValue(), ButtonInformation.class)); | ||||
| 					} | ||||
| 			); | ||||
| 		} | ||||
| 		PetroleumMod.getActiveMods().forEach(module -> { | ||||
| 			if (options.containsKey(module.getModuleName())) { | ||||
| 				cfg.deserializeModuleConfiguration(options.get(module.getModuleName()), module); | ||||
| 			} | ||||
| 		}); | ||||
| 		cfg.deserializeBindings(bindings); | ||||
| 		cfg.enabledModules = modules; | ||||
| 		return cfg; | ||||
| 	}); | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Gets serializer. | ||||
| 	 * | ||||
| 	 * @return the serializer | ||||
| 	 */ | ||||
| 	public static JsonSerializer<GlobalConfig> getGlobalSerializer() { | ||||
| 		return GLOBAL_CONFIG_JSON_SERIALIZER; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Gets deserializer. | ||||
| 	 * | ||||
| 	 * @return the deserializer | ||||
| 	 */ | ||||
| 	public static JsonDeserializer<GlobalConfig> getGlobalDeserializer() { | ||||
| 		return GLOBAL_CONFIG_JSON_DESERIALIZER; | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										15
									
								
								remappedSrc/pm/j4/petroleum/util/config/DefaultConfig.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								remappedSrc/pm/j4/petroleum/util/config/DefaultConfig.java
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,15 @@ | |||
| package pm.j4.petroleum.util.config; | ||||
| 
 | ||||
| import java.util.Collections; | ||||
| 
 | ||||
| /** | ||||
|  * The type Default config. | ||||
|  */ | ||||
| public class DefaultConfig extends GlobalConfig { | ||||
| 	/** | ||||
| 	 * Instantiates a new Default config. | ||||
| 	 */ | ||||
| 	public DefaultConfig() { | ||||
| 		this.enabledModules = Collections.singletonList("petroleum.splashtext"); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										189
									
								
								remappedSrc/pm/j4/petroleum/util/config/GlobalConfig.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										189
									
								
								remappedSrc/pm/j4/petroleum/util/config/GlobalConfig.java
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,189 @@ | |||
| package pm.j4.petroleum.util.config; | ||||
| 
 | ||||
| import java.util.*; | ||||
| import java.util.concurrent.atomic.AtomicBoolean; | ||||
| import net.minecraft.client.options.KeyBinding; | ||||
| import net.minecraft.client.util.InputUtil; | ||||
| import pm.j4.petroleum.PetroleumMod; | ||||
| import pm.j4.petroleum.modules.bindings.BindingInfo; | ||||
| import pm.j4.petroleum.util.data.ButtonInformation; | ||||
| import pm.j4.petroleum.util.data.OptionSerializiable; | ||||
| import pm.j4.petroleum.util.module.ModuleBase; | ||||
| import pm.j4.petroleum.util.module.option.ConfigurationOption; | ||||
| 
 | ||||
| /** | ||||
|  * The type Global config. | ||||
|  */ | ||||
| public class GlobalConfig extends Config { | ||||
| 	/** | ||||
| 	 * The Bindings. | ||||
| 	 */ | ||||
| 	public final Map<KeyBinding, ModuleBase> bindings = new HashMap<>(); | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Is bound boolean. | ||||
| 	 * | ||||
| 	 * @param func the func | ||||
| 	 * @return the boolean | ||||
| 	 */ | ||||
| 	public boolean isBound(ModuleBase func) { | ||||
| 		AtomicBoolean found = new AtomicBoolean(false); | ||||
| 		bindings.forEach((key, binding) -> { | ||||
| 			if (binding.equals(func)) { | ||||
| 				found.set(true); | ||||
| 			} | ||||
| 		}); | ||||
| 		return found.get(); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Sets binding. | ||||
| 	 * | ||||
| 	 * @param bind the bind | ||||
| 	 * @param func the func | ||||
| 	 */ | ||||
| 	public void setBinding(KeyBinding bind, ModuleBase func) { | ||||
| 		if (bindings.containsValue(func)) { | ||||
| 			bindings.forEach((key, binding) -> { | ||||
| 				if (binding.equals(func)) { | ||||
| 					PetroleumMod.removeBind(key); | ||||
| 					bindings.remove(key); | ||||
| 				} | ||||
| 			}); | ||||
| 		} | ||||
| 
 | ||||
| 		if (PetroleumMod.isActive(func.getModuleName())) { | ||||
| 			PetroleumMod.addBind(bind); | ||||
| 			bindings.put(bind, func); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Convert binding. | ||||
| 	 * | ||||
| 	 * @param info the info | ||||
| 	 */ | ||||
| 	private void convertBinding(BindingInfo info) { | ||||
| 		Optional<ModuleBase> match = PetroleumMod.getMod(info.attachedModuleName); | ||||
| 		match.ifPresent(moduleBase -> setBinding(reconstructBinding(info), | ||||
| 				moduleBase)); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Reconstruct binding key binding. | ||||
| 	 * | ||||
| 	 * @param info the info | ||||
| 	 * @return the key binding | ||||
| 	 */ | ||||
| 	public static KeyBinding reconstructBinding(BindingInfo info) { | ||||
| 		return new KeyBinding( | ||||
| 				info.translationKey, | ||||
| 				info.type, | ||||
| 				info.key, | ||||
| 				info.category | ||||
| 		); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Extract binding info. | ||||
| 	 * | ||||
| 	 * @param b the b | ||||
| 	 * @param f the f | ||||
| 	 * @return the binding info | ||||
| 	 */ | ||||
| 	public static BindingInfo extractBinding(KeyBinding b, ModuleBase f) { | ||||
| 		BindingInfo res = new BindingInfo(); | ||||
| 		res.attachedModuleName = f.getModuleName(); | ||||
| 
 | ||||
| 		res.translationKey = b.getTranslationKey(); | ||||
| 		InputUtil.Key k = b.getDefaultKey(); | ||||
| 		res.type = k.getCategory(); | ||||
| 		res.key = k.getCode(); | ||||
| 		res.category = b.getCategory(); | ||||
| 
 | ||||
| 		return res; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Serialize bindings list. | ||||
| 	 * | ||||
| 	 * @return the list | ||||
| 	 */ | ||||
| 	public List<BindingInfo> serializeBindings() { | ||||
| 		List<BindingInfo> b = new ArrayList<>(); | ||||
| 		bindings.forEach((k, f) -> b.add(extractBinding(k, f))); | ||||
| 		return b; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Deserialize bindings. | ||||
| 	 * | ||||
| 	 * @param info the info | ||||
| 	 */ | ||||
| 	public void deserializeBindings(List<BindingInfo> info) { | ||||
| 		info.forEach(this::convertBinding); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Serialize module configuration list. | ||||
| 	 * | ||||
| 	 * @param module the module | ||||
| 	 * @return the list | ||||
| 	 */ | ||||
| 	public static Map<String, OptionSerializiable> serializeModuleConfiguration(ModuleBase module) { | ||||
| 		Map<String, OptionSerializiable> opts = new HashMap<>(); | ||||
| 		Map<String, ConfigurationOption> configuration = module.getModuleConfiguration(); | ||||
| 		configuration.forEach((key, value) -> { | ||||
| 			opts.put(key, new OptionSerializiable(key, value.toJson())); | ||||
| 		}); | ||||
| 		return opts; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Deserialize module configuration. | ||||
| 	 * | ||||
| 	 * @param opts   the opts | ||||
| 	 * @param module the module | ||||
| 	 */ | ||||
| 	public void deserializeModuleConfiguration(List<OptionSerializiable> opts, ModuleBase module) { | ||||
| 		opts.forEach(option -> { | ||||
| 			if (module.hasOption(option.key)) { | ||||
| 				module.setConfigOption(option.key, option.value); | ||||
| 			} | ||||
| 		}); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * The Button locations. | ||||
| 	 */ | ||||
| 	private final Map<String, ButtonInformation> buttonLocations = new HashMap<>(); | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Sets button. | ||||
| 	 * | ||||
| 	 * @param category          the category | ||||
| 	 * @param buttonInformation the button information | ||||
| 	 */ | ||||
| 	public void setButton(String category, ButtonInformation buttonInformation) { | ||||
| 		if (buttonLocations.containsKey(category)) { | ||||
| 			buttonLocations.replace(category, buttonInformation); | ||||
| 		} else { | ||||
| 			buttonLocations.put(category, buttonInformation); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Gets button. | ||||
| 	 * | ||||
| 	 * @param category the category | ||||
| 	 * @return the button | ||||
| 	 */ | ||||
| 	public ButtonInformation getButton(String category) { | ||||
| 		if (buttonLocations.containsKey(category)) { | ||||
| 			return buttonLocations.get(category); | ||||
| 		} | ||||
| 		System.out.println("Could not find button of category " + category); | ||||
| 		return null; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
							
								
								
									
										11
									
								
								remappedSrc/pm/j4/petroleum/util/config/ServerConfig.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								remappedSrc/pm/j4/petroleum/util/config/ServerConfig.java
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,11 @@ | |||
| package pm.j4.petroleum.util.config; | ||||
| 
 | ||||
| /** | ||||
|  * The type Server config. | ||||
|  */ | ||||
| public class ServerConfig extends Config { | ||||
| 	/** | ||||
| 	 * The Address. | ||||
| 	 */ | ||||
| 	public String address = ""; | ||||
| } | ||||
							
								
								
									
										32
									
								
								remappedSrc/pm/j4/petroleum/util/data/ButtonInformation.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								remappedSrc/pm/j4/petroleum/util/data/ButtonInformation.java
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,32 @@ | |||
| package pm.j4.petroleum.util.data; | ||||
| 
 | ||||
| /** | ||||
|  * The type Button information. | ||||
|  */ | ||||
| public class ButtonInformation { | ||||
| 	/** | ||||
| 	 * The X. | ||||
| 	 */ | ||||
| 	public double x; | ||||
| 	/** | ||||
| 	 * The Y. | ||||
| 	 */ | ||||
| 	public double y; | ||||
| 	/** | ||||
| 	 * The Open. | ||||
| 	 */ | ||||
| 	public boolean open; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Instantiates a new Button information. | ||||
| 	 * | ||||
| 	 * @param x    the x | ||||
| 	 * @param y    the y | ||||
| 	 * @param open the open | ||||
| 	 */ | ||||
| 	public ButtonInformation(double x, double y, boolean open) { | ||||
| 		this.x = x; | ||||
| 		this.y = y; | ||||
| 		this.open = open; | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										47
									
								
								remappedSrc/pm/j4/petroleum/util/data/Category.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								remappedSrc/pm/j4/petroleum/util/data/Category.java
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,47 @@ | |||
| package pm.j4.petroleum.util.data; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import pm.j4.petroleum.PetroleumMod; | ||||
| import pm.j4.petroleum.util.module.ModuleBase; | ||||
| 
 | ||||
| /** | ||||
|  * The type Category. | ||||
|  */ | ||||
| public class Category { | ||||
| 	/** | ||||
| 	 * Gets category map. | ||||
| 	 * | ||||
| 	 * @return the category map | ||||
| 	 */ | ||||
| 	public static Map<String, List<ModuleBase>> getCategoryMap() { | ||||
| 		List<ModuleBase> modules = PetroleumMod.getActiveMods(); | ||||
| 		Map<String, List<ModuleBase>> categoryMap = new HashMap<>(); | ||||
| 		modules.forEach(module -> { | ||||
| 			if (!categoryMap.containsKey(module.getCategory())) { | ||||
| 				List<ModuleBase> m = new ArrayList<>(); | ||||
| 				m.add(module); | ||||
| 				categoryMap.put(module.getCategory(), m); | ||||
| 			} else { | ||||
| 				List<ModuleBase> m = categoryMap.get(module.getCategory()); | ||||
| 				List<ModuleBase> nm = new ArrayList<>(); | ||||
| 				nm.addAll(m); | ||||
| 				nm.add(module); | ||||
| 				categoryMap.replace(module.getCategory(), nm); | ||||
| 			} | ||||
| 		}); | ||||
| 		return categoryMap; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Gets by category. | ||||
| 	 * | ||||
| 	 * @param category the category | ||||
| 	 * @return the by category | ||||
| 	 */ | ||||
| 	public static List<ModuleBase> getByCategory(String category) { | ||||
| 		return getCategoryMap().containsKey(category) ? getCategoryMap().get(category) : new ArrayList<>(); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										13
									
								
								remappedSrc/pm/j4/petroleum/util/data/ModuleConfig.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								remappedSrc/pm/j4/petroleum/util/data/ModuleConfig.java
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,13 @@ | |||
| package pm.j4.petroleum.util.data; | ||||
| 
 | ||||
| import java.util.Map; | ||||
| 
 | ||||
| /** | ||||
|  * The type Module config. | ||||
|  */ | ||||
| public class ModuleConfig { | ||||
| 	/** | ||||
| 	 * The Options. | ||||
| 	 */ | ||||
| 	public Map<String, OptionSerializiable> options; | ||||
| } | ||||
|  | @ -0,0 +1,28 @@ | |||
| package pm.j4.petroleum.util.data; | ||||
| 
 | ||||
| import com.google.gson.JsonElement; | ||||
| 
 | ||||
| /** | ||||
|  * The type Option serializiable. | ||||
|  */ | ||||
| public class OptionSerializiable { | ||||
| 	/** | ||||
| 	 * Instantiates a new Option serializiable. | ||||
| 	 * | ||||
| 	 * @param key   the key | ||||
| 	 * @param value the value | ||||
| 	 */ | ||||
| 	public OptionSerializiable(String key, JsonElement value) { | ||||
| 		this.value = value; | ||||
| 		this.key = key; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * The Value. | ||||
| 	 */ | ||||
| 	public final JsonElement value; | ||||
| 	/** | ||||
| 	 * The Key. | ||||
| 	 */ | ||||
| 	public final String key; | ||||
| } | ||||
							
								
								
									
										229
									
								
								remappedSrc/pm/j4/petroleum/util/module/ModuleBase.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										229
									
								
								remappedSrc/pm/j4/petroleum/util/module/ModuleBase.java
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,229 @@ | |||
| package pm.j4.petroleum.util.module; | ||||
| 
 | ||||
| import com.google.gson.JsonElement; | ||||
| import java.util.*; | ||||
| import net.minecraft.client.MinecraftClient; | ||||
| import net.minecraft.text.TranslatableText; | ||||
| import pm.j4.petroleum.gui.PModuleConfigEntry; | ||||
| import pm.j4.petroleum.util.config.ConfigHolder; | ||||
| import pm.j4.petroleum.util.config.ConfigManager; | ||||
| import pm.j4.petroleum.util.module.option.ConfigurationOption; | ||||
| 
 | ||||
| /** | ||||
|  * The Basis for all mods, used so that modules all have a common activation point and settings. | ||||
|  */ | ||||
| public abstract class ModuleBase { | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Instantiates a new Module base. | ||||
| 	 * Parameters should be constant across restarts. | ||||
| 	 * | ||||
| 	 * @param name          The name of the module | ||||
| 	 * @param category      the category | ||||
| 	 * @param activatable   Whether a module can be activated, or if it will remain in the state it was upon startup | ||||
| 	 * @param hidden        Whether the module will show up in @link pm.j4.petroleum.modules.menu.ModMenu or the active module list | ||||
| 	 * @param hasConfigMenu whether a button in the configuration menu will show | ||||
| 	 */ | ||||
| 	public ModuleBase(String name, String category, boolean activatable, boolean hidden, boolean hasConfigMenu) { | ||||
| 		this.moduleName = name; | ||||
| 		this.category = category; | ||||
| 		this.readableName = new TranslatableText(name); | ||||
| 		this.activatable = activatable; | ||||
| 		this.hidden = hidden; | ||||
| 		this.hasConfigMenu = hasConfigMenu; | ||||
| 		this.moduleOptions = this.getDefaultConfig(); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Init. | ||||
| 	 */ | ||||
| 	public void init() { | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Activate. Should be overridden. | ||||
| 	 * | ||||
| 	 * @param client the client | ||||
| 	 */ | ||||
| 	public void activate(MinecraftClient client) { | ||||
| 		this.toggle(); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Toggle mod. | ||||
| 	 */ | ||||
| 	public void toggle() { | ||||
| 		Optional<ConfigHolder> config = ConfigManager.getConfig(); | ||||
| 		config.ifPresent(configHolder -> configHolder.toggleModule(this.moduleName)); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * The Module's name. | ||||
| 	 */ | ||||
| 	private final String moduleName; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Gets module name. | ||||
| 	 * | ||||
| 	 * @return the module name | ||||
| 	 */ | ||||
| 	public String getModuleName() { | ||||
| 		return this.moduleName; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * The Category. | ||||
| 	 */ | ||||
| 	private final String category; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Gets category. | ||||
| 	 * | ||||
| 	 * @return the category | ||||
| 	 */ | ||||
| 	public String getCategory() { | ||||
| 		return this.category; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * The Readable name. | ||||
| 	 */ | ||||
| 	private final TranslatableText readableName; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Gets readable name. | ||||
| 	 * | ||||
| 	 * @return the readable name | ||||
| 	 */ | ||||
| 	public TranslatableText getReadableName() { | ||||
| 		return this.readableName; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * The Activatable. | ||||
| 	 */ | ||||
| 	private final boolean activatable; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Is activatable boolean. | ||||
| 	 * | ||||
| 	 * @return the boolean | ||||
| 	 */ | ||||
| 	public boolean isActivatable() { | ||||
| 		return activatable; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * The Hidden. | ||||
| 	 */ | ||||
| 	private final boolean hidden; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Is hidden boolean. | ||||
| 	 * | ||||
| 	 * @return the boolean | ||||
| 	 */ | ||||
| 	public boolean isHidden() { | ||||
| 		return hidden; | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * The Has config menu. | ||||
| 	 */ | ||||
| 	private final boolean hasConfigMenu; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Configurable boolean. | ||||
| 	 * | ||||
| 	 * @return the boolean | ||||
| 	 */ | ||||
| 	public boolean configurable() { | ||||
| 		return hasConfigMenu; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * The Module options. | ||||
| 	 */ | ||||
| 	private final Map<String, ConfigurationOption> moduleOptions; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Gets module configuration. | ||||
| 	 * | ||||
| 	 * @return the module configuration | ||||
| 	 */ | ||||
| 	public Map<String, ConfigurationOption> getModuleConfiguration() { | ||||
| 		return moduleOptions; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Sets config option. | ||||
| 	 * This will fail if the option is not already present in a module. | ||||
| 	 * <p> | ||||
| 	 * | ||||
| 	 * @param key   the key | ||||
| 	 * @param value the value | ||||
| 	 * @return whether the operation was successful. | ||||
| 	 */ | ||||
| 	public boolean setConfigOption(String key, JsonElement value) { | ||||
| 		if (moduleOptions.containsKey(key)) { | ||||
| 			moduleOptions.get(key).fromJson(value); | ||||
| 			return true; | ||||
| 		} | ||||
| 		return false; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Has option boolean. | ||||
| 	 * | ||||
| 	 * @param key the key | ||||
| 	 * @return the boolean | ||||
| 	 */ | ||||
| 	public boolean hasOption(String key) { | ||||
| 		return moduleOptions.containsKey(key); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Gets default config. | ||||
| 	 * | ||||
| 	 * @return the default config | ||||
| 	 */ | ||||
| 	protected Map<String, ConfigurationOption> getDefaultConfig() { | ||||
| 		return new HashMap<>(); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Gets config option. | ||||
| 	 * | ||||
| 	 * @param key the key | ||||
| 	 * @return the config option | ||||
| 	 */ | ||||
| 	public Optional<ConfigurationOption> getConfigOption(String key) { | ||||
| 		if (moduleOptions.containsKey(key)) { | ||||
| 			return Optional.of(moduleOptions.get(key)); | ||||
| 		} | ||||
| 		return Optional.empty(); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Gets config entries. | ||||
| 	 * | ||||
| 	 * @return the config entries | ||||
| 	 */ | ||||
| 	public List<PModuleConfigEntry> getConfigEntries() { | ||||
| 		List<PModuleConfigEntry> entries = new ArrayList<>(); | ||||
| 		this.getModuleConfiguration().forEach((name, option) -> entries.add(new PModuleConfigEntry(option, new TranslatableText(name)))); | ||||
| 		return entries; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Equals boolean. | ||||
| 	 * | ||||
| 	 * @param other the other | ||||
| 	 * @return the boolean | ||||
| 	 */ | ||||
| 	public boolean equals(ModuleBase other) { | ||||
| 		return Objects.equals(this.moduleName, other.getModuleName()); | ||||
| 	} | ||||
| } | ||||
|  | @ -0,0 +1,38 @@ | |||
| package pm.j4.petroleum.util.module.option; | ||||
| 
 | ||||
| import com.google.gson.JsonElement; | ||||
| import com.google.gson.JsonPrimitive; | ||||
| 
 | ||||
| /** | ||||
|  * The type Boolean value. | ||||
|  */ | ||||
| public class BooleanOption extends ConfigurationOption { | ||||
| 	/** | ||||
| 	 * The Value. | ||||
| 	 */ | ||||
| 	private boolean value; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Instantiates a new Boolean option. | ||||
| 	 * | ||||
| 	 * @param description the description | ||||
| 	 */ | ||||
| 	public BooleanOption(String description) { | ||||
| 		super(description); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String getStringValue() { | ||||
| 		return Boolean.toString(value); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void fromJson(JsonElement e) { | ||||
| 		this.value = e.getAsBoolean(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public JsonElement toJson() { | ||||
| 		return new JsonPrimitive(value); | ||||
| 	} | ||||
| } | ||||
|  | @ -0,0 +1,59 @@ | |||
| package pm.j4.petroleum.util.module.option; | ||||
| 
 | ||||
| import com.google.gson.JsonElement; | ||||
| 
 | ||||
| /** | ||||
|  * The type Configuration option. | ||||
|  */ | ||||
| public abstract class ConfigurationOption { | ||||
| 	/** | ||||
| 	 * The Description. | ||||
| 	 */ | ||||
| 	private final String description; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Instantiates a new Configuration option. | ||||
| 	 * | ||||
| 	 * @param description the description | ||||
| 	 */ | ||||
| 	protected ConfigurationOption(String description) { | ||||
| 		this.description = description; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Gets description. | ||||
| 	 * | ||||
| 	 * @return the description | ||||
| 	 */ | ||||
| 	public final String getDescription() { | ||||
| 		return this.description; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Gets string value. | ||||
| 	 * | ||||
| 	 * @return the string value | ||||
| 	 */ | ||||
| 	public abstract String getStringValue(); | ||||
| 
 | ||||
| 	/** | ||||
| 	 * From json. | ||||
| 	 * | ||||
| 	 * @param e the e | ||||
| 	 */ | ||||
| 	public abstract void fromJson(JsonElement e); | ||||
| 
 | ||||
| 	/** | ||||
| 	 * To json json element. | ||||
| 	 * | ||||
| 	 * @return the json element | ||||
| 	 */ | ||||
| 	public abstract JsonElement toJson(); | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Update. | ||||
| 	 */ | ||||
| 	public void update() { | ||||
| 
 | ||||
| 	} | ||||
| } | ||||
|  | @ -0,0 +1,38 @@ | |||
| package pm.j4.petroleum.util.module.option; | ||||
| 
 | ||||
| import com.google.gson.JsonElement; | ||||
| import com.google.gson.JsonPrimitive; | ||||
| 
 | ||||
| /** | ||||
|  * The type Integer value. | ||||
|  */ | ||||
| public class IntegerOption extends ConfigurationOption { | ||||
| 	/** | ||||
| 	 * The Value. | ||||
| 	 */ | ||||
| 	private int value; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Instantiates a new Integer option. | ||||
| 	 * | ||||
| 	 * @param description the description | ||||
| 	 */ | ||||
| 	protected IntegerOption(String description) { | ||||
| 		super(description); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String getStringValue() { | ||||
| 		return Integer.toString(value); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void fromJson(JsonElement e) { | ||||
| 		this.value = e.getAsInt(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public JsonElement toJson() { | ||||
| 		return new JsonPrimitive(value); | ||||
| 	} | ||||
| } | ||||
|  | @ -0,0 +1,60 @@ | |||
| package pm.j4.petroleum.util.module.option; | ||||
| 
 | ||||
| import com.google.gson.JsonElement; | ||||
| import net.minecraft.client.options.KeyBinding; | ||||
| import pm.j4.petroleum.modules.bindings.BindingInfo; | ||||
| import pm.j4.petroleum.util.config.ConfigManager; | ||||
| import pm.j4.petroleum.util.config.GlobalConfig; | ||||
| import pm.j4.petroleum.util.module.ModuleBase; | ||||
| 
 | ||||
| /** | ||||
|  * The type Keybind value. | ||||
|  */ | ||||
| public class KeybindOption extends ConfigurationOption { | ||||
| 
 | ||||
| 	/** | ||||
| 	 * The Value. | ||||
| 	 */ | ||||
| 	private KeyBinding value; | ||||
| 	/** | ||||
| 	 * The Converted value. | ||||
| 	 */ | ||||
| 	private BindingInfo convertedValue; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Instantiates a new Keybind option. | ||||
| 	 * | ||||
| 	 * @param description the description | ||||
| 	 */ | ||||
| 	public KeybindOption(String description) { | ||||
| 		super(description); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String getStringValue() { | ||||
| 		return value.getDefaultKey().getLocalizedText().getString(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void fromJson(JsonElement e) { | ||||
| 		BindingInfo bindingInfo = ConfigManager.deserializeElement(e, BindingInfo.class); | ||||
| 		this.convertedValue = bindingInfo; | ||||
| 		this.value = GlobalConfig.reconstructBinding(bindingInfo); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public JsonElement toJson() { | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * From keybind. | ||||
| 	 * | ||||
| 	 * @param bind the bind | ||||
| 	 * @param base the base | ||||
| 	 */ | ||||
| 	public void fromKeybind(KeyBinding bind, ModuleBase base) { | ||||
| 		this.value = bind; | ||||
| 		this.convertedValue = GlobalConfig.extractBinding(bind, base); | ||||
| 	} | ||||
| } | ||||
|  | @ -0,0 +1,32 @@ | |||
| package pm.j4.petroleum.util.module.option; | ||||
| 
 | ||||
| import com.google.gson.JsonElement; | ||||
| 
 | ||||
| /** | ||||
|  * The type List option. | ||||
|  */ | ||||
| public class ListOption extends ConfigurationOption { | ||||
| 	/** | ||||
| 	 * Instantiates a new List option. | ||||
| 	 * | ||||
| 	 * @param description the description | ||||
| 	 */ | ||||
| 	protected ListOption(String description) { | ||||
| 		super(description); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String getStringValue() { | ||||
| 		return "ListObject"; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void fromJson(JsonElement e) { | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public JsonElement toJson() { | ||||
| 		return null; | ||||
| 	} | ||||
| } | ||||
|  | @ -0,0 +1,38 @@ | |||
| package pm.j4.petroleum.util.module.option; | ||||
| 
 | ||||
| import com.google.gson.JsonElement; | ||||
| import com.google.gson.JsonPrimitive; | ||||
| 
 | ||||
| /** | ||||
|  * The type String value. | ||||
|  */ | ||||
| public class StringOption extends ConfigurationOption { | ||||
| 
 | ||||
| 	/** | ||||
| 	 * The Value. | ||||
| 	 */ | ||||
| 	private String value; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Instantiates a new String option. | ||||
| 	 * | ||||
| 	 * @param description the description | ||||
| 	 */ | ||||
| 	protected StringOption(String description) { | ||||
| 		super(description); | ||||
| 	} | ||||
| 
 | ||||
| 	public String getStringValue() { | ||||
| 		return value; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void fromJson(JsonElement e) { | ||||
| 		this.value = e.getAsString(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public JsonElement toJson() { | ||||
| 		return new JsonPrimitive(value); | ||||
| 	} | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue