Skip to content

Commit

Permalink
merge private to public
Browse files Browse the repository at this point in the history
  • Loading branch information
TudbuT committed Dec 24, 2020
1 parent e0eeda2 commit 84a6532
Show file tree
Hide file tree
Showing 22 changed files with 583 additions and 287 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@
import java.io.IOException;
import java.util.Map;

@Mod(modid = Yac.MODID, name = Yac.NAME, version = Yac.VERSION)
public class Yac {
@Mod(modid = YAC.MODID, name = YAC.NAME, version = YAC.VERSION)
public class YAC {
public static final String MODID = "yac";
public static final String NAME = "YAC Client";
public static final String VERSION = "vB0.2.5a";
public static final String VERSION = "vB1.0.0a";

public static Module[] modules;
public static Module[] modules ;
public static EntityPlayerSP player;
public static Minecraft mc = Minecraft.getMinecraft();
public static FileRW file;
public static Map<String, String> cfg;
public static String prefix = ",";

public static Logger logger;

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
logger = event.getModLog();
Expand All @@ -44,12 +44,12 @@ public void preInit(FMLPreInitializationEvent event) {
e.printStackTrace();
}
}

@EventHandler
public void init(FMLInitializationEvent event) {
logger.info("YAC by TudbuT, public version");
logger.info("YAC by TudbuT");
ThreadManager.run(() -> {
JOptionPane.showMessageDialog(null, "YAC by TudbuT, public version");
JOptionPane.showMessageDialog(null, "YAC by TudbuT");
});
player = Minecraft.getMinecraft().player;
try {
Expand All @@ -58,34 +58,48 @@ public void init(FMLInitializationEvent event) {
catch (Exception e) {
e.printStackTrace();
}
modules = new Module[]{
modules = new Module[] {
new AutoTotem(),
new TPAParty(),
new SafeTotem(),
new Prefix(),
new ClickGUI(),
new Team(),
new AutoConfig(),
new TPATools(),
new Trap()
new ChatSuffix(),
new AutoConfig(),
new ChatColor(),
new Trap(),
new LeavePos(),
new ClickGUI(),
};

for (Module module : modules) {
module.cfg = Utils.stringToMap(module.saveConfig());
}

MinecraftForge.EVENT_BUS.register(new FMLEventHandler());

for (int i = 0; i < modules.length; i++) {
logger.info(modules[i].toString());
modules[i].saveConfig();
if (cfg.containsKey(modules[i].toString())) {
modules[i].loadConfig(Utils.stringToMap(cfg.get(modules[i].getClass().getSimpleName())));
try {
logger.info(modules[i].toString());
modules[i].saveConfig();
if (cfg.containsKey(modules[i].toString())) {
modules[i].loadConfig(Utils.stringToMap(cfg.get(modules[i].getClass().getSimpleName())));
}
} catch (Exception e) {
logger.warn("Couldn't load config of module " + modules[i].toString() + "!");
logger.warn(e);
}
}
prefix = cfg.getOrDefault("prefix", ",");

try {
Thread.sleep(2000);
}
catch (InterruptedException e) {
e.printStackTrace();
}

ThreadManager.run(() -> {
while (true) {
try {
Expand All @@ -94,7 +108,7 @@ public void init(FMLInitializationEvent event) {
cfg.put(modules[i].getClass().getSimpleName(), modules[i].saveConfig());
}
cfg.put("prefix", prefix);

file.setContent(Utils.mapToString(cfg));
}
catch (IOException e) {
Expand Down
128 changes: 52 additions & 76 deletions src/main/java/tudbut/mod/client/yac/events/FMLEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,138 +2,114 @@

import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.client.event.ClientChatEvent;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.network.FMLNetworkEvent;
import tudbut.mod.client.yac.Yac;
import tudbut.mod.client.yac.YAC;
import tudbut.mod.client.yac.mods.ChatColor;
import tudbut.mod.client.yac.mods.ChatSuffix;
import tudbut.mod.client.yac.mods.TPAParty;
import tudbut.mod.client.yac.utils.ChatUtils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;

public class FMLEventHandler {

private int chatHelper = 0;

@SubscribeEvent
public void onChat(ClientChatEvent event) {
if (event.getOriginalMessage().startsWith(Yac.prefix)) {
if(event.getOriginalMessage().startsWith(YAC.prefix)) {

event.setCanceled(true);
ChatUtils.print("Blocked message");
ChatUtils.history(event.getOriginalMessage());
String s = event.getOriginalMessage().substring(Yac.prefix.length());
String s = event.getOriginalMessage().substring(YAC.prefix.length());

try {
if (s.startsWith("t ")) {
for (int i = 0; i < Yac.modules.length; i++) {
if (Yac.modules[i].getClass().getSimpleName().equalsIgnoreCase(s.substring("t ".length()))) {
ChatUtils.print(String.valueOf(!Yac.modules[i].enabled));
for (int i = 0; i < YAC.modules.length; i++) {
if (YAC.modules[i].getClass().getSimpleName().equalsIgnoreCase(s.substring("t ".length()))) {
ChatUtils.print(String.valueOf(!YAC.modules[i].enabled));

if (Yac.modules[i].enabled = !Yac.modules[i].enabled)
Yac.modules[i].onEnable();
if(YAC.modules[i].enabled = !YAC.modules[i].enabled)
YAC.modules[i].onEnable();
else
Yac.modules[i].onDisable();
YAC.modules[i].onDisable();
}
}
}

if (s.startsWith("say ")) {
Yac.player.sendChatMessage(s.substring("say ".length()));
YAC.player.sendChatMessage(s.substring("say ".length()));
ChatUtils.history(event.getOriginalMessage());
}
for (int i = 0; i < Yac.modules.length; i++) {
if (Yac.modules[i].enabled)
if (s.toLowerCase().startsWith(Yac.modules[i].getClass().getSimpleName().toLowerCase())) {
String args = s.substring(Yac.modules[i].getClass().getSimpleName().length() + 1);
Yac.modules[i].onChat(args, args.split(" "));

for (int i = 0; i < YAC.modules.length; i++) {
if(YAC.modules[i].enabled)
if (s.toLowerCase().startsWith(YAC.modules[i].getClass().getSimpleName().toLowerCase())) {
String args = s.substring(YAC.modules[i].getClass().getSimpleName().length() + 1);
YAC.modules[i].onChat(args, args.split(" "));
}
}
}
catch (Exception e) {
} catch (Exception e) {
ChatUtils.print("Command failed!");
}

} else if (!event.getOriginalMessage().startsWith("/") && !event.getOriginalMessage().startsWith(".") && !event.getOriginalMessage().startsWith("#")) {

}
else if(!event.getOriginalMessage().startsWith("/") && !event.getOriginalMessage().startsWith(".") && !event.getOriginalMessage().startsWith("#")) {
event.setCanceled(true);
Yac.player.sendChatMessage(">" + event.getMessage() + (chatHelper == 0 ? " ›YAC‹" : ""));
YAC.player.sendChatMessage(ChatColor.getInstance().get() + event.getMessage() + (chatHelper == 0 && ChatSuffix.getInstance().enabled ? " ›YAC‹" : ""));
chatHelper++;
if (chatHelper == 6)
if(chatHelper == 6)
chatHelper = 0;

ChatUtils.history(event.getOriginalMessage());
}
}


@SubscribeEvent
public void onJoin(FMLNetworkEvent.ClientConnectedToServerEvent event) {
try {
URL updateCheckURL = new URL("https://raw.githubusercontent.com/TudbuT/yacpub/master/version.txt");
InputStream stream = updateCheckURL.openConnection().getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));

String s;
StringBuilder builder = new StringBuilder();
while ((s = reader.readLine()) != null) {
builder.append(s);
}

s = builder.toString();
if (!s.equals(Yac.VERSION)) {
ChatUtils.print(
"§a§lA new YAC version was found! Current: " +
Yac.VERSION +
", New: " +
s +
"! Please consider updating at " +
"https://github.com/TudbuT/yacpub/releases/tag/" +
s
);
}
}
catch (IOException e) {
ChatUtils.print("Unable to check for a new version!");
e.printStackTrace();
}
}

@SubscribeEvent
public void onServerChat(ClientChatReceivedEvent event) {
if (event.getMessage().getUnformattedText().startsWith("BayMax") && event.getMessage().getUnformattedText().contains("Please type '")) {
if(event.getMessage().getUnformattedText().startsWith("BayMax") && event.getMessage().getUnformattedText().contains("Please type '")) {
String key = event.getMessage().getUnformattedText().substring("BayMax _ Please type '".length(), "BayMax _ Please type '".length() + 4);
Yac.player.sendChatMessage(key);
YAC.player.sendChatMessage(key);
ChatUtils.print("Auto-solved");
}
for (int i = 0; i < Yac.modules.length; i++) {
if (Yac.modules[i].enabled)
Yac.modules[i].onServerChat(event.getMessage().getUnformattedText(), event.getMessage().getFormattedText());
for (int i = 0; i < YAC.modules.length; i++) {
if(YAC.modules[i].enabled)
YAC.modules[i].onServerChat(event.getMessage().getUnformattedText(), event.getMessage().getFormattedText());
}
}

@SubscribeEvent
public void onJoin(EntityJoinWorldEvent event) {
Yac.player = Minecraft.getMinecraft().player;
YAC.player = Minecraft.getMinecraft().player;
}

@SubscribeEvent
public void onDeath(LivingDeathEvent event) {
try {
if (event.getEntity().getName().equals(YAC.player.getName()) && event.getEntity() instanceof EntityPlayer) {
TPAParty.getInstance().enabled = false;
TPAParty.getInstance().onDisable();
YAC.player = Minecraft.getMinecraft().player;
}
} catch (Exception ignore) { }
}

@SubscribeEvent
public void onTick(TickEvent event) {
EntityPlayerSP player = Yac.player;
if (player == null)
EntityPlayerSP player = YAC.player;
if(player == null)
return;
for (int i = 0; i < Yac.modules.length; i++) {
if (Yac.modules[i].enabled)
for (int i = 0; i < YAC.modules.length; i++) {
if(YAC.modules[i].enabled)
try {
Yac.modules[i].onTick();
}
catch (Exception ignore) {}
Yac.modules[i].onEveryTick();
YAC.modules[i].onTick();
} catch (Exception ignore) {}
YAC.modules[i].onEveryTick();
}
}
}
Loading

0 comments on commit 84a6532

Please sign in to comment.