Skip to content

Commit

Permalink
Working on embeds for DiscordSRV
Browse files Browse the repository at this point in the history
Issue #37
  • Loading branch information
Dart2112 committed Feb 3, 2025
1 parent be00772 commit 1371647
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ repositories {
maven {
url = uri('https://repo.essentialsx.net/releases/')
}
//DiscordSRV Repo
maven {
url 'https://nexus.scarsz.me/content/groups/public/'
}
}

dependencies {
Expand All @@ -55,6 +59,7 @@ dependencies {
compileOnly 'net.essentialsx:EssentialsX:2.20.1'
compileOnly 'net.luckperms:api:5.4'
compileOnly 'org.spigotmc:spigot-api:1.21.1-R0.1-SNAPSHOT'
compileOnly 'com.discordsrv:discordsrv:1.29.0'
}

processResources {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/net/lapismc/afkplus/AFKPlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.lapismc.afkplus.api.AFKPlusAPI;
import net.lapismc.afkplus.api.AFKPlusPlayerAPI;
import net.lapismc.afkplus.commands.AFK;
import net.lapismc.afkplus.commands.AFKDiscordTest;
import net.lapismc.afkplus.commands.AFKPlusCmd;
import net.lapismc.afkplus.playerdata.AFKPlusPlayer;
import net.lapismc.afkplus.playerdata.AFKSession;
Expand Down Expand Up @@ -62,6 +63,8 @@ public void onEnable() {
prettyTime.removeUnit(Millisecond.class);
new AFK(this);
new AFKPlusCmd(this);
//TODO: Remove this before any releases
new AFKDiscordTest(this);
listeners = new AFKPlusListeners(this);
new AFKPlusAPI(this);
new AFKPlusPlayerAPI(this);
Expand Down
55 changes: 55 additions & 0 deletions src/main/java/net/lapismc/afkplus/commands/AFKDiscordTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2025 Benjamin Martin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.lapismc.afkplus.commands;

import github.scarsz.discordsrv.DiscordSRV;
import github.scarsz.discordsrv.dependencies.jda.api.EmbedBuilder;
import github.scarsz.discordsrv.dependencies.jda.api.entities.MessageEmbed;
import github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel;
import net.lapismc.afkplus.AFKPlus;
import net.lapismc.afkplus.util.AFKPlusCommand;
import org.bukkit.command.CommandSender;

import java.awt.*;
import java.util.ArrayList;
import java.util.Collections;

//TODO: Delete this when testing is complete
public class AFKDiscordTest extends AFKPlusCommand {

public AFKDiscordTest(AFKPlus plugin) {
super(plugin, "AFKDiscordTest", "A command to send test messages via DiscordSRV", new ArrayList<>(Collections.singleton("AFKD")));
}

@Override
protected void onCommand(CommandSender sender, String[] args) {
TextChannel globalChannel = DiscordSRV.getPlugin().getDestinationTextChannelForGameChannelName("global");

MessageEmbed embedStart = new EmbedBuilder()
.setAuthor("Player name is AFK", null, "https://api.mineatar.io/face/cc22782090604ebda00d511e4815f125?scale=16")
.setColor(Color.GREEN)
.build();

MessageEmbed embedEnd = new EmbedBuilder()
.setAuthor("Player name is no longer AFK", null, "https://api.mineatar.io/face/cc22782090604ebda00d511e4815f125?scale=16")
.addField("They were AFK for:", "1 minute and 30 seconds", true)
.setColor(Color.RED).build();

globalChannel.sendMessageEmbeds(embedStart).queue();
globalChannel.sendMessageEmbeds(embedEnd).queue();
}
}

0 comments on commit 1371647

Please sign in to comment.