Files
src
build.gradle
settings.gradle
Code
11 443
src/main/java/com/fidioland/fidiosmp/FidioSMP.java
package com.fidioland.fidiosmp;
import com.fidioland.fidiosmp.command.MeCommand;
import com.fidioland.fidiosmp.command.MessageCommand;
import com.fidioland.fidiosmp.command.ReplyCommand;
import com.fidioland.fidiosmp.listener.CommandListener;
import com.fidioland.fidiosmp.listener.PortalListener;
import com.fidioland.fidiosmp.message.MessageManager;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Objects;
public final class FidioSMP extends JavaPlugin {
private static final String PREFIX = "&6[Fidio Land] &r";
private static final LegacyComponentSerializer LEGACY_SERIALIZER = LegacyComponentSerializer.legacyAmpersand();
private MessageManager messageManager;
@Override
public void onEnable() {
saveDefaultConfig();
messageManager = new MessageManager();
warnIfWorldMissing("smp-world");
warnIfWorldMissing("smp-nether");
warnIfWorldMissing("smp-end");
Bukkit.getPluginManager().registerEvents(new PortalListener(this), this);
Bukkit.getPluginManager().registerEvents(new CommandListener(this), this);
MessageCommand messageCommand = new MessageCommand(this, messageManager);
ReplyCommand replyCommand = new ReplyCommand(this, messageManager);
registerCommand("m", messageCommand);
registerCommand("r", replyCommand);
registerCommand("me", new MeCommand(this));
}
private void registerCommand(String name, org.bukkit.command.CommandExecutor executor) {
PluginCommand command = Objects.requireNonNull(getCommand(name), "Command '" + name + "' is missing from plugin.yml");
command.setExecutor(executor);
}
private void warnIfWorldMissing(String configPath) {
String worldName = getConfig().getString(configPath, "");
if (worldName.isBlank() || Bukkit.getWorld(worldName) == null) {
getLogger().warning("Мир '" + worldName + "' из настройки '" + configPath + "' не найден. Плагин продолжит работу.");
}
}
public Component formatMessage(String text) {
return LEGACY_SERIALIZER.deserialize(PREFIX + text).decoration(TextDecoration.ITALIC, false);
}
public void send(CommandSender recipient, String text) {
recipient.sendMessage(formatMessage(text));
}
public MessageManager getMessageManager() {
return messageManager;
}
}