Code style update

master
Chikachi 2017-07-29 21:53:25 +02:00
parent 88c99ffe0e
commit e77c580af5
No known key found for this signature in database
GPG Key ID: 0136086A0AC09F5E
14 changed files with 309 additions and 277 deletions

20
.editorconfig Normal file
View File

@ -0,0 +1,20 @@
root = true
[*]
charset=utf-8
end_of_line=lf
indent_style = space
[*.java]
insert_final_newline = true
indent_size = 4
[*.gradle]
insert_final_newline = true
indent_size = 2
[*.{md,json}]
indent_size = 2
[{mcmod.info}]
indent_size = 2

View File

@ -1,176 +1,188 @@
buildscript {
repositories {
jcenter()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT'
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.4'
}
}
repositories {
ivy {
name "CurseForge"
artifactPattern 'http://addons-origin.cursecdn.com/files/[organisation]/[module]-[revision].[ext]'
}
jcenter()
flatDir {
dirs "libs"
}
}
apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java'
def mcVersion = '1.10.2'
def forgeVersion = '12.18.3.2185'
def modVersion = '3.0.0-alpha'
version = 'mc' + mcVersion + '-' + modVersion
group = "chikachi.discord"
archivesBaseName = "DiscordIntegration"
sourceCompatibility = 1.8
targetCompatibility = 1.8
minecraft {
version = mcVersion + '-' + forgeVersion
if (file('../run').exists()) {
runDir = '../run'
} else {
runDir = 'run'
}
mappings = "stable_29"
}
def printDebug(message) {
println '[' + archivesBaseName + '] ' + message
}
/*
* Copyright (C) 2017 Chikachi
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see http://www.gnu.org/licenses.
*/
class CurseForgeDependencyInfo {
public String module, version, ext
private String fileid
CurseForgeDependencyInfo(String module, String version, String ext, String fileid) {
this.module = module
this.version = version
this.ext = ext
this.fileid = fileid
}
String GetFileId() {
return Integer.parseInt(fileid.substring(0, 4)) + "/" + Integer.parseInt(fileid.substring(4))
}
}
// Dependencies on CurseForge
List<CurseForgeDependencyInfo> curseForgeDependencies = new ArrayList<CurseForgeDependencyInfo>()
curseForgeDependencies.add(new CurseForgeDependencyInfo("Dynmap", "2.4-forge-1.10.2", "jar", "2380601"))
dependencies {
compile files('./libs/JDA-3.2.0_226-withDependencies.jar')
compile 'com.vdurmont:emoji-java:3.2.0'
// CurseForge
for (CurseForgeDependencyInfo dependency : curseForgeDependencies) {
if (file('../' + dependency.module).exists()) {
printDebug 'Using local ' + dependency.module + ' project'
compile project(':' + dependency.module)
continue
}
if (file('./' + dependency.module + '.jar').exists()) {
printDebug 'Using local ' + dependency.module + ' compiled jar'
compile files('./' + dependency.module + '.jar')
continue
}
compile group: dependency.GetFileId(), name: dependency.module, version: dependency.version, ext: dependency.ext
}
// IntelliJ
compile 'org.jetbrains:annotations:15.0'
testCompile 'junit:junit:4.12'
}
jar {
manifest {
attributes(
"FMLAT": 'discordintegration_at.cfg'
)
}
}
shadowJar {
classifier = ""
relocate "com.mashape.unirest", "chikachi.discord.repack.com.mashape.unirest"
relocate "com.neovisionaries.ws.client", "chikachi.discord.repack.com.neovisionaries.ws.client"
relocate "com.sun.jna", "chikachi.discord.repack.com.sun.jna"
relocate "com.vdurmont.emoji", "chikachi.discord.repack.com.vdurmont.emoji"
relocate "javax.sound", "chikachi.discord.repack.javax.sound"
relocate "javazoom", "chikachi.discord.repack.javazoom"
relocate "net.dv8tion.jda", "chikachi.discord.repack.net.dv8tion.jda"
relocate "net.sourceforge.jaad", "chikachi.discord.repack.net.sourceforge.jaad"
relocate "org.apache.commons.codec", "chikachi.discord.repack.org.apache.commons.codec"
relocate "org.apache.commons.lang3", "chikachi.discord.repack.org.apache.commons.lang3"
relocate "org.json", "chikachi.discord.repack.org.json"
relocate "org.kc7bfi.jflac", "chikachi.discord.repack.orgkc7bfi.jflac"
relocate "org.tritonus", "chikachi.discord.repack.org.tritonus"
relocate "tomp2p.opuswrapper", "chikachi.discord.repack.tomp2p.opuswrapper"
relocate "org.apache.http", "chikachi.discord.repack.org.apache.http"
relocate "org.apache.commons.logging", "chikachi.discord.repack.org.apache.commons.logging"
dependencies {
include(dependency('net.dv8tion:JDA:3.2.0_226:withDependencies'))
include(dependency('com.vdurmont:emoji-java:3.2.0'))
}
}
processResources {
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version
// replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
// replace version and mcversion
expand 'version': modVersion, 'mcversion': project.minecraft.version
}
// copy everything else, thats not the mcmod.info
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}
test {
useJUnit()
}
reobf { shadowJar { mappingType = "SEARGE" } }
tasks.reobfShadowJar.mustRunAfter shadowJar
idea { module { inheritOutputDirs = true } }
buildscript {
repositories {
jcenter()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT'
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.4'
classpath 'com.diffplug.spotless:spotless-plugin-gradle:3.4.1'
}
}
repositories {
ivy {
name "CurseForge"
artifactPattern 'http://addons-origin.cursecdn.com/files/[organisation]/[module]-[revision].[ext]'
}
jcenter()
flatDir {
dirs "libs"
}
}
apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java'
apply plugin: 'com.diffplug.gradle.spotless'
def mcVersion = '1.10.2'
def forgeVersion = '12.18.3.2185'
def modVersion = '3.0.0-alpha'
version = 'mc' + mcVersion + '-' + modVersion
group = "chikachi.discord"
archivesBaseName = "DiscordIntegration"
sourceCompatibility = 1.8
targetCompatibility = 1.8
minecraft {
version = mcVersion + '-' + forgeVersion
if (file('../run').exists()) {
runDir = '../run'
} else {
runDir = 'run'
}
mappings = "stable_29"
}
def printDebug(message) {
println '[' + archivesBaseName + '] ' + message
}
/*
* Copyright (C) 2017 Chikachi
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see http://www.gnu.org/licenses.
*/
class CurseForgeDependencyInfo {
public String module, version, ext
private String fileid
CurseForgeDependencyInfo(String module, String version, String ext, String fileid) {
this.module = module
this.version = version
this.ext = ext
this.fileid = fileid
}
String GetFileId() {
return Integer.parseInt(fileid.substring(0, 4)) + "/" + Integer.parseInt(fileid.substring(4))
}
}
// Dependencies on CurseForge
List<CurseForgeDependencyInfo> curseForgeDependencies = new ArrayList<CurseForgeDependencyInfo>()
curseForgeDependencies.add(new CurseForgeDependencyInfo("Dynmap", "2.4-forge-1.10.2", "jar", "2380601"))
dependencies {
compile files('./libs/JDA-3.2.0_226-withDependencies.jar')
compile 'com.vdurmont:emoji-java:3.2.0'
// CurseForge
for (CurseForgeDependencyInfo dependency : curseForgeDependencies) {
if (file('../' + dependency.module).exists()) {
printDebug 'Using local ' + dependency.module + ' project'
compile project(':' + dependency.module)
continue
}
if (file('./' + dependency.module + '.jar').exists()) {
printDebug 'Using local ' + dependency.module + ' compiled jar'
compile files('./' + dependency.module + '.jar')
continue
}
compile group: dependency.GetFileId(), name: dependency.module, version: dependency.version, ext: dependency.ext
}
// IntelliJ
compile 'org.jetbrains:annotations:15.0'
testCompile 'junit:junit:4.12'
}
jar {
manifest {
attributes(
"FMLAT": 'discordintegration_at.cfg'
)
}
}
shadowJar {
classifier = ""
relocate "com.mashape.unirest", "chikachi.discord.repack.com.mashape.unirest"
relocate "com.neovisionaries.ws.client", "chikachi.discord.repack.com.neovisionaries.ws.client"
relocate "com.sun.jna", "chikachi.discord.repack.com.sun.jna"
relocate "com.vdurmont.emoji", "chikachi.discord.repack.com.vdurmont.emoji"
relocate "javax.sound", "chikachi.discord.repack.javax.sound"
relocate "javazoom", "chikachi.discord.repack.javazoom"
relocate "net.dv8tion.jda", "chikachi.discord.repack.net.dv8tion.jda"
relocate "net.sourceforge.jaad", "chikachi.discord.repack.net.sourceforge.jaad"
relocate "org.apache.commons.codec", "chikachi.discord.repack.org.apache.commons.codec"
relocate "org.apache.commons.lang3", "chikachi.discord.repack.org.apache.commons.lang3"
relocate "org.json", "chikachi.discord.repack.org.json"
relocate "org.kc7bfi.jflac", "chikachi.discord.repack.orgkc7bfi.jflac"
relocate "org.tritonus", "chikachi.discord.repack.org.tritonus"
relocate "tomp2p.opuswrapper", "chikachi.discord.repack.tomp2p.opuswrapper"
relocate "org.apache.http", "chikachi.discord.repack.org.apache.http"
relocate "org.apache.commons.logging", "chikachi.discord.repack.org.apache.commons.logging"
dependencies {
include(dependency('net.dv8tion:JDA:3.2.0_226:withDependencies'))
include(dependency('com.vdurmont:emoji-java:3.2.0'))
}
}
processResources {
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version
// replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
// replace version and mcversion
expand 'version': modVersion, 'mcversion': project.minecraft.version
}
// copy everything else, thats not the mcmod.info
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}
test {
useJUnit()
}
spotless {
java {
encoding 'UTF-8'
removeUnusedImports()
trimTrailingWhitespace()
indentWithSpaces(4)
endWithNewline()
}
}
reobf { shadowJar { mappingType = "SEARGE" } }
tasks.reobfShadowJar.mustRunAfter shadowJar
idea { module { inheritOutputDirs = true } }

View File

@ -16,9 +16,9 @@ package chikachi.discord;
import chikachi.discord.command.CommandDiscord;
import chikachi.discord.core.CoreConstants;
import chikachi.discord.core.Proxy;
import chikachi.discord.core.DiscordClient;
import chikachi.discord.core.Patterns;
import chikachi.discord.core.Proxy;
import chikachi.discord.listener.DiscordListener;
import chikachi.discord.listener.MinecraftListener;
import net.minecraft.util.text.TextFormatting;
@ -27,7 +27,6 @@ import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.regex.Pattern;
@Mod(modid = CoreConstants.MODID, name = CoreConstants.MODNAME, version = CoreConstants.VERSION, serverSideOnly = true, acceptableRemoteVersions = "*")
@ -37,53 +36,6 @@ public class DiscordIntegration {
private static Proxy proxy = new Proxy();
@Mod.EventHandler
public void onPreInit(FMLPreInitializationEvent event) {
proxy.onPreInit(event.getModConfigurationDirectory());
addPatterns();
MinecraftForge.EVENT_BUS.register(new MinecraftListener());
}
@Mod.EventHandler
public void onPostInit(FMLPostInitializationEvent event) {
event.buildSoftDependProxy("Dynmap", "chikachi.discord.integration.DynmapIntegration");
}
@Mod.EventHandler
public void onServerAboutToStart(FMLServerAboutToStartEvent event) {
}
@Mod.EventHandler
public void onServerStarting(FMLServerStartingEvent event) {
proxy.onServerStarting();
DiscordClient.getInstance().addEventListener(new DiscordListener());
event.registerServerCommand(new CommandDiscord());
}
@Mod.EventHandler
public void onServerStarted(FMLServerStartedEvent event) {
proxy.onServerStarted();
}
@Mod.EventHandler
public void onServerStopping(FMLServerStoppingEvent event) {
proxy.onServerStopping();
}
@Mod.EventHandler
public void onServerStopped(FMLServerStoppedEvent event) {
proxy.onServerStopped();
}
@Mod.EventHandler
public void imcReceived(FMLInterModComms.IMCEvent event) {
event.getMessages().forEach(IMCHandler::onMessageReceived);
}
public static void addPatterns() {
Patterns.clearCustomPatterns();
@ -228,4 +180,51 @@ public class DiscordIntegration {
}
});
}
@Mod.EventHandler
public void onPreInit(FMLPreInitializationEvent event) {
proxy.onPreInit(event.getModConfigurationDirectory());
addPatterns();
MinecraftForge.EVENT_BUS.register(new MinecraftListener());
}
@Mod.EventHandler
public void onPostInit(FMLPostInitializationEvent event) {
event.buildSoftDependProxy("Dynmap", "chikachi.discord.integration.DynmapIntegration");
}
@Mod.EventHandler
public void onServerAboutToStart(FMLServerAboutToStartEvent event) {
}
@Mod.EventHandler
public void onServerStarting(FMLServerStartingEvent event) {
proxy.onServerStarting();
DiscordClient.getInstance().addEventListener(new DiscordListener());
event.registerServerCommand(new CommandDiscord());
}
@Mod.EventHandler
public void onServerStarted(FMLServerStartedEvent event) {
proxy.onServerStarted();
}
@Mod.EventHandler
public void onServerStopping(FMLServerStoppingEvent event) {
proxy.onServerStopping();
}
@Mod.EventHandler
public void onServerStopped(FMLServerStoppedEvent event) {
proxy.onServerStopped();
}
@Mod.EventHandler
public void imcReceived(FMLInterModComms.IMCEvent event) {
event.getMessages().forEach(IMCHandler::onMessageReceived);
}
}

View File

@ -47,4 +47,4 @@ public class DiscordTeleporter extends Teleporter {
entity.motionZ = 0;
entity.fallDistance = 0;
}
}
}

View File

@ -14,8 +14,8 @@
package chikachi.discord;
import chikachi.discord.core.DiscordIntegrationLogger;
import chikachi.discord.core.DiscordClient;
import chikachi.discord.core.DiscordIntegrationLogger;
import chikachi.discord.core.Message;
import chikachi.discord.core.config.Configuration;
import chikachi.discord.core.config.imc.IMCConfig;

View File

@ -195,4 +195,4 @@ public class CommandDiscord extends CommandBase {
public int compareTo(@NotNull ICommand o) {
return super.compareTo(o);
}
}
}

View File

@ -15,7 +15,6 @@
package chikachi.discord.command;
import chikachi.discord.core.DiscordClient;
import chikachi.discord.core.DiscordIntegrationLogger;
import chikachi.discord.core.config.Configuration;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.text.TextComponentString;

View File

@ -145,4 +145,4 @@ public class CoreUtils {
public static String getAvatarUrl(String minecraftUsername) {
return String.format("https://minotar.net/helm/%s/128.png", minecraftUsername);
}
}
}

View File

@ -23,9 +23,8 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Patterns {
static final Pattern tagPattern = Pattern.compile("@([^\\s]+)");
public static final Pattern minecraftCodePattern = Pattern.compile("(?i)(\u00a7[0-9A-FK-OR])");
static final Pattern tagPattern = Pattern.compile("@([^\\s]+)");
private static final HashMap<Pattern, ReplacementCallback> discordFormattingPatterns = new HashMap<>();
private static final HashMap<Pattern, ReplacementCallback> minecraftFormattingPatterns = new HashMap<>();
@ -96,4 +95,4 @@ public class Patterns {
String post(String text);
}
}
}

View File

@ -25,6 +25,32 @@ public class Proxy {
private static boolean serverStopping = false;
private static long started;
public static String getUptime() {
if (started == 0) {
return "UNKNOWN";
}
long diff = new Date().getTime() - started;
int seconds = (int) Math.floorDiv(diff, 1000);
if (seconds < 60) {
return seconds + " second" + (seconds == 1 ? "" : "s");
}
int minutes = Math.floorDiv(seconds, 60);
seconds -= minutes * 60;
if (minutes < 60) {
return minutes + " minute" + (minutes == 1 ? "" : "s") + ", " + seconds + " second" + (seconds == 1 ? "" : "s");
}
int hours = Math.floorDiv(minutes, 60);
minutes -= hours * 60;
if (hours < 60) {
return hours + " hour" + (hours == 1 ? "" : "s") + ", " + minutes + " minute" + (minutes == 1 ? "" : "s") + ", " + seconds + " second" + (seconds == 1 ? "" : "s");
}
int days = Math.floorDiv(hours, 24);
hours -= days * 60;
return days + " day" + (days == 1 ? "" : "s") + ", " + hours + " hour" + (hours == 1 ? "" : "s") + ", " + minutes + " minute" + (minutes == 1 ? "" : "s") + ", " + seconds + " second" + (seconds == 1 ? "" : "s");
}
public void onPreInit(File configurationPath) {
if (preInit) {
return;
@ -75,30 +101,4 @@ public class Proxy {
DiscordClient.getInstance().disconnect(true);
}
public static String getUptime() {
if (started == 0) {
return "UNKNOWN";
}
long diff = new Date().getTime() - started;
int seconds = (int) Math.floorDiv(diff, 1000);
if (seconds < 60) {
return seconds + " second" + (seconds == 1 ? "" : "s");
}
int minutes = Math.floorDiv(seconds, 60);
seconds -= minutes * 60;
if (minutes < 60) {
return minutes + " minute" + (minutes == 1 ? "" : "s") + ", " + seconds + " second" + (seconds == 1 ? "" : "s");
}
int hours = Math.floorDiv(minutes, 60);
minutes -= hours * 60;
if (hours < 60) {
return hours + " hour" + (hours == 1 ? "" : "s") + ", " + minutes + " minute" + (minutes == 1 ? "" : "s") + ", " + seconds + " second" + (seconds == 1 ? "" : "s");
}
int days = Math.floorDiv(hours, 24);
hours -= days * 60;
return days + " day" + (days == 1 ? "" : "s") + ", " + hours + " hour" + (hours == 1 ? "" : "s") + ", " + minutes + " minute" + (minutes == 1 ? "" : "s") + ", " + seconds + " second" + (seconds == 1 ? "" : "s");
}
}

View File

@ -15,8 +15,8 @@
package chikachi.discord.core.config;
import chikachi.discord.core.config.discord.DiscordConfig;
import chikachi.discord.core.config.minecraft.MinecraftConfig;
import chikachi.discord.core.config.imc.IMCConfig;
import chikachi.discord.core.config.minecraft.MinecraftConfig;
import com.google.gson.annotations.Since;
public class ConfigWrapper {
@ -43,4 +43,4 @@ public class ConfigWrapper {
}
this.imc.fillFields();
}
}
}

View File

@ -25,12 +25,12 @@ import java.util.regex.Pattern;
@SuppressWarnings({"MismatchedQueryAndUpdateOfCollection", "unused"})
public class CommandConfig {
private static Pattern specificArgPattern = Pattern.compile("\\{ARG_([0-9]+)\\}", Pattern.CASE_INSENSITIVE);
private String name;
private String command;
private boolean enabled;
private List<String> aliases = new ArrayList<>();
private List<String> permissions = new ArrayList<>();
private static Pattern specificArgPattern = Pattern.compile("\\{ARG_([0-9]+)\\}", Pattern.CASE_INSENSITIVE);
public String getName() {
return name;

View File

@ -15,7 +15,6 @@
package chikachi.discord.integration;
import chikachi.discord.core.DiscordClient;
import chikachi.discord.core.DiscordIntegrationLogger;
import chikachi.discord.core.Message;
import chikachi.discord.core.config.Configuration;
import chikachi.discord.core.config.minecraft.MinecraftGenericConfig;

View File

@ -1,14 +1,18 @@
[{
"modid": "DiscordIntegration",
"name": "DiscordIntegration",
"description": "MC <=> Discord integration",
"version": "${version}",
"mcversion": "${mcversion}",
"url": "https://discordintegration.net",
"updateUrl": "",
"authorList": ["Chikachi"],
"credits": "",
"logoFile": "",
"screenshots": [],
"dependencies": []
}]
[
{
"modid": "DiscordIntegration",
"name": "DiscordIntegration",
"description": "MC <=> Discord integration",
"version": "${version}",
"mcversion": "${mcversion}",
"url": "https://discordintegration.net",
"updateUrl": "",
"authorList": [
"Chikachi"
],
"credits": "",
"logoFile": "",
"screenshots": [],
"dependencies": []
}
]