Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
WeAthFoLD committed Jun 12, 2019
2 parents 04a23bf + 2b31cb7 commit de418da
Show file tree
Hide file tree
Showing 24 changed files with 747 additions and 62 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

A Minecraft mod about superability. The inspiration of AcademyCraft comes from [A Certain Scientific Railgun (とある科学の超電磁砲)](https://en.wikipedia.org/wiki/A_Certain_Scientific_Railgun) but the mod content is not limited of the background.

Visit [AcademyCraft's Website](http://ac.li-dev.cn/) to get the latest release and know more about it.
Visit [AcademyCraft's Website](https://ac.li-dev.cn/) to get the latest release and know more about it.

Issue(Idea, Bug) Submission
============
Expand Down
17 changes: 15 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ repositories {
configurations {
provided
shade
compile.extendsFrom shade
deobfCompile.extendsFrom shade
}

// sourceSets.main.compileClasspath += [configurations.provided]
Expand All @@ -112,7 +112,10 @@ idea {


dependencies {
deobfCompile "cn.lambdalib2:LambdaLib2:${config.lambdalib_ver}"
// Shade dependencies
shade "cn.lambdalib2:LambdaLib2:${config.lambdalib_ver}"

// Optional dependencies
deobfCompile "codechicken:CodeChickenLib:1.12.2-${config.ccl_ver}:universal"
deobfCompile "mezz.jei:jei_1.12.2:4.8.0.119"
//deobfCompile "codechicken:NotEnoughItems:1.12.2-${config.nei_ver}:universal"
Expand Down Expand Up @@ -167,14 +170,24 @@ compileScala.options.encoding = "UTF-8"
task deobfJar(type: Jar, dependsOn: 'jar') {
classifier 'dev'
from sourceSets.main.output
manifest {
attributes 'FMLCorePluginContainsFMLMod' : 'true'
attributes 'FMLCorePlugin' : 'cn.lambdalib2.CorePlugin'
}
}

jar {
configurations.shade.each { dep ->
from(project.zipTree(dep)){
exclude 'META-INF', 'META-INF/**'
exclude 'mcmod.info'
exclude 'pack.mcmeta'
}
}
manifest {
attributes 'FMLCorePluginContainsFMLMod' : 'true'
attributes 'FMLCorePlugin' : 'cn.lambdalib2.CorePlugin'
}
}

// http://www.minecraftforge.net/forum/topic/36791-trying-to-shade-dependencies-into-jar/
Expand Down
4 changes: 2 additions & 2 deletions build.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
mod_name = AcademyCraft
mod_ver = 1.1.1
mod_ver = 1.1.2
mod_group = cn.academy
mc_ver = 1.12.2
forge_ver = 14.23.4.2705-1.12.2

nei_ver = 2.4.1.233
ccl_ver = 3.1.8.341

lambdalib_ver = 0.1.8
lambdalib_ver = 0.1.9


4 changes: 2 additions & 2 deletions src/main/java/cn/academy/AcademyCraft.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cn.academy;

import cn.academy.analyticUtil.AnalyticDataListener;
import cn.academy.analytic.AnalyticDataListener;
import cn.lambdalib2.crafting.CustomMappingHelper;
import cn.lambdalib2.crafting.RecipeRegistry;
import cn.lambdalib2.registry.RegistryMod;
Expand Down Expand Up @@ -72,7 +72,7 @@ public ItemStack createIcon() {
private static void preInit(FMLPreInitializationEvent event) {
log.info("Starting AcademyCraft");
log.info("Copyright (c) Lambda Innovation, 2013-2018");
log.info("http://ac.li-dev.cn/");
log.info("https://ac.li-dev.cn/");
recipes = new RecipeRegistry();

config = new Configuration(event.getSuggestedConfigurationFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import cn.academy.AcademyCraft;
import cn.academy.ability.context.Context.Status;
import cn.academy.analyticUtil.events.AnalyticSkillEvent;
import cn.academy.analytic.events.AnalyticSkillEvent;
import cn.academy.event.ability.CategoryChangeEvent;
import cn.academy.event.ability.OverloadEvent;
import cn.lambdalib2.s11n.network.NetworkMessage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import cn.lambdalib2.util.Raytrace;
import cn.lambdalib2.util.VecUtils;
import com.google.common.base.Preconditions;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
Expand All @@ -28,7 +30,6 @@
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.input.Keyboard;

import java.util.Optional;

Expand Down Expand Up @@ -136,7 +137,15 @@ void localMakeAlive() {
clientRuntime().addActivateHandler(activateHandler);

final String[] strs = new String[] { null, "a", "d", "w", "s"};
final int[] keys = new int[] { -1, Keyboard.KEY_A, Keyboard.KEY_D, Keyboard.KEY_W, Keyboard.KEY_S };
Minecraft mc = Minecraft.getMinecraft();
GameSettings settings = mc.gameSettings;
final int[] keys = new int[] {
-1,
settings.keyBindLeft.getKeyCode(),
settings.keyBindRight.getKeyCode(),
settings.keyBindForward.getKeyCode(),
settings.keyBindBack.getKeyCode()
};
for (int i = 0; i < 4; ++i) {
final int localid = i + 1;
clientRuntime().addKey(KEY_GROUP, keys[localid], new KeyDelegate() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cn.academy.analyticUtil;
package cn.academy.analytic;

import cn.academy.AcademyCraft;
import cn.academy.analyticUtil.events.AnalyticLevelUpEvent;
import cn.academy.analyticUtil.events.AnalyticSkillEvent;
import cn.academy.analytic.events.AnalyticLevelUpEvent;
import cn.academy.analytic.events.AnalyticSkillEvent;
import cn.academy.datapart.AbilityData;
import cn.academy.event.ability.LevelChangeEvent;
import cn.academy.event.ability.SkillLearnEvent;
Expand All @@ -21,9 +21,12 @@
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;

// Collects some **anonymous** analytics data
// What we collect: a unique hash of user, location, in-mod action (Level-up, use ability, etc.)
Expand All @@ -47,12 +50,16 @@ private AnalyticDataListener(){

@SubscribeEvent
public void loginListener(PlayerEvent.PlayerLoggedInEvent event){
String serverIp = getCurrentIPinfo();
Thread delaySender = new DelaySender(event.player);
delaySender.start();//avoid sending message to the client thread before it hasn't been initialized
}

public void serverGetter(EntityPlayer player,String serverIp){
if(null==serverSource) {
serverSource = new AnalyticDto();
serverSource.setVersion(AcademyCraft.VERSION);
serverSource.setUuidName("server");
serverSource.setStartTime(new Date().getTime());
serverSource.setStartTime(UTCZeroTime());
String[] ipArray =serverIp.split(" ");
if (ipArray.length < 6) {
serverSource.initNaNIPInfo();
Expand All @@ -63,7 +70,7 @@ public void loginListener(PlayerEvent.PlayerLoggedInEvent event){
serverSource.setCity(ipArray[5]);
}
}
NetworkMessage.sendTo(event.player,this,CHANNEL,event.player,serverIp);
NetworkMessage.sendTo(player,this,CHANNEL,player,serverIp);
}

//on Client
Expand All @@ -88,7 +95,7 @@ public void serverIpCollector(String ipInfo,EntityPlayer player,Boolean isServer
AnalyticDto playerData = new AnalyticDto();
playerData.setVersion(AcademyCraft.VERSION);
playerData.setUuidName(SHA(player.getUniqueID()+player.getName()));
playerData.setStartTime(new Date().getTime());
playerData.setStartTime(UTCZeroTime());
String[] ipArray = ipInfo.split(" ");
if (ipArray.length < 6) {
playerData.initNaNIPInfo();
Expand Down Expand Up @@ -153,11 +160,12 @@ public void skillLearnListener(SkillLearnEvent event){
}

//get ip info
private String getCurrentIPinfo(){
public String getCurrentIPinfo(){
String ipInfo = "";
try {
URL object = new URL("https://myip.ipip.net");
HttpURLConnection con = (HttpURLConnection)object.openConnection();
con.setRequestProperty("User-Agent","");
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8));
String line = null;
StringBuilder sb = new StringBuilder();
Expand Down Expand Up @@ -199,4 +207,31 @@ private String SHA(final String strText){
return strResult;
}

private long UTCZeroTime(){
SimpleDateFormat df =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
df.setTimeZone(TimeZone.getTimeZone("GMT+0:00"));
String currDate = df.format(new Date());
Timestamp timestamp = Timestamp.valueOf(currDate);
return timestamp.getTime();
}

}

class DelaySender extends Thread{
private EntityPlayer player;
private String serverIp;
DelaySender(EntityPlayer player){
this.player=player;
this.serverIp=serverIp;
}
@Override
public void run() {
try {
Thread.sleep(10000);
serverIp = AcademyCraft.analyticDataListener.getCurrentIPinfo();
AcademyCraft.analyticDataListener.serverGetter(player,serverIp);
}catch (Exception e){
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.academy.analyticUtil;
package cn.academy.analytic;

import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.academy.analyticUtil;
package cn.academy.analytic;

import cn.academy.AcademyCraft;
import com.google.gson.Gson;
Expand Down Expand Up @@ -26,7 +26,7 @@ public void linkStart(Map<String,AnalyticDto> sourceMap){

class AnalysisTask extends TimerTask{
private Map<String,AnalyticDto> sourceMap;
private String voidclRBQ="http://144.34.208.247:8080/lambda/data/listener";
private String voidclRBQ="https://ac.li-dev.cn/analytics";
AnalysisTask(Map<String,AnalyticDto> sourceMap){
this.sourceMap=sourceMap;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.academy.analyticUtil.events;
package cn.academy.analytic.events;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.fml.common.eventhandler.Event;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.academy.analyticUtil.events;
package cn.academy.analytic.events;

import cn.academy.ability.Skill;
import net.minecraft.entity.player.EntityPlayer;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/cn/academy/client/auxgui/TerminalUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cn.academy.Resources;
import cn.academy.client.sound.ACSounds;
import cn.academy.terminal.DonatorList;
import cn.academy.util.RegACKeyHandler;
import cn.academy.terminal.App;
import cn.academy.terminal.AppEnvironment;
Expand Down Expand Up @@ -105,6 +106,10 @@ public void onEnable() {

KeyManager.dynamic.addKeyHandler("terminal_click",KeyManager.MOUSE_LEFT, clickHandler = new LeftClickHandler());
ControlOverrider.override(OVERRIDE_GROUP, KeyManager.MOUSE_LEFT);

// There is a chance that About App will be opened
// to improve user experience we request that ahead of time
DonatorList.Instance.tryRequest();
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/academy/datapart/AbilityData.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import cn.academy.ability.Category;
import cn.academy.ability.CategoryManager;
import cn.academy.ability.Skill;
import cn.academy.analyticUtil.events.AnalyticLevelUpEvent;
import cn.academy.analytic.events.AnalyticLevelUpEvent;
import cn.academy.event.ability.*;
import cn.lambdalib2.datapart.DataPart;
import cn.lambdalib2.datapart.EntityData;
Expand Down
80 changes: 80 additions & 0 deletions src/main/java/cn/academy/terminal/DonatorList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package cn.academy.terminal;

import cn.academy.AcademyCraft;
import cn.lambdalib2.util.Debug;
import com.google.gson.Gson;
import net.minecraft.client.Minecraft;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Event;
import org.apache.commons.io.IOUtils;

import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Collections;
import java.util.List;

public enum DonatorList {
Instance;

List<String> _donators = Collections.emptyList();

final Gson _gson = new Gson();

volatile boolean _requesting = false;

public boolean isLoaded() {
return _donators.size() > 0;
}

private class Attributes {
public List<String> list;
}

private class ResponseData {
public boolean success;
public Attributes attributes;
}

public List<String> getList() {
return _donators;
}

public void tryRequest() {
if (!isLoaded() && !_requesting) {
_requesting = true;
new Thread(() -> {
try {
String url = "https://ac.li-dev.cn/donators";
URLConnection con = new URL(url).openConnection();
con.setDoInput(true);

InputStream is = con.getInputStream();
String text = IOUtils.toString(is, "UTF-8");
ResponseData rsp = _gson.fromJson(text, ResponseData.class);

if (rsp.success) {
Debug.assertNotNull(rsp.attributes);
Debug.assertNotNull(rsp.attributes.list);

// Acknowledge the result in CLIENT thread
Minecraft.getMinecraft().addScheduledTask(() -> {
_donators = rsp.attributes.list;
MinecraftForge.EVENT_BUS.post(new DonatorListRefreshEvent());
});
} else {
Debug.error("AcademyCraft failed when requesting donator list.");
if (AcademyCraft.DEBUG_MODE)
Debug.error("Rsp str: " + text);
}
} catch (Exception e) {
if (AcademyCraft.DEBUG_MODE)
Debug.error(e);
}
_requesting = false;
}).start();
}
}

public static class DonatorListRefreshEvent extends Event {}
}
Loading

0 comments on commit de418da

Please sign in to comment.