Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Semx11 committed Mar 18, 2017
0 parents commit 9cd4c24
Show file tree
Hide file tree
Showing 30 changed files with 2,135 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# eclipse
bin
*.launch
.settings
.metadata
.classpath
.project

# idea
out
*.ipr
*.iws
*.iml
.idea

# gradle
build
.gradle
gradle/
gradlew
gradlew.bat

# forge
*.txt

# other
eclipse
run
logs
44 changes: 44 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
buildscript {
repositories {
jcenter()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT'
}
}
apply plugin: 'net.minecraftforge.gradle.forge'

version = "2.0.3"
group = "me.semx11.autotip" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "Autotip"

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

minecraft {
version = "1.8.9-11.15.1.1722"
runDir = "run"
mappings = "stable_20"
}

processResources {
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version

from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
expand 'version': project.version, 'mcversion': project.minecraft.version
}

from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}

idea {
module.inheritOutputDirs = true
}
81 changes: 81 additions & 0 deletions src/main/java/me/semx11/autotip/Autotip.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package me.semx11.autotip;

import me.semx11.autotip.command.AUniversalCommand;
import me.semx11.autotip.command.AutotipCommand;
import me.semx11.autotip.command.LimboCommand;
import me.semx11.autotip.command.TipHistoryCommand;
import me.semx11.autotip.event.ChatListener;
import me.semx11.autotip.event.HypixelListener;
import me.semx11.autotip.event.Tipper;
import me.semx11.autotip.misc.AutotipThreadFactory;
import me.semx11.autotip.util.FileUtil;
import me.semx11.autotip.util.Hosts;
import me.semx11.autotip.util.MessageOption;
import me.semx11.autotip.util.MinecraftVersion;
import me.semx11.autotip.util.UniversalUtil;
import me.semx11.autotip.util.Version;
import net.minecraft.client.Minecraft;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Mod(modid = Autotip.MODID, version = Autotip.VERSION_STRING, clientSideOnly = true, acceptedMinecraftVersions = "[1.8, 1.11.2]")
public class Autotip {

public static final String MODID = "autotip";
public static final String VERSION_STRING = "2.0.3";
public static final Version VERSION = new Version(VERSION_STRING);
public static final ExecutorService THREAD_POOL = Executors.newCachedThreadPool(new AutotipThreadFactory());
public static String USER_DIR = "";

public static MinecraftVersion MC_VERSION;
public static Minecraft mc = Minecraft.getMinecraft();

public static MessageOption messageOption = MessageOption.SHOWN;
public static String playerUUID = "";
public static boolean onHypixel = false;
public static boolean toggle = true;

public static int totalTipsSent;
public static List<String> alreadyTipped = new ArrayList<>();

@EventHandler
public void init(FMLInitializationEvent event) {
try {
MC_VERSION = MinecraftVersion.fromString(UniversalUtil.getMinecraftVersion());
playerUUID = Minecraft.getMinecraft().getSession().getProfile().getId().toString();
USER_DIR = "mods" + File.separator + "autotip" + File.separator + playerUUID + File.separator;

registerEvents(this, new Tipper(), new HypixelListener(), new ChatListener());
registerCommands(new AutotipCommand(), new TipHistoryCommand(), new LimboCommand());

FileUtil.getVars();
Hosts.updateHosts();
} catch (IOException e) {
e.printStackTrace();
}
}

private void registerEvents(Object... events) {
Arrays.asList(events).forEach((event) -> {
MinecraftForge.EVENT_BUS.register(event);
FMLCommonHandler.instance().bus().register(event);
});
}

private void registerCommands(AUniversalCommand... commands) {
Arrays.asList(commands).forEach(ClientCommandHandler.instance::registerCommand);
}

}
44 changes: 44 additions & 0 deletions src/main/java/me/semx11/autotip/command/AUniversalCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package me.semx11.autotip.command;

import me.semx11.autotip.Autotip;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.BlockPos;

import javax.annotation.Nullable;
import java.util.List;

public abstract class AUniversalCommand extends CommandBase {

// Minecraft 1.8 | 1.8.8 | 1.8.9
// func_71515_b
public void processCommand(ICommandSender sender, String[] args) {
Autotip.THREAD_POOL.submit(() -> onCommand(sender, args));
}

// Minecraft 1.9 | 1.9.4 | 1.10 | 1.10.2 | 1.11 | 1.11.2
// func_184881_a
public void func_184881_a(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
Autotip.THREAD_POOL.submit(() -> onCommand(sender, args));
}

// Minecraft 1.8 | 1.8.8 | 1.8.9
// func_180525_a
public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) {
return onTabComplete(sender, args);
}

// Minecraft 1.9 | 1.9.4 | 1.10 | 1.10.2 | 1.11 | 1.11.2
// Does not seem to work?
// func_184883_a
public List<String> func_184883_a(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos pos) {
return onTabComplete(sender, args);
}

public abstract void onCommand(ICommandSender sender, String[] args);

public abstract List<String> onTabComplete(ICommandSender sender, String[] args);

}
175 changes: 175 additions & 0 deletions src/main/java/me/semx11/autotip/command/AutotipCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
package me.semx11.autotip.command;

import me.semx11.autotip.Autotip;
import me.semx11.autotip.event.HypixelListener;
import me.semx11.autotip.event.Tipper;
import me.semx11.autotip.misc.StartLogin;
import me.semx11.autotip.misc.Stats;
import me.semx11.autotip.misc.TipTracker;
import me.semx11.autotip.util.ChatColor;
import me.semx11.autotip.util.ClientMessage;
import me.semx11.autotip.util.FileUtil;
import me.semx11.autotip.util.MinecraftVersion;
import me.semx11.autotip.util.Versions;
import net.minecraft.command.ICommandSender;
import org.apache.commons.lang3.StringUtils;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.Year;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.List;

public class AutotipCommand extends AUniversalCommand {

@Override
public String getCommandName() {
return "autotip";
}

@Override
public int getRequiredPermissionLevel() {
return 0;
}

@Override
public String getCommandUsage(ICommandSender sender) {
return "/autotip <stats, info, messages, toggle, time>";
}

@Override
public List<String> getCommandAliases() {
if (!Autotip.MC_VERSION.equals(MinecraftVersion.V1_8)) return Collections.singletonList("at");
else return Collections.emptyList();
}

@Override
public void onCommand(ICommandSender sender, String[] args) {

if (args.length > 0) switch (args[0].toLowerCase()) {
case "m":
case "messages":
Autotip.messageOption = Autotip.messageOption.next();
ClientMessage.send("Tip Messages: " + Autotip.messageOption);
break;
case "?":
case "info":
ClientMessage.separator();
ClientMessage.send(
ChatColor.GOLD + "" + ChatColor.BOLD + "Autotip v" + Autotip.VERSION + " by Semx11",
null,
ChatColor.GOLD + "2Pi's legacy will live on."
);
ClientMessage.send("Running in " + Autotip.MC_VERSION + "-compatibility mode");
ClientMessage.send(
"Autotipper: " + (Autotip.toggle ? ChatColor.GREEN + "En" : ChatColor.RED + "Dis") + "abled");
ClientMessage.send("Tip Messages: " + Autotip.messageOption);
ClientMessage.send("Tips sent today: " + ChatColor.GOLD + TipTracker.tipsSent);
ClientMessage.send("Tips received today: " + ChatColor.GOLD + TipTracker.tipsReceived);
ClientMessage.send("Lifetime tips sent: " + ChatColor.GOLD + Autotip.totalTipsSent);
ClientMessage.send(ChatColor.GOLD + "Type /autotip stats to see what has been earned.");
ClientMessage.separator();
break;
case "s":
case "stats":
LocalDate now = LocalDate.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");

if (args.length == 2) switch (args[1].toLowerCase()) {
case "day":
case "daily":
case "today":
Stats.printStats(FileUtil.getDate());
break;
case "yesterday":
Stats.printStats(LocalDate.now().minusDays(1).format(formatter));
break;
case "week":
case "weekly":
Stats.printBetween(now.with(DayOfWeek.MONDAY).format(formatter),
now.with(DayOfWeek.SUNDAY).format(formatter));
break;
case "month":
case "monthly":
Stats.printBetween(now.withDayOfMonth(1).format(formatter),
now.withDayOfMonth(now.lengthOfMonth()).format(formatter));
break;
case "year":
case "yearly":
Stats.printBetween("01-01-" + Year.now().getValue(), "31-12-" + Year.now().getValue());
break;
case "all":
case "total":
case "life":
case "lifetime":
Stats.printBetween("25-06-2016", FileUtil.getDate());
break;
default:
ClientMessage.send(ChatColor.RED + "Usage: /autotip stats <day, week, month, year, lifetime>");
break;
}
else Stats.printStats(FileUtil.getDate());
break;
case "t":
case "toggle":
Autotip.toggle = !Autotip.toggle;
ClientMessage.send(
"Autotipper: " + (Autotip.toggle ? ChatColor.GREEN + "En" : ChatColor.RED + "Dis") + "abled");
break;
case "wave":
case "time":
if (Autotip.toggle) {
if (Autotip.onHypixel) {
ClientMessage.separator();
ClientMessage.send("Last wave: " +
ChatColor.GOLD + LocalTime.MIN.plusSeconds(Tipper.waveCounter)
.toString());
ClientMessage.send("Next wave: " +
ChatColor.GOLD + LocalTime.MIN.plusSeconds(
Tipper.waveLength - Tipper.waveCounter).toString());
ClientMessage.separator();
} else ClientMessage.send("Autotip is disabled as you are not playing on Hypixel.");
} else
ClientMessage.send("Autotip is disabled. Use " + ChatColor.GOLD + "/autotip toggle"
+ ChatColor.GRAY + " to enable it.");
break;
case "whatsnew":
ClientMessage.separator();
ClientMessage.send(ChatColor.GOLD + "What's new in Autotip v" + Autotip.VERSION + ":");
Versions.getInstance().getInfoByVersion(Autotip.VERSION).getChangelog().forEach(s -> {
ClientMessage.send(ChatColor.DARK_GRAY + "- " + ChatColor.GRAY + s);
});
ClientMessage.separator();
break;
case "update":
StartLogin.login();
break;
case "info+":
ClientMessage.separator();
ClientMessage.send("Last IP joined: " + HypixelListener.lastIp);
ClientMessage.send("Detected MC version: " + Autotip.MC_VERSION);
ClientMessage.send("Current tipqueue: " + StringUtils.join(Tipper.tipQueue, ", "));
ClientMessage.separator();
break;
default:
ClientMessage.send(ChatColor.RED + "Usage: " + getCommandUsage(sender));
break;
}
else ClientMessage.send(ChatColor.RED + "Usage: " + getCommandUsage(sender));
}

@Override
public List<String> onTabComplete(ICommandSender sender, String[] args) {
switch (args.length) {
case 1:
return getListOfStringsMatchingLastWord(args, "stats", "info", "messages", "toggle", "time");
case 2:
if (args[0].equalsIgnoreCase("stats") || args[0].equalsIgnoreCase("s"))
return getListOfStringsMatchingLastWord(args, "day", "yesterday", "week", "month", "year",
"lifetime");
}
return Collections.emptyList();
}
}
Loading

0 comments on commit 9cd4c24

Please sign in to comment.