This commit is contained in:
neroduckale 2024-06-27 00:12:23 +05:00
commit 6b8b35d736
6 changed files with 209 additions and 0 deletions

13
Welcome.iml Normal file
View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>PAPER</platformType>
</autoDetectTypes>
<projectReimportVersion>1</projectReimportVersion>
</configuration>
</facet>
</component>
</module>

71
pom.xml Normal file
View file

@ -0,0 +1,71 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>ru.neroduckale</groupId>
<artifactId>Welcome</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>Welcome</name>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>papermc-repo</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,32 @@
package ru.neroduckale.welcome;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
public final class Main extends JavaPlugin {
private final File welcomeFile = new File(getDataFolder(), "welcome.yml");
private final FileConfiguration welcomeConf = YamlConfiguration.loadConfiguration(welcomeFile);
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(new PlayerJoinListener(welcomeConf), this);
registerCMD("welcome", new WelcomeCommand(welcomeFile, welcomeConf));
}
@Override
public void onDisable() {
// Plugin shutdown logic
}
private void registerCMD(String cmdStr, CommandExecutor cmdClass) {
PluginCommand CMD = this.getCommand(cmdStr);
if(CMD != null) {
CMD.setExecutor(cmdClass);
}
}
}

View file

@ -0,0 +1,25 @@
package ru.neroduckale.welcome;
import net.kyori.adventure.text.Component;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.jetbrains.annotations.NotNull;
public class PlayerJoinListener implements Listener {
private final FileConfiguration welcomeConf;
public PlayerJoinListener(@NotNull FileConfiguration welcomeConf) {
this.welcomeConf = welcomeConf;
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
String nickname = event.getPlayer().getName();
String welcomeMsg = welcomeConf.getString(nickname);
if (welcomeMsg == null) {return;}
Component finalMsg = Component.text(welcomeMsg + "(" + nickname + ")");
event.getPlayer().getServer().sendMessage(finalMsg);
}
}

View file

@ -0,0 +1,54 @@
package ru.neroduckale.welcome;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
import java.util.Objects;
public class WelcomeCommand implements CommandExecutor {
private final File welcomeFile;
private final FileConfiguration welcomeConf;
public WelcomeCommand(File welcomeFile, FileConfiguration welcomeConf) {
this.welcomeFile = welcomeFile;
this.welcomeConf = welcomeConf;
}
@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
if(!(commandSender instanceof Player)) {
commandSender.sendMessage("Эту команду может использовать только игрок");
return true;
}
Player player = (Player) commandSender;
if (args.length == 0) {
player.sendMessage("Использование: /welcome <текст>");
return true;
}
StringBuilder msg = new StringBuilder();
for (String item : args) {
msg.append(item).append(" ");
}
if (msg.length() > 30) {
player.sendMessage("Максимум 30 символов!");
return true;
}
welcomeConf.set(player.getName(), msg.toString());
try {
welcomeConf.save(welcomeFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
player.sendMessage(Objects.requireNonNull(welcomeConf.getString(player.getName())));
return false;
}
}

View file

@ -0,0 +1,14 @@
name: Welcome
version: '${project.version}'
main: ru.neroduckale.welcome.Main
api-version: '1.20'
commands:
welcome: