Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A Special PR... #81

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/build
/classes
/run
/out
/*.iml
/bin/
/.settings/
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
- Change JavaCord to JDA for Discord API support
- Upgrade to Minecraft 1.12

## 2.4.2
- Add support for sending a player first join message when Nucleus is present.

## 2.4.1
- Update Discord API to support categories.
- Add Custom Emoji Handling.
- Fix pinning a message on Discord sending a blank message to Minecraft.

## 2.4.0
- Support sending message to Discord when a player die (check `deathTemplate`).
- Discord Bridge now ignores only messages from Discord Bridge and from the same server. Previously, the plugin ignores all messages from Discord Bridge regardless different servers.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Configuration is stored in `config.json` file.
- `authenticatedChatTemplate`: (optional) template for messages from Minecraft to Discord for authenticated user
- `broadcastTemplate`: (optional) template for messages in Discord from `/discord broadcast` command
- `deathTemplate`: (optional) template for a message in Discord when a player dies _(thanks, Mohron)_
- `firstJoinTemplate`: (optional, requires Nucleus) template for a message in Discord when a player first joins _(thanks, Mohron)_
- `minecraft`: templates in Minecraft
- `chatTemplate`: (optional) template for messages from Discord to Minecraft. For supporting placeholders in the template, check the section **Chat placeholder**
- `attachment`: _(thanks, Mohron)_
Expand Down
39 changes: 19 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'java'
id 'com.github.johnrengelman.shadow' version '1.2.3'
id 'com.github.johnrengelman.shadow' version '2.0.2'
}

defaultTasks 'build', 'shadowJar'
Expand All @@ -13,29 +13,29 @@ sourceCompatibility = 1.8
repositories {
mavenCentral()
maven {
name 'Sonatype'
url 'https://oss.sonatype.org/content/repositories/snapshots/'
name = 'Sonatype'
url = 'https://oss.sonatype.org/content/repositories/snapshots/'
}
maven {
name 'sponge'
url 'http://repo.spongepowered.org/maven'
name = 'sponge'
url = 'http://repo.spongepowered.org/maven'
}
maven {
name = 'jitpack.io'
url = 'https://jitpack.io'
}
maven {
name = "Nucleus"
url = "http://repo.drnaylor.co.uk/artifactory/list/minecraft"
}
jcenter()
}

dependencies {
compile('org.spongepowered:spongeapi:7.0.0')
//compile('org.spongepowered:spongeapi:5.0.0')
//compile files('libs/javacord-2.0.14-shaded.jar')
compile 'net.dv8tion:JDA:3.4.0_320'
compile 'org.spongepowered:spongeapi:7.+'
compile 'net.dv8tion:JDA:3.5.1_339'
compile 'com.mashape.unirest:unirest-java:1.4.9'
// compile('de.btobastian.javacord:javacord:2.0.11:shaded')
// compile "com.github.austinv11:Discord4j:2.4.9:shaded"
// compile 'org.apache.httpcomponents:httpcore:4.3.2'
// compile 'org.apache.httpcomponents:httpclient:4.3.3'
// compile 'org.java-websocket:Java-WebSocket:1.3.0'
// compile 'com.googlecode.json-simple:json-simple:1.1.1'
// compile 'net.jodah:typetools:0.4.3'
compile 'io.github.nucleuspowered:nucleus-api:+'
}

task fatJar(type: Jar) {
Expand All @@ -50,11 +50,10 @@ shadowJar {
include dependency('org.apache.commons:commons-lang3')
include dependency('org.apache.httpcomponents:httpcore')
include dependency('org.apache.httpcomponents:httpclient')
// include dependency('com.googlecode.json-simple:json-simple')
// include dependency('org.java-websocket:Java-WebSocket')
// include dependency('net.jodah:typetools')

relocate 'org.apache.http', 'shaded.apache.http'
relocate 'org.apache.commons', 'shaded.apache.commons'
}
}
}

build.dependsOn(shadowJar)
1 change: 1 addition & 0 deletions examples/config-multiple.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"leftTemplate": "_%s just left the server_",
"serverUpMessage": "Server has started.",
"serverDownMessage": "Server has stopped.",
"firstJoinTemplate": "_Welcome **%a** to the server!_",
"deathTemplate": "**%s**"
}
},
Expand Down
1 change: 1 addition & 0 deletions examples/config-simple.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"leftTemplate": "_%s just left the server_",
"serverUpMessage": "Server has started.",
"serverDownMessage": "Server has stopped.",
"firstJoinTemplate": "_Welcome **%a** to the server!_",
"broadcastTemplate": "_<BROADCAST> %s_",
"deathTemplate": "**%s**"
},
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Wed Jan 06 14:03:12 SGT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
78 changes: 43 additions & 35 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
warn () {
echo "$*"
}

die ( ) {
die () {
echo
echo "$*"
echo
Expand All @@ -30,6 +48,7 @@ die ( ) {
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
Expand All @@ -40,31 +59,11 @@ case "`uname`" in
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac

# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
APP_HOME="`pwd -P`"
cd "$SAVED" >&-

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
Expand All @@ -90,7 +89,7 @@ location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
Expand All @@ -114,6 +113,7 @@ fi
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
Expand Down Expand Up @@ -154,11 +154,19 @@ if $cygwin ; then
esac
fi

# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
APP_ARGS=$(save "$@")

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
exec "$JAVACMD" "$@"
14 changes: 4 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

Expand Down Expand Up @@ -46,10 +46,9 @@ echo location of your Java installation.
goto fail

:init
@rem Get command-line arguments, handling Windowz variants
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args

:win9xME_args
@rem Slurp the command line arguments.
Expand All @@ -60,11 +59,6 @@ set _SKIP=2
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*
goto execute

:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$

:execute
@rem Setup the command line
Expand Down
23 changes: 20 additions & 3 deletions src/main/java/com/nguyenquyhy/discordbridge/DiscordBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@
import com.nguyenquyhy.discordbridge.listeners.ChatListener;
import com.nguyenquyhy.discordbridge.listeners.ClientConnectionListener;
import com.nguyenquyhy.discordbridge.listeners.DeathListener;
import com.nguyenquyhy.discordbridge.listeners.FirstJoinListener;
import com.nguyenquyhy.discordbridge.logics.ConfigHandler;
import com.nguyenquyhy.discordbridge.logics.LoginHandler;
import com.nguyenquyhy.discordbridge.models.ChannelConfig;
import com.nguyenquyhy.discordbridge.models.GlobalConfig;
import com.nguyenquyhy.discordbridge.utils.ChannelUtil;
import com.nguyenquyhy.discordbridge.utils.ErrorMessages;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.entities.*;
import net.dv8tion.jda.core.entities.TextChannel;
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.spongepowered.api.Game;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.config.ConfigDir;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.*;
import org.spongepowered.api.event.game.state.GameInitializationEvent;
import org.spongepowered.api.event.game.state.GameStartingServerEvent;
import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
import org.spongepowered.api.plugin.Plugin;

import java.io.IOException;
Expand Down Expand Up @@ -55,6 +58,7 @@ public class DiscordBridge {
private IStorage storage;

private static DiscordBridge instance;
private int playerCount = 0;

@Listener
public void onInitialization(GameInitializationEvent event) throws IOException, ObjectMappingException {
Expand All @@ -64,10 +68,14 @@ public void onInitialization(GameInitializationEvent event) throws IOException,
Sponge.getEventManager().registerListeners(this, new ChatListener());
Sponge.getEventManager().registerListeners(this, new ClientConnectionListener());
Sponge.getEventManager().registerListeners(this, new DeathListener());

if (Sponge.getPluginManager().isLoaded("nucleus")) {
Sponge.getEventManager().registerListeners(this, new FirstJoinListener());
}
}

@Listener
public void onServerStart(GameStartedServerEvent event) {
public void onServerStarting(GameStartingServerEvent event) {
CommandRegistry.register();
LoginHandler.loginBotAccount();
}
Expand All @@ -82,6 +90,7 @@ public void onServerStop(GameStoppingServerEvent event) {
TextChannel channel = botClient.getTextChannelById(channelConfig.discordId);
if (channel != null) {
ChannelUtil.sendMessage(channel, channelConfig.discord.serverDownMessage);
ChannelUtil.setDescription(channel, "Offline");
} else {
ErrorMessages.CHANNEL_NOT_FOUND.log(channelConfig.discordId);
}
Expand Down Expand Up @@ -146,6 +155,14 @@ public void addClient(UUID player, JDA client) {
}
}

public void setPlayerCount(int change) {
playerCount += change;
}

public int getPlayerCount() {
return playerCount;
}

public void removeAndLogoutClient(UUID player) {
if (player == null) {
consoleClient.shutdown();
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/nguyenquyhy/discordbridge/hooks/Boop.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.nguyenquyhy.discordbridge.hooks;

public class Boop {

public static String getMessageChannelClass() {
return "flavor.pie.boop.BoopableChannel";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.nguyenquyhy.discordbridge.hooks;

public class Nucleus {

public static String getStaffMessageChannelClass() {
return "io.github.nucleuspowered.nucleus.modules.staffchat.StaffChatMessageChannel";
}
}
Loading