Files
src
build.gradle
Code
23 1,693
src/main/java/com/example/petssystem/PetsSystem.java
package com.example.petssystem;
import com.example.petssystem.command.PetAdminCommand;
import com.example.petssystem.command.PetPlayerCommand;
import com.example.petssystem.config.ConfigManager;
import com.example.petssystem.gui.GUIListener;
import com.example.petssystem.gui.GUIManager;
import com.example.petssystem.hook.VaultHook;
import com.example.petssystem.listener.ChatInputListener;
import com.example.petssystem.listener.PlayerJoinListener;
import com.example.petssystem.pet.PetManager;
import com.example.petssystem.task.PetFollowTask;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
@Getter
public class PetsSystem extends JavaPlugin {
private ConfigManager configManager;
private PetManager petManager;
private GUIManager guiManager;
private VaultHook vaultHook;
private ChatInputListener chatInputListener;
private PetFollowTask petFollowTask;
@Override
public void onEnable() {
this.configManager = new ConfigManager(this);
this.petManager = new PetManager(this);
this.guiManager = new GUIManager();
this.vaultHook = new VaultHook();
this.chatInputListener = new ChatInputListener();
Bukkit.getPluginManager().registerEvents(new GUIListener(guiManager), this);
Bukkit.getPluginManager().registerEvents(chatInputListener, this);
Bukkit.getPluginManager().registerEvents(new PlayerJoinListener(this), this);
getCommand("pet").setExecutor(new PetAdminCommand(this));
getCommand("pety").setExecutor(new PetPlayerCommand(this));
int updateFrequency = configManager.getUpdateFrequency();
this.petFollowTask = new PetFollowTask(this);
this.petFollowTask.runTaskTimer(this, 20L, updateFrequency);
getLogger().info("PetsSystem został włączony!");
if (vaultHook.isEnabled()) {
getLogger().info("Vault hook załadowany pomyślnie!");
} else {
getLogger().warning("Vault nie został znaleziony - mnożniki pieniędzy nie będą działać!");
}
}
@Override
public void onDisable() {
if (petFollowTask != null) {
petFollowTask.cancel();
}
Bukkit.getOnlinePlayers().forEach(player -> {
petManager.deactivateAllPets(player);
});
if (configManager.getConfig().getBoolean("ustawienia.zapisz-pety-przy-wylaczeniu", true)) {
petManager.savePets();
configManager.savePlayers();
}
getLogger().info("PetsSystem został wyłączony!");
}
}