From a12a3dbbc6f11ecbefea2f468b846f50b99e7bb2 Mon Sep 17 00:00:00 2001 From: DxxxxY Date: Fri, 21 Aug 2020 12:11:02 -0400 Subject: [PATCH] Initial commit --- .gitattributes | 2 + README.md | 2 + main/java/cc/dxxxxy/sh/Events.java | 111 ++++++++++++++++++++ main/java/cc/dxxxxy/sh/Gui.java | 29 +++++ main/java/cc/dxxxxy/sh/GuiConfig.java | 15 +++ main/java/cc/dxxxxy/sh/GuiFactory.java | 27 +++++ main/java/cc/dxxxxy/sh/Reference.java | 8 ++ main/java/cc/dxxxxy/sh/ReinviteCommand.java | 57 ++++++++++ main/java/cc/dxxxxy/sh/SplashHelper.java | 69 ++++++++++++ main/resources/mcmod.info | 16 +++ 10 files changed, 336 insertions(+) create mode 100644 .gitattributes create mode 100644 README.md create mode 100644 main/java/cc/dxxxxy/sh/Events.java create mode 100644 main/java/cc/dxxxxy/sh/Gui.java create mode 100644 main/java/cc/dxxxxy/sh/GuiConfig.java create mode 100644 main/java/cc/dxxxxy/sh/GuiFactory.java create mode 100644 main/java/cc/dxxxxy/sh/Reference.java create mode 100644 main/java/cc/dxxxxy/sh/ReinviteCommand.java create mode 100644 main/java/cc/dxxxxy/sh/SplashHelper.java create mode 100644 main/resources/mcmod.info diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/README.md b/README.md new file mode 100644 index 0000000..d64ba10 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# SplashHelper + diff --git a/main/java/cc/dxxxxy/sh/Events.java b/main/java/cc/dxxxxy/sh/Events.java new file mode 100644 index 0000000..54c7ed1 --- /dev/null +++ b/main/java/cc/dxxxxy/sh/Events.java @@ -0,0 +1,111 @@ +package cc.dxxxxy.sh; + +import net.minecraft.client.Minecraft; +import net.minecraft.scoreboard.ScoreObjective; +import net.minecraft.scoreboard.Scoreboard; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.IChatComponent; +import net.minecraftforge.client.event.ClientChatReceivedEvent; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; +import net.minecraftforge.fml.client.event.ConfigChangedEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.InputEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; +import org.apache.logging.log4j.Logger; +import org.lwjgl.input.Keyboard; + +import java.util.ArrayList; + +public class Events { + private final Configuration config = SplashHelper.getConfig(); + private final Logger logger = SplashHelper.getLogger(); + private final Minecraft mc = Minecraft.getMinecraft(); + private String name = null; + private final Property isOn = config.get("shs", "Enabled", false); + private final Property feeK = config.get("shs", "Fee Amount", 0); + private final Property joinMsg = config.get("shs", "Join Message", ""); + public static ArrayList members = new ArrayList(); + + + public static String getBoardTitle(Scoreboard board) { + ScoreObjective titleObjective = board.getObjectiveInDisplaySlot(1); + if (board.getObjectiveInDisplaySlot(0) != null) { + return board.getObjectiveInDisplaySlot(0).getName(); + } else { + return board.getObjectiveInDisplaySlot(1).getName(); + } + } + + public static void sendMessage(String msg) { + Minecraft.getMinecraft().thePlayer.addChatComponentMessage((IChatComponent) new ChatComponentText(msg)); + } + + @SubscribeEvent + public void onChatReceived(ClientChatReceivedEvent e) { + String msg = e.message.getFormattedText(); + if (mc.isSingleplayer()) return; + if (!mc.getCurrentServerData().serverIP.contains(".hypixel.net")) return; + if (!getBoardTitle(mc.theWorld.getScoreboard()).equals("SBScoreboard")) return; + if (msg.contains(":")) return; + if (isOn.getBoolean()) { + if (msg.contains("Trade completed with")) { + if (msg.contains("]")) { + name = msg.substring(msg.indexOf("]") + 2, msg.indexOf("!") - 4); + return; + } + name = msg.substring(msg.indexOf("h") + 6, msg.indexOf("!") - 4); + } + if (msg.contains("+") && msg.contains("coins") && name != null) { + int fee = Integer.parseInt(msg.substring(15, msg.indexOf("k"))); + if (fee >= feeK.getInt()) { + mc.thePlayer.sendChatMessage("/p " + name); + name = null; + } + } + if (!joinMsg.getString().equals("")) { + if (msg.contains("joined the party.")) { + mc.thePlayer.sendChatMessage("/pc " + joinMsg.getString()); + } + } + if (msg.contains("joined the party.")) { + if (!ReinviteCommand.reInv) { + if (msg.contains("]")) { + //sendMessage(msg.substring(msg.indexOf("]") + 2, msg.indexOf("joined") - 5)); + members.add(msg.substring(msg.indexOf("]") + 2, msg.indexOf("joined the") - 5)); + return; + } + //sendMessage(msg.substring(0, msg.indexOf("joined") - 5)); + members.add(msg.substring(2, msg.indexOf("joined the") - 5)); + } + } + if (msg.contains("left the party.")) { + if (msg.contains("You")) return; + if (msg.contains("]")) { + members.remove(members.indexOf(msg.substring(msg.indexOf("]") + 2, msg.indexOf("has left") - 5))); + return; + } + members.remove(members.indexOf(msg.substring(2, msg.indexOf("has left") - 5))); + } + if (msg.contains("You have joined")) { + if (isOn.getBoolean()) { + isOn.set(!isOn.getBoolean()); + } + } + } + } + + @SubscribeEvent + public void onKeyTyped(InputEvent.KeyInputEvent e) { + if (Keyboard.getEventKey() == SplashHelper.openGui.getKeyCode()) { + Minecraft.getMinecraft().displayGuiScreen(new GuiConfig(Minecraft.getMinecraft().currentScreen)); + } + } + + @SubscribeEvent + public void onConfigChanged(ConfigChangedEvent e) { + if (e.modID.equals(Reference.ID)) { + config.save(); + } + } +} diff --git a/main/java/cc/dxxxxy/sh/Gui.java b/main/java/cc/dxxxxy/sh/Gui.java new file mode 100644 index 0000000..32fe2ee --- /dev/null +++ b/main/java/cc/dxxxxy/sh/Gui.java @@ -0,0 +1,29 @@ +package cc.dxxxxy.sh; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +import java.awt.*; + +public class Gui extends net.minecraft.client.gui.Gui { + Configuration config = SplashHelper.getConfig(); + + Property isOn = config.get("shs", "Enabled", false); + Property fee = config.get("shs", "Fee Amount", 0); + Property joinMsg = config.get("shs", "Join Message", ""); + Property showInHub = config.get("shs", "Show Members in Hub", false); + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + + @SubscribeEvent + public void renderOverlay(RenderGameOverlayEvent e) { + if (showInHub.getBoolean()) { + if (e.type.equals(RenderGameOverlayEvent.ElementType.TEXT)) { + drawString(fr,"A", 9, 9, Color.cyan.getRGB()); + } + } + } +} diff --git a/main/java/cc/dxxxxy/sh/GuiConfig.java b/main/java/cc/dxxxxy/sh/GuiConfig.java new file mode 100644 index 0000000..154003f --- /dev/null +++ b/main/java/cc/dxxxxy/sh/GuiConfig.java @@ -0,0 +1,15 @@ +package cc.dxxxxy.sh; + +import net.minecraft.client.gui.GuiScreen; +import net.minecraftforge.common.config.ConfigElement; + +public class GuiConfig extends net.minecraftforge.fml.client.config.GuiConfig { + public GuiConfig(GuiScreen guiScreen) { + super(guiScreen, + new ConfigElement(SplashHelper.getConfig().getCategory("shs")).getChildElements(), + Reference.ID, + false, + false, + "Splash Helper Settings"); + } +} diff --git a/main/java/cc/dxxxxy/sh/GuiFactory.java b/main/java/cc/dxxxxy/sh/GuiFactory.java new file mode 100644 index 0000000..6952114 --- /dev/null +++ b/main/java/cc/dxxxxy/sh/GuiFactory.java @@ -0,0 +1,27 @@ +package cc.dxxxxy.sh; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraftforge.fml.client.IModGuiFactory; + +import java.util.Set; + +public class GuiFactory implements IModGuiFactory { + @Override + public void initialize(Minecraft minecraftInstance) { } + + @Override + public Class mainConfigGuiClass() { + return GuiConfig.class; + } + + @Override + public Set runtimeGuiCategories() { + return null; + } + + @Override + public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) { + return null; + } +} diff --git a/main/java/cc/dxxxxy/sh/Reference.java b/main/java/cc/dxxxxy/sh/Reference.java new file mode 100644 index 0000000..ee30b60 --- /dev/null +++ b/main/java/cc/dxxxxy/sh/Reference.java @@ -0,0 +1,8 @@ +package cc.dxxxxy.sh; + +public class Reference { + public static final String ID = "sh"; + public static final String NAME = "Splash Helper"; + public static final String VERSION = "1.0"; + public static final String GUI = "cc.dxxxxy.sh.GuiFactory"; +} diff --git a/main/java/cc/dxxxxy/sh/ReinviteCommand.java b/main/java/cc/dxxxxy/sh/ReinviteCommand.java new file mode 100644 index 0000000..f7e24cf --- /dev/null +++ b/main/java/cc/dxxxxy/sh/ReinviteCommand.java @@ -0,0 +1,57 @@ +package cc.dxxxxy.sh; + +import net.minecraft.client.Minecraft; +import net.minecraft.command.CommandBase; +import net.minecraft.command.CommandException; +import net.minecraft.command.ICommandSender; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; +import org.apache.logging.log4j.Logger; + +public class ReinviteCommand extends CommandBase { + private final Logger logger = SplashHelper.getLogger(); + public static boolean reInv; + public String rem; + public int tickcount; + public int counter; + @Override + public String getCommandName() { + return "sh-reinv"; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return null; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) throws CommandException { + reInv = true; + } + + @SubscribeEvent + public void onServerTick(TickEvent.ClientTickEvent e) { + if (e.phase.equals(TickEvent.Phase.END)) { + if (reInv) { + tickcount++; + if (counter > 0) { + Events.members.remove(rem); + } + for (String name : Events.members) { + if (tickcount == 2 * 20) { + Minecraft.getMinecraft().thePlayer.sendChatMessage("/p " + name); + rem = name; + tickcount = 0; + counter++; + } + } + if (Events.members.isEmpty()) { + reInv = false; + } + } + } + } + + @Override + public boolean canCommandSenderUseCommand(ICommandSender sender) { return true; } +} diff --git a/main/java/cc/dxxxxy/sh/SplashHelper.java b/main/java/cc/dxxxxy/sh/SplashHelper.java new file mode 100644 index 0000000..e15175e --- /dev/null +++ b/main/java/cc/dxxxxy/sh/SplashHelper.java @@ -0,0 +1,69 @@ +package cc.dxxxxy.sh; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.settings.KeyBinding; +import net.minecraftforge.client.ClientCommandHandler; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; +import net.minecraftforge.fml.client.registry.ClientRegistry; +import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.Mod.EventHandler; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.lwjgl.input.Keyboard; + +import java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; + +@Mod(modid = Reference.ID, name = Reference.NAME, version = Reference.VERSION, guiFactory = Reference.GUI) +public class SplashHelper { + private static Configuration config; + private static Logger logger = LogManager.getLogger(Reference.ID); + static String currentVersion; + static String newVersion; + public static final KeyBinding openGui = new KeyBinding("Open Gui", Keyboard.KEY_RSHIFT, "Splash Helper"); + + @EventHandler + public void preInit(FMLPreInitializationEvent e) { + File configFile = new File(Loader.instance().getConfigDir(), "sh.cfg"); + config = new Configuration(configFile); + config.load(); + Property isOn = config.get("shs", "Enabled", false); + Property fee = config.get("shs", "Fee Amount", 0); + Property joinMsg = config.get("shs", "Join Message", ""); + Property showInHub = config.get("shs", "Show Members in Hub", false); + if(config.hasChanged()){ + config.save(); + } + ClientRegistry.registerKeyBinding(openGui); + //ClientCommandHandler.instance.registerCommand(new ReinviteCommand()); + MinecraftForge.EVENT_BUS.register(new Events()); + //MinecraftForge.EVENT_BUS.register(new ReinviteCommand()); + } + + public void updateChecker() { + try { + HttpURLConnection c = (HttpURLConnection)new URL("https://api.spigotmc.org/legacy/update.php?resource=72777").openConnection(); + newVersion = new BufferedReader((Reader)new InputStreamReader(c.getInputStream())).readLine(); + c.disconnect(); + if (newVersion.equals(currentVersion)) { + //On latest version + } + else { + //Update available + } + } + catch (IOException ex) { + //Error + ex.printStackTrace(); + } + } + + public static Configuration getConfig() { return config; } + + public static Logger getLogger() { return logger; } +} diff --git a/main/resources/mcmod.info b/main/resources/mcmod.info new file mode 100644 index 0000000..0169b9b --- /dev/null +++ b/main/resources/mcmod.info @@ -0,0 +1,16 @@ +[ +{ + "modid": "sh", + "name": "Splash Helper", + "description": "A mod developed by DxxxxY#5818", + "version": "${version}", + "mcversion": "${mcversion}", + "url": "", + "updateUrl": "", + "authorList": ["DxxxxY"], + "credits": "DxxxxY#5818", + "logoFile": "", + "screenshots": [], + "dependencies": [] +} +]