Files
src
pom.xml
README.md
Code
9 1,047
src/main/java/com/averix/homes/AverixHomes.java
package com.averix.homes;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public final class AverixHomes extends JavaPlugin {
private HomeStorage homeStorage;
private TeleportManager teleportManager;
private HomeGuiListener homeGuiListener;
@Override
public void onEnable() {
saveDefaultConfig();
homeStorage = new HomeStorage(this);
teleportManager = new TeleportManager(this);
homeGuiListener = new HomeGuiListener(this);
Bukkit.getPluginManager().registerEvents(teleportManager, this);
Bukkit.getPluginManager().registerEvents(homeGuiListener, this);
HomeCommand commandExecutor = new HomeCommand(this);
getCommand("home").setExecutor(commandExecutor);
getCommand("home").setTabCompleter(commandExecutor);
getCommand("homes").setExecutor(commandExecutor);
getCommand("sethome").setExecutor(commandExecutor);
getCommand("sethome").setTabCompleter(commandExecutor);
getCommand("delhome").setExecutor(commandExecutor);
getCommand("delhome").setTabCompleter(commandExecutor);
getCommand("renamehome").setExecutor(commandExecutor);
getCommand("renamehome").setTabCompleter(commandExecutor);
getCommand("homesee").setExecutor(commandExecutor);
getCommand("homesee").setTabCompleter(commandExecutor);
getCommand("averixhomes").setExecutor(commandExecutor);
}
public HomeStorage getHomeStorage() {
return homeStorage;
}
public TeleportManager getTeleportManager() {
return teleportManager;
}
public HomeGuiListener getHomeGuiListener() {
return homeGuiListener;
}
public int getHomeLimit(Player player) {
int configuredLimit = Math.min(5, Math.max(0, getConfig().getInt("max-homes", 2)));
for (int limit = 1; limit <= 5; limit++) {
if (player.hasPermission("averixhomes.slot." + limit)) {
configuredLimit = Math.max(configuredLimit, limit);
}
}
var limits = getConfig().getConfigurationSection("permission-limits");
if (limits == null) {
return configuredLimit;
}
Integer permissionLimit = null;
for (String permission : limits.getKeys(false)) {
if (!player.hasPermission(permission)) {
continue;
}
int value = Math.min(5, Math.max(0, limits.getInt(permission, configuredLimit)));
if (permissionLimit == null || value > permissionLimit) {
permissionLimit = value;
}
}
return permissionLimit == null ? configuredLimit : Math.max(configuredLimit, permissionLimit);
}
public void sendMessage(Player player, String key) {
sendMessage(player, key, "", "");
}
public void sendMessage(Player player, String key, String placeholder, String value) {
String message = getConfig().getString("messages." + key, "&dᴀᴠᴇʀɪx &8» &cᴇʀʀᴏʀ.");
message = message.replace(placeholder, value);
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
}
public void playConfiguredSound(Player player, String key) {
String sound = getConfig().getString("sounds." + key, "");
if (sound != null && !sound.isBlank()) {
player.playSound(player.getLocation(), sound, 1.0f, 1.0f);
}
}
}