-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5087074
Showing
46 changed files
with
2,369 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea/modules.xml | ||
.idea/jarRepositories.xml | ||
.idea/compiler.xml | ||
.idea/libraries/ | ||
*.iws | ||
*.iml | ||
*.ipr | ||
.idea/ | ||
dependency-reduced-pom.xml | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
 | ||
|
||
# 📝 CrazyMotd [](https://github.com/kerpsondev/CrazyMotd/releases) | ||
|
||
CrazyMotd is a simple plugin to support MOTD of minecraft servers. | ||
</br> | ||
|
||
It supports the [velocity](https://papermc.io/downloads/velocity) and [bungeecord](https://ci.md-5.net/job/BungeeCord/) platforms. | ||
</br> | ||
|
||
Although it is simple it has interesting options to make your MOTD look better! The plugin supports [minimessage](https://docs.advntr.dev/minimessage/format.html) formatting. | ||
<br> | ||
|
||
# ⚙️ Installation | ||
### Requirements | ||
- [ ] Java 8 or newer (for bungeecord) | ||
- [ ] Java 11 or newer (for velocity) | ||
|
||
### Motd installation | ||
- [ ] Select version for your enginee. | ||
- [ ] Put plugin into folder plugins. | ||
- [ ] Restart the server. | ||
- [ ] If the plugin has been started correctly, you will see such a message in the console | ||
<br> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<packaging>jar</packaging> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>bungeecord</artifactId> | ||
|
||
<parent> | ||
<groupId>dev.kerpson</groupId> | ||
<artifactId>crazymotd</artifactId> | ||
<version>1.0.1</version> | ||
</parent> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
</properties> | ||
|
||
<repositories> | ||
<!-- Bungeecord repository --> | ||
<repository> | ||
<id>bungeecord-repo</id> | ||
<url>https://oss.sonatype.org/content/repositories/snapshots</url> | ||
</repository> | ||
|
||
<!-- Commands repository --> | ||
<repository> | ||
<id>panda-repository</id> | ||
<url>https://repo.panda-lang.org/releases</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<!-- Bungeecord engine --> | ||
<dependency> | ||
<groupId>net.md-5</groupId> | ||
<artifactId>bungeecord-api</artifactId> | ||
<version>1.20-R0.2</version> | ||
<type>jar</type> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>net.md-5</groupId> | ||
<artifactId>bungeecord-api</artifactId> | ||
<version>1.20-R0.2</version> | ||
<type>javadoc</type> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- Adventure libraries --> | ||
<dependency> | ||
<groupId>net.kyori</groupId> | ||
<artifactId>adventure-api</artifactId> | ||
<version>4.16.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>net.kyori</groupId> | ||
<artifactId>adventure-text-serializer-legacy</artifactId> | ||
<version>4.16.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>net.kyori</groupId> | ||
<artifactId>adventure-text-minimessage</artifactId> | ||
<version>4.16.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>net.kyori</groupId> | ||
<artifactId>adventure-platform-bungeecord</artifactId> | ||
<version>4.3.2</version> | ||
</dependency> | ||
|
||
<!-- Commands library --> | ||
<dependency> | ||
<groupId>dev.rollczi</groupId> | ||
<artifactId>litecommands-bungeecord</artifactId> | ||
<version>3.4.0</version> | ||
</dependency> | ||
|
||
<!-- Shared library --> | ||
<dependency> | ||
<groupId>dev.kerpson</groupId> | ||
<artifactId>shared</artifactId> | ||
<version>1.0.1</version> | ||
</dependency> | ||
|
||
<!-- BStats --> | ||
<dependency> | ||
<groupId>org.bstats</groupId> | ||
<artifactId>bstats-bungeecord</artifactId> | ||
<version>3.0.2</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>crazymotd-bungeecord-${project.parent.version}</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.12.1</version> | ||
<configuration> | ||
<source>${maven.compiler.source}</source> | ||
<target>${maven.compiler.target}</target> | ||
<compilerArgs> | ||
<arg>-parameters</arg> | ||
</compilerArgs> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.5.2</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<relocations> | ||
<relocation> | ||
<pattern>eu.crazycast.motd.shared</pattern> | ||
<shadedPattern>dev.kerpson.motd.bungee.shared</shadedPattern> | ||
</relocation> | ||
<relocation> | ||
<pattern>org.bstats</pattern> | ||
<shadedPattern>dev.kerpson.motd.bungee.libs.bstats</shadedPattern> | ||
</relocation> | ||
<relocation> | ||
<pattern>net.kyori</pattern> | ||
<shadedPattern>dev.kerpson.motd.bungee.libs.adventure</shadedPattern> | ||
</relocation> | ||
<relocation> | ||
<pattern>eu.okaeri</pattern> | ||
<shadedPattern>dev.kerpson.motd.bungee.libs.okaeri</shadedPattern> | ||
</relocation> | ||
<relocation> | ||
<pattern>dev.rollczi.litecommands</pattern> | ||
<shadedPattern>dev.kerpson.motd.bungee.libs.litecommands</shadedPattern> | ||
</relocation> | ||
<relocation> | ||
<pattern>panda</pattern> | ||
<shadedPattern>dev.kerpson.motd.bungee.libs.panda</shadedPattern> | ||
</relocation> | ||
</relocations> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
144 changes: 144 additions & 0 deletions
144
bungeecord/src/main/java/dev/kerpson/motd/bungee/BungeeMotd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
package dev.kerpson.motd.bungee; | ||
|
||
import dev.kerpson.motd.bungee.command.CrazyMotdCommand; | ||
import dev.kerpson.motd.bungee.factory.BungeeCommandFactory; | ||
import dev.kerpson.motd.bungee.factory.BungeeListenerFactory; | ||
import dev.kerpson.motd.bungee.feature.BungeeMessageOfTheDayService; | ||
import dev.kerpson.motd.bungee.listener.ProxyPingListener; | ||
import dev.kerpson.motd.bungee.listener.ServerConnectListener; | ||
import dev.kerpson.motd.bungee.placeholder.BungeePluginPlaceholders; | ||
import dev.kerpson.motd.bungee.provider.BungeeLoggerProvider; | ||
import dev.kerpson.motd.bungee.provider.BungeeServerProvider; | ||
import eu.crazycast.motd.shared.configuration.Configuration; | ||
import eu.crazycast.motd.shared.configuration.serializer.MessageOfTheDaySerializer; | ||
import eu.crazycast.motd.shared.factory.CommandFactory; | ||
import eu.crazycast.motd.shared.factory.ConfigurationFactory; | ||
import eu.crazycast.motd.shared.factory.ListenerFactory; | ||
import eu.crazycast.motd.shared.notifier.PluginStartupNotifier; | ||
import eu.crazycast.motd.shared.notifier.PluginUpdater; | ||
import eu.crazycast.motd.shared.placeholer.PluginPlaceholders; | ||
import eu.crazycast.motd.shared.provider.LoggerProvider; | ||
import eu.crazycast.motd.shared.provider.ServerProvider; | ||
import eu.crazycast.motd.shared.util.Optionals; | ||
import eu.okaeri.configs.exception.OkaeriException; | ||
import java.io.File; | ||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.Optional; | ||
import java.util.concurrent.TimeUnit; | ||
import net.kyori.adventure.platform.bungeecord.BungeeAudiences; | ||
import net.md_5.bungee.api.ProxyServer; | ||
import net.md_5.bungee.api.plugin.Plugin; | ||
import net.md_5.bungee.api.scheduler.ScheduledTask; | ||
import org.bstats.bungeecord.Metrics; | ||
|
||
public class BungeeMotd extends Plugin { | ||
|
||
private final File configFile = new File("plugins/crazymotd", "configuration.yml"); | ||
|
||
private ProxyServer proxyServer; | ||
|
||
private BungeeAudiences adventure; | ||
private PluginUpdater pluginUpdater; | ||
private Configuration configuration; | ||
private LoggerProvider loggerProvider; | ||
private ServerProvider serverProvider; | ||
private BungeeCommandFactory commandFactory; | ||
private BungeeListenerFactory listenerFactory; | ||
private BungeeMessageOfTheDayService messageOfTheDayService; | ||
|
||
private Optional<ScheduledTask> messageOfTheDayTask = Optional.empty(); | ||
|
||
@Override | ||
public void onEnable() { | ||
new Metrics(this, 21091); | ||
|
||
Instant startEnableTime = Instant.now(); | ||
this.adventure = BungeeAudiences.create(this); | ||
this.proxyServer = this.getProxy(); | ||
this.loggerProvider = new BungeeLoggerProvider(this.getLogger()); | ||
this.serverProvider = new BungeeServerProvider(this.proxyServer); | ||
this.createConfiguration(); | ||
|
||
PluginPlaceholders pluginPlaceholders = new BungeePluginPlaceholders( | ||
this.configuration, | ||
this.serverProvider, | ||
this.proxyServer | ||
); | ||
|
||
this.messageOfTheDayService = new BungeeMessageOfTheDayService( | ||
this.configuration, | ||
pluginPlaceholders | ||
); | ||
|
||
this.pluginUpdater = new PluginUpdater(this.adventure.console(), this.serverProvider); | ||
|
||
this.registerCommands(); | ||
this.registerListeners(); | ||
this.setupMessageOfTheDayTask(); | ||
|
||
PluginStartupNotifier pluginStartupNotifier = new PluginStartupNotifier(this.adventure.console(), this.serverProvider); | ||
pluginStartupNotifier.notify(Duration.between(startEnableTime, Instant.now())); | ||
|
||
this.pluginUpdater.check(); | ||
} | ||
|
||
@Override | ||
public void onDisable() { | ||
Optional.ofNullable(this.adventure).ifPresent(BungeeAudiences::close); | ||
Optional.ofNullable(this.commandFactory).ifPresent(CommandFactory::unregisterCommands); | ||
Optional.ofNullable(this.listenerFactory).ifPresent(ListenerFactory::unregisterListeners); | ||
this.proxyServer.getScheduler().cancel(this); | ||
} | ||
|
||
private void registerCommands() { | ||
this.commandFactory = new BungeeCommandFactory(this, this.loggerProvider); | ||
this.commandFactory.addCommands(new CrazyMotdCommand( | ||
this, | ||
this.adventure, | ||
this.configuration | ||
)); | ||
|
||
this.commandFactory.registerCommands(); | ||
} | ||
|
||
private void registerListeners() { | ||
this.listenerFactory = new BungeeListenerFactory(this.loggerProvider, this, this.proxyServer); | ||
this.listenerFactory.addListeners( | ||
new ProxyPingListener(this.messageOfTheDayService), | ||
new ServerConnectListener(this.adventure, this.pluginUpdater) | ||
); | ||
|
||
this.listenerFactory.registerListeners(); | ||
} | ||
|
||
private void createConfiguration() { | ||
ConfigurationFactory configurationFactory = new ConfigurationFactory(this.serverProvider); | ||
this.configuration = configurationFactory.createConfiguration( | ||
Configuration.class, | ||
this.configFile, | ||
registry -> registry.register(new MessageOfTheDaySerializer()) | ||
); | ||
|
||
this.getLogger().info("Successfully created configuration"); | ||
} | ||
|
||
private void setupMessageOfTheDayTask() { | ||
this.messageOfTheDayTask.ifPresent(ScheduledTask::cancel); | ||
this.messageOfTheDayTask = Optionals.when( | ||
!this.configuration.getUpdateTime().isNegative() && !this.configuration.getUpdateTime().isZero(), | ||
this.proxyServer.getScheduler().schedule( | ||
this, | ||
() -> this.messageOfTheDayService.update(), | ||
0L, | ||
this.configuration.getUpdateTime().getSeconds(), | ||
TimeUnit.SECONDS | ||
) | ||
); | ||
} | ||
|
||
public void reloadConfiguration() throws OkaeriException { | ||
this.configuration.load(true); | ||
this.setupMessageOfTheDayTask(); | ||
} | ||
} |
Oops, something went wrong.