-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from wiviw5/main
Updating Skyblock Joining & Leaving Logic, Fixed Location updates, Added Logging.
- Loading branch information
Showing
11 changed files
with
439 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/main/java/io/github/skyblockcore/command/SkyblockCoreCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package io.github.skyblockcore.command; | ||
|
||
import com.mojang.brigadier.Command; | ||
import com.mojang.brigadier.CommandDispatcher; | ||
import com.mojang.brigadier.builder.LiteralArgumentBuilder; | ||
import io.github.skyblockcore.event.ConfigManager; | ||
import io.github.skyblockcore.event.ModConfig; | ||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.text.Style; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Formatting; | ||
|
||
import static io.github.skyblockcore.SkyblockCore.*; | ||
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; | ||
|
||
|
||
public class SkyblockCoreCommand { | ||
public static boolean NBTCOPYING = false; | ||
|
||
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher) { | ||
LiteralArgumentBuilder<FabricClientCommandSource> skyblockcore = literal("skyblockcore"); | ||
skyblockcore.then(literal("reload").executes(ctx -> reloadConfig())); | ||
skyblockcore.then(literal("nbt").executes(ctx -> nbt())); | ||
skyblockcore.then(literal("dev").executes(ctx -> dev())); | ||
skyblockcore.then(literal("test").executes(ctx -> test())); | ||
skyblockcore.then(literal("LogSpam").executes(ctx -> player())); | ||
skyblockcore.then(literal("location").executes(ctx -> location())); | ||
dispatcher.register(skyblockcore); | ||
} | ||
|
||
private static int test() { | ||
// example command | ||
if (ConfigManager.getConfig() != null && ConfigManager.getConfig().isDev()) { | ||
LOGGER.info(TITLE + " woah!! [dev]"); | ||
} | ||
if (MinecraftClient.getInstance().player == null) return 0; | ||
MinecraftClient.getInstance().player.sendMessage(Text.literal(TITLE + " Test command, cool that you found this, easter egg ig! well anyways, hi from Axle!").formatted(Formatting.AQUA), false); | ||
return Command.SINGLE_SUCCESS; | ||
} | ||
|
||
private static int reloadConfig() { | ||
ConfigManager.reloadConfig(); // Reload the config | ||
LOGGER.info(TITLE + " Reloaded Config!"); | ||
if (MinecraftClient.getInstance().player == null) return 0; | ||
MinecraftClient.getInstance().player.sendMessage(Text.literal(TITLE + " Config file Reloaded in: " + System.currentTimeMillis() + " ms").formatted(Formatting.WHITE), false); | ||
|
||
|
||
return Command.SINGLE_SUCCESS; | ||
} | ||
|
||
private static int nbt() { | ||
// Practically done. Needs help in the main class for copying. | ||
// TODO Implement NBT Handling Logic here | ||
// This will be similar to "/sba dev" or "/skytils dev nbt". | ||
if (MinecraftClient.getInstance().player == null) return 0; | ||
NBTCOPYING = !NBTCOPYING; | ||
MinecraftClient.getInstance().player.sendMessage(Text.literal(TITLE + " NBT copying has been " + (NBTCOPYING ? "enabled! (Tip, use Right Control to copy items NBT data to clipboard.)" : "disabled!")).formatted(Formatting.WHITE), false); | ||
return Command.SINGLE_SUCCESS; | ||
} | ||
|
||
private static int dev() { | ||
ModConfig config = ConfigManager.getConfig(); | ||
if (config != null) { | ||
boolean currentDevSetting = config.isDev(); | ||
config.setDev(!currentDevSetting); // Toggle the dev mode setting | ||
ConfigManager.saveConfig(); // Save the updated config | ||
LOGGER.info(TITLE + " Successfully " + (currentDevSetting ? "disabled" : "enabled") + " Developer mode!"); | ||
if (MinecraftClient.getInstance().player == null) return 0; | ||
MinecraftClient.getInstance().player.sendMessage(Text.literal(TITLE + " Dev mode " + (currentDevSetting ? "Disabled" : "Enabled")).formatted(Formatting.WHITE), false); | ||
} | ||
return Command.SINGLE_SUCCESS; | ||
} | ||
|
||
private static int location() { | ||
ModConfig config = ConfigManager.getConfig(); | ||
if (config != null) { | ||
boolean currentLocationSetting = config.isLocation(); | ||
config.setLocation(!currentLocationSetting); // Toggle the location setting | ||
ConfigManager.saveConfig(); // Save the updated config | ||
LOGGER.info(TITLE + " Successfully " + (currentLocationSetting ? "disabled" : "enabled") + " location logging!"); | ||
if (MinecraftClient.getInstance().player == null) return 0; | ||
MinecraftClient.getInstance().player.sendMessage(Text.literal(TITLE + " Location data " + (currentLocationSetting ? "Disabled" : "Enabled")).formatted(Formatting.WHITE), false); | ||
} | ||
|
||
|
||
return Command.SINGLE_SUCCESS; | ||
} | ||
|
||
|
||
private static int player() { | ||
// example command | ||
ModConfig config = ConfigManager.getConfig(); | ||
if (config != null) { | ||
boolean currentPlayerSetting = config.isUnknownPlayer(); | ||
config.setUnknownPlayer(!currentPlayerSetting); // Toggle the location setting | ||
ConfigManager.saveConfig(); // Save the updated config | ||
if (MinecraftClient.getInstance().player == null) return 0; | ||
if (ConfigManager.getConfig() != null && ConfigManager.getConfig().isDev()) { | ||
LOGGER.info(TITLE + " Warning! You have " + (currentPlayerSetting ? "disabled" : "enabled") + " \"Ignoring player info update\""); | ||
} | ||
MinecraftClient.getInstance().player.sendMessage( | ||
Text.literal(TITLE + " Warning! You have " + (currentPlayerSetting ? "disabled" : "enabled") + " \"Ignoring player info update\"") | ||
.setStyle(Style.EMPTY.withColor(Formatting.WHITE)), | ||
false | ||
); | ||
} | ||
return Command.SINGLE_SUCCESS; | ||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
src/main/java/io/github/skyblockcore/event/ConfigManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package io.github.skyblockcore.event; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import net.fabricmc.loader.api.FabricLoader; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.io.*; | ||
|
||
import static io.github.skyblockcore.SkyblockCore.LOGGER; | ||
import static io.github.skyblockcore.SkyblockCore.TITLE; | ||
|
||
public class ConfigManager { | ||
|
||
|
||
|
||
private static ModConfig config; | ||
|
||
public static void loadConfig() { | ||
File configFile = getConfigFile(); | ||
if (configFile.exists()) { | ||
try (FileReader reader = new FileReader(configFile)) { | ||
Gson gson = new GsonBuilder().create(); | ||
config = gson.fromJson(reader, ModConfig.class); | ||
if (config != null && config.isDev()) { | ||
LOGGER.info(TITLE + " Config file loaded. [Dev]"); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} else { | ||
createConfig(); | ||
LOGGER.info(TITLE + " Config successfully created! Welcome to SkyblockCore, a Skyblock mod designed for modern Minecraft."); | ||
} | ||
} | ||
/* | ||
* Config Guide ~~ Please add to this if you plan on adding config values! | ||
* setDev: False = do not show // True = show | ||
* setUnknownPlayer: True = hide spam // False = show spam | ||
* setLocation: False = do not show // True = show | ||
*/ | ||
public static void createConfig() { | ||
config = new ModConfig(); // Below toggles will only change every time you wipe a config! | ||
config.setDev(false); // This will set all development features and logs to "TRUE". this is used for debugging errors with leaving/joining skyblock. | ||
config.setUnknownPlayer(true); // Don't use unless you want random UUID strings its annoying and I hated it. so now its gone! | ||
config.setLocation(false); // this is used for location output (see SkyblockCore file > location stuff) this is used for debugging new locations. | ||
saveConfig(); | ||
} | ||
|
||
public static void reloadConfig() { | ||
loadConfig(); | ||
} | ||
|
||
public static ModConfig getConfig() { | ||
return config; // see io.github.skyblockcore/event/ModConfig | ||
} | ||
|
||
private static File getConfigFile() { | ||
return FabricLoader.getInstance().getConfigDir().resolve("SkyblockCoreConfig.json").toFile(); | ||
} | ||
|
||
public static void saveConfig() { | ||
Gson gson = new GsonBuilder().setPrettyPrinting().create(); | ||
String json = gson.toJson(config); | ||
File configFile = getConfigFile(); | ||
try (FileWriter writer = new FileWriter(configFile)) { | ||
writer.write(json); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/io/github/skyblockcore/event/ConsoleLogFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.github.skyblockcore.event; | ||
|
||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.core.LogEvent; | ||
import org.apache.logging.log4j.core.LoggerContext; | ||
import org.apache.logging.log4j.core.config.Configuration; | ||
import org.apache.logging.log4j.core.config.LoggerConfig; | ||
import org.apache.logging.log4j.core.filter.AbstractFilter; | ||
|
||
public class ConsoleLogFilter extends AbstractFilter { | ||
|
||
private static final String UNWANTED_LOG_MESSAGE = "Ignoring player info update for unknown player"; | ||
|
||
public ConsoleLogFilter() { | ||
super(Result.NEUTRAL, Result.DENY); | ||
} | ||
|
||
@Override | ||
public Result filter(LogEvent event) { | ||
if (ConfigManager.getConfig() != null && ConfigManager.getConfig().isUnknownPlayer() && | ||
event.getMessage().getFormattedMessage().contains(UNWANTED_LOG_MESSAGE)) { | ||
return Result.DENY; // Ignore the log event | ||
} | ||
return Result.NEUTRAL; // Allow the log event to proceed | ||
} | ||
|
||
public static void installFilter() { | ||
LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false); | ||
Configuration configuration = loggerContext.getConfiguration(); | ||
LoggerConfig loggerConfig = configuration.getLoggerConfig(LogManager.ROOT_LOGGER_NAME); | ||
loggerConfig.addFilter(new ConsoleLogFilter()); | ||
loggerContext.updateLoggers(); | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
// if you're reading this you're a femboy now | ||
// Meow! >.< |
Oops, something went wrong.