Skip to content

Commit

Permalink
Release v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sciwhiz12 committed Mar 29, 2021
2 parents dfbf4e6 + e59d0d1 commit add8834
Show file tree
Hide file tree
Showing 21 changed files with 465 additions and 349 deletions.
16 changes: 5 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
# eclipse
build
.gradle

bin
*.launch
.settings
.metadata
.classpath
.project

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

# gradle
build
.gradle

# other
eclipse
run

# Files from Forge MDK
forge*changelog.txt
repo
logs
4 changes: 1 addition & 3 deletions src/README.md → README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Concord
# Concord [![](http://cf.way2muchnoise.eu/418010.svg?badge_style=flat)](https://www.curseforge.com/minecraft/mc-mods/concord)

> _A Discord chat integration mod, for servers._
[![CurseForge](https://cf.way2muchnoise.eu/concord.svg?badge_style=flat)](https://www.curseforge.com/minecraft/mc-mods/concord)

Discord chat bridging between a Minecraft server and a Discord text channel.
- Compatibility with vanilla clients
- Localization with Forge clients with this mod installed
Expand Down
116 changes: 52 additions & 64 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,24 @@ buildscript {
name = "MinecraftForge"
url = 'https://files.minecraftforge.net/maven'
}
jcenter()
mavenCentral()
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
classpath group: 'org.ajoberstar.grgit', name: 'grgit-gradle', 'version': '4.0.2'
classpath group: 'com.github.jengelman.gradle.plugins', name: 'shadow', version: '4.0.4'
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '4.1.+', changing: true
}
}
plugins {
id 'eclipse'
id 'idea'
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '6.1.0'
}
apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'org.ajoberstar.grgit'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'maven-publish'
apply plugin: 'com.github.johnrengelman.shadow'

def mod_version = getVersion()
version = "${mc_version}-${mod_version}"
apply from: 'version.gradle'

group = 'tk.sciwhiz12'
archivesBaseName = 'concord'
archivesBaseName = "concord"
def mod_version = versionInfo["version"] ?: "unknown"
version = "${mod_version}"

println("Mod version: ${mod_version}")
println('Java: ' + System.getProperty('java.version') + '; JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + '); Arch: ' + System.getProperty('os.arch'))
Expand All @@ -38,7 +36,10 @@ sourceSets {
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'

repositories {
jcenter()
maven {
name 'm2-dv8tion'
url 'https://m2.dv8tion.net/releases'
}
mavenCentral()
}

Expand Down Expand Up @@ -115,15 +116,6 @@ dependencies {
dataCompileClasspath sourceSets.main.compileClasspath
}

def commit_id = "unknown"
def git_timestamp = "unknown"
try {
commit_id = grgit.head().id
def datetime = grgit.head().dateTime
git_timestamp = datetime.toLocalDateTime().toString() + datetime.getOffset().toString().replace(':', '');
} catch (Exception e) {
logger.error("Error while trying to get commit info: {}", e)
}
jar {
manifest {
attributes([
Expand All @@ -132,20 +124,29 @@ jar {
"Implementation-Title" : project.name,
"Implementation-Version": "${mod_version}",
"Implementation-Vendor" : "sciwhiz12",
"Build-Timestamp" : new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
"Git-Commit" : commit_id,
"Git-Commit-Timestamp" : git_timestamp
"Git-Commit" : versionInfo["hash"] ?: "0000000000000000000000000000000000000000",
"Git-Commit-Timestamp" : versionInfo["timestamp"] ?: "1980-01-01T00:00:00+00:00"
] as LinkedHashMap)
}
includeEmptyDirs false
preserveFileTimestamps = false
reproducibleFileOrder = true
archivesBaseName = "concord-${mc_version}"
version = mod_version

archiveClassifier = 'lite'
finalizedBy 'reobfJar'
finalizedBy 'sourcesJar'
}

def relocate(origin) {
shadowJar.relocate(origin, "tk.sciwhiz12.concord.shadow.$origin")
}

shadowJar {
classifier = ''
preserveFileTimestamps = false
reproducibleFileOrder = true
archiveClassifier = ''
configurations = [project.configurations.shade]
relocate 'com.iwebpp.crypto'
relocate 'org.json'
Expand All @@ -172,59 +173,46 @@ shadowJar {
exclude 'META-INF/LICENSE*'
exclude 'META-INF/NOTICE*'
exclude 'module-info.class'
}

reobf {
shadowJar {}
}

jar {
classifier = 'lite'
finalizedBy 'reobfJar'
finalizedBy 'sourcesJar'
finalizedBy 'reobfShadowJar'
}

build.dependsOn('reobfShadowJar')
assemble.dependsOn shadowJar
}

task sourcesJar(type: Jar, dependsOn: classes) {
from sourceSets.main.allSource
classifier = 'sources'
preserveFileTimestamps = false
reproducibleFileOrder = true
archiveClassifier = 'sources'
}

String getVersion() {
try {
final String branchName = grgit.branch.current().name
boolean non_main = !branchName.matches("\\d+.\\d+.x")
if (non_main) println("Currently on non-main branch: " + branchName)
String ver = grgit.describe(commit: grgit.head(), longDescr: non_main, tags: true);
if (ver != null) {
if (non_main) ver = ver + "@" + branchName
if (ver.startsWith("v")) return ver.substring(1)
return ver
}
} catch (Exception e) {
logger.error("Error while getting version information: {}", e)
}
return "unknown"
reobf {
shadowJar {}
}

artifacts {
archives sourcesJar
tasks.withType(net.minecraftforge.gradle.userdev.tasks.RenameJarInPlace) {
String[] args = getArgs()
args += "--stable"
setArgs(args)
}

publishing {
publications {
rebofJar(MavenPublication) {
artifactId = archivesBaseName
artifact jar
}
srcJar(MavenPublication) {
artifactId = archivesBaseName
maven(MavenPublication) {
artifactId = "concord"
version = "${versionInfo["raw_version"]}-${mc_version}${versionInfo["snapshot"] ? "-SNAPSHOT" : ""}"
artifact(jar) {
classifier = ""
}
artifact(shadowJar) {
classifier = "shadow"
}
artifact sourcesJar
}
}
repositories {
mavenLocal()
maven {
url = "file://" + file("repo").getAbsolutePath() + "/"
}
}
}
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false

mc_version=1.16.5
forge_version=36.0.0
mappings_version=20201028-1.16.3
forge_version=36.1.2
mappings_version=20210309-1.16.5

jda_version=4.2.0_227
webhook_version=0.5.0
jda_version=4.2.0_250
webhook_version=0.5.6

logging_markers=REGISTRIES
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip
Empty file modified gradlew
100644 → 100755
Empty file.
44 changes: 25 additions & 19 deletions src/main/java/tk/sciwhiz12/concord/ChatBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.GuildChannel;
import net.dv8tion.jda.api.events.ReadyEvent;
import net.dv8tion.jda.api.hooks.AnnotatedEventManager;
import net.dv8tion.jda.api.hooks.SubscribeEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.requests.restaction.MessageAction;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.common.MinecraftForge;
import org.apache.logging.log4j.Marker;
Expand All @@ -20,58 +21,64 @@
import tk.sciwhiz12.concord.msg.PlayerListener;
import tk.sciwhiz12.concord.msg.StatusListener;

import java.util.Collections;
import java.util.EnumSet;

public class ChatBot {
public class ChatBot extends ListenerAdapter {
private static final Marker BOT = MarkerManager.getMarker("BOT");
public static final EnumSet<Permission> REQUIRED_PERMISSIONS =
EnumSet.of(Permission.VIEW_CHANNEL, Permission.MESSAGE_READ, Permission.MESSAGE_WRITE);

private final JDA discord;
private final MinecraftServer server;
private final MessageListener msgListener;
private final PlayerListener playerListener;
private final StatusListener statusListener;

ChatBot(JDA discord) {
ChatBot(JDA discord, MinecraftServer server) {
this.discord = discord;
discord.setEventManager(new AnnotatedEventManager());
this.server = server;
discord.addEventListener(this);
discord.addEventListener(msgListener = new MessageListener(this));
discord.addEventListener(playerListener = new PlayerListener(this));
discord.addEventListener(statusListener = new StatusListener(this));
MinecraftForge.EVENT_BUS.register(msgListener);
MinecraftForge.EVENT_BUS.register(playerListener);
MinecraftForge.EVENT_BUS.register(statusListener);
msgListener = new MessageListener(this);
playerListener = new PlayerListener(this);
statusListener = new StatusListener(this);

// Prevent any mentions not explicitly specified
MessageAction.setDefaultMentions(Collections.emptySet());
}

public JDA getDiscord() {
return discord;
}

@SubscribeEvent
void onReady(ReadyEvent event) {
public MinecraftServer getServer() {
return server;
}

@Override
public void onReady(ReadyEvent event) {
discord.getPresence().setPresence(OnlineStatus.ONLINE, Activity.playing("some Minecraft"));

boolean satisfied = true;
Concord.LOGGER.debug(BOT, "Checking guild and channel existence, and satisfaction of required permissions...");
// Checking if specified guild and channel IDs are correct
final Guild guild = discord.getGuildById(ConcordConfig.GUILD_ID);
final Guild guild = discord.getGuildById(ConcordConfig.GUILD_ID.get());
if (guild == null) {
Concord.LOGGER.warn(BOT, "This bot is not connected to a guild with ID {}, as specified in the config.",
ConcordConfig.GUILD_ID);
ConcordConfig.GUILD_ID.get());
Concord.LOGGER.warn(BOT, "This indicates either the bot was not invited to the guild, or a wrongly-typed guild ID.");
satisfied = false;

} else {
final GuildChannel channel = guild.getGuildChannelById(ConcordConfig.CHANNEL_ID);
final GuildChannel channel = guild.getGuildChannelById(ConcordConfig.CHANNEL_ID.get());
if (channel == null) {
Concord.LOGGER.error(BOT, "There is no channel with ID {} within the guild, as specified in the config.",
ConcordConfig.CHANNEL_ID);
ConcordConfig.CHANNEL_ID.get());
satisfied = false;

} else if (channel.getType() != ChannelType.TEXT) {
Concord.LOGGER.error(BOT, "The channel with ID {} is not a TEXT channel, it was of type {}.",
ConcordConfig.CHANNEL_ID, channel.getType());
ConcordConfig.CHANNEL_ID.get(), channel.getType());
satisfied = false;

} else { // Guild and channel IDs are correct, now to check permissions
Expand All @@ -95,7 +102,6 @@ void onReady(ReadyEvent event) {
Concord.LOGGER.debug(BOT, "Guild and channel are correct, and permissions are satisfied.");

Concord.LOGGER.info(BOT, "Discord bot is ready!");
Concord.LOGGER.info(BOT, "Invite URL for bot: {}", discord.getInviteUrl(REQUIRED_PERMISSIONS));

Messaging.sendToChannel(discord, new TranslationTextComponent("message.concord.bot.start").getString());
}
Expand Down
Loading

0 comments on commit add8834

Please sign in to comment.