first commit
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.dirt</groupId>
|
||||
<artifactId>DirtFirstJoin</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>DirtFirstJoin</name>
|
||||
<description>Run configurable commands when a player joins for the first time.</description>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.release>21</maven.compiler.release>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>papermc-repo</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.21.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.13.0</version>
|
||||
<configuration>
|
||||
<release>21</release>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.dirt.firstjoin;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DirtFirstJoinPlugin extends JavaPlugin implements Listener {
|
||||
|
||||
private final Set<UUID> processedThisSession = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
saveDefaultConfig();
|
||||
getServer().getPluginManager().registerEvents(this, this);
|
||||
getLogger().info("DirtFirstJoin enabled.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
processedThisSession.clear();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (player.hasPlayedBefore()) {
|
||||
debug("Skipping " + player.getName() + " because they have joined before.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (processedThisSession.contains(player.getUniqueId())) {
|
||||
debug("Skipping " + player.getName() + " because they were already processed this session.");
|
||||
return;
|
||||
}
|
||||
|
||||
int delay = Math.max(0, getConfig().getInt("settings.run-delay-ticks", 40));
|
||||
boolean markBeforeRunning = getConfig().getBoolean("settings.mark-before-running", true);
|
||||
|
||||
if (markBeforeRunning) {
|
||||
processedThisSession.add(player.getUniqueId());
|
||||
}
|
||||
|
||||
debug("Scheduling first-join commands for " + player.getName() + " in " + delay + " ticks.");
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(this, () -> {
|
||||
Player onlinePlayer = Bukkit.getPlayer(player.getUniqueId());
|
||||
if (onlinePlayer == null || !onlinePlayer.isOnline()) {
|
||||
debug("Player " + player.getName() + " went offline before commands could run.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!markBeforeRunning) {
|
||||
if (processedThisSession.contains(player.getUniqueId())) {
|
||||
debug("Skipping " + player.getName() + " because they were already processed before run.");
|
||||
return;
|
||||
}
|
||||
processedThisSession.add(player.getUniqueId());
|
||||
}
|
||||
|
||||
runFirstJoinCommands(onlinePlayer);
|
||||
}, delay);
|
||||
}
|
||||
|
||||
private void runFirstJoinCommands(Player player) {
|
||||
List<String> commands = getConfig().getStringList("commands");
|
||||
|
||||
if (commands.isEmpty()) {
|
||||
debug("No commands configured for first join.");
|
||||
return;
|
||||
}
|
||||
|
||||
for (String command : commands) {
|
||||
String parsed = command
|
||||
.replace("{player}", player.getName())
|
||||
.replace("{uuid}", player.getUniqueId().toString());
|
||||
|
||||
debug("Running command: " + parsed);
|
||||
boolean success = Bukkit.dispatchCommand(Bukkit.getConsoleSender(), parsed);
|
||||
|
||||
if (!success) {
|
||||
getLogger().warning("Failed to execute command for " + player.getName() + ": " + parsed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void debug(String message) {
|
||||
if (getConfig().getBoolean("settings.debug", false)) {
|
||||
getLogger().info("[Debug] " + message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
|
||||
if (!sender.hasPermission("dirtfirstjoin.admin")) {
|
||||
sender.sendMessage(color(getConfig().getString("messages.no-permission", "&cYou do not have permission.")));
|
||||
return true;
|
||||
}
|
||||
|
||||
reloadConfig();
|
||||
sender.sendMessage(color(getConfig().getString("messages.reload", "&aDirtFirstJoin config reloaded.")));
|
||||
return true;
|
||||
}
|
||||
|
||||
sender.sendMessage(color(getConfig().getString("messages.usage", "&eUsage: /dirtfirstjoin reload")));
|
||||
return true;
|
||||
}
|
||||
|
||||
private String color(String message) {
|
||||
return ChatColor.translateAlternateColorCodes('&', message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
settings:
|
||||
run-delay-ticks: 40
|
||||
mark-before-running: true
|
||||
debug: false
|
||||
|
||||
messages:
|
||||
reload: "&aDirtFirstJoin config reloaded."
|
||||
no-permission: "&cYou do not have permission."
|
||||
usage: "&eUsage: /dirtfirstjoin reload"
|
||||
|
||||
commands:
|
||||
- "rtp {player}"
|
||||
@@ -0,0 +1,17 @@
|
||||
name: DirtFirstJoin
|
||||
version: 1.0-SNAPSHOT
|
||||
main: com.dirt.firstjoin.DirtFirstJoinPlugin
|
||||
api-version: '1.21'
|
||||
authors: [Dirt]
|
||||
description: Run configurable commands when a player joins for the first time.
|
||||
|
||||
commands:
|
||||
dirtfirstjoin:
|
||||
description: Main command for DirtFirstJoin
|
||||
usage: /<command> reload
|
||||
aliases: [dfj]
|
||||
|
||||
permissions:
|
||||
dirtfirstjoin.admin:
|
||||
description: Allows reloading DirtFirstJoin
|
||||
default: op
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,12 @@
|
||||
settings:
|
||||
run-delay-ticks: 40
|
||||
mark-before-running: true
|
||||
debug: false
|
||||
|
||||
messages:
|
||||
reload: "&aDirtFirstJoin config reloaded."
|
||||
no-permission: "&cYou do not have permission."
|
||||
usage: "&eUsage: /dirtfirstjoin reload"
|
||||
|
||||
commands:
|
||||
- "rtp {player}"
|
||||
@@ -0,0 +1,17 @@
|
||||
name: DirtFirstJoin
|
||||
version: 1.0-SNAPSHOT
|
||||
main: com.dirt.firstjoin.DirtFirstJoinPlugin
|
||||
api-version: '1.21'
|
||||
authors: [Dirt]
|
||||
description: Run configurable commands when a player joins for the first time.
|
||||
|
||||
commands:
|
||||
dirtfirstjoin:
|
||||
description: Main command for DirtFirstJoin
|
||||
usage: /<command> reload
|
||||
aliases: [dfj]
|
||||
|
||||
permissions:
|
||||
dirtfirstjoin.admin:
|
||||
description: Allows reloading DirtFirstJoin
|
||||
default: op
|
||||
@@ -0,0 +1,5 @@
|
||||
#Generated by Maven
|
||||
#Sat Jun 13 17:09:45 EDT 2026
|
||||
artifactId=DirtFirstJoin
|
||||
groupId=com.dirt
|
||||
version=1.0-SNAPSHOT
|
||||
@@ -0,0 +1 @@
|
||||
com/dirt/firstjoin/DirtFirstJoinPlugin.class
|
||||
@@ -0,0 +1 @@
|
||||
/home/bitnix/Desktop/DirtFirstJoin/src/main/java/com/dirt/firstjoin/DirtFirstJoinPlugin.java
|
||||
Reference in New Issue
Block a user