Files
src
build.gradle
manifest.kod
settings.gradle
Code
27 1,026
src/main/java/com/teamxhome/TeamXHomePlugin.java
package com.teamxhome;
import com.teamxhome.command.HomeCommand;
import com.teamxhome.command.TeamCommand;
import com.teamxhome.gui.GUIManager;
import com.teamxhome.gui.Menu;
import com.teamxhome.listener.PluginListener;
import com.teamxhome.service.HomeManager;
import com.teamxhome.service.MessageService;
import com.teamxhome.service.TeamManager;
import com.teamxhome.service.TeleportService;
import com.teamxhome.storage.SqlStorage;
import com.teamxhome.storage.Storage;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
import java.sql.SQLException;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
public class TeamXHomePlugin extends JavaPlugin implements com.teamxhome.service.TeamXHomePlugin, Menu.TeamXHomeGuiAccess, TeleportService.TeamXHomeAccess {
private Storage storage;
private MessageService messages;
private TeamManager teams;
private HomeManager homes;
private TeleportService teleports;
private GUIManager gui;
private final Map<UUID, String> prompts = new ConcurrentHashMap<>();
@Override public void onEnable() {
saveDefaultConfig();
messages = new MessageService(getConfig());
try {
storage = new SqlStorage(getDataFolder(), getConfig());
teams = new TeamManager(storage, getConfig().getInt("limits.max-team-size", 8));
homes = new HomeManager(storage);
} catch (SQLException | RuntimeException e) {
getLogger().log(Level.SEVERE, "Could not initialize storage", e);
if (storage != null) {
storage.close();
storage = null;
}
getServer().getPluginManager().disablePlugin(this);
return;
}
teleports = new TeleportService(this);
gui = new GUIManager();
TeamCommand teamCommand = new TeamCommand(this);
HomeCommand homeCommand = new HomeCommand(this);
register("team", teamCommand); register("tc", teamCommand); register("sethome", homeCommand); register("home", homeCommand); register("delhome", homeCommand); register("homes", homeCommand); register("teamxhome", homeCommand);
Bukkit.getPluginManager().registerEvents(new PluginListener(this), this);
if (getConfig().getBoolean("placeholders.enabled", true) && Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) new TeamXHomeExpansion(this).register();
}
private void register(String name, org.bukkit.command.CommandExecutor executor) { PluginCommand command = getCommand(name); if (command != null) { command.setExecutor(executor); if (executor instanceof org.bukkit.command.TabCompleter tab) command.setTabCompleter(tab); } }
@Override public void onDisable() { if (storage != null) storage.close(); }
public void reloadPlugin() { reloadConfig(); messages = new MessageService(getConfig()); teams.reload(getConfig().getInt("limits.max-team-size", 8)); homes.reload(); }
public boolean teamHomesEnabled() { return getConfig().getBoolean("limits.team-home-enabled", true); }
@Override public void prompt(org.bukkit.entity.Player player, String action) {
prompts.put(player.getUniqueId(), action);
player.closeInventory();
player.sendMessage(action.equals("invite") ? "§bType the online player's name in chat, or type §fcancel§b." : action.equals("create") ? "§bType the new team name in chat, or type §fcancel§b." : "§bType a team color in chat, or type §fcancel§b.");
}
public String consumePrompt(UUID player) { return prompts.remove(player); }
@Override public MessageService messages() { return messages; }
@Override public org.bukkit.plugin.java.JavaPlugin plugin() { return this; }
@Override public org.bukkit.configuration.file.FileConfiguration config() { return getConfig(); }
@Override public TeamManager teams() { return teams; }
@Override public HomeManager homes() { return homes; }
@Override public TeleportService teleports() { return teleports; }
@Override public GUIManager gui() { return gui; }
}