Skip to content

Commit

Permalink
Add command to receive discord invitation link
Browse files Browse the repository at this point in the history
- Use /discord to receive discord invitation link in the ingame chat
- Link must be set up in the config.yml
- Whole command can be disabled in the config.yml
  • Loading branch information
Falyrion committed Nov 22, 2021
1 parent 0d0fb53 commit 199fc35
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
26 changes: 24 additions & 2 deletions src/com/falyrion/discordbridge/DiscordBridgeMain.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.falyrion.discordbridge;

import commands.Cmd_DiscordLink;
import gamelistener.GameEventListener_Chat;
import gamelistener.GameEventListener_Death;
import gamelistener.GameEventListener_Join;
Expand All @@ -24,6 +25,8 @@ public static DiscordBridgeMain getInstance() {
return instance;
}

public String discordLink;
public String discordInfoMsg;
public String readChannelID;
private String writeChannelID;
private String serverStartMessage;
Expand All @@ -33,6 +36,7 @@ public static DiscordBridgeMain getInstance() {
private String playerDeathMessage;
private String playerMessageToGame;
private String playerMessageToDiscord;
private boolean enableCmdLink;
private boolean botLoaded = false;

FileConfiguration config = getConfig();
Expand All @@ -52,10 +56,18 @@ public void onEnable() {
// Create config file if not existing
this.saveDefaultConfig();

// -------------------------------------------------------------------------------------------------------------
// Read values from config

String discordBotToken = config.getString("clientID");
readChannelID = config.getString("textChannelRead");
writeChannelID = config.getString("textChannelWrite");
discordLink = config.getString("discordLink");
discordInfoMsg = config.getString("discordInfoMessage");
enableCmdLink = config.getBoolean("enableLinkCommand");

// -------------------------------------------------------------------------------------------------------------
// Bot related

if (discordBotToken == null || readChannelID == null || writeChannelID == null) {
log.warning("[EasyDiscordBridge] Config file not available or invalid.");
Expand Down Expand Up @@ -128,7 +140,17 @@ public void onEnable() {

}

log.info("[EasyDiscordBridge] Plugin v1.0.2.0 enabled");
// -------------------------------------------------------------------------------------------------------------
// Enable Commands

if (enableCmdLink) {
getCommand("discord").setExecutor(new Cmd_DiscordLink());
}

// -------------------------------------------------------------------------------------------------------------
// Log

log.info("[EasyDiscordBridge] Plugin v1.1.0.0 enabled");

}

Expand All @@ -140,7 +162,7 @@ public void onDisable() {
sendMessageToDiscord(null, null, 2);
}

log.info("[EasyDiscordBridge] Plugin v1.0.2.0 disabled");
log.info("[EasyDiscordBridge] Plugin v1.1.0.0 disabled");
}

/**
Expand Down
26 changes: 26 additions & 0 deletions src/commands/Cmd_DiscordLink.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package commands;

import com.falyrion.discordbridge.DiscordBridgeMain;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class Cmd_DiscordLink implements CommandExecutor {

@Override
public boolean onCommand(CommandSender commandSender, Command command, String commandLabel, String[] arguments) {

if (commandSender instanceof Player) {
Player player = (Player) commandSender;
TextComponent textComponentDiscordLink = new TextComponent(DiscordBridgeMain.getInstance().discordInfoMsg);
textComponentDiscordLink.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, DiscordBridgeMain.getInstance().discordLink));
commandSender.spigot().sendMessage(textComponentDiscordLink);
}

return true;

}
}
12 changes: 12 additions & 0 deletions src/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ textChannelRead: "0"
# The discord channel to send messages to (channel ID, not channel name)
textChannelWrite: "0"

# ######################################################################################################################
# Discord-Join-Link-Command

# Enable the /discord command functionality of this plugin
enableLinkCommand: false

# The message to display when using the command /discord
discordInfoMessage: "§6§l§nClick here to join our discord server!"

# The link to open when clicked on the discord message
discordLink: "none"

# ######################################################################################################################
# Discord messages

Expand Down
8 changes: 7 additions & 1 deletion src/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
name: DiscordBridge
author: Falyrion
description: DiscordBridge
version: 1.0.2.0
version: 1.1.0.0
api-version: 1.17

main: com.falyrion.discordbridge.DiscordBridgeMain

commands:
discord:
usage: /discord
description: Shows the player a clickable link to a discord server in the chat
permission: discordbridge.getlink

0 comments on commit 199fc35

Please sign in to comment.