-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit aae7305
Showing
12 changed files
with
627 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# User-specific stuff | ||
.idea/ | ||
|
||
*.iml | ||
*.ipr | ||
*.iws | ||
|
||
# IntelliJ | ||
out/ | ||
|
||
# Compiled class file | ||
*.class | ||
|
||
# Log file | ||
*.log | ||
|
||
# BlueJ files | ||
*.ctxt | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.nar | ||
*.ear | ||
*.zip | ||
*.tar.gz | ||
*.rar | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
|
||
*~ | ||
|
||
# temporary files which can be created if a process still has a handle open of a deleted file | ||
.fuse_hidden* | ||
|
||
# KDE directory preferences | ||
.directory | ||
|
||
# Linux trash folder which might appear on any partition or disk | ||
.Trash-* | ||
|
||
# .nfs files are created when an open file is removed but is still being accessed | ||
.nfs* | ||
|
||
# General | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
# Windows thumbnail cache files | ||
Thumbs.db | ||
Thumbs.db:encryptable | ||
ehthumbs.db | ||
ehthumbs_vista.db | ||
|
||
# Dump file | ||
*.stackdump | ||
|
||
# Folder config file | ||
[Dd]esktop.ini | ||
|
||
# Recycle Bin used on file shares | ||
$RECYCLE.BIN/ | ||
|
||
# Windows Installer files | ||
*.cab | ||
*.msi | ||
*.msix | ||
*.msm | ||
*.msp | ||
|
||
# Windows shortcuts | ||
*.lnk | ||
|
||
target/ | ||
|
||
pom.xml.tag | ||
pom.xml.releaseBackup | ||
pom.xml.versionsBackup | ||
pom.xml.next | ||
|
||
release.properties | ||
dependency-reduced-pom.xml | ||
buildNumber.properties | ||
.mvn/timing.properties | ||
.mvn/wrapper/maven-wrapper.jar | ||
.flattened-pom.xml | ||
|
||
# Common working directory | ||
run/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>de.dragonrexx</groupId> | ||
<artifactId>SimpleJavaBasicsPlugin</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>SimpleJavaBasicsPlugin</name> | ||
|
||
<properties> | ||
<java.version>1.8</java.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.1</version> | ||
<configuration> | ||
<source>${java.version}</source> | ||
<target>${java.version}</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.2.4</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<createDependencyReducedPom>false</createDependencyReducedPom> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
</build> | ||
|
||
<repositories> | ||
<repository> | ||
<id>papermc-repo</id> | ||
<url>https://papermc.io/repo/repository/maven-public/</url> | ||
</repository> | ||
<repository> | ||
<id>sonatype</id> | ||
<url>https://oss.sonatype.org/content/groups/public/</url> | ||
</repository> | ||
<repository> | ||
<id>dv8tion</id> | ||
<name>m2-dv8tion</name> | ||
<url>https/m2.dv8tion.net/releases</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.papermc.paper</groupId> | ||
<artifactId>paper-api</artifactId> | ||
<version>1.18.1-R0.1-SNAPSHOT</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>net.dv8tion</groupId> | ||
<artifactId>JDA</artifactId> | ||
<version>4.3.0_298</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
80 changes: 80 additions & 0 deletions
80
src/main/java/de/dragonrexx/simplejavabasicsplugin/SimpleJavaBasicsPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package de.dragonrexx.simplejavabasicsplugin; | ||
|
||
import de.dragonrexx.simplejavabasicsplugin.commands.HealCommand; | ||
import de.dragonrexx.simplejavabasicsplugin.commands.McToDcCommand; | ||
import de.dragonrexx.simplejavabasicsplugin.discordBot.DiscordMcBot; | ||
import de.dragonrexx.simplejavabasicsplugin.listener.JoinListener; | ||
import de.dragonrexx.simplejavabasicsplugin.utils.FileBuilder; | ||
import de.dragonrexx.simplejavabasicsplugin.utils.PluginSetup; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.plugin.PluginManager; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import javax.security.auth.login.LoginException; | ||
|
||
public final class SimpleJavaBasicsPlugin extends JavaPlugin implements PluginSetup { | ||
private static SimpleJavaBasicsPlugin instance; | ||
private final DiscordMcBot discordMcBot = new DiscordMcBot(); | ||
private static final FileBuilder fileBuilder = new FileBuilder("plugins//DiscordBot", "config.yml"); | ||
@Override | ||
public void onEnable() { | ||
initConfig(); | ||
commandRegistry(); | ||
eventRegistry(); | ||
instance = this; | ||
if(!fileBuilder.getBoolean("DISCORD_BOT_CAN_START")){ | ||
Bukkit.getConsoleSender().sendMessage("§3[Discord Bot] §4The Bot can Not Start"); | ||
Bukkit.getConsoleSender().sendMessage("§3[Discord Bot] §4Because the the Bool §3DISCORD_BOT_CAN_START §4is set of False"); | ||
Bukkit.getConsoleSender().sendMessage("§3[Discord Bot] §4Please set it of true"); | ||
} else { | ||
try { | ||
discordMcBot.McBot(); | ||
} catch (LoginException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void onDisable() { | ||
if(!fileBuilder.getBoolean("DISCORD_BOT_CAN_START")){ | ||
Bukkit.getConsoleSender().sendMessage("§3[Discord Bot] §4The Bot can Not shutdown"); | ||
Bukkit.getConsoleSender().sendMessage("§3[Discord Bot] §4Because the the Bool §3DISCORD_BOT_CAN_START §4is set of False"); | ||
Bukkit.getConsoleSender().sendMessage("§3[Discord Bot] §4Please set it of true"); | ||
} else { | ||
discordMcBot.shutdownBot(); | ||
} | ||
} | ||
|
||
@Override | ||
public void commandRegistry() { | ||
getCommand("heal").setExecutor(new HealCommand()); | ||
getCommand("mctodc").setExecutor(new McToDcCommand()); | ||
} | ||
|
||
@Override | ||
public void eventRegistry() { | ||
PluginManager pluginManager = Bukkit.getPluginManager(); | ||
pluginManager.registerEvents(new JoinListener(), this); | ||
} | ||
|
||
public void initConfig(){ | ||
if(!fileBuilder.exist()){ | ||
fileBuilder.setValue("DISCORD_TOKEN", "Your Token Here"); | ||
fileBuilder.setValue("DISCORD_GUILD_ID", "Your Guild id Here"); | ||
fileBuilder.setValue("DISCORDTOMC_CHANNEL_ID", "Test_Channel_Id"); | ||
fileBuilder.setValue("DISCORDTOMC_BROADCASTER_ID", "The Id of the Broadcaster role"); | ||
fileBuilder.setValue("DISCORD_BOT_CAN_START", false); | ||
fileBuilder.save(); | ||
} | ||
} | ||
|
||
public static SimpleJavaBasicsPlugin getInstance() { | ||
return instance; | ||
} | ||
|
||
public static FileBuilder getFileBuilder() { | ||
return fileBuilder; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/de/dragonrexx/simplejavabasicsplugin/commands/HealCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package de.dragonrexx.simplejavabasicsplugin.commands; | ||
|
||
import de.dragonrexx.simplejavabasicsplugin.SimpleJavaBasicsPlugin; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.potion.PotionEffect; | ||
import org.bukkit.potion.PotionEffectType; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class HealCommand implements CommandExecutor { | ||
@Override | ||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { | ||
if (!(sender instanceof Player))return false; | ||
Player player = (Player) sender; | ||
|
||
if(args.length == 1){ | ||
Player target = Bukkit.getPlayer(args[0]); | ||
if(target != null){ | ||
target.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 100, 5, true, false, false)); | ||
player.sendMessage("§3[SimpleJavaBasicsPlugin] §6Du hast dem Spieler: " + target.getName() + " Heilung gegeben!"); | ||
} else { | ||
player.sendMessage("§3[SimpleJavaBasicsPlugin] §6Der angegebene Spieler ist nicht online!"); | ||
} | ||
} else { | ||
player.sendMessage("§3[SimpleJavaBasicsPlugin] §6Bitte benutze /heal <playername>"); | ||
} | ||
// /heal <playername> | ||
|
||
return false; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/de/dragonrexx/simplejavabasicsplugin/commands/McToDcCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package de.dragonrexx.simplejavabasicsplugin.commands; | ||
|
||
import de.dragonrexx.simplejavabasicsplugin.SimpleJavaBasicsPlugin; | ||
import de.dragonrexx.simplejavabasicsplugin.discordBot.DiscordMcBot; | ||
import net.dv8tion.jda.api.entities.TextChannel; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class McToDcCommand implements CommandExecutor { | ||
|
||
private final String guildId = SimpleJavaBasicsPlugin.getFileBuilder().getString("DISCORD_GUILD_ID"); | ||
private final String channelId = SimpleJavaBasicsPlugin.getFileBuilder().getString("DISCORDTOMC_CHANNEL_ID"); | ||
|
||
@Override | ||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { | ||
if(!(sender instanceof Player))return false; | ||
Player player = (Player) sender; | ||
TextChannel textChannelById = DiscordMcBot.getDiscordBot().getGuildById(guildId).getTextChannelById(channelId); | ||
|
||
String message = player.getName() + " >> " + args[0]; | ||
textChannelById.sendMessage(message).queue(); | ||
player.sendMessage("§3[SimpleJavaBasicsPlugin] §6Your Message is sent to the Discord Server"); | ||
return false; | ||
} | ||
// /mctodc <channel> <message> | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/de/dragonrexx/simplejavabasicsplugin/discordBot/DiscordMcBot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package de.dragonrexx.simplejavabasicsplugin.discordBot; | ||
|
||
import de.dragonrexx.simplejavabasicsplugin.SimpleJavaBasicsPlugin; | ||
import de.dragonrexx.simplejavabasicsplugin.discordBot.commands.SlashcommandsListener; | ||
import de.dragonrexx.simplejavabasicsplugin.discordBot.listener.MessageListener; | ||
import de.dragonrexx.simplejavabasicsplugin.utils.FileBuilder; | ||
import net.dv8tion.jda.api.JDA; | ||
import net.dv8tion.jda.api.JDABuilder; | ||
import net.dv8tion.jda.api.OnlineStatus; | ||
import net.dv8tion.jda.api.entities.Activity; | ||
import net.dv8tion.jda.api.interactions.commands.OptionType; | ||
import net.dv8tion.jda.api.interactions.commands.build.CommandData; | ||
|
||
import javax.security.auth.login.LoginException; | ||
|
||
public class DiscordMcBot { | ||
|
||
private static JDA discordBot; | ||
private final FileBuilder fileBuilder = SimpleJavaBasicsPlugin.getFileBuilder(); | ||
|
||
public void McBot() throws LoginException { | ||
discordBot = JDABuilder.createDefault(fileBuilder.getString("DISCORD_TOKEN")).build(); | ||
discordBot.getPresence().setStatus(OnlineStatus.ONLINE); | ||
discordBot.getPresence().setActivity(Activity.listening("www.Cubyx.eu")); | ||
discordBot.addEventListener(new MessageListener()); | ||
discordBot.addEventListener(new SlashcommandsListener()); | ||
initSlashCommands(); | ||
} | ||
|
||
public void shutdownBot() { | ||
discordBot.getPresence().setStatus(OnlineStatus.OFFLINE); | ||
discordBot.getPresence().setActivity(Activity.listening("The Bot is not Online")); | ||
discordBot.shutdown(); | ||
} | ||
|
||
public void initSlashCommands(){ | ||
discordBot.updateCommands().addCommands(new CommandData("avatar", "With this Command you can get your Avatar Picture")).queue(); | ||
discordBot.updateCommands().addCommands(new CommandData("serverstatus", "This Command sent you a Embed from the Minecraft Server")).queue(); | ||
discordBot.updateCommands().addCommands(new CommandData("mctodc", "With this Command you can sent Messages to the Minecraft Server").addOption(OptionType.STRING, "msg", "Please put your Message here", true)).queue(); | ||
discordBot.updateCommands().addCommands(new CommandData("broadcastermsg", "With this Command you can sent Broadcaster Messages to the Minecraft Server").addOption(OptionType.STRING, "broadcastmsg", "Please put your Broadcast Message here", true)).queue(); | ||
discordBot.updateCommands().queue(); | ||
|
||
} | ||
|
||
public static JDA getDiscordBot() { | ||
return discordBot; | ||
} | ||
} |
Oops, something went wrong.