Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ version = ""
repositories {
mavenCentral()

maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://repo.papermc.io/repository/maven-public/")
}

dependencies {
compileOnly("org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT")
compileOnly("dev.folia:folia-api:1.20.4-R0.1-SNAPSHOT")

implementation(files("./libs/config.jar"))

}
}
23 changes: 21 additions & 2 deletions src/main/java/dev/hadimhz/welcome/command/CommandHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ public class CommandHandler implements CommandExecutor {
private final PlayerListener listener;
private final Config config;

private final boolean isFolia = classExist("io.papermc.paper.threadedregions.RegionizedServerInitEvent");

private static boolean classExist(String className) {
try {
Class.forName(className);
return true;
} catch (ClassNotFoundException e) {
return false;
}
}

public CommandHandler(Plugin plugin, PlayerListener listener, Config config) {
this.plugin = plugin;
this.listener = listener;
Expand Down Expand Up @@ -56,15 +67,23 @@ public CommandHandler(Plugin plugin, PlayerListener listener, Config config) {
if (config.displayFirstXWelcomeMessages == -1 || listener.getWelcomed().size() < config.displayFirstXWelcomeMessages)
player.chat(config.firstJoin.get(random.nextInt(config.firstJoin.size())).replaceAll("%player%", listener.getPlayer().getName()));

for (String command : config.CommandsToExecuteOnFirstJoin) {
if(isFolia)
for (String command : config.CommandsToExecuteOnFirstJoin) {
Bukkit.getGlobalRegionScheduler().run(plugin, run -> Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command.replaceAll("%player%", player.getName())));
}
else for (String command : config.CommandsToExecuteOnFirstJoin) {
Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(), command.replaceAll("%player%", player.getName()));
}

} else {
if (config.displayFirstXWelcomeMessages == -1 || listener.getWelcomed().size() < config.displayFirstXWelcomeMessages)
player.chat(config.joinBack.get(random.nextInt(config.joinBack.size())).replaceAll("%player%", listener.getPlayer().getName()));

for (String command : config.commandsToExecute) {
if(isFolia)
for (String command : config.commandsToExecute) {
Bukkit.getGlobalRegionScheduler().run(plugin, run -> Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command.replaceAll("%player%", player.getName())));
}
else for (String command : config.commandsToExecute) {
Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(), command.replaceAll("%player%", player.getName()));
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: WelcomeBack
main: dev.hadimhz.welcome.WelcomePlugin
version: 1.8
api-version: 1.13
folia-supported: true

commands:
welcome:
aliases: [ wb ]
aliases: [ wb ]