Files
src
build.gradle
Code
19 1,148
src/main/java/com/custommodernhome/CustomModernHome.java
package com.custommodernhome;
import com.custommodernhome.command.DelHomeCommand;
import com.custommodernhome.command.HomeCommand;
import com.custommodernhome.command.SetHomeCommand;
import com.custommodernhome.inventory.gui.GUIListener;
import com.custommodernhome.inventory.gui.GUIManager;
import com.custommodernhome.listener.PlayerListener;
import com.custommodernhome.util.ColorUtil;
import com.custommodernhome.util.HomeManager;
import com.custommodernhome.util.PermissionManager;
import com.custommodernhome.util.TeleportManager;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.function.Consumer;
@Getter
public class CustomModernHome extends JavaPlugin {
private HomeManager homeManager;
private TeleportManager teleportManager;
private PermissionManager permissionManager;
private GUIManager guiManager;
private final Map<UUID, Consumer<String>> chatPrompts = new HashMap<>();
@Override
public void onEnable() {
saveDefaultConfig();
this.homeManager = new HomeManager(this);
this.teleportManager = new TeleportManager(this);
this.permissionManager = new PermissionManager(this);
this.guiManager = new GUIManager();
GUIListener guiListener = new GUIListener(guiManager);
Bukkit.getPluginManager().registerEvents(guiListener, this);
PlayerListener playerListener = new PlayerListener(this);
Bukkit.getPluginManager().registerEvents(playerListener, this);
getCommand("home").setExecutor(new HomeCommand(this));
getCommand("sethome").setExecutor(new SetHomeCommand(this));
getCommand("delhome").setExecutor(new DelHomeCommand(this));
// Periodic rank-scan: delete excess homes when rank changes
int interval = getConfig().getInt("settings.rank-scan-interval", 60);
Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
for (Player player : Bukkit.getOnlinePlayers()) {
int maxHomes = permissionManager.getMaxHomes(player);
int homeCount = homeManager.getHomeCount(player.getUniqueId());
if (homeCount > maxHomes) {
Bukkit.getScheduler().runTask(this, () -> {
homeManager.deleteExcessHomes(player.getUniqueId(), maxHomes);
if (player.isOnline()) {
player.sendMessage(ColorUtil.colorize(
getConfig().getString("messages.homes-exceeded-rank")
.replace("<limit>", String.valueOf(maxHomes))));
}
});
}
}
}, 200L, interval * 20L);
getLogger().info("CustomModernHome has been enabled!");
}
@Override
public void onDisable() {
if (homeManager != null) {
homeManager.saveData();
}
getLogger().info("CustomModernHome has been disabled!");
}
public void addChatPrompt(UUID uuid, Consumer<String> callback) {
chatPrompts.put(uuid, callback);
}
public boolean hasChatPrompt(UUID uuid) {
return chatPrompts.containsKey(uuid);
}
public void handleChatInput(UUID uuid, String input) {
Consumer<String> callback = chatPrompts.remove(uuid);
if (callback != null) {
// Run on main thread since we modify data
Bukkit.getScheduler().runTask(this, () -> callback.accept(input));
}
}
public void removeChatPrompt(UUID uuid) {
chatPrompts.remove(uuid);
}
}