2024-05-16 16:11:13 +08:00
|
|
|
# MinecraftPluginUtils
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
2024-05-19 14:45:05 +08:00
|
|
|
### Maven
|
|
|
|
|
2024-05-16 16:11:13 +08:00
|
|
|
```xml
|
|
|
|
<repositories>
|
|
|
|
<repository>
|
|
|
|
<id>lunadeer-repo</id>
|
2024-05-21 11:19:25 +08:00
|
|
|
<url>https://ssl.lunadeer.cn:14454/repository/maven-snapshots/</url>
|
2024-05-16 16:11:13 +08:00
|
|
|
</repository>
|
|
|
|
</repositories>
|
|
|
|
|
|
|
|
<dependencies>
|
2024-06-06 10:47:06 +08:00
|
|
|
<dependency>
|
|
|
|
<groupId>cn.lunadeer</groupId>
|
|
|
|
<artifactId>MinecraftPluginUtils</artifactId>
|
2024-07-04 14:10:24 +08:00
|
|
|
<version>1.3.4-SNAPSHOT</version>
|
2024-06-06 10:47:06 +08:00
|
|
|
</dependency>
|
2024-05-16 16:11:13 +08:00
|
|
|
</dependencies>
|
2024-05-19 14:45:05 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
### Gradle
|
|
|
|
|
|
|
|
```groovy
|
|
|
|
repositories {
|
|
|
|
maven {
|
2024-05-21 11:19:25 +08:00
|
|
|
url 'https://ssl.lunadeer.cn:14454/repository/maven-snapshots/'
|
2024-05-19 14:45:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dependencies {
|
2024-05-27 16:50:53 +08:00
|
|
|
implementation 'cn.lunadeer:MinecraftPluginUtils:1.3.0-SNAPSHOT'
|
2024-05-19 14:45:05 +08:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
```kotlin
|
|
|
|
import cn.lunadeer.MinecraftPluginUtils
|
2024-05-27 17:00:28 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
### Logger
|
|
|
|
|
|
|
|
```java
|
|
|
|
import cn.lunadeer.minecraftpluginutils.XLogger;
|
|
|
|
|
|
|
|
public final class YourPlugin extends JavaPlugin {
|
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
|
|
|
new XLogger(this); // Initialize the logger with the plugin instance once
|
2024-06-06 10:47:06 +08:00
|
|
|
|
2024-05-27 17:00:28 +08:00
|
|
|
XLogger.setDebug(true); // Enable debug mode if needed
|
2024-06-06 10:47:06 +08:00
|
|
|
|
2024-05-27 17:00:28 +08:00
|
|
|
XLogger.info("Hello, world!"); // Call the static method
|
|
|
|
XLogger.warn("This is a %s", "warning"); // Call the static method with format
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Notification
|
|
|
|
|
|
|
|
```java
|
|
|
|
import cn.lunadeer.minecraftpluginutils.Notification;
|
|
|
|
|
|
|
|
public final class YourPlugin extends JavaPlugin {
|
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
|
|
|
new Notification(this); // Initialize the notification with the plugin instance once
|
|
|
|
|
|
|
|
Bukkit.getPluginManager().registerEvents(new PlayerEvents(), this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-06-06 10:47:06 +08:00
|
|
|
public class PlayerEvents implements Listener {
|
2024-05-27 17:00:28 +08:00
|
|
|
@EventHandler
|
|
|
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
|
|
|
Notification.info(event.getPlayer(), "Welcome to the server!"); // Send a notification to the player
|
|
|
|
Notification.all("Greetings from %s!", event.getPlayer().getName()); // Send a notification to all players
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
2024-06-06 10:47:06 +08:00
|
|
|
|
|
|
|
### Scheduler
|
|
|
|
|
|
|
|
```java
|
|
|
|
import cn.lunadeer.minecraftpluginutils.Scheduler;
|
|
|
|
|
|
|
|
public final class YourPlugin extends JavaPlugin {
|
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
|
|
|
new Scheduler(this); // Initialize the scheduler with the plugin instance once
|
|
|
|
|
|
|
|
Scheduler.runTaskLater(() -> {
|
|
|
|
XLogger.info("Hello, world!"); // Call the static method
|
|
|
|
}, 20L); // Delay 20 ticks
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
|
|
|
Scheduler.cancelAll(); // Cancel all tasks to prevent memory leaks
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|