├── .idea
├── .name
├── modules
│ ├── .rebel-remote.xml.bak
│ ├── .rebel.xml.bak
│ ├── Minecordbot.iml
│ └── Minecordbot_test.iml
├── vcs.xml
├── kotlinc.xml
├── artifacts
│ └── Minecordbot_jar.xml
├── misc.xml
├── compiler.xml
├── libraries
│ ├── Gradle__com_squareup_okio_okio_1_13_0.xml
│ ├── Gradle__com_squareup_okhttp3_okhttp_3_8_1.xml
│ ├── Gradle__com_google_code_findbugs_jsr305_3_0_2.xml
│ ├── Gradle__com_neovisionaries_nv_websocket_client_2_2.xml
│ └── Gradle__net_sf_trove4j_trove4j_3_0_3.xml
├── modules.xml
└── gradle.xml
├── settings.gradle
├── libs
├── mv.jar
├── Towny.jar
├── mcMMO.jar
├── TownyChat.jar
├── EssentialsX.jar
├── SuperVanish.jar
├── VentureChat.jar
├── PermissionsEx-1.23.4.jar
└── licenses
│ ├── VentureChat (GPLv3).license
│ └── Multiverse (BSD).license
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── src
└── main
│ ├── java
│ └── us
│ │ └── cyrien
│ │ ├── minecordbot
│ │ ├── commands
│ │ │ ├── Updatable.java
│ │ │ ├── discordCommand
│ │ │ │ ├── StartCmd.java
│ │ │ │ ├── ShutdownCmd.java
│ │ │ │ ├── ReloadCmd.java
│ │ │ │ ├── PingCmd.java
│ │ │ │ ├── DiagnosticsCmd.java
│ │ │ │ ├── PurgeCmd.java
│ │ │ │ ├── McUUIDCmd.java
│ │ │ │ ├── TpsCmd.java
│ │ │ │ ├── McApiStatusCmd.java
│ │ │ │ ├── McSkinCmd.java
│ │ │ │ ├── McServerCmd.java
│ │ │ │ ├── McUsernameCmd.java
│ │ │ │ ├── HelpCmd.java
│ │ │ │ ├── ListCmd.java
│ │ │ │ └── InfoCmd.java
│ │ │ └── minecraftCommand
│ │ │ │ ├── Dcmd.java
│ │ │ │ ├── Dme.java
│ │ │ │ ├── DConfirm.java
│ │ │ │ └── McbCommands.java
│ │ ├── utils
│ │ │ ├── StringImplicit.java
│ │ │ ├── exception
│ │ │ │ └── TooManyRequestsException.java
│ │ │ ├── ArrayUtils.java
│ │ │ ├── mcpinger
│ │ │ │ └── pcping
│ │ │ │ │ ├── MinecraftPingOptions.java
│ │ │ │ │ └── MinecraftPingUtil.java
│ │ │ └── SearchUtil.java
│ │ ├── configuration
│ │ │ ├── Node.java
│ │ │ ├── PermissionConfig.java
│ │ │ ├── BaseConfig.java
│ │ │ ├── ChatConfig.java
│ │ │ ├── BotConfig.java
│ │ │ ├── BroadcastConfig.java
│ │ │ └── MCBConfigsManager.java
│ │ ├── hooks
│ │ │ ├── mcMMOHook.java
│ │ │ ├── MCBHook.java
│ │ │ ├── MVHook.java
│ │ │ ├── EssentialsHook.java
│ │ │ ├── SuperVanishHook.java
│ │ │ ├── VentureChatHook.java
│ │ │ ├── PermissionsExHook.java
│ │ │ ├── GriefPreventionHook.java
│ │ │ └── VaultHook.java
│ │ ├── chat
│ │ │ ├── exception
│ │ │ │ └── IllegalTextChannelException.java
│ │ │ ├── listeners
│ │ │ │ ├── discordListeners
│ │ │ │ │ ├── DiscordRelayListener.java
│ │ │ │ │ └── ModChannelListener.java
│ │ │ │ └── mcListeners
│ │ │ │ │ ├── McMMOListener.java
│ │ │ │ │ ├── MCBListener.java
│ │ │ │ │ ├── BroadcastCommandListener.java
│ │ │ │ │ ├── CommandListener.java
│ │ │ │ │ ├── SuperVanishListener.java
│ │ │ │ │ ├── MentionListener.java
│ │ │ │ │ ├── DeathListener.java
│ │ │ │ │ └── HelpOpListener.java
│ │ │ ├── ChatStatus.java
│ │ │ ├── ChatManager.java
│ │ │ └── entity
│ │ │ │ ├── ConvoTracker.java
│ │ │ │ └── DiscordCommandSender.java
│ │ ├── accountSync
│ │ │ ├── DataKey.java
│ │ │ ├── exceptions
│ │ │ │ ├── IllegalConfirmKeyException.java
│ │ │ │ ├── IllegalConfirmRequesterException.java
│ │ │ │ └── IllegalConfirmSessionIDException.java
│ │ │ ├── Authentication
│ │ │ │ ├── AuthManager.java
│ │ │ │ └── AuthToken.java
│ │ │ ├── AccountDataFormat.java
│ │ │ ├── listener
│ │ │ │ └── UserConnectionListener.java
│ │ │ └── Database.java
│ │ ├── reporters
│ │ │ ├── OSReporter.java
│ │ │ ├── JReporter.java
│ │ │ ├── MemReporter.java
│ │ │ ├── CfgReporter.java
│ │ │ ├── InfoHeader.java
│ │ │ └── PlReporter.java
│ │ ├── events
│ │ │ ├── listener
│ │ │ │ ├── OnShut.java
│ │ │ │ └── OnStart.java
│ │ │ ├── StartEvent.java
│ │ │ └── ShutdownEvent.java
│ │ ├── entity
│ │ │ ├── Lag.java
│ │ │ ├── UpTimer.java
│ │ │ ├── UnifiedUser.java
│ │ │ └── MCBUser.java
│ │ ├── handle
│ │ │ ├── MinecraftMentionHandler.java
│ │ │ └── RoleNameChangeHandler.java
│ │ ├── HookContainer.java
│ │ ├── prefix
│ │ │ ├── PrefixParser.java
│ │ │ └── DiscordPlaceHolders.java
│ │ ├── api
│ │ │ └── IMessenger.java
│ │ └── localization
│ │ │ └── Locale.java
│ │ └── mcutils
│ │ ├── inject
│ │ ├── Injector.java
│ │ └── FrameInjector.java
│ │ ├── diagnosis
│ │ ├── TypeDiagnosis.java
│ │ ├── Diagnostics.java
│ │ ├── IReporter.java
│ │ ├── ReportLoader.java
│ │ ├── impl
│ │ │ └── DiagnosticsImpl.java
│ │ └── DiagnosticsBuilder.java
│ │ ├── dispatcher
│ │ ├── exception
│ │ │ ├── NoPermissionException.java
│ │ │ ├── UnsupportedTypeException.java
│ │ │ ├── CommandNotFoundException.java
│ │ │ ├── NotEnoughArgumentsException.java
│ │ │ ├── CommandExistsException.java
│ │ │ └── IncorrectArgumentsException.java
│ │ └── help
│ │ │ ├── IndexTopic.java
│ │ │ ├── ManagedHelpTopic.java
│ │ │ └── HelpTopicUtil.java
│ │ ├── annotations
│ │ ├── Text.java
│ │ ├── HelpTopic.java
│ │ ├── Hook.java
│ │ ├── Setting.java
│ │ ├── Optional.java
│ │ ├── InjectConfig.java
│ │ ├── SubCommand.java
│ │ ├── InjectModule.java
│ │ ├── Configuration.java
│ │ ├── Permission.java
│ │ ├── Sender.java
│ │ └── Command.java
│ │ ├── loader
│ │ ├── exception
│ │ │ ├── InaccessibleClassException.java
│ │ │ ├── InaccessibleMethodException.java
│ │ │ └── InaccessibleFieldException.java
│ │ ├── CommandInjector.java
│ │ └── CommandMapping.java
│ │ ├── events
│ │ └── BukkitEventsInjector.java
│ │ ├── hook
│ │ ├── HookLoader.java
│ │ ├── IPluginHook.java
│ │ ├── HookInjector.java
│ │ └── PluginHook.java
│ │ ├── config
│ │ └── ConfigurationInjector.java
│ │ ├── module
│ │ ├── ModuleLoader.java
│ │ └── ModuleInjector.java
│ │ ├── logger
│ │ ├── Logger.java
│ │ └── Debugger.java
│ │ └── Frame.java
│ └── resources
│ └── plugin.yml
├── .travis.yml
├── .github
├── PULL_REQUEST_TEMPLATE.md
├── ISSUE_TEMPLATE.md
└── CODE_OF_CONDUCT.md
├── .gitignore
├── gradlew.bat
└── README.md
/.idea/.name:
--------------------------------------------------------------------------------
1 | Minecordbot
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'Minecordbot'
2 |
3 |
--------------------------------------------------------------------------------
/libs/mv.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyR1en/Minecordbot/HEAD/libs/mv.jar
--------------------------------------------------------------------------------
/libs/Towny.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyR1en/Minecordbot/HEAD/libs/Towny.jar
--------------------------------------------------------------------------------
/libs/mcMMO.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyR1en/Minecordbot/HEAD/libs/mcMMO.jar
--------------------------------------------------------------------------------
/libs/TownyChat.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyR1en/Minecordbot/HEAD/libs/TownyChat.jar
--------------------------------------------------------------------------------
/libs/EssentialsX.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyR1en/Minecordbot/HEAD/libs/EssentialsX.jar
--------------------------------------------------------------------------------
/libs/SuperVanish.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyR1en/Minecordbot/HEAD/libs/SuperVanish.jar
--------------------------------------------------------------------------------
/libs/VentureChat.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyR1en/Minecordbot/HEAD/libs/VentureChat.jar
--------------------------------------------------------------------------------
/libs/PermissionsEx-1.23.4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyR1en/Minecordbot/HEAD/libs/PermissionsEx-1.23.4.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CyR1en/Minecordbot/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/commands/Updatable.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.commands;
2 |
3 | public interface Updatable {
4 |
5 | void update();
6 | }
7 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/inject/Injector.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.inject;
2 |
3 | public interface Injector {
4 | void inject(Class> c, Object instance);
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/utils/StringImplicit.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.utils;
2 |
3 | public interface StringImplicit {
4 | public void run(String s);
5 | }
--------------------------------------------------------------------------------
/.idea/modules/.rebel-remote.xml.bak:
--------------------------------------------------------------------------------
1 |
2 |
3 | Minecordbot
4 |
5 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/diagnosis/TypeDiagnosis.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.diagnosis;
2 |
3 |
4 | public enum TypeDiagnosis {
5 | ALL,
6 | PARTIAL,
7 | MANUAL
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/dispatcher/exception/NoPermissionException.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.dispatcher.exception;
2 |
3 | public class NoPermissionException extends Exception {
4 | }
5 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/dispatcher/exception/UnsupportedTypeException.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.dispatcher.exception;
2 |
3 | public class UnsupportedTypeException extends Exception {
4 | }
5 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/dispatcher/exception/CommandNotFoundException.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.dispatcher.exception;
2 |
3 | public class CommandNotFoundException extends Exception {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/dispatcher/exception/NotEnoughArgumentsException.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.dispatcher.exception;
2 |
3 | public class NotEnoughArgumentsException extends Exception {
4 | }
5 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/configuration/Node.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.configuration;
2 |
3 | public interface Node {
4 |
5 | Object getDefaultValue();
6 |
7 | String[] getComment();
8 |
9 | String key();
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/annotations/Text.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.annotations;
2 |
3 | import java.lang.annotation.Retention;
4 | import java.lang.annotation.RetentionPolicy;
5 |
6 | @Retention(RetentionPolicy.RUNTIME)
7 | public @interface Text {
8 | }
9 |
--------------------------------------------------------------------------------
/.idea/artifacts/Minecordbot_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | $PROJECT_DIR$/out/artifacts/Minecordbot_jar
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | jdk:
3 | - openjdk8
4 | ##before_install:
5 | ## - wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar -O BuildTools.jar && java -jar BuildTools.jar --rev 1.12.2
6 | notifications:
7 | email: false
8 |
9 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Mar 25 14:33:53 PDT 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/annotations/HelpTopic.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.annotations;
2 |
3 | import java.lang.annotation.Retention;
4 | import java.lang.annotation.RetentionPolicy;
5 |
6 | @Retention(RetentionPolicy.RUNTIME)
7 | public @interface HelpTopic {
8 | String value();
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/hooks/mcMMOHook.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.hooks;
2 |
3 | import com.gmail.nossr50.mcMMO;
4 | import us.cyrien.mcutils.hook.PluginHook;
5 |
6 | public class mcMMOHook extends PluginHook {
7 |
8 | public mcMMOHook() {
9 | this.name = "mcMMO";
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/dispatcher/exception/CommandExistsException.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.dispatcher.exception;
2 |
3 | public class CommandExistsException extends Exception {
4 | String command;
5 |
6 | public CommandExistsException(String command) {
7 | this.command = command;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/chat/exception/IllegalTextChannelException.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.chat.exception;
2 |
3 | public class IllegalTextChannelException extends Exception {
4 |
5 | String msg;
6 |
7 | public IllegalTextChannelException(String msg) {
8 | this.msg = msg;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/hooks/MCBHook.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.hooks;
2 |
3 | import us.cyrien.mcutils.hook.PluginHook;
4 | import us.cyrien.minecordbot.Minecordbot;
5 |
6 | public class MCBHook extends PluginHook {
7 |
8 | public MCBHook() {
9 | this.name = "MineCordBot";
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/hooks/MVHook.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.hooks;
2 |
3 | import com.onarandombox.MultiverseCore.MultiverseCore;
4 | import us.cyrien.mcutils.hook.PluginHook;
5 |
6 | public class MVHook extends PluginHook {
7 |
8 | public MVHook() {
9 | this.name = "Multiverse-Core";
10 | }
11 | }
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/hooks/EssentialsHook.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.hooks;
2 |
3 | import com.earth2me.essentials.Essentials;
4 | import us.cyrien.mcutils.hook.PluginHook;
5 |
6 | public class EssentialsHook extends PluginHook {
7 |
8 | public EssentialsHook() {
9 | this.name = "Essentials";
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/hooks/SuperVanishHook.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.hooks;
2 |
3 | import de.myzelyam.supervanish.SuperVanish;
4 | import us.cyrien.mcutils.hook.PluginHook;
5 |
6 | public class SuperVanishHook extends PluginHook{
7 |
8 | public SuperVanishHook() {
9 | this.name = "SuperVanish";
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/hooks/VentureChatHook.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.hooks;
2 |
3 | import mineverse.Aust1n46.chat.MineverseChat;
4 | import us.cyrien.mcutils.hook.PluginHook;
5 |
6 | public class VentureChatHook extends PluginHook {
7 |
8 | public VentureChatHook() {
9 | this.name = "VentureChat";
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/annotations/Hook.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.annotations;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target(ElementType.FIELD)
10 | public @interface Hook {
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/annotations/Setting.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.annotations;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target(ElementType.FIELD)
10 | public @interface Setting {
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/hooks/PermissionsExHook.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.hooks;
2 |
3 | import ru.tehkode.permissions.bukkit.PermissionsEx;
4 | import us.cyrien.mcutils.hook.PluginHook;
5 |
6 | public class PermissionsExHook extends PluginHook {
7 |
8 | public PermissionsExHook() {
9 | this.name = "PermissionsEx";
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/annotations/Optional.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.annotations;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target(ElementType.PARAMETER)
10 | public @interface Optional {
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/annotations/InjectConfig.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.annotations;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target(ElementType.FIELD)
10 | public @interface InjectConfig {
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/annotations/SubCommand.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.annotations;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target(ElementType.PARAMETER)
10 | public @interface SubCommand {
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/annotations/InjectModule.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.annotations;
2 |
3 |
4 | import java.lang.annotation.ElementType;
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 | import java.lang.annotation.Target;
8 |
9 | @Retention(RetentionPolicy.RUNTIME)
10 | @Target(ElementType.FIELD)
11 | public @interface InjectModule {
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/hooks/GriefPreventionHook.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.hooks;
2 |
3 | import me.ryanhamshire.GriefPrevention.GriefPrevention;
4 | import us.cyrien.mcutils.hook.PluginHook;
5 |
6 | public class GriefPreventionHook extends PluginHook {
7 |
8 | public GriefPreventionHook() {
9 | this.name = "GriefPrevention";
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/dispatcher/help/IndexTopic.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.dispatcher.help;
2 |
3 | import org.bukkit.help.HelpTopic;
4 | import org.bukkit.help.IndexHelpTopic;
5 |
6 | import java.util.List;
7 |
8 | public class IndexTopic extends IndexHelpTopic {
9 | public IndexTopic(String name, List topics) {
10 | super(name, "HelpCmd for " + name, "", topics);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/annotations/Configuration.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.annotations;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target(ElementType.TYPE)
10 | public @interface Configuration {
11 | String value();
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/loader/exception/InaccessibleClassException.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.loader.exception;
2 |
3 | public class InaccessibleClassException extends Exception {
4 |
5 | private Class offender;
6 |
7 | public InaccessibleClassException(Class clazz) {
8 | this.offender = clazz;
9 | }
10 |
11 | public Class getOffender() {
12 | return this.offender;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/utils/exception/TooManyRequestsException.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.utils.exception;
2 |
3 | public class TooManyRequestsException extends Exception {
4 |
5 | private String msg;
6 |
7 | public TooManyRequestsException(String msg) {
8 | this.msg = msg;
9 | }
10 |
11 | @Override
12 | public String getMessage() {
13 | return msg;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/annotations/Permission.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.annotations;
2 |
3 | import java.lang.annotation.Retention;
4 | import java.lang.annotation.RetentionPolicy;
5 |
6 | /**
7 | * Optional annotation.
8 | *
9 | * It let you specify a required permission node for this command.
10 | */
11 | @Retention(RetentionPolicy.RUNTIME)
12 | public @interface Permission {
13 | String value();
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/dispatcher/exception/IncorrectArgumentsException.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.dispatcher.exception;
2 |
3 | public class IncorrectArgumentsException extends Exception {
4 |
5 | private String message;
6 |
7 | public IncorrectArgumentsException(String msg) {
8 | this.message = msg;
9 | }
10 |
11 | public String getReason() {
12 | return this.message;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/accountSync/DataKey.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.accountSync;
2 |
3 | public enum DataKey {
4 | MC_USERNAME("Minecraft-Username"),
5 | DISCORD_ID("Discord-ID"),
6 | DISCORD_USERNAME("Discord-Username");
7 |
8 | private String s;
9 |
10 | DataKey(String s) {
11 | this.s = s;
12 | }
13 |
14 | @Override
15 | public String toString() {
16 | return s;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/annotations/Sender.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.annotations;
2 |
3 | import java.lang.annotation.Retention;
4 | import java.lang.annotation.RetentionPolicy;
5 |
6 | /**
7 | * This annotation tells the dispatcher that this parameter should be the sender object (the person who sent the command).
8 | *
9 | * Can be any subclass of CommandSender.
10 | */
11 | @Retention(RetentionPolicy.RUNTIME)
12 | public @interface Sender {
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/loader/exception/InaccessibleMethodException.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.loader.exception;
2 |
3 | import java.lang.reflect.Method;
4 |
5 | public class InaccessibleMethodException extends Exception {
6 |
7 | private Method offender;
8 |
9 | public InaccessibleMethodException(Method m) {
10 | this.offender = m;
11 | }
12 |
13 | public Method getOffender() {
14 | return this.offender;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/loader/exception/InaccessibleFieldException.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.loader.exception;
2 |
3 | import java.lang.reflect.Field;
4 |
5 | public class InaccessibleFieldException extends Exception {
6 |
7 | private Field offender;
8 |
9 | public InaccessibleFieldException(Field f) {
10 | this.offender = f;
11 | }
12 |
13 | public InaccessibleFieldException(){}
14 |
15 | public Field getOffender() {
16 | return offender;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/diagnosis/Diagnostics.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.diagnosis;
2 |
3 | import java.io.File;
4 | import java.util.LinkedList;
5 |
6 | /**
7 | *
Gathers reporters and have a full read back through a file or Output
8 | */
9 | public interface Diagnostics {
10 |
11 | String LINE_SEPARATOR = "\r\n";
12 | String DOUBLE_LINE_SEPARATOR = "\r\n\r\n";
13 |
14 | LinkedList getReporters();
15 |
16 | File fullReport();
17 |
18 | TypeDiagnosis getTypeDiagnosis();
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/accountSync/exceptions/IllegalConfirmKeyException.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.accountSync.exceptions;
2 |
3 | public class IllegalConfirmKeyException extends Exception {
4 | String msg;
5 |
6 | public IllegalConfirmKeyException() {
7 | msg = "Confirm key did not match MCBSync's verification code key";
8 | }
9 |
10 | public IllegalConfirmKeyException(String msg) {
11 | this.msg = msg;
12 | }
13 |
14 | public String getMsg() {
15 | return msg;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/events/BukkitEventsInjector.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.events;
2 |
3 | import us.cyrien.mcutils.inject.Injector;
4 | import org.bukkit.Bukkit;
5 | import org.bukkit.event.Listener;
6 | import org.bukkit.plugin.java.JavaPlugin;
7 |
8 | public class BukkitEventsInjector implements Injector {
9 | @Override
10 | public void inject(Class> c, Object instance) {
11 | if (instance instanceof Listener)
12 | Bukkit.getPluginManager().registerEvents((Listener) instance, JavaPlugin.getProvidingPlugin(c));
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/accountSync/exceptions/IllegalConfirmRequesterException.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.accountSync.exceptions;
2 |
3 | public class IllegalConfirmRequesterException extends Exception{
4 | String msg;
5 |
6 | public IllegalConfirmRequesterException() {
7 | msg = "Confirm requester did not match MCBSync's verification code requester";
8 | }
9 |
10 |
11 | public IllegalConfirmRequesterException(String msg) {
12 | this.msg = msg;
13 | }
14 |
15 | public String getMsg() {
16 | return msg;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/accountSync/exceptions/IllegalConfirmSessionIDException.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.accountSync.exceptions;
2 |
3 | public class IllegalConfirmSessionIDException extends Exception {
4 |
5 | String msg;
6 |
7 | public IllegalConfirmSessionIDException() {
8 | msg = "Confirm session id did not match MCBSync's verification code session id";
9 | }
10 |
11 |
12 | public IllegalConfirmSessionIDException(String msg) {
13 | this.msg = msg;
14 | }
15 |
16 | public String getMsg() {
17 | return msg;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_squareup_okio_okio_1_13_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_squareup_okhttp3_okhttp_3_8_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/chat/listeners/discordListeners/DiscordRelayListener.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.chat.listeners.discordListeners;
2 |
3 | import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
4 | import us.cyrien.minecordbot.Minecordbot;
5 |
6 | public class DiscordRelayListener extends TextChannelListener {
7 |
8 | public DiscordRelayListener(Minecordbot mcb) {
9 | super(mcb);
10 | this.channelType = MCBChannelType.BOUND_CHANNEL;
11 | }
12 |
13 | @Override
14 | public void execute(MessageReceivedEvent event) {
15 | relayMessage(event);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_google_code_findbugs_jsr305_3_0_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_neovisionaries_nv_websocket_client_2_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/annotations/Command.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.annotations;
2 |
3 | import java.lang.annotation.Retention;
4 | import java.lang.annotation.RetentionPolicy;
5 |
6 | /**
7 | * Tells Frame to register the method as a command.
8 | */
9 | @Retention(RetentionPolicy.RUNTIME)
10 | public @interface Command {
11 | /**
12 | * Names for the command (e.g. an alias of hello results in the command "/hello" in Minecraft).
13 | */
14 | String[] aliases();
15 |
16 | /**
17 | * Used for the /help usage.
18 | */
19 | String usage() default "";
20 |
21 | /**
22 | * Used for the /help description.
23 | */
24 | String desc();
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/hook/HookLoader.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.hook;
2 |
3 | import us.cyrien.mcutils.logger.Logger;
4 |
5 | import java.util.HashMap;
6 |
7 | public class HookLoader {
8 |
9 | private static HashMap, IPluginHook> hooks = new HashMap<>();
10 |
11 | public static void addHook(Class extends IPluginHook> clazz) {
12 | try {
13 | hooks.put(clazz, clazz.newInstance());
14 | } catch (InstantiationException | IllegalAccessException e) {
15 | Logger.err("Error instantiating hook class; is it private? Offender: " + clazz.getName());
16 | }
17 | }
18 |
19 | public static IPluginHook get(Class clazz) {
20 | return hooks.get(clazz);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/libs/licenses/VentureChat (GPLv3).license:
--------------------------------------------------------------------------------
1 | Copyright (C) {2014} {Austin Brolly}
2 | This program is free software: you can redistribute it and/or modify
3 | it under the terms of the GNU General Public License as published by
4 | the Free Software Foundation, either version 3 of the License, or
5 | (at your option) any later version.
6 |
7 | This program is distributed in the hope that it will be useful,
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | GNU General Public License for more details.
11 |
12 | You should have received a copy of the GNU General Public License
13 | along with this program. If not, see .
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
2 | ## Purpose
3 | _Describe the problem or feature in addition to a link to the issues._
4 |
5 | ## Approach
6 | _How does this change address the problem?_
7 |
8 | #### Open Questions and Pre-Merge TODOs
9 | - [ ] Use github checklists. When solved, check the box and explain the answer.
10 | - [X] [Closed example]
11 |
12 | ## Learning
13 | _Describe the research stage_
14 |
15 | _Links to blog posts, patterns, libraries or addons used to solve this problem_
16 |
17 | #### Blog Posts
18 | - [How to Pull Request](https://github.com/flexyford/pull-request) Github Repo with Learning focused Pull Request Template.
19 |
--------------------------------------------------------------------------------
/.idea/modules/.rebel.xml.bak:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/diagnosis/IReporter.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.diagnosis;
2 |
3 | public interface IReporter extends Comparable {
4 |
5 | String getName();
6 |
7 | String report();
8 |
9 | int getPriority();
10 |
11 | @Override
12 | default int compareTo(IReporter o) {
13 | return this.getPriority() - o.getPriority();
14 | }
15 |
16 | default String reportHeader() {
17 | if(getName() == null)
18 | return null;
19 | return "------------------------------------------------------" + Diagnostics.LINE_SEPARATOR +
20 | getName() + Diagnostics.LINE_SEPARATOR +
21 | "------------------------------------------------------";
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/inject/FrameInjector.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.inject;
2 |
3 | import us.cyrien.mcutils.logger.Logger;
4 | import us.cyrien.mcutils.module.ModuleLoader;
5 |
6 | import java.util.ArrayList;
7 |
8 | public class FrameInjector {
9 | private ArrayList injectors = new ArrayList<>();
10 |
11 | public FrameInjector injector(Injector injector) {
12 | injectors.add(injector);
13 | return this;
14 | }
15 |
16 | public void injectAll() {
17 | for (Class> clazz : ModuleLoader.getModuleClasses()) {
18 | Object instance = ModuleLoader.getInstance(clazz);
19 |
20 | injectors.forEach(i -> i.inject(clazz, instance));
21 | }
22 | Logger.info("- Module classes injected.");
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__net_sf_trove4j_trove4j_3_0_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/loader/CommandInjector.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.loader;
2 |
3 | import us.cyrien.mcutils.annotations.Command;
4 | import us.cyrien.mcutils.dispatcher.CommandDispatcher;
5 | import us.cyrien.mcutils.inject.Injector;
6 |
7 | import java.lang.reflect.Method;
8 |
9 | public class CommandInjector implements Injector {
10 | @Override
11 | public void inject(Class> c, Object instance) {
12 | final Method[] methods = c.getDeclaredMethods();
13 |
14 | for (Method method : methods) {
15 | if (method.isAnnotationPresent(Command.class)) {
16 | Command details = method.getAnnotation(Command.class);
17 |
18 | CommandDispatcher.getDispatcher().registerCommand(details, method, instance);
19 | }
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/.idea/modules/Minecordbot.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/hook/IPluginHook.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.hook;
2 |
3 | /**
4 | * Hooks are specialised objects designed to be used to hook into other plugins.
5 | * To create a hook, you'll want a class that implements {@link IPluginHook}, like so:
6 | *
7 | * public class MyHook implements IPluginHook {
8 | * public boolean available() {
9 | * return false;
10 | * }
11 | * }
12 | *
13 | *
14 | * You'll want to register your hook with Frame in your onEnable() like so:
15 | *
16 | * Frame.addHook(MyHook.class);
17 | *
18 | */
19 | public interface IPluginHook {
20 |
21 | /**
22 | * @return whether the hook is available or not; if false, the hook will never be injected, and null will be passed instead.
23 | */
24 | boolean available();
25 |
26 | String getPluginName();
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/chat/listeners/discordListeners/ModChannelListener.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.chat.listeners.discordListeners;
2 |
3 | import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
4 | import us.cyrien.minecordbot.Minecordbot;
5 | import us.cyrien.minecordbot.configuration.ModChannelConfig;
6 |
7 | public class ModChannelListener extends TextChannelListener {
8 |
9 | private boolean isOneWay;
10 |
11 | public ModChannelListener(Minecordbot mcb) {
12 | super(mcb);
13 | this.channelType = MCBChannelType.MOD_CHANNEL;
14 | isOneWay = configsManager.getModChannelConfig().getBoolean(ModChannelConfig.Nodes.ONE_WAY);
15 | }
16 |
17 | @Override
18 | public void execute(MessageReceivedEvent event) {
19 | if(!isOneWay)
20 | relayMessage(event);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/config/ConfigurationInjector.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.config;
2 |
3 | import us.cyrien.mcutils.annotations.InjectConfig;
4 | import us.cyrien.mcutils.inject.Injector;
5 | import us.cyrien.mcutils.logger.Logger;
6 |
7 | import java.lang.reflect.Field;
8 |
9 | public class ConfigurationInjector implements Injector {
10 | @Override
11 | public void inject(Class> c, Object instance) {
12 | for (Field f : c.getDeclaredFields()) {
13 | if (f.isAnnotationPresent(InjectConfig.class)) {
14 | Object config = ConfigurationBuilder.get(f.getType());
15 |
16 | if (config != null) {
17 | try {
18 | f.setAccessible(true);
19 | f.set(instance, config);
20 | } catch (IllegalAccessException e) {
21 | Logger.err("Failed to inject a configuration into field " + f.getName() + " in " + c.getName());
22 | }
23 | }
24 | }
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/dispatcher/help/ManagedHelpTopic.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.dispatcher.help;
2 |
3 | import us.cyrien.mcutils.annotations.Command;
4 | import org.bukkit.ChatColor;
5 | import org.bukkit.command.CommandSender;
6 | import org.bukkit.help.HelpTopic;
7 |
8 | public class ManagedHelpTopic extends HelpTopic {
9 |
10 | public ManagedHelpTopic(String name, Command command, String permission) {
11 | this.name = "/" + name;
12 | this.shortText = command.desc();
13 | this.fullText = ChatColor.GOLD + "Description: " + ChatColor.RESET + command.desc() +
14 | ChatColor.GOLD + "\nUsage: " + ChatColor.RESET + command.usage();
15 | this.amendedPermission = permission;
16 | }
17 |
18 | @Override
19 | public boolean canSee(CommandSender commandSender) {
20 | return commandSender.hasPermission(this.amendedPermission);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/diagnosis/ReportLoader.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.diagnosis;
2 |
3 | import us.cyrien.mcutils.logger.Logger;
4 |
5 | import java.util.HashMap;
6 |
7 | public class ReportLoader {
8 |
9 | private static HashMap, IReporter> reporters = new HashMap<>();
10 |
11 | public static void addReporter(Class extends IReporter> clazz) {
12 | try {
13 | reporters.put(clazz, clazz.newInstance());
14 | } catch (InstantiationException | IllegalAccessException e) {
15 | Logger.err("Error instantiating reporter class; is it private? Offender: " + clazz.getName());
16 | }
17 | }
18 |
19 | public static HashMap, IReporter> getReporters() {
20 | return reporters;
21 | }
22 |
23 | public static IReporter get(Class clazz) {
24 | return reporters.get(clazz);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/resources/plugin.yml:
--------------------------------------------------------------------------------
1 | name: MineCordBot
2 | version: 2.2.5
3 | author: CyRien
4 | softdepend: [GriefPrevention, Multiverse-Core, Vault, Essentials, mcMMO, PermissionsEx, SuperVanish]
5 | description: A powerful way to bridge Minecraft and Discord
6 |
7 | main: us.cyrien.minecordbot.Minecordbot
8 |
9 | permissions:
10 | minecordbot.start:
11 | description: Allow to start the bot.
12 | default: op
13 | minecordbot.reload:
14 | description: Allow to reload MineCordBot config.
15 | default: op
16 | minecordbot.incognito:
17 | description: Hide player from all broadcast to discord.
18 | default: false
19 | minecordbot.dme:
20 | description: Allow user to express themselves to discord and minecraft.
21 | default: op
22 | minecordbot.discordsync:
23 | description: Allow user to sync their Discord account to their Minecraft account.
24 | default: op
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/module/ModuleLoader.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.module;
2 |
3 | import us.cyrien.mcutils.logger.Logger;
4 |
5 | import java.util.HashMap;
6 | import java.util.HashSet;
7 | import java.util.Set;
8 |
9 | public class ModuleLoader {
10 | private static HashSet annotated = new HashSet<>();
11 | private static HashMap instances = new HashMap<>();
12 |
13 | public static void add(Class clazz) {
14 | annotated.add(clazz);
15 | }
16 |
17 | public static Set getModuleClasses() {
18 | return annotated;
19 | }
20 |
21 | public static Object getInstance(Class clazz) {
22 | if (!instances.containsKey(clazz)) {
23 | try {
24 | instances.put(clazz, clazz.newInstance());
25 | } catch (InstantiationException | IllegalAccessException e) {
26 | Logger.err("Failed to instantiate a module!");
27 | return null;
28 | }
29 | }
30 |
31 | return instances.get(clazz);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/accountSync/Authentication/AuthManager.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.accountSync.Authentication;
2 |
3 | import java.util.HashMap;
4 |
5 | public class AuthManager {
6 |
7 | private HashMap authSessions;
8 |
9 | public AuthManager() {
10 | authSessions = new HashMap<>();
11 | }
12 |
13 | public AuthSession getSession(String authToken) {
14 | return authSessions.get(authToken);
15 | }
16 |
17 | public void addSession(AuthSession authSession) {
18 | authSessions.put(authSession.getAuthToken().toString(), authSession);
19 | }
20 |
21 | public void removeSession(String authToken) {
22 | authSessions.remove(authToken);
23 | }
24 |
25 | public void clearSessions() {
26 | authSessions.clear();
27 | }
28 |
29 | public HashMap getAuthSessions() {
30 | return authSessions;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/reporters/OSReporter.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.reporters;
2 |
3 | import us.cyrien.mcutils.diagnosis.Diagnostics;
4 | import us.cyrien.mcutils.diagnosis.IReporter;
5 |
6 | public class OSReporter implements IReporter {
7 |
8 | private String name;
9 | private int priority;
10 |
11 | public OSReporter() {
12 | this.name = "OS Reporter";
13 | this.priority = 1;
14 | }
15 |
16 | @Override
17 | public String getName() {
18 | return name;
19 | }
20 |
21 | @Override
22 | public String report() {
23 | return "OS name: " + System.getProperty("os.name") + Diagnostics.LINE_SEPARATOR +
24 | "OS arch: " + System.getProperty("os.arch") + Diagnostics.LINE_SEPARATOR +
25 | "OS version: " + System.getProperty("os.version");
26 | }
27 |
28 | @Override
29 | public int getPriority() {
30 | return priority;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/module/ModuleInjector.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.module;
2 |
3 | import us.cyrien.mcutils.annotations.InjectModule;
4 | import us.cyrien.mcutils.inject.Injector;
5 | import us.cyrien.mcutils.logger.Logger;
6 |
7 | import java.lang.reflect.Field;
8 |
9 | public class ModuleInjector implements Injector {
10 | @Override
11 | public void inject(Class> c, Object instance) {
12 | for (Field f : c.getDeclaredFields()) {
13 | if (f.isAnnotationPresent(InjectModule.class)) {
14 | if (!ModuleLoader.getModuleClasses().contains(f.getType())) {
15 | Logger.err("Couldn't find module of class " + f.getType().getName() + "!");
16 | continue;
17 | }
18 |
19 | f.setAccessible(true);
20 | try {
21 | f.set(instance, ModuleLoader.getInstance(f.getType()));
22 | } catch (IllegalAccessException e) {
23 | Logger.err("Couldn't access field " + f.getName() + "!");
24 | }
25 | }
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/chat/listeners/mcListeners/McMMOListener.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.chat.listeners.mcListeners;
2 |
3 | import com.gmail.nossr50.events.chat.McMMOAdminChatEvent;
4 | import com.gmail.nossr50.events.chat.McMMOPartyChatEvent;
5 | import org.bukkit.event.EventHandler;
6 | import org.bukkit.event.EventPriority;
7 | import us.cyrien.minecordbot.Minecordbot;
8 |
9 | public class McMMOListener extends MCBListener{
10 |
11 | public McMMOListener(Minecordbot mcb) {
12 | super(mcb);
13 | }
14 |
15 | @EventHandler(priority = EventPriority.HIGHEST)
16 | public void onmcMMOAdminChat(McMMOAdminChatEvent e) {
17 | mcb.getChatManager().getChatStatus().setIsmcmmoAdminChat(true);
18 | }
19 |
20 |
21 | @EventHandler(priority = EventPriority.HIGHEST)
22 | public void onmcMMOPartyChat(McMMOPartyChatEvent e) {
23 | mcb.getChatManager().getChatStatus().setmcmmopartychat(true);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/events/listener/OnShut.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.events.listener;
2 |
3 | import net.dv8tion.jda.core.EmbedBuilder;
4 | import org.bukkit.event.EventHandler;
5 | import org.bukkit.event.Listener;
6 | import us.cyrien.minecordbot.Bot;
7 | import us.cyrien.minecordbot.Minecordbot;
8 | import us.cyrien.minecordbot.events.ShutdownEvent;
9 | import us.cyrien.minecordbot.localization.Locale;
10 |
11 | public class OnShut implements Listener {
12 |
13 | private Minecordbot mcb;
14 |
15 | public OnShut(Minecordbot mcb) {
16 | this.mcb = mcb;
17 | }
18 |
19 | @EventHandler
20 | public void onShut(ShutdownEvent event) {
21 | if(!event.isCancelled()) {
22 | EmbedBuilder eb = new EmbedBuilder().setDescription(Locale.getEventMessage("shut").finish()).setColor(Bot.BOT_COLOR);
23 | mcb.getMessenger().sendMessageEmbedToAllBoundChannel(eb.build());
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/commands/discordCommand/StartCmd.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.commands.discordCommand;
2 |
3 | import com.jagrosh.jdautilities.commandclient.CommandEvent;
4 | import us.cyrien.minecordbot.Bot;
5 | import us.cyrien.minecordbot.Minecordbot;
6 | import us.cyrien.minecordbot.commands.MCBCommand;
7 | import us.cyrien.minecordbot.localization.Locale;
8 |
9 | public class StartCmd extends MCBCommand {
10 |
11 | public StartCmd(Minecordbot minecordbot) {
12 | super(minecordbot);
13 | this.name = "start";
14 | this.help = Locale.getCommandsMessage("start.description").finish();
15 | this.ownerCommand = true;
16 | this.category = Bot.OWNER;
17 | this.type = MCBCommand.Type.EMBED;
18 | }
19 |
20 | @Override
21 | protected void doCommand(CommandEvent e) {
22 | respond(e, Locale.getCommandsMessage("start.starting").finish());
23 | getMcb().getBot().shutdown();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/commands/discordCommand/ShutdownCmd.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.commands.discordCommand;
2 |
3 | import com.jagrosh.jdautilities.commandclient.CommandEvent;
4 | import us.cyrien.minecordbot.Bot;
5 | import us.cyrien.minecordbot.Minecordbot;
6 | import us.cyrien.minecordbot.commands.MCBCommand;
7 | import us.cyrien.minecordbot.localization.Locale;
8 |
9 | public class ShutdownCmd extends MCBCommand {
10 |
11 | public ShutdownCmd(Minecordbot minecordbot) {
12 | super(minecordbot);
13 | this.name = "shutdown";
14 | this.help = Locale.getCommandsMessage("shutdown.description").finish();
15 | this.ownerCommand = true;
16 | this.category = Bot.OWNER;
17 | this.type = Type.EMBED;
18 | }
19 |
20 | @Override
21 | protected void doCommand(CommandEvent e) {
22 | respond(e, Locale.getCommandMessage("shutdown.shutting").finish());
23 | getMcb().getBot().shutdown();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/commands/minecraftCommand/Dcmd.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.commands.minecraftCommand;
2 |
3 | import org.bukkit.ChatColor;
4 | import org.bukkit.command.CommandSender;
5 | import us.cyrien.mcutils.annotations.Command;
6 | import us.cyrien.mcutils.annotations.Permission;
7 | import us.cyrien.mcutils.annotations.Sender;
8 | import us.cyrien.mcutils.annotations.Text;
9 | import us.cyrien.minecordbot.Minecordbot;
10 | import us.cyrien.minecordbot.chat.Messenger;
11 |
12 | public class Dcmd {
13 | @Command(aliases = "dcmd", usage = "/dcmd ", desc = "Do discord commands from minecraft")
14 | @Permission("minecordbot.dcmd")
15 | public void command(@Sender CommandSender sender, @Text String arg) {
16 | Messenger msg = new Messenger(Minecordbot.getInstance());
17 | msg.sendMessageToAllBoundChannel(arg);
18 | sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lExecuting command."));
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/hook/HookInjector.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.hook;
2 |
3 | import us.cyrien.mcutils.annotations.Hook;
4 | import us.cyrien.mcutils.inject.Injector;
5 | import us.cyrien.mcutils.logger.Logger;
6 |
7 | import java.lang.reflect.Field;
8 |
9 | public class HookInjector implements Injector {
10 | @Override
11 | public void inject(Class> c, Object instance) {
12 | for (Field f : c.getDeclaredFields()) {
13 | if (f.isAnnotationPresent(Hook.class)) {
14 | IPluginHook hook = HookLoader.get(f.getType());
15 | f.setAccessible(true);
16 |
17 | if (hook == null) {
18 | Logger.warn("Couldn't find hook " + f.getType().getName() + ", was it registered?");
19 | continue;
20 | }
21 |
22 | try {
23 | if (hook.available())
24 | f.set(instance, hook);
25 | else
26 | f.set(instance, null);
27 | } catch (IllegalAccessException e) {
28 | Logger.err("Couldn't access field " + f.getName() + "!");
29 | }
30 | }
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/chat/listeners/mcListeners/MCBListener.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.chat.listeners.mcListeners;
2 |
3 | import org.bukkit.event.Listener;
4 | import us.cyrien.minecordbot.Minecordbot;
5 | import us.cyrien.minecordbot.chat.Messenger;
6 | import us.cyrien.minecordbot.configuration.MCBConfigsManager;
7 | import us.cyrien.minecordbot.handle.MinecraftMentionHandler;
8 |
9 | public class MCBListener implements Listener {
10 |
11 | protected final Minecordbot mcb;
12 | protected final Messenger messenger;
13 | protected final MinecraftMentionHandler mentionHandler;
14 | protected MCBConfigsManager configsManager;
15 |
16 | public MCBListener(Minecordbot mcb) {
17 | this.mcb = mcb;
18 | messenger = mcb.getMessenger();
19 | mentionHandler = new MinecraftMentionHandler(mcb);
20 | configsManager = mcb.getMcbConfigsManager();
21 | }
22 |
23 | public MCBConfigsManager getConfigsManager() {
24 | return configsManager;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/events/listener/OnStart.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.events.listener;
2 |
3 | import net.dv8tion.jda.core.EmbedBuilder;
4 | import org.bukkit.event.EventHandler;
5 | import org.bukkit.event.Listener;
6 | import us.cyrien.minecordbot.Bot;
7 | import us.cyrien.minecordbot.Minecordbot;
8 | import us.cyrien.minecordbot.events.StartEvent;
9 | import us.cyrien.minecordbot.localization.Locale;
10 |
11 | public class OnStart implements Listener {
12 |
13 | private Minecordbot mcb;
14 |
15 | public OnStart(Minecordbot mcb) {
16 | this.mcb = mcb;
17 | }
18 |
19 | @EventHandler
20 | public void onStart(StartEvent event) {
21 | if (!event.isCancelled()) {
22 | EmbedBuilder eb = new EmbedBuilder().setDescription(Locale.getEventMessage("start").finish()).setColor(Bot.BOT_COLOR);
23 | mcb.getMessenger().sendMessageEmbedToAllBoundChannel(eb.build());
24 | mcb.getMessenger().sendMessageEmbedToAllModChannel(eb.build());
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/entity/Lag.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.entity;
2 |
3 | public class Lag implements Runnable{
4 | public static int TICK_COUNT = 0;
5 | public static long[] TICKS = new long[600];
6 |
7 | public static double getTPS() {
8 | return getTPS(100);
9 | }
10 |
11 | public static double getTPS(int ticks) {
12 | if (TICK_COUNT < ticks) {
13 | return 20.0D;
14 | }
15 | int target = (TICK_COUNT - 1 - ticks) % TICKS.length;
16 | long elapsed = System.currentTimeMillis() - TICKS[target];
17 |
18 | return ticks / (elapsed / 1000.0D);
19 | }
20 |
21 | public static long getElapsed(int tickID) {
22 | if (TICK_COUNT - tickID >= TICKS.length) {
23 | }
24 |
25 | long time = TICKS[(tickID % TICKS.length)];
26 | return System.currentTimeMillis() - time;
27 | }
28 |
29 | public void run() {
30 | TICKS[(TICK_COUNT % TICKS.length)] = System.currentTimeMillis();
31 |
32 | TICK_COUNT += 1;
33 | }
34 | }
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/dispatcher/help/HelpTopicUtil.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.dispatcher.help;
2 |
3 | import org.bukkit.Bukkit;
4 | import org.bukkit.help.HelpTopic;
5 | import us.cyrien.mcutils.loader.CommandMapping;
6 | import us.cyrien.mcutils.logger.Logger;
7 |
8 | import java.util.ArrayList;
9 | import java.util.HashMap;
10 |
11 | public class HelpTopicUtil {
12 | private static HashMap> topics = new HashMap<>();
13 |
14 | public static void addHelpTopic(CommandMapping mapping) {
15 | if (!topics.containsKey(mapping.getHelpTopic()))
16 | topics.put(mapping.getHelpTopic(), new ArrayList<>());
17 |
18 | ManagedHelpTopic topic = new ManagedHelpTopic(mapping.getName(), mapping.getCommand(), mapping.getPermission());
19 |
20 | topics.get(mapping.getHelpTopic()).add(topic);
21 | Bukkit.getHelpMap().addTopic(topic);
22 | }
23 |
24 | public static void index() {
25 | topics.forEach((parent, topics) -> Bukkit.getHelpMap().addTopic(new IndexTopic(parent, topics)));
26 |
27 | Logger.info("- HelpTopics indexed.");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/configuration/PermissionConfig.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.configuration;
2 |
3 | import us.cyrien.mcutils.config.ConfigManager;
4 |
5 | public class PermissionConfig extends BaseConfig {
6 |
7 | public PermissionConfig(ConfigManager configManager, String[] header) {
8 | super(configManager, header);
9 | }
10 |
11 | @Override
12 | public void initialize() {
13 | if (config.get("Default") == null) {
14 | String[] comArr = new String[]{"Permission for users that doesn't have a role", "or if a role doesn't have permission flags"};
15 | config.set("Default", "{-all}, {+Help}, {+info}, {+Misc}", comArr);
16 | config.saveConfig();
17 | }
18 | if (config.get("RoleID.RoleName") == null) {
19 | config.set("RoleID.RoleName", "sample");
20 | config.saveConfig();
21 | }
22 | if (config.get("RoleID.Permission") == null) {
23 | config.set("RoleID.Permission", "{-category} {+command}");
24 | config.saveConfig();
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/reporters/JReporter.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.reporters;
2 |
3 | import us.cyrien.mcutils.diagnosis.Diagnostics;
4 | import us.cyrien.mcutils.diagnosis.IReporter;
5 |
6 | public class JReporter implements IReporter {
7 |
8 | private String name;
9 | private int priority;
10 |
11 | public JReporter() {
12 | this.name = "Java Reporter";
13 | this.priority = 3;
14 | }
15 |
16 | @Override
17 | public String getName() {
18 | return name;
19 | }
20 |
21 | @Override
22 | public String report() {
23 | String javaProperty = System.getProperty("java.version");
24 | javaProperty = javaProperty.replaceAll("_", " ");
25 | String[] jProps = javaProperty.split(" ");
26 | String javaVersion = jProps[0];
27 | String buildNumber = jProps[1];
28 | return "Java Version: " + javaVersion + Diagnostics.LINE_SEPARATOR +
29 | "Build: " + buildNumber;
30 | }
31 |
32 | @Override
33 | public int getPriority() {
34 | return priority;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/hook/PluginHook.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.hook;
2 |
3 | import org.bukkit.Bukkit;
4 |
5 | /**
6 | * Easily hook other plugins by extending this class to a subclass.
7 | * Interfaces {@link us.cyrien.mcutils.hook.IPluginHook}
8 | *
9 | *
PluginHook implementation example.
10 | *
11 | * {@code
12 | * public MCBHook extends PluginHook {
13 | * public MCBHook() {
14 | * this.name = "MineCordBot";
15 | * }
16 | * }
17 | * }
18 | *
19 | *
20 | *
21 | * @param Type of Plugin that's going to get hooked.
22 | */
23 | public class PluginHook implements IPluginHook {
24 |
25 | protected String name = "";
26 |
27 | @Override
28 | public boolean available() {
29 | return Bukkit.getPluginManager().isPluginEnabled(getPluginName());
30 | }
31 |
32 | @Override
33 | public String getPluginName() {
34 | return name;
35 | }
36 |
37 | public T getPlugin() {
38 | return (T) Bukkit.getPluginManager().getPlugin(getPluginName());
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/utils/ArrayUtils.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.utils;
2 |
3 |
4 | import net.dv8tion.jda.core.Permission;
5 |
6 | import java.util.List;
7 |
8 | public class ArrayUtils {
9 |
10 | public static String concatenateArgs(int first, int last, String[] args) {
11 | String out = "";
12 | for(int i = first; i < last; i++) {
13 | out += args[i] + " ";
14 | }
15 | return out.trim();
16 | }
17 |
18 | public static String concatenateArgs(String[] args, int last) {
19 | return concatenateArgs(0, last, args);
20 | }
21 |
22 | public static String concatenateArgs(int first, String[] args) {
23 | return concatenateArgs(first, args.length, args);
24 | }
25 |
26 | public static String concatenateArgs(String[] args) {
27 | return concatenateArgs(0, args.length, args);
28 | }
29 |
30 | public static Permission[] permsAsArray(List perms) {
31 | Permission[] tempArr = new Permission[perms.size()];
32 | for(int i = 0; i < tempArr.length; i++) {
33 | tempArr[0] = perms.get(i);
34 | }
35 | return tempArr;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/commands/discordCommand/ReloadCmd.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.commands.discordCommand;
2 |
3 | import com.jagrosh.jdautilities.commandclient.CommandEvent;
4 | import net.dv8tion.jda.core.EmbedBuilder;
5 | import us.cyrien.minecordbot.Bot;
6 | import us.cyrien.minecordbot.Minecordbot;
7 | import us.cyrien.minecordbot.commands.MCBCommand;
8 | import us.cyrien.minecordbot.localization.Locale;
9 |
10 | public class ReloadCmd extends MCBCommand {
11 |
12 | public ReloadCmd(Minecordbot minecordbot) {
13 | super(minecordbot);
14 | this.name = "reload";
15 | this.help = Locale.getCommandsMessage("reload.description").finish();
16 | this.category = Bot.ADMIN;
17 | this.type = Type.EMBED;
18 | }
19 |
20 | @Override
21 | protected void doCommand(CommandEvent e) {
22 | configsManager.reloadAllConfig();
23 | configsManager.setupConfigurations();
24 | EmbedBuilder eb = new EmbedBuilder().setColor(e.getGuild().getMember(e.getJDA().getSelfUser()).getColor());
25 | eb.setTitle(Locale.getCommandsMessage("reload.reloaded").finish(), null);
26 | respond(e, eb.build());
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/chat/ChatStatus.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.chat;
2 |
3 | public class ChatStatus {
4 |
5 | private boolean ismcmmoAdminChat;
6 | private boolean ismcmmoPartyChat;
7 | private boolean isCancelled;
8 |
9 | public ChatStatus() {
10 | ismcmmoPartyChat = false;
11 | ismcmmoPartyChat =false;
12 | }
13 |
14 | public boolean isCancelled() {
15 | return isCancelled;
16 | }
17 |
18 | public void setCancelled(boolean cancelled) {
19 | isCancelled = cancelled;
20 | }
21 |
22 | public boolean isIsmcmmoAdminChat() {
23 |
24 | return ismcmmoAdminChat;
25 | }
26 |
27 | public void setIsmcmmoAdminChat(boolean ismcmmoAdminChat) {
28 | this.ismcmmoAdminChat = ismcmmoAdminChat;
29 | }
30 |
31 | public boolean ismcmmopartychat() {
32 | return ismcmmoPartyChat;
33 | }
34 |
35 | public void setmcmmopartychat(boolean ismcmmopartychat) {
36 | this.ismcmmoPartyChat = ismcmmopartychat;
37 | }
38 |
39 | public void reset() {
40 | ismcmmoAdminChat = false;
41 | ismcmmoPartyChat = false;
42 | isCancelled = false;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/entity/UpTimer.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.entity;
2 |
3 | import org.bukkit.Bukkit;
4 | import us.cyrien.minecordbot.Minecordbot;
5 |
6 | import java.util.concurrent.TimeUnit;
7 |
8 | public class UpTimer{
9 |
10 | private long startTime;
11 |
12 | public UpTimer(Minecordbot mcb) {
13 | startTime = System.currentTimeMillis();
14 | Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(mcb, new Lag(), 100L, 1L);
15 | mcb.getScheduler().scheduleWithFixedDelay(() -> mcb.getBot().getUpdatableMap()
16 | .get("tps").update(), 0, 5, TimeUnit.SECONDS);
17 | }
18 |
19 | public double getCurrentTps() {
20 | double tps = Lag.getTPS();
21 | if(tps > 20.0D)
22 | tps = 20.0000D;
23 | return tps;
24 | }
25 |
26 | public String getCurrentUptime() {
27 | long currTime = System.currentTimeMillis();
28 | long diff = currTime - startTime;
29 | return (int) (diff / 86400000L) + "d " + (int)
30 | (diff / 3600000L % 24L) + "h " + (int)
31 | (diff / 60000L % 60L) + "m " + (int)
32 | (diff / 1000L % 60L) + "s";
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/events/StartEvent.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.events;
2 |
3 | import org.bukkit.event.Cancellable;
4 | import org.bukkit.event.Event;
5 | import org.bukkit.event.HandlerList;
6 | import us.cyrien.minecordbot.Minecordbot;
7 | import us.cyrien.minecordbot.configuration.BroadcastConfig;
8 |
9 | public class StartEvent extends Event implements Cancellable {
10 |
11 | private static HandlerList handlerList = new HandlerList();
12 | private Minecordbot mcb;
13 | private boolean isCancelled;
14 |
15 | public StartEvent(Minecordbot mcb) {
16 | this.mcb = mcb;
17 | this.isCancelled = false;
18 | }
19 |
20 | public static HandlerList getHandlerList() {
21 | return handlerList;
22 | }
23 |
24 | @Override
25 | public HandlerList getHandlers() {
26 | return handlerList;
27 | }
28 |
29 | @Override
30 | public boolean isCancelled() {
31 | isCancelled = !mcb.getMcbConfigsManager().getBroadcastConfig().getBoolean(BroadcastConfig.Nodes.SERVER_START);
32 | return isCancelled;
33 | }
34 |
35 | @Override
36 | public void setCancelled(boolean b) {
37 | isCancelled = b;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/events/ShutdownEvent.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.events;
2 |
3 | import org.bukkit.event.Cancellable;
4 | import org.bukkit.event.Event;
5 | import org.bukkit.event.HandlerList;
6 | import us.cyrien.minecordbot.Minecordbot;
7 | import us.cyrien.minecordbot.configuration.BroadcastConfig;
8 |
9 | public class ShutdownEvent extends Event implements Cancellable {
10 |
11 | private static HandlerList handlerList = new HandlerList();
12 | private Minecordbot mcb;
13 | private boolean isCancelled;
14 |
15 | public ShutdownEvent(Minecordbot mcb) {
16 | this.mcb = mcb;
17 | isCancelled = false;
18 | }
19 |
20 | public static HandlerList getHandlerList() {
21 | return handlerList;
22 | }
23 |
24 | @Override
25 | public HandlerList getHandlers() {
26 | return handlerList;
27 | }
28 |
29 | @Override
30 | public boolean isCancelled() {
31 | isCancelled = !mcb.getMcbConfigsManager().getBroadcastConfig().getBoolean(BroadcastConfig.Nodes.SERVER_SHUT);
32 | return isCancelled;
33 | }
34 |
35 | @Override
36 | public void setCancelled(boolean b) {
37 | isCancelled = b;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/logger/Logger.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.logger;
2 |
3 | import org.bukkit.Bukkit;
4 | import org.bukkit.ChatColor;
5 |
6 | import java.util.logging.Level;
7 |
8 | public class Logger {
9 |
10 | public static final String ANSI_RESET = "\033[0m";
11 | public static final String ANSI_GOLD_FOREGROUND = "\033[33m";
12 | public static final String ANSI_RED_FOREGROUND = "\033[31m";
13 |
14 | private static String prefix = "[MineCordBot] ";
15 |
16 | public Logger(String prefix) {
17 | this.prefix = prefix;
18 | }
19 |
20 | public static void log(Level level, String msg) {
21 | Bukkit.getLogger().log(level, getPrefix() + msg);
22 | }
23 |
24 | public static void info(String msg) {
25 | log(Level.INFO, msg);
26 | }
27 |
28 | public static void warn(String msg) {
29 | log(Level.WARNING, ANSI_GOLD_FOREGROUND + msg + ANSI_RESET);
30 | }
31 |
32 | public static void err(String msg) {
33 | log(Level.SEVERE, ANSI_RED_FOREGROUND + msg + ANSI_RESET);
34 | }
35 |
36 | public static void bukkitWarn(String msg) {
37 | Bukkit.getConsoleSender().sendMessage(ChatColor.GOLD + getPrefix() + msg);
38 | }
39 |
40 | private static String getPrefix() {
41 | return prefix;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/logger/Debugger.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.logger;
2 |
3 | import org.bukkit.Bukkit;
4 | import org.bukkit.ChatColor;
5 |
6 | import java.util.logging.Level;
7 |
8 | public class Debugger {
9 |
10 | public static final String ANSI_RESET = "\033[0m";
11 | public static final String ANSI_GOLD_FOREGROUND = "\033[33m";
12 | public static final String ANSI_RED_FOREGROUND = "\033[31m";
13 |
14 | private static String prefix = "[MCB-Debug] ";
15 |
16 | public static void log(Level level, String msg) {
17 | Bukkit.getLogger().log(level, getPrefix() + msg);
18 | }
19 |
20 | public static void info(String msg) {
21 | log(Level.INFO, msg);
22 | }
23 |
24 | public static void warn(String msg) {
25 | log(Level.WARNING, ANSI_GOLD_FOREGROUND + msg + ANSI_RESET);
26 | }
27 |
28 | public static void err(String msg) {
29 | log(Level.SEVERE, ANSI_RED_FOREGROUND + msg + ANSI_RESET);
30 | }
31 |
32 | public static void bukkitWarn(String msg) {
33 | Bukkit.getConsoleSender().sendMessage(ChatColor.GOLD + getPrefix() + msg);
34 | }
35 |
36 | private static String getPrefix() {
37 | return prefix;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/handle/MinecraftMentionHandler.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.handle;
2 |
3 | import net.dv8tion.jda.core.JDA;
4 | import net.dv8tion.jda.core.entities.Member;
5 | import us.cyrien.minecordbot.Minecordbot;
6 | import us.cyrien.minecordbot.utils.SearchUtil;
7 | import us.cyrien.minecordbot.utils.SRegex;
8 |
9 | import java.util.List;
10 | import java.util.regex.Pattern;
11 |
12 | public class MinecraftMentionHandler {
13 |
14 | private JDA jda;
15 |
16 | public MinecraftMentionHandler(Minecordbot mcb) {
17 | jda = mcb.getBot().getJda();
18 | }
19 |
20 | public String handleMention(String s) {
21 | List mentions = new SRegex(s).find(Pattern.compile("@[!-\\/:-@A-Z\\[-~\\d]+")).getResultsList();
22 | for (String m : mentions) {
23 | m = m.replaceAll("_", " ").replaceAll("-", "_").replaceAll("@", "");
24 | Member member = SearchUtil.findMember(m);
25 | if(member != null) {
26 | m = m.replaceAll("[^\\w\\s]", "\\\\$0");
27 | s = s.replaceAll("@" + m, "<@" + member.getUser().getId() + ">");
28 | } else {
29 | }
30 | }
31 | return s;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/chat/listeners/mcListeners/BroadcastCommandListener.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.chat.listeners.mcListeners;
2 |
3 | import org.bukkit.ChatColor;
4 | import org.bukkit.event.EventHandler;
5 | import org.bukkit.event.EventPriority;
6 | import org.bukkit.event.server.ServerCommandEvent;
7 | import us.cyrien.minecordbot.Minecordbot;
8 | import us.cyrien.minecordbot.configuration.ModChannelConfig;
9 |
10 | public class BroadcastCommandListener extends MCBListener {
11 |
12 | public BroadcastCommandListener(Minecordbot mcb) {
13 | super(mcb);
14 | }
15 |
16 | @EventHandler(priority = EventPriority.NORMAL)
17 | public void onBroadcastCommand(ServerCommandEvent event) {
18 | String cmd = ChatColor.stripColor(event.getCommand());
19 | if (cmd.equals("broadcast ") || cmd.equals("bc ")) {
20 | String msg = cmd.split(" ", 2)[1];
21 | messenger.sendMessageToAllBoundChannel("\uD83D\uDCE2 " + msg);
22 | boolean seeBc = configsManager.getModChannelConfig().getBoolean(ModChannelConfig.Nodes.SEE_BROADCAST);
23 | if(seeBc) {
24 | messenger.sendMessageToAllModChannel("\uD83D\uDCE2 " + msg );
25 | }
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/handle/RoleNameChangeHandler.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.handle;
2 |
3 | import net.dv8tion.jda.core.entities.Role;
4 | import net.dv8tion.jda.core.events.role.update.RoleUpdateNameEvent;
5 | import net.dv8tion.jda.core.hooks.ListenerAdapter;
6 | import us.cyrien.minecordbot.Minecordbot;
7 |
8 | import java.util.Set;
9 |
10 | public class RoleNameChangeHandler extends ListenerAdapter {
11 |
12 | private Minecordbot mcb;
13 |
14 | public RoleNameChangeHandler(Minecordbot mcb) {
15 | this.mcb = mcb;
16 | }
17 |
18 | @Override
19 | public void onRoleUpdateName(RoleUpdateNameEvent event) {
20 | super.onRoleUpdateName(event);
21 | if (exists(event.getRole())) {
22 | mcb.getMcbConfigsManager().getPermConfig().getConfig().set(event.getRole().getId() + ".RoleName", event.getRole().getName());
23 | mcb.getMcbConfigsManager().getPermConfig().getConfig().saveConfig();
24 | mcb.getMcbConfigsManager().reloadAllConfig();
25 | }
26 | }
27 |
28 | private boolean exists(Role role) {
29 | Set keys = mcb.getMcbConfigsManager().getPermConfig().getConfig().getKeys();
30 | return keys.contains(role.getId());
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/commands/minecraftCommand/Dme.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.commands.minecraftCommand;
2 |
3 | import org.bukkit.Bukkit;
4 | import org.bukkit.ChatColor;
5 | import org.bukkit.command.CommandSender;
6 | import org.bukkit.entity.Player;
7 | import us.cyrien.mcutils.annotations.Command;
8 | import us.cyrien.mcutils.annotations.Permission;
9 | import us.cyrien.mcutils.annotations.Sender;
10 | import us.cyrien.mcutils.annotations.Text;
11 | import us.cyrien.minecordbot.Minecordbot;
12 | import us.cyrien.minecordbot.chat.Messenger;
13 |
14 | public class Dme {
15 | @Command(aliases = "dme", usage = "/dme ", desc = "/me command but for discord.")
16 | @Permission("minecordbot.dme")
17 | public void command(@Sender CommandSender sender, @Text String arg) {
18 | if(sender instanceof Player) {
19 | Player p = (Player) sender;
20 | for (Player pl : Bukkit.getServer().getOnlinePlayers())
21 | pl.sendMessage(ChatColor.translateAlternateColorCodes('&', "&5* " + "&r" + p.getDisplayName() + " &5" + arg));
22 | new Messenger(Minecordbot.getInstance()).sendMessageToAllBoundChannel("**" + p.getName() + "** " + "_" + arg + "_");
23 | } else {
24 | sender.sendMessage("Only players can do that execute /dme command");
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/reporters/MemReporter.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.reporters;
2 |
3 | import us.cyrien.mcutils.diagnosis.Diagnostics;
4 | import us.cyrien.mcutils.diagnosis.IReporter;
5 |
6 | public class MemReporter implements IReporter {
7 |
8 | private String name;
9 | private int priority;
10 |
11 | public MemReporter() {
12 | this.name = "Memory Reporter";
13 | this.priority = 2;
14 | }
15 |
16 | @Override
17 | public String getName() {
18 | return name;
19 | }
20 |
21 | @Override
22 | public String report() {
23 | StringBuilder sb = new StringBuilder();
24 | long allocated = Runtime.getRuntime().totalMemory() / 1024L / 1024L;
25 | long free = Runtime.getRuntime().freeMemory() / 1024L / 1024L;
26 | long used = allocated - free;
27 | sb.append("Allocated Memory: ").append(allocated).append("mb").append(Diagnostics.LINE_SEPARATOR);
28 | sb.append("Free Memory: ").append(free).append("mb").append(Diagnostics.LINE_SEPARATOR);
29 | sb.append("Used Memory: ").append(used).append("mb").append(Diagnostics.LINE_SEPARATOR);
30 | sb.append("Memory Usage: ").append(((double) used / allocated) * 100.0).append("%");
31 | return sb.toString();
32 | }
33 |
34 | @Override
35 | public int getPriority() {
36 | return priority;
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/chat/listeners/mcListeners/CommandListener.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.chat.listeners.mcListeners;
2 |
3 | import net.dv8tion.jda.core.EmbedBuilder;
4 | import org.bukkit.ChatColor;
5 | import org.bukkit.command.CommandSender;
6 | import org.bukkit.event.EventHandler;
7 | import org.bukkit.event.EventPriority;
8 | import org.bukkit.event.player.PlayerCommandPreprocessEvent;
9 | import us.cyrien.minecordbot.Bot;
10 | import us.cyrien.minecordbot.Minecordbot;
11 | import us.cyrien.minecordbot.configuration.ModChannelConfig;
12 |
13 | import java.awt.*;
14 |
15 | public class CommandListener extends MCBListener {
16 |
17 | public CommandListener(Minecordbot mcb) {
18 | super(mcb);
19 | }
20 |
21 | @EventHandler(priority = EventPriority.NORMAL)
22 | public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
23 | boolean seeCommands = configsManager.getModChannelConfig().getBoolean(ModChannelConfig.Nodes.SEE_COMMADS);
24 | CommandSender s = e.getPlayer();
25 | String msg = "**" + ChatColor.stripColor(s.getName()) + "**: " + e.getMessage();
26 | if (seeCommands) {
27 | Color color = Bot.BOT_COLOR;
28 | EmbedBuilder eb = new EmbedBuilder().setColor(color);
29 | eb.addField("Command-Event", msg, false);
30 | messenger.sendMessageEmbedToAllModChannel(eb.build());
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/commands/discordCommand/PingCmd.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.commands.discordCommand;
2 |
3 | import com.jagrosh.jdautilities.commandclient.CommandEvent;
4 | import com.jagrosh.jdautilities.waiter.EventWaiter;
5 | import us.cyrien.minecordbot.Bot;
6 | import us.cyrien.minecordbot.Minecordbot;
7 | import us.cyrien.minecordbot.commands.MCBCommand;
8 | import us.cyrien.minecordbot.localization.Locale;
9 |
10 | import java.time.temporal.ChronoUnit;
11 | import java.util.concurrent.TimeUnit;
12 |
13 | public class PingCmd extends MCBCommand {
14 |
15 | private EventWaiter waiter;
16 |
17 | public PingCmd(Minecordbot minecordbot) {
18 | super(minecordbot);
19 | this.name = "ping";
20 | this.aliases = new String[]{"pong, p"};
21 | this.help = Locale.getCommandsMessage("ping.description").finish();
22 | this.category = Bot.MISC;
23 | waiter = minecordbot.getEventWaiter();
24 | }
25 |
26 | @Override
27 | protected void doCommand(CommandEvent e) {
28 | e.getTextChannel().sendMessage("ping...").queue(msg -> msg.editMessage("ping: `" + e.getMessage().getCreationTime()
29 | .until(msg.getCreationTime(), ChronoUnit.MILLIS) + " ms`").queue((m) -> {
30 | scheduler.schedule(() -> {
31 | if (auto)
32 | m.delete().queue();
33 | }, RESPONSE_DURATION, TimeUnit.MINUTES);
34 | }));
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/accountSync/AccountDataFormat.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.accountSync;
2 |
3 | import org.bukkit.ChatColor;
4 | import org.json.JSONObject;
5 | import us.cyrien.minecordbot.entity.UnifiedUser;
6 |
7 | import java.util.LinkedHashMap;
8 |
9 | public class AccountDataFormat {
10 |
11 | private String discordID;
12 | private String mcUsername;
13 | private String discordUsername;
14 |
15 | public AccountDataFormat(UnifiedUser mcUser) {
16 | discordID = mcUser.getMcbUser() == null ? "Not Synced yet" : mcUser.getMcbUser().getID();
17 | mcUsername = ChatColor.stripColor(mcUser.getPlayer().getName());
18 | discordUsername = mcUser.getMcbUser() == null ? "Not Synced yet" : mcUser.getMcbUser().getName() ;
19 | }
20 |
21 | public AccountDataFormat(String keyUUID, JSONObject accData) {
22 | discordID = accData.getString(DataKey.DISCORD_ID.toString());
23 | mcUsername = accData.getString(DataKey.MC_USERNAME.toString());
24 | discordUsername = accData.getString(DataKey.DISCORD_USERNAME.toString());
25 | }
26 |
27 | public LinkedHashMap dataAsMap() {
28 | LinkedHashMap map = new LinkedHashMap<>();
29 | map.put(DataKey.MC_USERNAME.toString(), mcUsername);
30 | map.put(DataKey.DISCORD_ID.toString(), discordID);
31 | map.put(DataKey.DISCORD_USERNAME.toString(), discordUsername);
32 | return map;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/entity/UnifiedUser.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.entity;
2 |
3 | import net.dv8tion.jda.core.entities.User;
4 | import org.bukkit.entity.Player;
5 | import us.cyrien.minecordbot.accountSync.AccountDataFormat;
6 | import us.cyrien.minecordbot.utils.SearchUtil;
7 |
8 | import java.util.LinkedHashMap;
9 |
10 | public class UnifiedUser {
11 |
12 | private Player p;
13 | private MCBUser mcbUser;
14 | private AccountDataFormat accountDataFormat;
15 |
16 | public UnifiedUser(Player p) {
17 | this.p = p;
18 | User user = SearchUtil.findUserInDatabase(p);
19 | this.mcbUser = user == null ? null : new MCBUser(user);
20 | }
21 |
22 | public UnifiedUser(Player p, MCBUser mcbUser) {
23 | this.p = p;
24 | this.mcbUser = mcbUser;
25 | }
26 |
27 | public void setMcbUser(MCBUser mcbUser) {
28 | this.mcbUser = mcbUser;
29 | }
30 |
31 | public boolean isSynced() {
32 | return mcbUser != null && p != null;
33 | }
34 |
35 | public AccountDataFormat getAccountDataFormat() {
36 | accountDataFormat = new AccountDataFormat(this);
37 | return accountDataFormat;
38 | }
39 |
40 | public Player getPlayer() {
41 | return p;
42 | }
43 |
44 | public MCBUser getMcbUser() {
45 | return mcbUser;
46 | }
47 |
48 | public LinkedHashMap getDataAsMap() {
49 | accountDataFormat = new AccountDataFormat(this);
50 | return accountDataFormat.dataAsMap();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/libs/licenses/Multiverse (BSD).license:
--------------------------------------------------------------------------------
1 | Copyright (c) 2011, The Multiverse Team
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 | * Redistributions of source code must retain the above copyright
7 | notice, this list of conditions and the following disclaimer.
8 | * Redistributions in binary form must reproduce the above copyright
9 | notice, this list of conditions and the following disclaimer in the
10 | documentation and/or other materials provided with the distribution.
11 | * Neither the name of the The Multiverse Team nor the
12 | names of its contributors may be used to endorse or promote products
13 | derived from this software without specific prior written permission.
14 |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY
19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/commands/discordCommand/DiagnosticsCmd.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.commands.discordCommand;
2 |
3 | import com.jagrosh.jdautilities.commandclient.CommandEvent;
4 | import net.dv8tion.jda.core.MessageBuilder;
5 | import us.cyrien.mcutils.diagnosis.Diagnostics;
6 | import us.cyrien.mcutils.diagnosis.DiagnosticsBuilder;
7 | import us.cyrien.mcutils.diagnosis.TypeDiagnosis;
8 | import us.cyrien.minecordbot.Bot;
9 | import us.cyrien.minecordbot.Minecordbot;
10 | import us.cyrien.minecordbot.commands.MCBCommand;
11 | import us.cyrien.minecordbot.localization.Locale;
12 |
13 | import java.util.concurrent.TimeUnit;
14 |
15 | public class DiagnosticsCmd extends MCBCommand {
16 |
17 | public DiagnosticsCmd(Minecordbot minecordbot) {
18 | super(minecordbot);
19 | this.name = "diagnostics";
20 | this.help = Locale.getCommandsMessage("diagnostics.description").finish();
21 | this.aliases = new String[]{"diagnose", "report"};
22 | this.ownerCommand = true;
23 | this.category = Bot.OWNER;
24 | this.type = Type.EMBED;
25 | }
26 |
27 | @Override
28 | protected void doCommand(CommandEvent e) {
29 | DiagnosticsBuilder dB = new DiagnosticsBuilder();
30 | dB = dB.setTypeDiagnosis(TypeDiagnosis.ALL);
31 | Diagnostics diagnostics = dB.build();
32 | respond("Generating diagnostic report...", e).queue((msg) -> msg.delete().queueAfter(2, TimeUnit.SECONDS, (m) -> {
33 | e.getTextChannel().sendFile(diagnostics.fullReport(), new MessageBuilder().append("Diagnostics report: ").build()).queue();
34 | }));
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/chat/listeners/mcListeners/SuperVanishListener.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.chat.listeners.mcListeners;
2 |
3 | import de.myzelyam.api.vanish.PlayerHideEvent;
4 | import de.myzelyam.api.vanish.PlayerShowEvent;
5 | import de.myzelyam.api.vanish.VanishAPI;
6 | import org.bukkit.Bukkit;
7 | import org.bukkit.event.EventHandler;
8 | import org.bukkit.event.EventPriority;
9 | import org.bukkit.event.player.PlayerJoinEvent;
10 | import org.bukkit.event.player.PlayerQuitEvent;
11 | import us.cyrien.minecordbot.Minecordbot;
12 |
13 | public class SuperVanishListener extends MCBListener {
14 |
15 | public SuperVanishListener(Minecordbot mcb) {
16 | super(mcb);
17 | }
18 |
19 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
20 | public void onPlayerHide(PlayerHideEvent event) {
21 | if (VanishAPI.getConfiguration().getBoolean("Configuration.Messages.VanishReappearMessages.BroadcastMessageOnVanish")) {
22 | PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(event.getPlayer(), "Fake");
23 | Bukkit.getServer().getPluginManager().callEvent(playerQuitEvent);
24 | }
25 | }
26 |
27 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
28 | public void onPlayerShow(PlayerShowEvent event) {
29 | if (VanishAPI.getConfiguration().getBoolean("Configuration.Messages.VanishReappearMessages.BroadcastMessageOnReappear")) {
30 | PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(event.getPlayer(), "Fake");
31 | Bukkit.getServer().getPluginManager().callEvent(playerJoinEvent);
32 | }
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/chat/ChatManager.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.chat;
2 |
3 | import com.jagrosh.jdautilities.commandclient.CommandEvent;
4 | import net.dv8tion.jda.core.entities.Message;
5 | import us.cyrien.minecordbot.Minecordbot;
6 |
7 | import java.util.HashMap;
8 | import java.util.Map;
9 |
10 | public class ChatManager {
11 |
12 | private Map savedLists;
13 | private Map savedTPS;
14 |
15 | private Minecordbot mcb;
16 | private ChatStatus chatStatus;
17 |
18 | public ChatManager(Minecordbot mcb) {
19 | savedLists = new HashMap<>();
20 | savedTPS = new HashMap<>();
21 | this.mcb = mcb;
22 | chatStatus = new ChatStatus();
23 | }
24 |
25 | public void clearCache(){
26 | savedLists.putAll(savedTPS);
27 | savedLists.forEach((k, v) -> k.delete().queue());
28 | }
29 |
30 | public Map getSavedLists() {
31 | return savedLists;
32 | }
33 |
34 | public void addSavedList(Message message, CommandEvent event) {
35 | savedLists.put(message, event);
36 | }
37 |
38 | public void removeSavedList(Message message) {
39 | savedLists.remove(message);
40 | }
41 |
42 | public Map getSavedTPS() {
43 | return savedTPS;
44 | }
45 |
46 | public void addSavedTPS(Message message, CommandEvent event) {
47 | savedTPS.put(message, event);
48 | }
49 |
50 | public void removeSavedTPS(Message message) {
51 | savedTPS.remove(message);
52 | }
53 |
54 |
55 | public ChatStatus getChatStatus() {
56 | return chatStatus;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/chat/listeners/mcListeners/MentionListener.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.chat.listeners.mcListeners;
2 |
3 | import net.dv8tion.jda.core.JDA;
4 | import net.dv8tion.jda.core.entities.Member;
5 | import net.dv8tion.jda.core.entities.TextChannel;
6 | import org.bukkit.event.EventHandler;
7 | import org.bukkit.event.server.TabCompleteEvent;
8 | import us.cyrien.minecordbot.Minecordbot;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | public class MentionListener extends MCBListener {
14 |
15 | private JDA jda;
16 | private List tcArray;
17 |
18 | public MentionListener(Minecordbot mcb) {
19 | super(mcb);
20 | jda = mcb.getBot().getJda();
21 | tcArray= mcb.getRelayChannels();
22 | }
23 |
24 | @EventHandler
25 | public void onTabComplete(TabCompleteEvent e) {
26 | String[] buffers = e.getBuffer().split(" ");
27 | List all = new ArrayList<>();
28 | if (e.getBuffer().endsWith("@")) {
29 | tcArray.forEach((tc) -> {
30 | for (Member m : tc.getMembers())
31 | all.add("@" + m.getUser().getName().replaceAll("_", "-").replaceAll(" ", "_"));
32 | });
33 | e.setCompletions(all);
34 | } else if (buffers[buffers.length - 1].startsWith("@")) {
35 | tcArray.forEach((tc) -> {
36 | for (Member m : tc.getMembers())
37 | if(m.getUser().getName().startsWith(buffers[buffers.length - 1].replaceAll("@", "")))
38 | all.add("@" + m.getUser().getName().replaceAll(" ", "_"));
39 | });
40 | e.setCompletions(all);
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/HookContainer.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot;
2 |
3 | import us.cyrien.mcutils.annotations.Hook;
4 | import us.cyrien.minecordbot.hooks.*;
5 |
6 | public class HookContainer {
7 |
8 | @Hook
9 | private static EssentialsHook essentialsHook;
10 | @Hook
11 | private static GriefPreventionHook griefPreventionHook;
12 | @Hook
13 | private static MCBHook mcbHook;
14 | @Hook
15 | private static mcMMOHook mcMMOHook;
16 | @Hook
17 | private static MVHook mvHook;
18 | @Hook
19 | private static PermissionsExHook permissionsExHook;
20 | @Hook
21 | private static VaultHook vaultHook;
22 | @Hook
23 | private static SuperVanishHook superVanishHook;
24 | @Hook
25 | private static VentureChatHook ventureChatHook;
26 |
27 | public static SuperVanishHook getSuperVanishHook() {
28 | return superVanishHook;
29 | }
30 |
31 | public static VentureChatHook getVentureChatHook() {
32 | return ventureChatHook;
33 | }
34 |
35 | public static GriefPreventionHook getGriefPreventionHook() {
36 | return griefPreventionHook;
37 | }
38 |
39 | public static MCBHook getMcbHook() {
40 | return mcbHook;
41 | }
42 |
43 | public static mcMMOHook getMcMMOHook() {
44 | return mcMMOHook;
45 | }
46 |
47 | public static MVHook getMvHook() {
48 | return mvHook;
49 | }
50 |
51 | public static PermissionsExHook getPermissionsExHook() {
52 | return permissionsExHook;
53 | }
54 |
55 | public static VaultHook getVaultHook() {
56 | return vaultHook;
57 | }
58 |
59 | public static EssentialsHook getEssentialsHook() {
60 | return essentialsHook;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ################################################################
2 | # Build Artifacts Generated by the Gradle wrapper. #
3 | # Will prevent contributors from accidentally committing files #
4 | # Prevents shipping completed builds within the source code. #
5 | ################################################################
6 | /.gradle/
7 | /build/
8 |
9 | ################################################################
10 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
11 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
12 | ################################################################
13 |
14 | # User-specific stuff:
15 | .idea/**/workspace.xml
16 | .idea/**/tasks.xml
17 | .idea/dictionaries
18 | .idea/libraries
19 |
20 | # Sensitive or high-churn files:
21 | .idea/**/dataSources/
22 | .idea/**/dataSources.ids
23 | .idea/**/dataSources.xml
24 | .idea/**/dataSources.local.xml
25 | .idea/**/sqlDataSources.xml
26 | .idea/**/dynamic.xml
27 | .idea/**/uiDesigner.xml
28 |
29 | # CMake
30 | cmake-build-debug/
31 |
32 | # Mongo Explorer plugin:
33 | .idea/**/mongoSettings.xml
34 |
35 | ## File-based project format:
36 | *.iws
37 |
38 | ## Plugin-specific files:
39 |
40 | # IntelliJ
41 | /out/
42 |
43 | # mpeltonen/sbt-idea plugin
44 | .idea_modules/
45 |
46 | # JIRA plugin
47 | atlassian-ide-plugin.xml
48 |
49 | # Cursive Clojure plugin
50 | .idea/replstate.xml
51 |
52 | # Crashlytics plugin (for Android Studio and IntelliJ)
53 | com_crashlytics_export_strings.xml
54 | crashlytics.properties
55 | crashlytics-build.properties
56 | fabric.properties
57 | .idea/gradle.xml
58 |
59 | # System Specific
60 | *.DS_Store
61 | *desktop.ini
62 | *.lnk
63 | *thumbs.db
64 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/prefix/PrefixParser.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.prefix;
2 |
3 | import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
4 | import org.bukkit.entity.Player;
5 | import us.cyrien.minecordbot.utils.SRegex;
6 |
7 | import java.util.List;
8 | import java.util.regex.Pattern;
9 |
10 | public class PrefixParser {
11 |
12 | public static String parseDiscordPrefixes(String prefix, MessageReceivedEvent e) {
13 | return parseDiscord(prefix, e);
14 | }
15 |
16 |
17 | public static String parseMinecraftPrefix(String prefix, Player p) {
18 | if(p == null)
19 | return "";
20 | for(MinecraftPlaceHolder s : MinecraftPlaceHolder.values()) {
21 | s.init(p);
22 | String pH = "{" + s.name().toLowerCase() + "}";
23 | String pH0 ="\\{" + s.name().toLowerCase() + "}";
24 | if (prefix.contains(pH)) {
25 | prefix = prefix.replaceAll(pH0, s.toString());
26 | }
27 | }
28 | return prefix.replaceAll("\\s", " ");
29 | }
30 |
31 | private static String parseDiscord(String prefix, MessageReceivedEvent e) {
32 | for(DiscordPlaceHolders s : DiscordPlaceHolders.values() ) {
33 | s.init(e);
34 | String pH = "{" + s.name().toLowerCase() + "}";
35 | String pH0 ="\\{" + s.name().toLowerCase() + "}";
36 | if (prefix.contains(pH)) {
37 | prefix = prefix.replaceAll(pH0, s.toString());
38 | }
39 | }
40 | SRegex sRegex = new SRegex(prefix , Pattern.compile("&\\w\\s"));
41 | List results = sRegex.getResultsList();
42 | for (String s : results ) {
43 | prefix = prefix.replaceAll(s, s.trim());
44 | }
45 | return prefix;
46 | }
47 |
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 | ### What is supposed to happen?
8 | *Describe how you expected it to output or perform*
9 |
10 |
11 | ### What actually happens?
12 | *Describe how the plugin behaves in this instance.*
13 |
14 |
15 | ### What steps reproduce the problem?
16 | 1.
17 | 2.
18 | 3.
19 |
20 | ------
21 | ### What is your Minecordbot version?
22 | *Do not say latest. Please provide either a version or git commit number.*
23 |
24 |
25 | ### What is your craftbukkit / spigot version?
26 | *We do not provide support for forks of Spigot (Taco, Paper), Glowstone, or Sponge. If you have an issue with a fork, please test it with either Spigot or Craftbukkit before reporting your issue.*
27 |
28 |
29 | ### Please provide a link to the following:
30 | *Please use Hastebin or GitHub Gists for these files.*
31 | * Server Log - [Hastebin](http://hastebin.example.com)
32 | * MCB Diagnostics Report - [Gist](http://gist.github.example.com)
33 | * MCB Configuration File - [SomePasteSite](http://paste.example.com)
34 | * Some other relevant config file - http://relevant.example.com
35 |
36 | #### Screenshots / Video (*Optional*)
37 | *Only relevant screenshots and videos, please.*
38 |
39 | 
40 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/commands/minecraftCommand/DConfirm.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.commands.minecraftCommand;
2 |
3 | import org.bukkit.ChatColor;
4 | import org.bukkit.command.CommandSender;
5 | import org.bukkit.entity.Player;
6 | import us.cyrien.mcutils.annotations.Command;
7 | import us.cyrien.mcutils.annotations.Permission;
8 | import us.cyrien.mcutils.annotations.Sender;
9 | import us.cyrien.minecordbot.Minecordbot;
10 | import us.cyrien.minecordbot.accountSync.Authentication.AuthManager;
11 | import us.cyrien.minecordbot.accountSync.Authentication.AuthSession;
12 | import us.cyrien.minecordbot.accountSync.Authentication.AuthToken;
13 | import us.cyrien.minecordbot.accountSync.exceptions.IllegalConfirmKeyException;
14 |
15 | public class DConfirm {
16 | @Command(aliases = "syncconfirm", usage = "/syncconfirm ", desc = "Confirm Minecraft and Discord account sync")
17 | @Permission("minecordbot.discordsync")
18 | public void syncConfirm(@Sender CommandSender commandSender, String verificationCode) {
19 | if (!(commandSender instanceof Player)) {
20 | commandSender.sendMessage("Only players can use this command");
21 | return;
22 | }
23 | AuthToken authToken = null;
24 | try {
25 | authToken = new AuthToken((Player) commandSender, verificationCode);
26 | AuthManager authManager = Minecordbot.getInstance().getAuthManager();
27 | AuthSession authSession = authManager.getSession(authToken.toString());
28 | authSession.authorize((Player) commandSender, authToken);
29 | } catch (IllegalConfirmKeyException e) {
30 | commandSender.sendMessage(ChatColor.translateAlternateColorCodes('&',
31 | "&6[MCBSync] &cThe verification code that you entered is invalid."));
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/reporters/CfgReporter.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.reporters;
2 |
3 | import org.bukkit.configuration.file.FileConfiguration;
4 | import org.bukkit.configuration.file.YamlConfiguration;
5 | import us.cyrien.mcutils.diagnosis.Diagnostics;
6 | import us.cyrien.mcutils.diagnosis.IReporter;
7 | import us.cyrien.minecordbot.Minecordbot;
8 | import us.cyrien.minecordbot.configuration.BotConfig;
9 |
10 | import java.io.File;
11 |
12 | public class CfgReporter implements IReporter {
13 |
14 | private String name;
15 | private int priority;
16 |
17 | public CfgReporter() {
18 | this.name = "Configuration Reporter";
19 | this.priority = 5;
20 | }
21 |
22 | @Override
23 | public String getName() {
24 | return name;
25 | }
26 |
27 | @Override
28 | public int getPriority() {
29 | return priority;
30 | }
31 |
32 | @Override
33 | public String report() {
34 | StringBuilder sb = new StringBuilder();
35 | File dataFolder = Minecordbot.getInstance().getDataFolder();
36 | File[] files = dataFolder.listFiles() == null ? new File[]{} : dataFolder.listFiles();
37 | for (File f : files)
38 | if (!f.isDirectory() && f.getName().contains("Config") && f.getPath().endsWith(".yml")) {
39 | FileConfiguration config = YamlConfiguration.loadConfiguration(f);
40 | if(config.getKeys(false).contains(BotConfig.Nodes.BOT_TOKEN.key()))
41 | config.set(BotConfig.Nodes.BOT_TOKEN.key(), "-- Token omitted for security --");
42 | String s = config.saveToString().replaceAll("\\R", Diagnostics.LINE_SEPARATOR);
43 | sb.append("-").append(f.getName()).append("-").append(Diagnostics.LINE_SEPARATOR);
44 | sb.append(s).append(Diagnostics.LINE_SEPARATOR);
45 | }
46 | return sb.toString();
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/accountSync/listener/UserConnectionListener.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.accountSync.listener;
2 |
3 | import org.bukkit.event.EventHandler;
4 | import org.bukkit.event.Listener;
5 | import org.bukkit.event.player.PlayerJoinEvent;
6 | import org.json.JSONException;
7 | import org.json.JSONObject;
8 | import us.cyrien.mcutils.logger.Logger;
9 | import us.cyrien.minecordbot.accountSync.DataKey;
10 | import us.cyrien.minecordbot.accountSync.Database;
11 | import us.cyrien.minecordbot.entity.UnifiedUser;
12 |
13 | public class UserConnectionListener implements Listener {
14 |
15 | @EventHandler
16 | public void onJoin(PlayerJoinEvent event) {
17 | JSONObject data = Database.get(event.getPlayer().getUniqueId().toString());
18 | UnifiedUser unifiedUser = new UnifiedUser(event.getPlayer());
19 | if(data == null) {
20 | Database.set(unifiedUser.getPlayer().getUniqueId().toString(), new JSONObject(unifiedUser.getDataAsMap()));
21 | } else if (checkDataNodes(unifiedUser, data)){
22 | if(!data.get(DataKey.MC_USERNAME.toString()).equals(event.getPlayer().getName())) {
23 | data.put(DataKey.MC_USERNAME.toString(), event.getPlayer().getName());
24 | Database.set(event.getPlayer().getUniqueId().toString(), new JSONObject(data));
25 | }
26 | } else {
27 | Logger.warn("There was an issue with " + event.getPlayer().getName() + "'s account sync data and have been re-initiated.");
28 | }
29 | }
30 |
31 | private boolean checkDataNodes(UnifiedUser unifiedUser, JSONObject data) {
32 | for(DataKey dataKey : DataKey.values())
33 | try {
34 | data.get(dataKey.toString());
35 | } catch (JSONException ex) {
36 | Database.set(unifiedUser.getPlayer().getUniqueId().toString(), new JSONObject(unifiedUser.getDataAsMap()));
37 | return false;
38 | }
39 | return true;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/reporters/InfoHeader.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.reporters;
2 |
3 | import net.dv8tion.jda.core.JDA;
4 | import net.dv8tion.jda.core.entities.Guild;
5 | import org.bukkit.Bukkit;
6 | import org.joda.time.DateTime;
7 | import org.joda.time.format.DateTimeFormat;
8 | import org.joda.time.format.DateTimeFormatter;
9 | import us.cyrien.mcutils.diagnosis.Diagnostics;
10 | import us.cyrien.mcutils.diagnosis.IReporter;
11 | import us.cyrien.minecordbot.Minecordbot;
12 |
13 | import java.util.List;
14 |
15 | public class InfoHeader implements IReporter {
16 |
17 | private int priority;
18 |
19 | public InfoHeader() {
20 | this.priority = 0;
21 | }
22 |
23 | @Override
24 | public String getName() {
25 | return null;
26 | }
27 |
28 | @Override
29 | public String report() {
30 | StringBuilder sb = new StringBuilder();
31 | JDA jda = Minecordbot.getInstance().getBot().getJda();
32 | DateTime dt = DateTime.now();
33 | DateTimeFormatter dTF = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
34 | String serverIP = Bukkit.getServer().getIp();
35 | String serverVersion = Bukkit.getVersion();
36 | int serverPort = Bukkit.getPort();
37 | List guilds = jda.getGuilds();
38 | sb.append(dt.toString(dTF)).append(Diagnostics.DOUBLE_LINE_SEPARATOR);
39 | sb.append("Server IP: ").append(serverIP).append(Diagnostics.LINE_SEPARATOR);
40 | sb.append("Port: ").append(serverPort).append(Diagnostics.LINE_SEPARATOR);
41 | sb.append("Version: ").append(serverVersion).append(Diagnostics.DOUBLE_LINE_SEPARATOR);
42 | sb.append("Guild(s):").append(Diagnostics.LINE_SEPARATOR);
43 | guilds.forEach(g -> {
44 | sb.append("- ").append(g.getName());
45 | sb.append(":(").append(g.getId()).append(")").append(Diagnostics.LINE_SEPARATOR);
46 | });
47 | return sb.toString();
48 | }
49 |
50 | @Override
51 | public int getPriority() {
52 | return priority;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/prefix/DiscordPlaceHolders.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.prefix;
2 |
3 | import net.dv8tion.jda.core.entities.Member;
4 | import net.dv8tion.jda.core.entities.Role;
5 | import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
6 | import us.cyrien.minecordbot.entity.MCBUser;
7 |
8 | import java.util.*;
9 |
10 | public enum DiscordPlaceHolders {
11 | CHANNEL {
12 | @Override
13 | public String toString() {
14 | return mre.getTextChannel().getName();
15 | }
16 | },
17 | GUILD {
18 | @Override
19 | public String toString() {
20 | return mre.getGuild().getName();
21 | }
22 | },
23 | SENDER {
24 | @Override
25 | public String toString() {
26 | return mre.getAuthor().getName();
27 | }
28 | },
29 | NAME {
30 | @Override
31 | public String toString() {
32 | MCBUser user = new MCBUser(mre);
33 | return user.getName();
34 | }
35 | },
36 | ROLE {
37 |
38 | @Override
39 | public String toString() {
40 | Member member = mre.getGuild().getMember(mre.getAuthor());
41 | Role role = getPrimaryRole(member);
42 | return role == null ? "" : role.getName();
43 | }
44 |
45 | private Role getPrimaryRole(Member member) {
46 | List roles = member.getRoles();
47 | if(roles == null) return null;
48 | if(roles.size() == 0) return null;
49 | Role role = roles.get(0);
50 | for(Role r : roles)
51 | if(role.getPosition() < r.getPosition())
52 | role = r;
53 | return role;
54 | }
55 |
56 | },
57 | ENAME {
58 | @Override
59 | public String toString() {
60 | return mre.getMember().getEffectiveName();
61 | }
62 | };
63 |
64 | private static MessageReceivedEvent mre;
65 |
66 | public void init(MessageReceivedEvent mre) {
67 | DiscordPlaceHolders.mre = mre;
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/diagnosis/impl/DiagnosticsImpl.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.diagnosis.impl;
2 |
3 | import us.cyrien.mcutils.diagnosis.Diagnostics;
4 | import us.cyrien.mcutils.diagnosis.IReporter;
5 | import us.cyrien.mcutils.diagnosis.TypeDiagnosis;
6 |
7 | import java.io.File;
8 | import java.io.FileWriter;
9 | import java.io.IOException;
10 | import java.io.PrintWriter;
11 | import java.util.LinkedList;
12 |
13 | public class DiagnosticsImpl implements Diagnostics {
14 |
15 | private LinkedList reporters;
16 | private TypeDiagnosis typeDiagnosis;
17 |
18 | public DiagnosticsImpl setReporters(LinkedList reporters) {
19 | this.reporters = reporters;
20 | return this;
21 | }
22 |
23 | public DiagnosticsImpl setTypeDiagnosis(TypeDiagnosis typeDiagnosis) {
24 | this.typeDiagnosis = typeDiagnosis;
25 | return this;
26 | }
27 |
28 | @Override
29 | public LinkedList getReporters() {
30 | return null;
31 | }
32 |
33 | @Override
34 | public TypeDiagnosis getTypeDiagnosis() {
35 | return typeDiagnosis;
36 | }
37 |
38 | @Override
39 | public File fullReport() {
40 | try {
41 | File file = new File("Diagnostics.txt");
42 | FileWriter fW = new FileWriter(file);
43 | PrintWriter pWriter = new PrintWriter(fW);
44 | pWriter.println(buildReport());
45 | pWriter.flush();
46 | pWriter.close();
47 | return file;
48 | } catch (IOException e) {
49 | e.printStackTrace();
50 | }
51 | return null;
52 | }
53 |
54 |
55 |
56 | private String buildReport() {
57 | final StringBuilder sb = new StringBuilder();
58 | reporters.forEach(r -> {
59 | if(r.reportHeader() != null) {
60 | sb.append(r.reportHeader());
61 | }
62 | sb.append(Diagnostics.LINE_SEPARATOR).append(r.report())
63 | .append(Diagnostics.DOUBLE_LINE_SEPARATOR);
64 | });
65 | return sb.toString();
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/commands/discordCommand/PurgeCmd.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.commands.discordCommand;
2 |
3 | import com.jagrosh.jdautilities.commandclient.CommandEvent;
4 | import net.dv8tion.jda.core.entities.Message;
5 | import us.cyrien.minecordbot.Bot;
6 | import us.cyrien.minecordbot.Minecordbot;
7 | import us.cyrien.minecordbot.commands.MCBCommand;
8 | import us.cyrien.minecordbot.localization.Locale;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | public class PurgeCmd extends MCBCommand {
14 |
15 | public PurgeCmd(Minecordbot minecordbot) {
16 | super(minecordbot);
17 | this.name = "purge";
18 | this.help = Locale.getCommandsMessage("purge.description").finish();
19 | this.arguments = "";
20 | this.category = Bot.OWNER;
21 | this.ownerCommand = true;
22 | this.type = Type.EMBED;
23 | }
24 |
25 | @Override
26 | protected void doCommand(CommandEvent event) {
27 | String args = event.getArgs();
28 | int num = 100;
29 | try {
30 | if (!args.isEmpty())
31 | num = Integer.parseInt(args);
32 | } catch (NumberFormatException e) {
33 | respond(event, Locale.getCommandsMessage("purge.invalidNum").finish());
34 | return;
35 | }
36 | if (num < 1 || num > 100) {
37 | respond(event, Locale.getCommandsMessage("purge.invalidNum").finish());
38 | return;
39 | }
40 | try {
41 | event.getChannel().getHistory().retrievePast(num == 100 ? 100 : num + 1).queue(success -> {
42 | List list = new ArrayList<>(success);
43 | list.forEach(m -> m.delete().queue());
44 | respond(event, Locale.getCommandsMessage("purge.deleting").finish(), (m) -> m.delete().queue());
45 | }, failure -> respond(event, Locale.getCommandsMessage("purge.failedToRetrieve").finish()));
46 | } catch (Exception e) {
47 | respond(event, Locale.getCommandsMessage("purge.couldNotRetrieve").finish());
48 | }
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/chat/listeners/mcListeners/DeathListener.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.chat.listeners.mcListeners;
2 |
3 | import org.bukkit.ChatColor;
4 | import org.bukkit.event.EventHandler;
5 | import org.bukkit.event.EventPriority;
6 | import org.bukkit.event.entity.PlayerDeathEvent;
7 | import us.cyrien.mcutils.logger.Logger;
8 | import us.cyrien.minecordbot.Minecordbot;
9 | import us.cyrien.minecordbot.configuration.BroadcastConfig;
10 | import us.cyrien.minecordbot.configuration.ModChannelConfig;
11 |
12 | public class DeathListener extends MCBListener {
13 |
14 | public DeathListener(Minecordbot mcb) {
15 | super(mcb);
16 | }
17 |
18 | @EventHandler(priority = EventPriority.HIGHEST)
19 | public void onPlayerDeath(PlayerDeathEvent event) {
20 | boolean isDeathBroadCast = configsManager.getBroadcastConfig().getBoolean(BroadcastConfig.Nodes.PLAYER_DEATH);
21 | boolean allowIncog = configsManager.getBroadcastConfig().getBoolean(BroadcastConfig.Nodes.HIDE_INCOGNITO);
22 | if (isDeathBroadCast) {
23 | if (allowIncog) {
24 | if (!event.getEntity().hasPermission("minecordbot.incognito")) {
25 | sendDeathMessage(event);
26 | }
27 | } else
28 | sendDeathMessage(event);
29 | }
30 | }
31 |
32 | private void sendDeathMessage(PlayerDeathEvent event) {
33 | if(!safeToSend(event))
34 | return;
35 | boolean bc = configsManager.getModChannelConfig().getBoolean(ModChannelConfig.Nodes.SEE_PLAYER_DEATH);
36 | String msg = ChatColor.stripColor(event.getDeathMessage());
37 | messenger.sendMessageToAllBoundChannel("```css" + "\n[" + msg + "]\n```");
38 | if (bc)
39 | messenger.sendMessageToAllModChannel("```css" + "\n[" + msg + "]\n```");
40 | }
41 |
42 | private boolean safeToSend(PlayerDeathEvent event) {
43 | boolean safe = event.getDeathMessage() != null && !event.getDeathMessage().isEmpty();
44 | if(!safe)
45 | Logger.warn("Previous PlayerDeathEvent message is null or missing!");
46 | return safe;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/api/IMessenger.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.api;
2 |
3 | import net.dv8tion.jda.core.entities.Message;
4 | import net.dv8tion.jda.core.entities.MessageEmbed;
5 | import net.dv8tion.jda.core.entities.TextChannel;
6 | import net.dv8tion.jda.core.entities.User;
7 | import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
8 | import us.cyrien.minecordbot.chat.exception.IllegalTextChannelException;
9 |
10 | import java.util.function.Consumer;
11 |
12 | public interface IMessenger {
13 |
14 | //To Minecraft
15 | void sendGlobalMessageToMC(String message);
16 |
17 | //To Discord
18 | void sendMessage(MessageReceivedEvent e, String message, Consumer consumer) ;
19 |
20 | void sendMessageEmbed(MessageReceivedEvent e, MessageEmbed me, Consumer consumer);
21 |
22 | void sendMessageEmbed(MessageReceivedEvent e, MessageEmbed me);
23 |
24 | void sendMessage(MessageReceivedEvent e, String message);
25 |
26 | void sendTempMessage(MessageReceivedEvent e, String message, int duration);
27 |
28 | void sendTempMessageEmbed(MessageReceivedEvent e, MessageEmbed me, int duration);
29 |
30 | void sendMessageToAllBoundChannel(String message);
31 |
32 | void sendMessageEmbedToAllBoundChannel(MessageEmbed messageEmbed);
33 |
34 | void sendMessageToAllModChannel(String message);
35 |
36 | void sendMessageEmbedToAllModChannel(MessageEmbed messageEmbed);
37 |
38 | void sendMessageEmbedToDiscord(TextChannel textChannel, MessageEmbed message);
39 |
40 | void sendMessageToDiscord(TextChannel textchannel, String message) ;
41 |
42 | //By ID stuff
43 | void sendMessageEmbedToDiscordByID(String id, MessageEmbed message) throws IllegalTextChannelException;
44 |
45 | void sendMessageToDiscordByID(String id, String message) throws IllegalTextChannelException ;
46 |
47 | void sendTempMessageToDiscordByID(String id, String message, int duration) throws IllegalTextChannelException;
48 |
49 | void sendTempMessageEmbedToDiscordByID(String id, MessageEmbed message, int duration) throws IllegalTextChannelException;
50 |
51 | void sendMessageToDM(User user, String message);
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/configuration/BaseConfig.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.configuration;
2 |
3 | import us.cyrien.mcutils.config.Config;
4 | import us.cyrien.mcutils.config.ConfigManager;
5 | import us.cyrien.mcutils.logger.Logger;
6 |
7 | import java.io.File;
8 | import java.util.List;
9 |
10 | public abstract class BaseConfig {
11 |
12 | private final String[] header;
13 | private ConfigManager configManager;
14 | protected Config config;
15 |
16 | public BaseConfig(ConfigManager configManager, String[] header) {
17 | this.configManager = configManager;
18 | this.header = header;
19 | }
20 |
21 | void initNode(Node node) {
22 | String[] comment = node.getComment();
23 | if (config.get(node.key()) == null) {
24 | config.set(node.key(), node.getDefaultValue(), comment);
25 | config.saveConfig();
26 | }
27 | }
28 |
29 | public boolean init() {
30 | File f = configManager.getConfigFile(this.getClass().getSimpleName() + ".yml");
31 | if (!f.exists()) {
32 | Logger.warn(this.getClass().getSimpleName() + ".yml" + " have been generated or new fields have been added. " +
33 | "Please make sure to fill in all config fields correctly. Server will be stopped for safety.");
34 | config = configManager.getNewConfig(this.getClass().getSimpleName() + ".yml", header);
35 | initialize();
36 | return false;
37 | }
38 | config = configManager.getNewConfig(this.getClass().getSimpleName() + ".yml", header);
39 | initialize();
40 | return true;
41 | }
42 |
43 | public String getString(Node node) {
44 | return config.getString(node.key());
45 | }
46 |
47 | public boolean getBoolean(Node node) {
48 | return config.getBoolean(node.key());
49 | }
50 |
51 | public int getInt(Node node) {
52 | return config.getInt(node.key());
53 | }
54 |
55 | public List getList(Node node) {
56 | return config.getList(node.key());
57 | }
58 |
59 | public abstract void initialize();
60 |
61 | public Config getConfig() {
62 | return config;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/commands/minecraftCommand/McbCommands.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.commands.minecraftCommand;
2 |
3 |
4 | import org.bukkit.ChatColor;
5 | import org.bukkit.command.CommandSender;
6 | import us.cyrien.mcutils.annotations.Command;
7 | import us.cyrien.mcutils.annotations.Sender;
8 | import us.cyrien.minecordbot.Minecordbot;
9 |
10 | public class McbCommands {
11 | @Command(aliases = {"minecordbot", "mcb"}, usage = "do /minecordbot help", desc = "general Minecordbot commands")
12 | public void command(@Sender CommandSender commandSender, String s) {
13 | if (s.equalsIgnoreCase("help")) {
14 | help(commandSender);
15 | } else if (s.equalsIgnoreCase("reload") && commandSender.hasPermission("minecordbot.reload")) {
16 | Minecordbot.getInstance().getMcbConfigsManager().reloadAllConfig();
17 | Minecordbot.getInstance().getMcbConfigsManager().setupConfigurations();
18 | commandSender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&a[&6Minecordbot&a] Reloaded configuration!"));
19 | } else if(s.equalsIgnoreCase("start")){
20 | Minecordbot mcb = Minecordbot.getInstance();
21 | if(mcb.getBot().getJda() == null) {
22 | mcb.getBot().start();
23 | } else {
24 | commandSender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&a[&6Minecordbot&a] Minecordbot already running!"));
25 | }
26 | } else {
27 | help(commandSender);
28 | }
29 | }
30 |
31 | public boolean help(CommandSender cs) {
32 | cs.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&l=== MineCordBot Commands ==="));
33 | cs.sendMessage("/dme ");
34 | cs.sendMessage("/dcmd ");
35 | cs.sendMessage("/mcbsync ");
36 | cs.sendMessage("/syncconfirm ");
37 | cs.sendMessage("/mcb reload");
38 | cs.sendMessage("/mcb start");
39 | cs.sendMessage(ChatColor.translateAlternateColorCodes('&', "&0&7do \"/help \" for more \n detailed command help"));
40 | cs.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&l==========================="));
41 | return false;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/hooks/VaultHook.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.hooks;
2 |
3 | import net.milkbowl.vault.chat.Chat;
4 | import net.milkbowl.vault.economy.Economy;
5 | import net.milkbowl.vault.permission.Permission;
6 | import org.bukkit.Bukkit;
7 | import org.bukkit.plugin.RegisteredServiceProvider;
8 | import us.cyrien.mcutils.hook.PluginHook;
9 |
10 | public class VaultHook extends PluginHook {
11 |
12 | private RegisteredServiceProvider rgP;
13 | private RegisteredServiceProvider rgC;
14 | private RegisteredServiceProvider rgE;
15 |
16 | private static Chat chat;
17 | private static Permission permission;
18 | private static Economy economy;
19 |
20 | public VaultHook() {
21 | this.name = "Vault";
22 | setupEconomy();
23 | setupChat();
24 | setupPermissions();
25 | }
26 |
27 | private boolean setupEconomy() {
28 | if (!available()) {
29 | return false;
30 | }
31 | RegisteredServiceProvider rsp = Bukkit.getServicesManager().getRegistration(Economy.class);
32 | if (rsp == null) {
33 | return false;
34 | }
35 | economy = rsp.getProvider();
36 | return economy != null;
37 | }
38 |
39 | private boolean setupChat() {
40 | if (!available()) {
41 | return false;
42 | }
43 | RegisteredServiceProvider rsp = Bukkit.getServicesManager().getRegistration(Chat.class);
44 | if (rsp == null) {
45 | return false;
46 | }
47 | chat = rsp.getProvider();
48 | return chat != null;
49 | }
50 |
51 | private boolean setupPermissions() {
52 | if (!available()) {
53 | return false;
54 | }
55 | RegisteredServiceProvider rsp = Bukkit.getServicesManager().getRegistration(Permission.class);
56 | if (rsp == null) {
57 | return false;
58 | }
59 | permission = rsp.getProvider();
60 | return permission != null;
61 | }
62 |
63 | public Chat getChat() {
64 | return chat;
65 | }
66 |
67 | public Permission getPermission() {
68 | return permission;
69 | }
70 |
71 | public Economy getEconomy() {
72 | return economy;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/commands/discordCommand/McUUIDCmd.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.commands.discordCommand;
2 |
3 | import com.google.gson.JsonObject;
4 | import com.google.gson.JsonParser;
5 | import com.jagrosh.jdautilities.commandclient.CommandEvent;
6 | import net.dv8tion.jda.core.EmbedBuilder;
7 | import us.cyrien.minecordbot.Bot;
8 | import us.cyrien.minecordbot.Minecordbot;
9 | import us.cyrien.minecordbot.commands.MCBCommand;
10 | import us.cyrien.minecordbot.localization.Locale;
11 | import us.cyrien.minecordbot.utils.HTTPUtils;
12 | import us.cyrien.minecordbot.utils.UUIDFetcher;
13 |
14 | import java.io.IOException;
15 |
16 | public class McUUIDCmd extends MCBCommand{
17 |
18 | public McUUIDCmd(Minecordbot minecordbot) {
19 | super(minecordbot);
20 | this.name = "mcuuid";
21 | this.help = Locale.getCommandsMessage("mcuuid.description").finish();
22 | this.arguments = "";
23 | this.category = Bot.INFO;
24 | this.type = Type.EMBED;
25 | }
26 |
27 | @Override
28 | protected void doCommand(CommandEvent e) {
29 | if (e.getArgs().isEmpty()) {
30 | respond(ResponseLevel.LEVEL_3, Locale.getCommandMessage("invalid-arguments").finish(), e).queue();
31 | return;
32 | }
33 |
34 | String s = null;
35 | try {
36 | s = HTTPUtils.performGetRequest(HTTPUtils.constantURL("https://api.mojang.com/users/profiles/minecraft/" + e.getArgs()));
37 | } catch (IOException ex) {
38 | respond(ResponseLevel.LEVEL_3, "Error getting player's UUID: `java.io.IOException`", e).queue();
39 | return;
40 | }
41 | try {
42 | JsonObject json = (new JsonParser()).parse(s).getAsJsonObject();
43 | EmbedBuilder eb = new EmbedBuilder();
44 | eb.addField("**" + e.getArgs() + "'s UUID**:", "`" + UUIDFetcher.getUUID(json.get("id").getAsString()).toString() + "`", false);
45 | respond(embedMessage(e, eb.build(), null), e).queue();
46 | } catch (IllegalStateException ex) {
47 | respond(ResponseLevel.LEVEL_3, Locale.getCommandsMessage("mcuuid.cannot-find").finish(), e).queue();
48 | } catch (Exception ex) {
49 | ex.printStackTrace();
50 | respond(ResponseLevel.LEVEL_3, Locale.getCommandsMessage("mcuuid.error").finish(), e).queue();
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/configuration/ChatConfig.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.configuration;
2 |
3 | import us.cyrien.mcutils.config.ConfigManager;
4 |
5 | public class ChatConfig extends BaseConfig {
6 |
7 | public ChatConfig(ConfigManager configManager, String[] header) {
8 | super(configManager, header);
9 | }
10 |
11 | @Override
12 | public void initialize() {
13 | for (Nodes node : Nodes.values())
14 | initNode(node);
15 | }
16 |
17 | public enum Nodes implements Node {
18 | RELAY_CHANNELS("Relay_Channels", new String[]{"MCBChannel ID's of text channels you", "want to bind Minecraft chat with"},
19 | new String[]{"12345", "12345"}),
20 | MESSAGE_FORMAT("Message_Format", new String[]{"Formatting codes for messages coming from Discord"}, "&7"),
21 | DISCORD_PREFIX("Discord_Prefix", new String[]{"Prefix of messages that came from Discord.", "This can be formatted."}, "&6&l[Discord] &r{role} {ename}"),
22 | MINECRAFT_PREFIX("Minecraft_Prefix", new String[]{"Prefix of messages that came from Minecraft."}, "[Minecraft] {erank} {ename}"),
23 | BLOCKED_PREFIX("Blocked_Prefix", new String[]{"If a message from Discord is a command with any of the prefix",
24 | "below. That message won't be relayed to Minecraft.",
25 | "You can block your own bot's prefix", "by placing {this} place holder."}, new String[]{"~", "~~", "{this}"}),
26 | BLOCKED_BOTS("Blocked_Bots", new String[]{"If a message from Discord came from any of the Bots below.",
27 | "That message won't be relayed to Minecraft."}, new String[]{"123123123", "123123123"});
28 |
29 |
30 | private String key;
31 | private String[] comment;
32 | private Object defaultValue;
33 |
34 | Nodes(String key, String[] comment, Object defaultValue) {
35 | this.key = key;
36 | this.comment = comment;
37 | this.defaultValue = defaultValue;
38 | }
39 |
40 | public Object getDefaultValue() {
41 | return defaultValue;
42 | }
43 |
44 | public String[] getComment() {
45 | return comment;
46 | }
47 |
48 | public String key() {
49 | return toString();
50 | }
51 |
52 | @Override
53 | public String toString() {
54 | return key;
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/entity/MCBUser.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.entity;
2 |
3 | import com.jagrosh.jdautilities.commandclient.CommandEvent;
4 | import net.dv8tion.jda.core.entities.Guild;
5 | import net.dv8tion.jda.core.entities.User;
6 | import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
7 | import org.bukkit.entity.Player;
8 | import us.cyrien.minecordbot.Minecordbot;
9 | import us.cyrien.minecordbot.utils.SearchUtil;
10 |
11 | import java.util.HashMap;
12 | import java.util.UUID;
13 |
14 | public class MCBUser {
15 |
16 | private String name;
17 | private HashMap nickNames;
18 | private String ID;
19 | private UUID mcUUID;
20 | private User user;
21 |
22 | public MCBUser(MessageReceivedEvent e) {
23 | nickNames = new HashMap<>();
24 | name = e.getAuthor().getName();
25 | nickNames.put(e.getGuild(), e.getMember().getNickname());
26 | ID = e.getAuthor().getId();
27 | mcUUID = null;
28 | user = e.getAuthor();
29 | }
30 |
31 | public MCBUser(CommandEvent e) {
32 | this(e.getEvent());
33 | }
34 |
35 | public MCBUser(User user, Guild guild) {
36 | nickNames = new HashMap<>();
37 | name = user.getName();
38 | nickNames.put(guild, guild.getMember(user).getNickname());
39 | ID = user.getId();
40 | }
41 |
42 | public MCBUser(User user) {
43 | nickNames = new HashMap<>();
44 | name = user.getName();
45 | ID = user.getId();
46 | Minecordbot.getInstance().getBot().getJda().getMutualGuilds(user).forEach(guild -> nickNames.put(guild, guild.getMember(user).getNickname()));
47 | }
48 |
49 | public Player parseAsPlayer() {
50 | return SearchUtil.findPlayerInDatabase(this.ID);
51 | }
52 |
53 | public User getUser() {
54 | return user;
55 | }
56 |
57 | public UUID getMcUUID() {
58 | return mcUUID;
59 | }
60 |
61 | public void setMcUUID(UUID uuid) {
62 | mcUUID = uuid;
63 | }
64 |
65 | public String getName() {
66 | return name;
67 | }
68 |
69 | public HashMap getNickNames() {
70 | return nickNames;
71 | }
72 |
73 | public String getID() {
74 | return ID;
75 | }
76 |
77 | @Override
78 | public String toString() {
79 | return getName() + "|" + getNickNames().toString() + "|" + getID();
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/configuration/BotConfig.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.configuration;
2 |
3 | import us.cyrien.mcutils.config.ConfigManager;
4 |
5 | public class BotConfig extends BaseConfig {
6 |
7 | public BotConfig(ConfigManager configManager, String[] header) {
8 | super(configManager, header);
9 | }
10 |
11 | @Override
12 | public void initialize() {
13 | for (Nodes node : Nodes.values())
14 | initNode(node);
15 | }
16 |
17 | public enum Nodes implements Node {
18 | BOT_TOKEN("Bot_Token", new String[]{"Bot token can be found on your", "Discord application page."}, "sample.token"),
19 | BOT_ID("Bot_ID", new String[]{"Bot ID, this is also known as Client ID", "on your Discord application page."}, "12345"),
20 | OWNER_ID("Owner_ID", new String[]{"Owner ID of the owner of the bot, server, or guild.",
21 | "You can easily get your id by right", "clicking your self and copy id.",
22 | "This only works when developer mode is enabled.",
23 | "Go to settings>appearance and enable developer mode"}, "12345"),
24 | COMMAND_TRIGGER("Command_Trigger", new String[]{"Set of character that distinguish if it's a command."}, "!!"),
25 | DELETE_RESPONSE("Delete_Response", new String[]{"Should bot's command responses be deleted after 5 minutes?"}, false),
26 | LOCALICAZATION("Localization", new String[]{"What language should the bot respond with"}, "en"),
27 | DEFAULT_GAME("Default_Game", new String[]{"This will be the game of the bot", "and will be shown under the name",
28 | "of the bot as \"Playing \""}, "default");
29 |
30 | private String key;
31 | private String[] comment;
32 | private Object defaultValue;
33 |
34 | Nodes(String key, String[] comment, Object defaultValue) {
35 | this.key = key;
36 | this.comment = comment;
37 | this.defaultValue = defaultValue;
38 | }
39 |
40 | public Object getDefaultValue() {
41 | return defaultValue;
42 | }
43 |
44 | public String[] getComment() {
45 | return comment;
46 | }
47 |
48 | public String key() {
49 | return toString();
50 | }
51 |
52 | @Override
53 | public String toString() {
54 | return key;
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/configuration/BroadcastConfig.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.configuration;
2 |
3 | import us.cyrien.mcutils.config.ConfigManager;
4 |
5 | public class BroadcastConfig extends BaseConfig {
6 |
7 | public BroadcastConfig(ConfigManager configManager, String[] header) {
8 | super(configManager, header);
9 | }
10 |
11 | @Override
12 | public void initialize() {
13 | for (Nodes node : Nodes.values()) {
14 | initNode(node);
15 | }
16 | }
17 |
18 | public enum Nodes implements Node {
19 | PLUGIN_BROADCAST("See_Plugin_Broadcast", new String[]{"Will broadcast from other plugins be relayed to Discord?"}, true),
20 | PLAYER_JOIN("See_Player_Join", new String[]{"Will player join event broadcast be relayed to Discord?"}, true),
21 | PLAYER_QUIT("See_Player_Quit", new String[]{"Will player quit event broadcast be relayed to Discord?"}, true),
22 | PLAYER_DEATH("See_Player_Death", new String[]{"Will player death event broadcast be relayed to Discord?"}, true),
23 | CLEARLAG("See_ClearLag", new String[]{"Will ClearLag broadcasts be relayed to Discord?"}, true),
24 | SERVER_START("See_Server_Start", new String[]{
25 | "Do you want a broadcast",
26 | "when server starts?"}, true),
27 | SERVER_SHUT("See_Server_Shut", new String[]{
28 | "Do you want a broadcast",
29 | "when server starts?"}, true),
30 | HIDE_INCOGNITO("Hide_Incognito_Player", new String[]{"Do players with minecordbot.incognito",
31 | "permission be hidden from",
32 | "Join/Quit broadcast that are being relayed to Discord."}, false);
33 |
34 | private String key;
35 | private String[] comment;
36 | private Object defaultValue;
37 |
38 | Nodes(String key, String[] comment, Object defaultValue) {
39 | this.key = key;
40 | this.comment = comment;
41 | this.defaultValue = defaultValue;
42 | }
43 |
44 | public Object getDefaultValue() {
45 | return defaultValue;
46 | }
47 |
48 | public String[] getComment() {
49 | return comment;
50 | }
51 |
52 | public String key() {
53 | return toString();
54 | }
55 |
56 | @Override
57 | public String toString() {
58 | return key;
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/commands/discordCommand/TpsCmd.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.commands.discordCommand;
2 |
3 | import com.jagrosh.jdautilities.commandclient.CommandEvent;
4 | import net.dv8tion.jda.core.EmbedBuilder;
5 | import net.dv8tion.jda.core.entities.MessageEmbed;
6 | import us.cyrien.minecordbot.Bot;
7 | import us.cyrien.minecordbot.Minecordbot;
8 | import us.cyrien.minecordbot.commands.MCBCommand;
9 | import us.cyrien.minecordbot.commands.Updatable;
10 | import us.cyrien.minecordbot.localization.Locale;
11 |
12 | import java.text.DecimalFormat;
13 |
14 | public class TpsCmd extends MCBCommand implements Updatable {
15 |
16 | public TpsCmd(Minecordbot minecordbot) {
17 | super(minecordbot);
18 | this.name = "tps";
19 | this.help = Locale.getCommandsMessage("tps.description").finish();
20 | this.category = Bot.INFO;
21 | this.type = Type.EMBED;
22 | }
23 |
24 | @Override
25 | protected void doCommand(CommandEvent e) {
26 | respond("Generating info...", e).queue(message -> {
27 | mcb.getChatManager().addSavedTPS(message, e);
28 | update();
29 | });
30 | }
31 |
32 | private MessageEmbed generate(double tps) {
33 | EmbedBuilder eb = new EmbedBuilder();
34 | double lagPercentage = Math.round((1.0D - tps / 20.0D) * 100.0D);
35 | eb.addField("TPS:", "`" + new DecimalFormat("#.####").format(tps) + "`", true);
36 | eb.addField("Lag Percentage: ", lagPercentage + "%", true);
37 | eb.addField("Free RAM: ", Runtime.getRuntime().freeMemory() / 1024L / 1024L + "mb", true);
38 | eb.addField("Total Memory: ", Runtime.getRuntime().totalMemory() / 1024L / 1024L + "mb", true);
39 | eb.addField("Allocated Memory: ", Runtime.getRuntime().totalMemory() / 1024L / 1024L + "mb", true);
40 | eb.addBlankField(true);
41 | return eb.build();
42 | }
43 |
44 | public void update() {
45 | double tps = mcb.getUpTimer().getCurrentTps();
46 |
47 | ResponseLevel level;
48 | if (tps >= 18.0D) {
49 | level = ResponseLevel.LEVEL_1;
50 | } else if (tps >= 15.0D) {
51 | level = ResponseLevel.LEVEL_2;
52 | } else {
53 | level = ResponseLevel.LEVEL_3;
54 | }
55 |
56 | mcb.getChatManager().getSavedTPS().forEach((msg, event) ->
57 | msg.editMessage(embedMessage(event, generate(tps), level, "Information")).queue());
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/localization/Locale.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.localization;
2 |
3 | import org.bukkit.Bukkit;
4 | import org.bukkit.configuration.file.YamlConfiguration;
5 | import us.cyrien.mcutils.logger.Logger;
6 | import us.cyrien.minecordbot.configuration.BotConfig;
7 | import us.cyrien.minecordbot.configuration.MCBConfigsManager;
8 |
9 | import java.io.File;
10 |
11 |
12 | public class Locale {
13 | private static MCBConfigsManager configsManager;
14 |
15 | public static void init(MCBConfigsManager config) {
16 | Locale.configsManager = config;
17 | }
18 |
19 | private static YamlConfiguration getLocalization() {
20 | String loc = configsManager.getBotConfig().getString(BotConfig.Nodes.LOCALICAZATION);
21 | File f = new File(Bukkit.getPluginManager().getPlugin("MineCordBot").getDataFolder() + "/localizations/" + loc + ".yml");
22 | if (!f.exists())
23 | f = new File(Bukkit.getPluginManager().getPlugin("MineCordBot").getDataFolder() + "localizations/en.yml");
24 | return YamlConfiguration.loadConfiguration(f);
25 | }
26 |
27 | private static String getTranslatedMessage(String messagePath) {
28 | String s = getLocalization().getString(messagePath);
29 | if (s == null) {
30 | Logger.warn("Can not get localization for " + messagePath + ". Returned path");
31 | return messagePath;
32 | }
33 | return getLocalization().getString(messagePath);
34 | }
35 |
36 | public static Formatter getEventMessage(String path) {
37 | return new Formatter(getTranslatedMessage("mcb.event." + path));
38 | }
39 |
40 | public static Formatter getCommandMessage(String path) {
41 | return new Formatter(getTranslatedMessage("mcb.command." + path));
42 | }
43 |
44 | public static Formatter getCommandsMessage(String path) {
45 | return new Formatter(getTranslatedMessage("mcb.commands." + path));
46 | }
47 |
48 | public static Formatter getResponsLvlMsg(String path) {
49 | return new Formatter(getTranslatedMessage("mcb.responselevel." + path));
50 | }
51 |
52 | public static class Formatter {
53 | private String message;
54 |
55 | public Formatter(String message) {
56 | this.message = message;
57 | }
58 |
59 | public String f(Object... objects) {
60 | return String.format(message, objects);
61 | }
62 |
63 | public String finish() {
64 | return message;
65 | }
66 | }
67 | }
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/configuration/MCBConfigsManager.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.configuration;
2 |
3 | import us.cyrien.mcutils.config.ConfigManager;
4 |
5 |
6 | public class MCBConfigsManager {
7 |
8 | private final String[] BOTCONFIG_HEADER = new String[]{"Bot Configuration", "All bot configuration"};
9 | private final String[] CHATCONFIG_HEADER = new String[]{"Chat Configuration", "All chat configurations"};
10 | private final String[] BROADCASTCONFIG_HEADER = new String[]{"Broadcast Configuration", "All broadcast configuration",
11 | "Some nodes below will also be", "effective to Mod Channels"};
12 | private final String[] MODCHANNELCONFIG_HEADER = new String[]{"Mod Channel Configuration", "All mod channel configuration"};
13 | private final String[] PERMISSIONCONFIG_HEADER = new String[]{"Permission Configuration", " ", "can be configured using perm command"};
14 |
15 | private ConfigManager manager;
16 | private BaseConfig[] configs;
17 |
18 | public MCBConfigsManager(ConfigManager manager) {
19 | this.manager = manager;
20 | configs = new BaseConfig[]{new BotConfig(manager, BOTCONFIG_HEADER), new ChatConfig(manager, CHATCONFIG_HEADER),
21 | new BroadcastConfig(manager, BROADCASTCONFIG_HEADER), new ModChannelConfig(manager, MODCHANNELCONFIG_HEADER),
22 | new PermissionConfig(manager, PERMISSIONCONFIG_HEADER)};
23 | }
24 |
25 | public boolean setupConfigurations() {
26 | boolean shutdown = true;
27 | for (BaseConfig bCfg : configs) {
28 | if (!bCfg.init())
29 | shutdown = false;
30 | }
31 | return shutdown;
32 | }
33 |
34 | public void reloadAllConfig() {
35 | for (BaseConfig bCfg : configs) {
36 | bCfg.getConfig().reloadConfig();
37 | }
38 | }
39 |
40 | public ConfigManager getManager() {
41 | return manager;
42 | }
43 |
44 | public BotConfig getBotConfig() {
45 | return (BotConfig) configs[0];
46 | }
47 |
48 | public ChatConfig getChatConfig() {
49 | return (ChatConfig) configs[1];
50 | }
51 |
52 | public BroadcastConfig getBroadcastConfig() {
53 | return (BroadcastConfig) configs[2];
54 | }
55 |
56 | public ModChannelConfig getModChannelConfig() {
57 | return (ModChannelConfig) configs[3];
58 | }
59 |
60 | public PermissionConfig getPermConfig() {
61 | return (PermissionConfig) configs[4];
62 | }
63 |
64 | public BaseConfig[] getConfigs() {
65 | return configs;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/utils/mcpinger/pcping/MinecraftPingOptions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Adapted from the Wizardry License
3 | *
4 | * Copyright (c) 2016 DaPorkchop_
5 | *
6 | * Permission is hereby granted to any persons and/or organizations using this software to copy, modify, merge, publish, and distribute it.
7 | * Said persons and/or organizations are not allowed to use the software or any derivatives of the work for commercial use or any other means to generate income, nor are they allowed to claim this software as their own.
8 | *
9 | * The persons and/or organizations are also disallowed from sub-licensing and/or trademarking this software without explicit permission from DaPorkchop_.
10 | *
11 | * Any persons and/or organizations using this software must disclose their source code and have it publicly available, include this license, provide sufficient credit to the original authors of the project (IE: DaPorkchop_), as well as provide a link to the original project.
12 | *
13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14 | *
15 | */
16 | package us.cyrien.minecordbot.utils.mcpinger.pcping;
17 |
18 | /**
19 | * Storage class for {@link MinecraftPing} options.
20 | */
21 | public class MinecraftPingOptions {
22 |
23 | private String hostname;
24 | private int port = 25565;
25 | private int timeout = 2000;
26 | private String charset = "UTF-8";
27 |
28 | public String getHostname() {
29 | return this.hostname;
30 | }
31 |
32 | public MinecraftPingOptions setHostname(String hostname) {
33 | this.hostname = hostname;
34 | return this;
35 | }
36 |
37 | public int getPort() {
38 | return this.port;
39 | }
40 |
41 | public MinecraftPingOptions setPort(int port) {
42 | this.port = port;
43 | return this;
44 | }
45 |
46 | public int getTimeout() {
47 | return this.timeout;
48 | }
49 |
50 | public MinecraftPingOptions setTimeout(int timeout) {
51 | this.timeout = timeout;
52 | return this;
53 | }
54 |
55 | public String getCharset() {
56 | return this.charset;
57 | }
58 |
59 | public MinecraftPingOptions setCharset(String charset) {
60 | this.charset = charset;
61 | return this;
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/Frame.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils;
2 |
3 |
4 | import us.cyrien.mcutils.config.ConfigurationBuilder;
5 | import us.cyrien.mcutils.config.ConfigurationInjector;
6 | import us.cyrien.mcutils.diagnosis.ReportLoader;
7 | import us.cyrien.mcutils.dispatcher.help.HelpTopicUtil;
8 | import us.cyrien.mcutils.events.BukkitEventsInjector;
9 | import us.cyrien.mcutils.hook.HookInjector;
10 | import us.cyrien.mcutils.hook.HookLoader;
11 | import us.cyrien.mcutils.hook.IPluginHook;
12 | import us.cyrien.mcutils.inject.FrameInjector;
13 | import us.cyrien.mcutils.loader.CommandInjector;
14 | import us.cyrien.mcutils.logger.Logger;
15 | import us.cyrien.mcutils.module.ModuleInjector;
16 | import us.cyrien.mcutils.module.ModuleLoader;
17 |
18 | public class Frame {
19 | public static void main() {
20 | Logger.info("- Starting plugin framework initialization.");
21 |
22 | // Build configurations
23 | try {
24 | ConfigurationBuilder.buildAwaiting();
25 | } catch (Exception e) {
26 | Logger.err("- Error building configurations!");
27 | Logger.err(e.getMessage());
28 | e.printStackTrace();
29 | }
30 |
31 | new FrameInjector()
32 | .injector(new CommandInjector())
33 | .injector(new HookInjector())
34 | .injector(new ModuleInjector())
35 | .injector(new ConfigurationInjector())
36 | .injector(new BukkitEventsInjector())
37 | .injectAll();
38 | HelpTopicUtil.index();
39 |
40 | Logger.info("- Finished plugin framework initialization.");
41 | }
42 |
43 | /*
44 | * Util functions for adding modules, configurations and hooks.
45 | */
46 |
47 | /**
48 | * Register and load your module into Frame
49 | *
50 | * @param clazz Class containing your module
51 | */
52 | public static void addModule(Class clazz) {
53 | ModuleLoader.add(clazz);
54 | }
55 |
56 | /**
57 | * Register and load diagnostics reporter into Frame
58 | *
59 | * @param clazz Class that implements {@link IPluginHook}
60 | */
61 | public static void addReporter(Class clazz) {
62 | ReportLoader.addReporter(clazz);
63 | }
64 |
65 | public static void addConfiguration(Class clazz) {
66 | ConfigurationBuilder.add(clazz);
67 | }
68 |
69 | /**
70 | * Register specified hook in Frame
71 | *
72 | * @param clazz Class that implements {@link IPluginHook}
73 | */
74 | public static void addHook(Class extends IPluginHook> clazz) {
75 | HookLoader.addHook(clazz);
76 | }
77 |
78 | public static Object getConfig(Class clazz) {
79 | return ConfigurationBuilder.get(clazz);
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/chat/listeners/mcListeners/HelpOpListener.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.chat.listeners.mcListeners;
2 |
3 | import com.earth2me.essentials.Essentials;
4 | import com.earth2me.essentials.IUser;
5 | import com.earth2me.essentials.User;
6 | import com.earth2me.essentials.textreader.IText;
7 | import com.earth2me.essentials.textreader.SimpleTextInput;
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.entity.Player;
10 | import org.bukkit.event.EventHandler;
11 | import org.bukkit.event.EventPriority;
12 | import org.bukkit.event.player.PlayerCommandPreprocessEvent;
13 | import us.cyrien.minecordbot.Minecordbot;
14 | import us.cyrien.minecordbot.chat.Messenger;
15 | import us.cyrien.minecordbot.entity.UnifiedUser;
16 | import us.cyrien.minecordbot.HookContainer;
17 | import us.cyrien.minecordbot.utils.ArrayUtils;
18 |
19 | import java.util.Collection;
20 |
21 | public class HelpOpListener extends MCBListener {
22 |
23 | private final Essentials essentialsHook = HookContainer.getEssentialsHook().getPlugin();
24 | private Messenger messenger;
25 |
26 | public HelpOpListener(Minecordbot mcb) {
27 | super(mcb);
28 | messenger = new Messenger(mcb);
29 | }
30 |
31 | @EventHandler(priority = EventPriority.NORMAL)
32 | public void onServerCommand(PlayerCommandPreprocessEvent event) {
33 | if(essentialsHook != null) {
34 | String[] msgSplit = event.getMessage().split(" ");
35 | boolean isHelpOp = msgSplit[0].equals("/helpop") || msgSplit[0].contains("helpop");
36 | String message = ArrayUtils.concatenateArgs(1, msgSplit);
37 | IUser sender = essentialsHook.getUser(event.getPlayer());
38 | if (isHelpOp) {
39 | broadcastMessage(sender, "essentials.helpop.receive", message);
40 | }
41 | }
42 | }
43 |
44 | private void broadcastMessage(IUser sender, final String permission, final String message) {
45 | if(essentialsHook != null) {
46 | IText broadcast = new SimpleTextInput(message);
47 | final Collection players = (Collection) Bukkit.getOnlinePlayers();
48 | for (Player player : players) {
49 | final User user = essentialsHook.getUser(player);
50 | if ((permission == null && (sender == null || !user.isIgnoredPlayer(sender))) || (permission != null && user.isAuthorized(permission))) {
51 | for (String messageText : broadcast.getLines()) {
52 | UnifiedUser unifiedUser = new UnifiedUser(player);
53 | if (unifiedUser.isSynced())
54 | messenger.sendMessageToDM(unifiedUser.getMcbUser().getUser(), messageText);
55 | }
56 | }
57 | }
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/commands/discordCommand/McApiStatusCmd.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.commands.discordCommand;
2 |
3 | import com.google.gson.JsonElement;
4 | import com.google.gson.JsonObject;
5 | import com.google.gson.JsonParser;
6 | import com.jagrosh.jdautilities.commandclient.CommandEvent;
7 | import net.dv8tion.jda.core.EmbedBuilder;
8 | import us.cyrien.minecordbot.Bot;
9 | import us.cyrien.minecordbot.Minecordbot;
10 | import us.cyrien.minecordbot.commands.MCBCommand;
11 | import us.cyrien.minecordbot.localization.Locale;
12 | import us.cyrien.minecordbot.utils.HTTPUtils;
13 |
14 | import java.io.IOException;
15 | import java.util.Map;
16 |
17 | public class McApiStatusCmd extends MCBCommand {
18 |
19 | public McApiStatusCmd(Minecordbot minecordbot) {
20 | super(minecordbot);
21 | this.name = "mcstat";
22 | this.help = Locale.getCommandsMessage("mcstat.description").finish();
23 | this.category = Bot.INFO;
24 | this.type = Type.EMBED;
25 | }
26 |
27 | @Override
28 | protected void doCommand(CommandEvent event) {
29 | String s;
30 | try {
31 | s = HTTPUtils.performGetRequest(HTTPUtils.constantURL("https://mcapi.ca/mcstatus"));
32 | } catch (IOException ex) {
33 | respond(ResponseLevel.LEVEL_3, "Error getting server info: `java.io.IOException`", event).queue();
34 | return;
35 | }
36 |
37 | try {
38 | JsonObject json = (new JsonParser()).parse(s).getAsJsonObject();
39 | EmbedBuilder builder = new EmbedBuilder();
40 | builder.setTitle("**Mojang status:**", "https://mojang.com");
41 | boolean isAllOnline = true;
42 | int onlineCount = 0;
43 | for (Map.Entry entry : json.entrySet()) {
44 | if (entry.getValue().getAsJsonObject().get("status").getAsString().equals("Online")) {
45 | onlineCount++;
46 | builder.addField(entry.getKey(), "\u2B06 "+ "*Online*", true);
47 | } else {
48 | isAllOnline = false;
49 | builder.addField(entry.getKey(), "\u2B07 " + "*Offline*", true);
50 | }
51 | }
52 | if (isAllOnline) {
53 | respond(event, embedMessage(event, builder.build(), ResponseLevel.LEVEL_1));
54 | } else {
55 | if (onlineCount > 0) {
56 | respond(event, embedMessage(event, builder.build(), ResponseLevel.LEVEL_2));
57 | } else {
58 | respond(event, embedMessage(event, builder.build(), ResponseLevel.LEVEL_3));
59 | }
60 | }
61 | } catch (IllegalStateException e) {
62 | respond(ResponseLevel.LEVEL_3, "Unable to parse minecraft status!", event).queue();
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/commands/discordCommand/McSkinCmd.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.commands.discordCommand;
2 |
3 | import com.google.gson.JsonObject;
4 | import com.google.gson.JsonParser;
5 | import com.jagrosh.jdautilities.commandclient.CommandEvent;
6 | import net.dv8tion.jda.core.EmbedBuilder;
7 | import net.dv8tion.jda.core.MessageBuilder;
8 | import us.cyrien.minecordbot.Bot;
9 | import us.cyrien.minecordbot.Minecordbot;
10 | import us.cyrien.minecordbot.commands.MCBCommand;
11 | import us.cyrien.minecordbot.localization.Locale;
12 | import us.cyrien.minecordbot.utils.HTTPUtils;
13 | import us.cyrien.minecordbot.utils.MessageUtils;
14 | import us.cyrien.minecordbot.utils.UUIDFetcher;
15 |
16 | import java.io.IOException;
17 | import java.util.concurrent.TimeUnit;
18 |
19 | public class McSkinCmd extends MCBCommand {
20 |
21 | public McSkinCmd(Minecordbot minecordbot) {
22 | super(minecordbot);
23 | this.name = "mcskin";
24 | this.arguments = "";
25 | this.category = Bot.INFO;
26 | this.help = Locale.getCommandsMessage("mcskin.description").finish();
27 | this.type = Type.EMBED;
28 | }
29 |
30 | @Override
31 | protected void doCommand(CommandEvent e) {
32 | if (e.getArgs().isEmpty()) {
33 | respond(ResponseLevel.LEVEL_3, Locale.getCommandMessage("invalid-arguments").finish(), e).queue();
34 | return;
35 | }
36 |
37 | String s;
38 | try {
39 | s = HTTPUtils.performGetRequest(HTTPUtils.constantURL("https://api.mojang.com/users/profiles/minecraft/" + e.getArgs()));
40 | } catch (IOException ex) {
41 | respond(ResponseLevel.LEVEL_3, "Error getting player's UUID: `java.io.IOException`", e).queue();
42 | return;
43 | }
44 | try {
45 | JsonObject json = (new JsonParser()).parse(s).getAsJsonObject();
46 | EmbedBuilder eb = new EmbedBuilder();
47 |
48 | byte[] image = MessageUtils.downloadImage("https://crafatar.com/renders/body/" + UUIDFetcher.getUUID(json.get("id").getAsString()).toString() + "?overlay&default=MHF_Steve");
49 | eb.addField("**" + e.getArgs() + "'s Skin**:", "", false);
50 | eb.setImage("attachment://image.png");
51 | respond("querying skin...", e).queue((m) -> scheduler.schedule(() -> {
52 | m.delete().queue();
53 | e.getTextChannel().sendFile(image, "image.png", new MessageBuilder().setEmbed(embedMessage(e, eb.build(), ResponseLevel.DEFAULT, "Information")).build()).queue();
54 | }, 1, TimeUnit.SECONDS));
55 | } catch (IllegalStateException ex) {
56 | respond(ResponseLevel.LEVEL_3, Locale.getCommandsMessage("mcskin.cannot-find").finish(), e).queue();
57 | } catch (Exception ex) {
58 | ex.printStackTrace();
59 | respond(ResponseLevel.LEVEL_3, Locale.getCommandsMessage("mcskin.error").finish(), e).queue();
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/chat/entity/ConvoTracker.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.chat.entity;
2 |
3 | import org.bukkit.Bukkit;
4 | import org.bukkit.conversations.Conversation;
5 | import org.bukkit.conversations.ConversationAbandonedEvent;
6 | import org.bukkit.conversations.ManuallyAbandonedConversationCanceller;
7 |
8 | import java.util.Iterator;
9 | import java.util.LinkedList;
10 | import java.util.logging.Level;
11 |
12 | public class ConvoTracker {
13 |
14 | private LinkedList conversationQueue = new LinkedList();
15 |
16 | public ConvoTracker() {
17 | }
18 |
19 | public synchronized boolean beginConversation(Conversation conversation) {
20 | if (!this.conversationQueue.contains(conversation)) {
21 | this.conversationQueue.addLast(conversation);
22 | if (this.conversationQueue.getFirst() == conversation) {
23 | conversation.begin();
24 | conversation.outputNextPrompt();
25 | return true;
26 | }
27 | }
28 |
29 | return true;
30 | }
31 |
32 | public synchronized void abandonConversation(Conversation conversation, ConversationAbandonedEvent details) {
33 | if (!this.conversationQueue.isEmpty()) {
34 | if (this.conversationQueue.getFirst() == conversation) {
35 | conversation.abandon(details);
36 | }
37 |
38 | if (this.conversationQueue.contains(conversation)) {
39 | this.conversationQueue.remove(conversation);
40 | }
41 |
42 | if (!this.conversationQueue.isEmpty()) {
43 | ((Conversation) this.conversationQueue.getFirst()).outputNextPrompt();
44 | }
45 | }
46 |
47 | }
48 |
49 | public synchronized void abandonAllConversations() {
50 | LinkedList oldQueue = this.conversationQueue;
51 | this.conversationQueue = new LinkedList();
52 | Iterator var2 = oldQueue.iterator();
53 |
54 | while (var2.hasNext()) {
55 | Conversation conversation = (Conversation) var2.next();
56 |
57 | try {
58 | conversation.abandon(new ConversationAbandonedEvent(conversation, new ManuallyAbandonedConversationCanceller()));
59 | } catch (Throwable var5) {
60 | Bukkit.getLogger().log(Level.SEVERE, "Unexpected exception while abandoning a conversation", var5);
61 | }
62 | }
63 |
64 | }
65 |
66 | public synchronized void acceptConversationInput(String input) {
67 | if (this.isConversing()) {
68 | ((Conversation) this.conversationQueue.getFirst()).acceptInput(input);
69 | }
70 |
71 | }
72 |
73 | public synchronized boolean isConversing() {
74 | return !this.conversationQueue.isEmpty();
75 | }
76 |
77 | public synchronized boolean isConversingModaly() {
78 | return this.isConversing() && ((Conversation) this.conversationQueue.getFirst()).isModal();
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/commands/discordCommand/McServerCmd.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.commands.discordCommand;
2 |
3 | import com.jagrosh.jdautilities.commandclient.CommandEvent;
4 | import net.dv8tion.jda.core.EmbedBuilder;
5 | import net.dv8tion.jda.core.MessageBuilder;
6 | import org.bukkit.ChatColor;
7 | import sun.misc.BASE64Decoder;
8 | import us.cyrien.minecordbot.Bot;
9 | import us.cyrien.minecordbot.Minecordbot;
10 | import us.cyrien.minecordbot.commands.MCBCommand;
11 | import us.cyrien.minecordbot.localization.Locale;
12 | import us.cyrien.minecordbot.utils.mcpinger.MCPing;
13 |
14 | import java.awt.*;
15 | import java.io.IOException;
16 |
17 | public class McServerCmd extends MCBCommand {
18 |
19 | public McServerCmd(Minecordbot mcb) {
20 | super(mcb);
21 | this.name = "mcserver";
22 | this.arguments = "";
23 | this.help = Locale.getCommandsMessage("mcserver.description").finish();
24 | this.category = Bot.INFO;
25 | this.type = Type.EMBED;
26 | }
27 |
28 | @Override
29 | protected void doCommand(CommandEvent e) {
30 | MCPing.McPing ping = ping(e.getArgs(), e);
31 | EmbedBuilder eb = new EmbedBuilder();
32 | if (ping != null)
33 | respond("pinging...", e).queue((m) -> {
34 | try {
35 | if (ping.status) {
36 | eb.setColor(Color.GREEN);
37 |
38 | String[] parts = ping.favicon.split("\\,");
39 | String imageString = parts[1];
40 | byte[] imageByte;
41 | BASE64Decoder decoder = new BASE64Decoder();
42 | imageByte = decoder.decodeBuffer(imageString);
43 |
44 | eb.setThumbnail("attachment://image.png");
45 |
46 | eb.addField("**" + e.getArgs() + "**", "Status: ***ONLINE***", false);
47 | eb.addField("Ping:", ping.ping, true);
48 | eb.addField("Version:", ping.version, true);
49 | eb.addField("Players:", ping.players, true);
50 | eb.addField("MOTD:", ChatColor.stripColor(ping.motd), false);
51 |
52 | m.delete().queue();
53 | e.getTextChannel().sendFile(imageByte, "image.png", new MessageBuilder()
54 | .setEmbed(embedMessage(e, eb.build(), ResponseLevel.LEVEL_1, "Information")).build())
55 | .queue();
56 | } else {
57 | eb.setColor(Color.RED);
58 | eb.addField("**" + e.getArgs() + "**", "Status: ***OFFLINE***", false);
59 | m.delete().queue();
60 | respond(embedMessage(e, eb.build(), ResponseLevel.LEVEL_3), e).queue();
61 | }
62 | } catch (IOException ignore) {
63 | }
64 | });
65 | }
66 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #  __MineCordBot__ [](https://travis-ci.org/CyR1en/Minecordbot) [](https://discord.cyr1en.com) [](https://donate.cyr1en.com/)
2 |
3 |
4 | ## This project is abandoned and support for this plugin will no longer be provided
5 |
6 | ### A Powerful Way to Bridge Discord and Minecraft
7 | ##### Configurable, Simple, Easy
8 |
9 | [](https://github.com/CyR1en/Minecordbot/releases)
10 | [](https://github.com/CyR1en/Minecordbot/wiki)
11 | [](https://github.com/CyR1en/Minecordbot/issues)
12 |
13 | __Supports:__ *BukkitAPI 1.8 - 1.12.2* | __Previous Version:__ *[MineCordBot 2.2.4](https://github.com/CyR1en/Minecordbot/releases/tag/v2.2.4)* | __Current Version:__ *[MineCordBot 2.2.5](https://github.com/CyR1en/Minecordbot/releases/tag/2.2.5)*
14 |
15 | ---
16 | ## Features
17 | * Sync your Discord and Minecraft accounts with MCBSync™
18 | * Simple and Lightweight Installation
19 | * Intuitive command usage
20 | * Capable of Explicit Configuration
21 | * Bind many channels, or one
22 | * Cross-server command execution
23 | * Localized in English, Polish, German, Romanian, French and Pirate *YARRRR!*
24 | * Compatibility with many other chat plugins
25 | * Sleek command response interface
26 | * Tab auto-completion for in-game mentions
27 | * Four levels of permissions
28 |
29 | ## Learn More
30 | You can learn more about MineCordBot by visiting the [official website](https://minecordbot.cyr1en.com) or by visiting the wiki [here](https://github.com/CyR1en/Minecordbot/wiki)
31 |
32 | ## You can also...
33 | [ Check out Auri](https://github.com/CyR1en/Project-Auri) - A MusicBot you can run with Minecraft or Standalone
34 | [:airplane: Try ExperiencedFlight](https://github.com/CyR1en/ExperiencedFlight) - Allow your players to trade their levels for flight-time.
35 | [ Join the Discord](https://discord.gg/bETVHje) - Talk with the developers and other server admins
36 |
37 | ---
38 | __License__
39 | MineCordBot is licensed under the [GNU General Public License Version 3 (GPLv3)](https://github.com/CyR1en/Minecordbot/blob/master/LICENSE).
40 | __Third-Party Licenses__
41 | *MineCordBot relies on some third-party apps and libraries to provide certain functions. Their licenses are available in the [`/libs/licenses/` directory](https://github.com/CyR1en/Minecordbot/tree/master/libs/licenses).*
42 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/commands/discordCommand/McUsernameCmd.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.commands.discordCommand;
2 |
3 | import com.google.gson.JsonObject;
4 | import com.google.gson.JsonParser;
5 | import com.jagrosh.jdautilities.commandclient.CommandEvent;
6 | import net.dv8tion.jda.core.EmbedBuilder;
7 | import us.cyrien.minecordbot.Bot;
8 | import us.cyrien.minecordbot.Minecordbot;
9 | import us.cyrien.minecordbot.commands.MCBCommand;
10 | import us.cyrien.minecordbot.localization.Locale;
11 | import us.cyrien.minecordbot.utils.HTTPUtils;
12 | import us.cyrien.minecordbot.utils.UUIDFetcher;
13 | import us.cyrien.minecordbot.utils.exception.TooManyRequestsException;
14 |
15 | import java.io.IOException;
16 |
17 | public class McUsernameCmd extends MCBCommand{
18 |
19 | public McUsernameCmd(Minecordbot minecordbot) {
20 | super(minecordbot);
21 | this.name = "mcusername";
22 | this.help = Locale.getCommandsMessage("mcusername.description").finish();
23 | this.arguments = "";
24 | this.aliases = new String[]{"mcuser"};
25 | this.category = Bot.INFO;
26 | this.type = MCBCommand.Type.EMBED;
27 | }
28 |
29 | @Override
30 | protected void doCommand(CommandEvent e) {
31 | if (e.getArgs().isEmpty()) {
32 | respond(MCBCommand.ResponseLevel.LEVEL_3, Locale.getCommandMessage("invalid-arguments").finish(), e).queue();
33 | return;
34 | }
35 |
36 | String s = null;
37 | try {
38 | s = HTTPUtils.performGetRequest(HTTPUtils.constantURL
39 | ("https://sessionserver.mojang.com/session/minecraft/profile/" + UUIDFetcher.removeDiscriminant(e.getArgs())));
40 | } catch (IOException ex) {
41 | respond(MCBCommand.ResponseLevel.LEVEL_3, "Error getting player's Username: `java.io.IOException`", e).queue();
42 | return;
43 | }
44 | try {
45 | JsonObject json = (new JsonParser()).parse(s).getAsJsonObject();
46 | if(json.has("error"))
47 | throw new TooManyRequestsException(json.get("errorMessage").getAsString());
48 | EmbedBuilder eb = new EmbedBuilder();
49 | eb.addField("**Minecraft Username**:", json.get("name").getAsString(), false);
50 | respond(embedMessage(e, eb.build(), null), e).queue();
51 | } catch (IllegalStateException ex) {
52 | respond(MCBCommand.ResponseLevel.LEVEL_3, Locale.getCommandsMessage("mcusername.cannot-find").finish(), e).queue();
53 | } catch (TooManyRequestsException ex) {
54 | EmbedBuilder eb = new EmbedBuilder();
55 | eb.addField("**Error**: " + ex.getClass().getSimpleName(), ex.getMessage(), false);
56 | respond(embedMessage(e, eb.build(), ResponseLevel.LEVEL_3), e).queue();
57 | } catch (Exception ex) {
58 | ex.printStackTrace();
59 | respond(MCBCommand.ResponseLevel.LEVEL_3, Locale.getCommandsMessage("mcusername.error").finish(), e).queue();
60 | }
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/accountSync/Authentication/AuthToken.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.accountSync.Authentication;
2 |
3 | import org.apache.commons.lang3.RandomStringUtils;
4 | import org.bukkit.entity.Player;
5 | import us.cyrien.minecordbot.Minecordbot;
6 | import us.cyrien.minecordbot.accountSync.exceptions.IllegalConfirmKeyException;
7 | import us.cyrien.minecordbot.accountSync.exceptions.IllegalConfirmRequesterException;
8 | import us.cyrien.minecordbot.accountSync.exceptions.IllegalConfirmSessionIDException;
9 |
10 | public class AuthToken implements Comparable {
11 |
12 | private String token;
13 | private Player mcAcc;
14 | private String sessionID;
15 |
16 | public AuthToken(String sessionID, Player mcAcc) {
17 | this.sessionID = sessionID;
18 | this.mcAcc = mcAcc;
19 | token = generateToken();
20 | }
21 |
22 | public AuthToken(Player mcAcc, AuthSession authSession) {
23 | this.sessionID = authSession.getSessionID();
24 | this.mcAcc = mcAcc;
25 | token = generateToken();
26 | }
27 |
28 | public AuthToken(Player mcAcc, String token) throws IllegalConfirmKeyException {
29 | AuthManager authManager = Minecordbot.getInstance().getAuthManager();
30 | AuthSession authSession = authManager.getSession(token);
31 | if(authSession == null) {
32 | throw new IllegalConfirmKeyException();
33 | }
34 | this.mcAcc = mcAcc;
35 | this.token = token;
36 | this.sessionID = authSession.getSessionID();
37 | }
38 |
39 | private String generateToken() {
40 | token = RandomStringUtils.randomAlphanumeric(6);
41 | return token;
42 | }
43 |
44 | protected boolean authenticateToken(AuthToken token) throws IllegalConfirmRequesterException, IllegalConfirmKeyException, IllegalConfirmSessionIDException {
45 | if (!compareToken(token))
46 | return false;
47 | if(!this.toString().equals(token.toString())) {
48 | throw new IllegalConfirmKeyException();
49 | } else if (!this.getMcAcc().equals(token.getMcAcc())) {
50 | throw new IllegalConfirmRequesterException();
51 | } else if (!this.getSessionID().equals(token.getSessionID())) {
52 | throw new IllegalConfirmSessionIDException();
53 | }
54 | return true;
55 | }
56 |
57 | private void setToken(String s) {
58 | token = s;
59 | }
60 |
61 | public AuthToken getToken() {
62 | return this;
63 | }
64 |
65 | public boolean compareToken(AuthToken token) {
66 | return this.compareTo(token) > 0;
67 | }
68 |
69 | public String toString() {
70 | return token;
71 | }
72 |
73 | public Player getMcAcc() {
74 | return mcAcc;
75 | }
76 |
77 | public String getSessionID() {
78 | return sessionID;
79 | }
80 |
81 | @Override
82 | public int compareTo(Object o) {
83 | if (o instanceof AuthToken || ((AuthToken) o).getToken() == this.getToken())
84 | return 1;
85 | return -1;
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/reporters/PlReporter.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.reporters;
2 |
3 | import org.bukkit.Bukkit;
4 | import org.bukkit.plugin.Plugin;
5 | import us.cyrien.mcutils.diagnosis.Diagnostics;
6 | import us.cyrien.mcutils.diagnosis.IReporter;
7 |
8 | import java.io.*;
9 | import java.util.ArrayList;
10 | import java.util.Arrays;
11 | import java.util.zip.ZipFile;
12 |
13 | public class PlReporter implements IReporter {
14 |
15 | private String name;
16 | private int priority;
17 |
18 | public PlReporter() {
19 | this.name = "Plugin Reporter";
20 | this.priority = 4;
21 | }
22 |
23 | @Override
24 | public String getName() {
25 | return name;
26 | }
27 |
28 | @Override
29 | public String report() {
30 | StringBuilder sb = new StringBuilder();
31 | Plugin[] plugins = Bukkit.getPluginManager().getPlugins();
32 | sb.append("- Loaded Plugins(").append(plugins.length).append(") -").append(Diagnostics.LINE_SEPARATOR);
33 | for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
34 | sb.append(plugin.getName()).append(":").append(plugin.getDescription().getVersion()).append(Diagnostics.LINE_SEPARATOR);
35 | }
36 | sb.append(Diagnostics.LINE_SEPARATOR);
37 | File pluginsFolder = new File("plugins");
38 | File[] files = pluginsFolder.listFiles() == null ? new File[]{} : pluginsFolder.listFiles();
39 | ArrayList fList = new ArrayList<>(Arrays.asList(files));
40 | for (int i = 0; i < fList.size(); i++) {
41 | try {
42 | if (!isJarFile(fList.get(i))) {
43 | fList.remove(i);
44 | i--;
45 | }
46 | } catch (IOException e) {
47 | e.printStackTrace();
48 | }
49 | }
50 | sb.append("- Jars in plugins folder(").append(fList.size()).append(") -").append(Diagnostics.LINE_SEPARATOR);
51 | fList.forEach(f -> sb.append(f.getName()).append(Diagnostics.LINE_SEPARATOR));
52 | return sb.toString();
53 | }
54 |
55 | private boolean isJarFile(File file) throws IOException {
56 | if (!isZipFile(file)) {
57 | return false;
58 | }
59 | ZipFile zip = new ZipFile(file);
60 | boolean manifest = zip.getEntry("META-INF/MANIFEST.MF") != null;
61 | zip.close();
62 | return manifest;
63 | }
64 |
65 | private boolean isZipFile(File file) throws IOException {
66 | if(file.isDirectory()) {
67 | return false;
68 | }
69 | if(!file.canRead()) {
70 | throw new IOException("Cannot read file "+file.getAbsolutePath());
71 | }
72 | if(file.length() < 4) {
73 | return false;
74 | }
75 | DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
76 | int test = in.readInt();
77 | in.close();
78 | return test == 0x504b0304;
79 | }
80 |
81 | @Override
82 | public int getPriority() {
83 | return priority;
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/mcutils/diagnosis/DiagnosticsBuilder.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.mcutils.diagnosis;
2 |
3 | import us.cyrien.mcutils.diagnosis.impl.DiagnosticsImpl;
4 | import us.cyrien.mcutils.logger.Logger;
5 |
6 | import java.util.Collections;
7 | import java.util.LinkedList;
8 | import java.util.Map;
9 |
10 | public class DiagnosticsBuilder {
11 |
12 | private LinkedList reporters;
13 | private TypeDiagnosis typeDiagnosis;
14 |
15 | public DiagnosticsBuilder() {
16 | this(null);
17 | }
18 |
19 | public DiagnosticsBuilder(Diagnostics diagnosis) {
20 | if (diagnosis != null)
21 | reporters = diagnosis.getReporters();
22 | else
23 | reporters = new LinkedList<>();
24 | typeDiagnosis = TypeDiagnosis.MANUAL;
25 | }
26 |
27 | @SafeVarargs
28 | public final DiagnosticsBuilder setTypeDiagnosis(TypeDiagnosis typeDiagnosis, Class extends IReporter>... reporters) {
29 | if(typeDiagnosis == null)
30 | return this;
31 | this.typeDiagnosis = typeDiagnosis;
32 | switch (typeDiagnosis) {
33 | case ALL:
34 | if(reporters.length != 0)
35 | throw new IllegalArgumentException("TypeDiagnosis.ALL can't have any explicit reporters.");
36 | ReportLoader.getReporters().forEach((cK, cV) -> this.reporters.add(cV));
37 | break;
38 | case PARTIAL:
39 | if(reporters == null)
40 | throw new IllegalArgumentException("No explicit reporters have been provided for TypeDiagnosis.PARTIAL.");
41 | for (Class extends IReporter> iReporter : reporters) {
42 | Map, IReporter> rList = ReportLoader.getReporters();
43 | if(rList.containsKey(iReporter))
44 | this.reporters.add(rList.get(iReporter));
45 | else
46 | Logger.err("Could not include " + iReporter.getSimpleName() + " to TypeDiagnosis.Partial; Was it registered?");
47 | }
48 | break;
49 | }
50 | return this;
51 | }
52 |
53 | public DiagnosticsBuilder appendReporter(IReporter reporter) {
54 | if (!reporters.contains(reporter) && typeDiagnosis == TypeDiagnosis.MANUAL)
55 | reporters.add(reporter);
56 | return this;
57 | }
58 |
59 |
60 | public Diagnostics build() {
61 | if (isValidDiagnosis()) {
62 | Collections.sort(reporters);
63 | return new DiagnosticsImpl().setTypeDiagnosis(typeDiagnosis).setReporters(reporters);
64 | } else
65 | throw new IllegalStateException("Could not build Diagnostic because of improper use of " + this.getClass().getSimpleName());
66 | }
67 |
68 | private boolean isValidDiagnosis() {
69 | switch (typeDiagnosis) {
70 | case ALL:
71 | return true;
72 | case PARTIAL:
73 | return reporters.size() != 0;
74 | case MANUAL:
75 | return reporters.size() != 0;
76 | default:
77 | return false;
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/us/cyrien/minecordbot/utils/SearchUtil.java:
--------------------------------------------------------------------------------
1 | package us.cyrien.minecordbot.utils;
2 |
3 | import net.dv8tion.jda.core.JDA;
4 | import net.dv8tion.jda.core.entities.Guild;
5 | import net.dv8tion.jda.core.entities.Member;
6 | import net.dv8tion.jda.core.entities.TextChannel;
7 | import net.dv8tion.jda.core.entities.User;
8 | import org.apache.commons.lang3.StringUtils;
9 | import org.bukkit.Bukkit;
10 | import org.bukkit.entity.Player;
11 | import us.cyrien.minecordbot.Minecordbot;
12 | import us.cyrien.minecordbot.accountSync.SimplifiedDatabase;
13 |
14 | import java.util.ArrayList;
15 | import java.util.List;
16 | import java.util.Map;
17 | import java.util.UUID;
18 |
19 | public class SearchUtil {
20 |
21 | public static List findValidTextChannels(List tcID) {
22 | List out = new ArrayList<>();
23 | tcID.forEach((s) -> {
24 | JDA jda = Minecordbot.getInstance().getBot().getJda();
25 | if (!s.isEmpty() && jda != null) {
26 | if(StringUtils.isNumeric(s)) {
27 | TextChannel tc = jda.getTextChannelById(s);
28 | if (tc != null)
29 | out.add(tc);
30 | } else {
31 | List guilds = jda.getGuilds();
32 | guilds.forEach(g -> g.getTextChannels().forEach(tc -> {
33 | if(tc.getName().equals(s))
34 | out.add(tc);
35 | }));
36 | }
37 | }
38 | });
39 | return out;
40 | }
41 |
42 | public static Member findMember(String query) {
43 | List guilds = Minecordbot.getInstance().getBot().getJda().getGuilds();
44 | List members;
45 | for (Guild guild : guilds) {
46 | members = com.jagrosh.jdautilities.utils.FinderUtil.findMembers(query, guild);
47 | if (members.size() > 0)
48 | return members.get(0);
49 | }
50 | return null;
51 | }
52 |
53 | public static Player findPlayerInDatabase(String discordID) {
54 | Map