Update to Minecraft 1.21.8, add checkstyle, fix compilation errors

- Update Paper API: 1.20.1 -> 1.21.4
- Update plugin version: 1.5.5-1.20.1 -> 1.5.5-1.21.8
- Add checkstyle plugin with reasonable rules
- Fix Enchantment.LUCK -> Enchantment.UNBREAKING
- Fix EntityType.FIREWORK -> EntityType.FIREWORK_ROCKET
- Remove unused imports
- Add temp_*/ to .gitignore
- 118 files changed, 1633 insertions(+), 1301 deletions(-)
This commit is contained in:
loki5512344 2026-02-24 00:04:03 +01:00
parent 6a4c8a7886
commit e78d8a2de4
121 changed files with 1792 additions and 1301 deletions

View file

@ -11,67 +11,67 @@ import com.loki.lohub.utils.PlaceholderUtil;
import org.bukkit.plugin.java.JavaPlugin;
public class LoHub extends JavaPlugin {
private ConfigManager configManager;
private SpawnManager spawnManager;
private RegionManager regionManager;
private ActionManager actionManager;
private CooldownManager cooldownManager;
@Override
public void onEnable() {
getLogger().info("Loading LoHub v" + getDescription().getVersion());
saveDefaultConfig();
PlaceholderUtil.init();
this.configManager = new ConfigManager(this);
this.spawnManager = new SpawnManager(this);
this.regionManager = new RegionManager(this);
this.actionManager = new ActionManager(this);
this.cooldownManager = new CooldownManager();
registerListeners();
registerCommands();
regionManager.createHubRegion();
getLogger().info("LoHub successfully loaded!");
}
@Override
public void onDisable() {
getLogger().info("LoHub disabled!");
}
private void registerListeners() {
getServer().getPluginManager().registerEvents(new HubProtectionListener(this), this);
getServer().getPluginManager().registerEvents(new PlayerJoinListener(this), this);
}
private void registerCommands() {
getCommand("hub").setExecutor(new com.loki.lohub.commands.HubCommand(this));
getCommand("sethub").setExecutor(new com.loki.lohub.commands.SetHubCommand(this));
getCommand("lohub").setExecutor(new com.loki.lohub.commands.LoHubCommand(this));
}
public ConfigManager getConfigManager() {
return configManager;
}
public SpawnManager getSpawnManager() {
return spawnManager;
}
public RegionManager getRegionManager() {
return regionManager;
}
public ActionManager getActionManager() {
return actionManager;
}
public CooldownManager getCooldownManager() {
return cooldownManager;
}

View file

@ -3,8 +3,8 @@ package com.loki.lohub.actions;
import org.bukkit.entity.Player;
public interface Action {
void execute(Player player);
ActionType getType();
}

View file

@ -12,7 +12,7 @@ public enum ActionType {
EFFECT,
CLOSE,
UNKNOWN;
public static ActionType fromString(String type) {
try {
return valueOf(type.toUpperCase());

View file

@ -8,19 +8,19 @@ import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
public class ActionbarAction implements Action {
private final String message;
public ActionbarAction(String message) {
this.message = message;
}
@Override
public void execute(Player player) {
String parsed = PlaceholderUtil.parse(message, player);
player.sendActionBar(Component.text(TextUtil.colorize(parsed)));
}
@Override
public ActionType getType() {
return ActionType.ACTIONBAR;

View file

@ -8,19 +8,19 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class BroadcastAction implements Action {
private final String message;
public BroadcastAction(String message) {
this.message = message;
}
@Override
public void execute(Player player) {
String parsed = PlaceholderUtil.parse(message, player);
Bukkit.broadcastMessage(TextUtil.colorize(parsed));
}
@Override
public ActionType getType() {
return ActionType.BROADCAST;

View file

@ -5,12 +5,12 @@ import com.loki.lohub.actions.ActionType;
import org.bukkit.entity.Player;
public class CloseAction implements Action {
@Override
public void execute(Player player) {
player.closeInventory();
}
@Override
public ActionType getType() {
return ActionType.CLOSE;

View file

@ -6,19 +6,19 @@ import com.loki.lohub.utils.PlaceholderUtil;
import org.bukkit.entity.Player;
public class CommandAction implements Action {
private final String command;
public CommandAction(String command) {
this.command = command;
}
@Override
public void execute(Player player) {
String parsed = PlaceholderUtil.parse(command, player);
player.performCommand(parsed);
}
@Override
public ActionType getType() {
return ActionType.COMMAND;

View file

@ -7,19 +7,19 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class ConsoleAction implements Action {
private final String command;
public ConsoleAction(String command) {
this.command = command;
}
@Override
public void execute(Player player) {
String parsed = PlaceholderUtil.parse(command, player);
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), parsed);
}
@Override
public ActionType getType() {
return ActionType.CONSOLE;

View file

@ -7,36 +7,36 @@ import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public class EffectAction implements Action {
private final PotionEffectType effectType;
private final int amplifier;
private final int duration;
public EffectAction(String effectData) {
String[] parts = effectData.split(";");
PotionEffectType parsed;
try {
parsed = PotionEffectType.getByName(parts[0].toUpperCase());
} catch (Exception e) {
parsed = PotionEffectType.SPEED;
}
this.effectType = parsed != null ? parsed : PotionEffectType.SPEED;
this.amplifier = parts.length > 1 ? parseInt(parts[1], 0) : 0;
this.duration = parts.length > 2 ? parseInt(parts[2], 999999) : 999999;
}
@Override
public void execute(Player player) {
player.addPotionEffect(new PotionEffect(effectType, duration * 20, amplifier, false, false));
}
@Override
public ActionType getType() {
return ActionType.EFFECT;
}
private int parseInt(String value, int defaultValue) {
try {
return Integer.parseInt(value);

View file

@ -6,9 +6,9 @@ import org.bukkit.GameMode;
import org.bukkit.entity.Player;
public class GamemodeAction implements Action {
private final GameMode gameMode;
public GamemodeAction(String mode) {
GameMode parsed;
try {
@ -24,12 +24,12 @@ public class GamemodeAction implements Action {
}
this.gameMode = parsed;
}
@Override
public void execute(Player player) {
player.setGameMode(gameMode);
}
@Override
public ActionType getType() {
return ActionType.GAMEMODE;

View file

@ -7,19 +7,19 @@ import com.loki.lohub.utils.TextUtil;
import org.bukkit.entity.Player;
public class MessageAction implements Action {
private final String message;
public MessageAction(String message) {
this.message = message;
}
@Override
public void execute(Player player) {
String parsed = PlaceholderUtil.parse(message, player);
player.sendMessage(TextUtil.colorize(parsed));
}
@Override
public ActionType getType() {
return ActionType.MESSAGE;

View file

@ -6,36 +6,36 @@ import org.bukkit.Sound;
import org.bukkit.entity.Player;
public class SoundAction implements Action {
private final Sound sound;
private final float volume;
private final float pitch;
public SoundAction(String soundData) {
String[] parts = soundData.split(";");
Sound parsedSound;
try {
parsedSound = Sound.valueOf(parts[0].toUpperCase());
} catch (IllegalArgumentException e) {
parsedSound = Sound.ENTITY_EXPERIENCE_ORB_PICKUP;
}
this.sound = parsedSound;
this.volume = parts.length > 1 ? parseFloat(parts[1], 1.0f) : 1.0f;
this.pitch = parts.length > 2 ? parseFloat(parts[2], 1.0f) : 1.0f;
}
@Override
public void execute(Player player) {
player.playSound(player.getLocation(), sound, volume, pitch);
}
@Override
public ActionType getType() {
return ActionType.SOUND;
}
private float parseFloat(String value, float defaultValue) {
try {
return Float.parseFloat(value);

View file

@ -11,46 +11,46 @@ import org.bukkit.entity.Player;
import java.time.Duration;
public class TitleAction implements Action {
private final String title;
private final String subtitle;
private final int fadeIn;
private final int stay;
private final int fadeOut;
public TitleAction(String titleData) {
String[] parts = titleData.split(";");
this.title = parts.length > 0 ? parts[0] : "";
this.subtitle = parts.length > 1 ? parts[1] : "";
this.fadeIn = parts.length > 2 ? parseInt(parts[2], 10) : 10;
this.stay = parts.length > 3 ? parseInt(parts[3], 40) : 40;
this.fadeOut = parts.length > 4 ? parseInt(parts[4], 10) : 10;
}
@Override
public void execute(Player player) {
String parsedTitle = PlaceholderUtil.parse(title, player);
String parsedSubtitle = PlaceholderUtil.parse(subtitle, player);
Component titleComponent = Component.text(TextUtil.colorize(parsedTitle));
Component subtitleComponent = Component.text(TextUtil.colorize(parsedSubtitle));
Title.Times times = Title.Times.times(
Duration.ofMillis(fadeIn * 50L),
Duration.ofMillis(stay * 50L),
Duration.ofMillis(fadeOut * 50L)
Duration.ofMillis(fadeIn * 50L),
Duration.ofMillis(stay * 50L),
Duration.ofMillis(fadeOut * 50L)
);
Title title = Title.title(titleComponent, subtitleComponent, times);
player.showTitle(title);
}
@Override
public ActionType getType() {
return ActionType.TITLE;
}
private int parseInt(String value, int defaultValue) {
try {
return Integer.parseInt(value);

View file

@ -8,28 +8,28 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class HubCommand implements CommandExecutor {
private final LoHub plugin;
public HubCommand(LoHub plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player player)) {
sender.sendMessage(TextUtil.colorize("&cThis command is only for players!"));
return true;
}
if (plugin.getSpawnManager().getSpawn() == null) {
player.sendMessage(TextUtil.colorize(plugin.getConfig().getString("messages.no-spawn")));
return true;
}
plugin.getSpawnManager().teleportToSpawn(player);
player.sendMessage(TextUtil.colorize(plugin.getConfig().getString("messages.spawn-teleport")));
return true;
}
}

View file

@ -7,32 +7,32 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class LoHubCommand implements CommandExecutor {
private final LoHub plugin;
public LoHubCommand(LoHub plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!sender.hasPermission("lohub.admin")) {
sender.sendMessage(TextUtil.colorize(plugin.getConfig().getString("messages.no-permission")));
return true;
}
if (args.length == 0) {
sender.sendMessage(TextUtil.colorize("&7LoHub v" + plugin.getDescription().getVersion()));
sender.sendMessage(TextUtil.colorize("&7Use: &e/lohub reload"));
return true;
}
if (args[0].equalsIgnoreCase("reload")) {
plugin.getConfigManager().reload();
sender.sendMessage(TextUtil.colorize("&aConfiguration reloaded!"));
return true;
}
return true;
}
}

View file

@ -8,35 +8,35 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class SetHubCommand implements CommandExecutor {
private final LoHub plugin;
public SetHubCommand(LoHub plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player player)) {
sender.sendMessage(TextUtil.colorize("&cThis command is only for players!"));
return true;
}
if (!player.hasPermission("lohub.admin")) {
player.sendMessage(TextUtil.colorize(plugin.getConfig().getString("messages.no-permission")));
return true;
}
plugin.getSpawnManager().setSpawn(player.getLocation());
player.sendMessage(TextUtil.colorize(plugin.getConfig().getString("messages.spawn-set")));
plugin.getRegionManager().deleteHubRegion();
plugin.getRegionManager().createHubRegion();
if (plugin.getConfig().getBoolean("worldguard.auto-create-region")) {
player.sendMessage(TextUtil.colorize(plugin.getConfig().getString("messages.region-created")));
}
return true;
}
}

View file

@ -4,52 +4,52 @@ import com.loki.lohub.LoHub;
import org.bukkit.configuration.file.FileConfiguration;
public class ConfigManager {
private final LoHub plugin;
private FileConfiguration config;
public ConfigManager(LoHub plugin) {
this.plugin = plugin;
this.config = plugin.getConfig();
}
public void reload() {
plugin.reloadConfig();
this.config = plugin.getConfig();
}
public FileConfiguration getConfig() {
return config;
}
public boolean isProtectionEnabled() {
return config.getBoolean("protection.enabled", true);
}
public boolean isBlockBreakProtected() {
return config.getBoolean("protection.block-break", true);
}
public boolean isBlockPlaceProtected() {
return config.getBoolean("protection.block-place", true);
}
public boolean isPvPProtected() {
return config.getBoolean("protection.pvp", true);
}
public boolean isItemDropProtected() {
return config.getBoolean("protection.item-drop", true);
}
public boolean isItemPickupProtected() {
return config.getBoolean("protection.item-pickup", true);
}
public boolean isFoodLevelProtected() {
return config.getBoolean("protection.food-level", true);
}
public boolean isMobSpawningProtected() {
return config.getBoolean("protection.mob-spawning", true);
}

View file

@ -13,90 +13,120 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
public class HubProtectionListener implements Listener {
private final LoHub plugin;
public HubProtectionListener(LoHub plugin) {
this.plugin = plugin;
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
if (plugin.getConfig().getBoolean("spawn.teleport-on-join", true)) {
plugin.getSpawnManager().teleportToSpawn(event.getPlayer());
}
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
if (!plugin.getConfigManager().isProtectionEnabled()) return;
if (!plugin.getConfigManager().isProtectionEnabled()) {
return;
}
Player player = event.getPlayer();
if (player.hasPermission("lohub.bypass.protection")) return;
if (player.hasPermission("lohub.bypass.protection")) {
return;
}
if (plugin.getConfigManager().isBlockBreakProtected()) {
event.setCancelled(true);
}
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
if (!plugin.getConfigManager().isProtectionEnabled()) return;
if (!plugin.getConfigManager().isProtectionEnabled()) {
return;
}
Player player = event.getPlayer();
if (player.hasPermission("lohub.bypass.protection")) return;
if (player.hasPermission("lohub.bypass.protection")) {
return;
}
if (plugin.getConfigManager().isBlockPlaceProtected()) {
event.setCancelled(true);
}
}
@EventHandler
public void onPvP(EntityDamageByEntityEvent event) {
if (!plugin.getConfigManager().isProtectionEnabled()) return;
if (!(event.getDamager() instanceof Player)) return;
if (!(event.getEntity() instanceof Player)) return;
if (!plugin.getConfigManager().isProtectionEnabled()) {
return;
}
if (!(event.getDamager() instanceof Player)) {
return;
}
if (!(event.getEntity() instanceof Player)) {
return;
}
Player damager = (Player) event.getDamager();
if (damager.hasPermission("lohub.bypass.protection")) return;
if (damager.hasPermission("lohub.bypass.protection")) {
return;
}
if (plugin.getConfigManager().isPvPProtected()) {
event.setCancelled(true);
}
}
@EventHandler
public void onItemDrop(PlayerDropItemEvent event) {
if (!plugin.getConfigManager().isProtectionEnabled()) return;
if (!plugin.getConfigManager().isProtectionEnabled()) {
return;
}
Player player = event.getPlayer();
if (player.hasPermission("lohub.bypass.protection")) return;
if (player.hasPermission("lohub.bypass.protection")) {
return;
}
if (plugin.getConfigManager().isItemDropProtected()) {
event.setCancelled(true);
}
}
@EventHandler
public void onItemPickup(PlayerPickupItemEvent event) {
if (!plugin.getConfigManager().isProtectionEnabled()) return;
if (!plugin.getConfigManager().isProtectionEnabled()) {
return;
}
Player player = event.getPlayer();
if (player.hasPermission("lohub.bypass.protection")) return;
if (player.hasPermission("lohub.bypass.protection")) {
return;
}
if (plugin.getConfigManager().isItemPickupProtected()) {
event.setCancelled(true);
}
}
@EventHandler
public void onFoodLevelChange(FoodLevelChangeEvent event) {
if (!plugin.getConfigManager().isProtectionEnabled()) return;
if (!(event.getEntity() instanceof Player)) return;
if (!plugin.getConfigManager().isProtectionEnabled()) {
return;
}
if (!(event.getEntity() instanceof Player)) {
return;
}
Player player = (Player) event.getEntity();
if (player.hasPermission("lohub.bypass.protection")) return;
if (player.hasPermission("lohub.bypass.protection")) {
return;
}
if (plugin.getConfigManager().isFoodLevelProtected()) {
event.setCancelled(true);
}

View file

@ -20,37 +20,61 @@ import org.bukkit.inventory.meta.FireworkMeta;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
public class PlayerJoinListener implements Listener {
private static final Map<String, Color> COLOR_MAP = new HashMap<>();
static {
COLOR_MAP.put("AQUA", Color.AQUA);
COLOR_MAP.put("BLACK", Color.BLACK);
COLOR_MAP.put("BLUE", Color.BLUE);
COLOR_MAP.put("FUCHSIA", Color.FUCHSIA);
COLOR_MAP.put("GRAY", Color.GRAY);
COLOR_MAP.put("GREEN", Color.GREEN);
COLOR_MAP.put("LIME", Color.LIME);
COLOR_MAP.put("MAROON", Color.MAROON);
COLOR_MAP.put("NAVY", Color.NAVY);
COLOR_MAP.put("OLIVE", Color.OLIVE);
COLOR_MAP.put("ORANGE", Color.ORANGE);
COLOR_MAP.put("PURPLE", Color.PURPLE);
COLOR_MAP.put("RED", Color.RED);
COLOR_MAP.put("SILVER", Color.SILVER);
COLOR_MAP.put("TEAL", Color.TEAL);
COLOR_MAP.put("WHITE", Color.WHITE);
COLOR_MAP.put("YELLOW", Color.YELLOW);
}
private final LoHub plugin;
public PlayerJoinListener(LoHub plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if (isWorldDisabled(player.getWorld().getName())) {
return;
}
handleJoinMessage(event, player);
handleJoinSettings(player);
handleJoinEvents(player);
handleFirework(player);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
if (isWorldDisabled(player.getWorld().getName())) {
return;
}
if (plugin.getConfig().getBoolean("join_leave_messages.enabled", true)) {
String quitMessage = plugin.getConfig().getString("join_leave_messages.quit_message", "");
if (quitMessage.isEmpty()) {
@ -60,15 +84,15 @@ public class PlayerJoinListener implements Listener {
}
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerRespawn(PlayerRespawnEvent event) {
Player player = event.getPlayer();
if (isWorldDisabled(player.getWorld().getName())) {
return;
}
if (plugin.getConfig().getBoolean("spawn.teleport-on-respawn", true)) {
Location spawn = plugin.getSpawnManager().getSpawn();
if (spawn != null) {
@ -76,18 +100,18 @@ public class PlayerJoinListener implements Listener {
}
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerDeath(PlayerDeathEvent event) {
if (isWorldDisabled(event.getPlayer().getWorld().getName())) {
return;
}
if (plugin.getConfig().getBoolean("world_settings.disable_death_message", true)) {
event.deathMessage(null);
}
}
private void handleJoinMessage(PlayerJoinEvent event, Player player) {
if (plugin.getConfig().getBoolean("join_leave_messages.enabled", true)) {
String joinMessage = plugin.getConfig().getString("join_leave_messages.join_message", "");
@ -98,7 +122,7 @@ public class PlayerJoinListener implements Listener {
}
}
}
private void handleJoinSettings(Player player) {
if (plugin.getConfig().getBoolean("join_settings.spawn_join", true)) {
Location spawn = plugin.getSpawnManager().getSpawn();
@ -106,43 +130,43 @@ public class PlayerJoinListener implements Listener {
player.teleport(spawn);
}
}
if (plugin.getConfig().getBoolean("join_settings.heal", true)) {
player.setHealth(player.getMaxHealth());
player.setFoodLevel(20);
player.setSaturation(20);
}
if (plugin.getConfig().getBoolean("join_settings.extinguish", true)) {
player.setFireTicks(0);
}
if (plugin.getConfig().getBoolean("join_settings.clear_inventory", false)) {
player.getInventory().clear();
}
}
private void handleJoinEvents(Player player) {
List<String> actions = plugin.getConfig().getStringList("join_events");
if (!actions.isEmpty()) {
plugin.getActionManager().executeActions(player, actions, false);
}
}
private void handleFirework(Player player) {
if (!plugin.getConfig().getBoolean("join_settings.firework.enabled", false)) {
return;
}
boolean firstJoinOnly = plugin.getConfig().getBoolean("join_settings.firework.first_join_only", true);
if (firstJoinOnly && player.hasPlayedBefore()) {
return;
}
Location loc = player.getLocation();
Firework firework = (Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK);
Firework firework = (Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK_ROCKET);
FireworkMeta meta = firework.getFireworkMeta();
String typeStr = plugin.getConfig().getString("join_settings.firework.type", "BALL_LARGE");
FireworkEffect.Type type;
try {
@ -150,7 +174,7 @@ public class PlayerJoinListener implements Listener {
} catch (IllegalArgumentException e) {
type = FireworkEffect.Type.BALL_LARGE;
}
List<Color> colors = new ArrayList<>();
for (String colorStr : plugin.getConfig().getStringList("join_settings.firework.colors")) {
Color color = parseColor(colorStr);
@ -158,51 +182,32 @@ public class PlayerJoinListener implements Listener {
colors.add(color);
}
}
if (colors.isEmpty()) {
colors.add(Color.AQUA);
}
FireworkEffect effect = FireworkEffect.builder()
.with(type)
.withColor(colors)
.flicker(plugin.getConfig().getBoolean("join_settings.firework.flicker", true))
.trail(plugin.getConfig().getBoolean("join_settings.firework.trail", true))
.build();
.with(type)
.withColor(colors)
.flicker(plugin.getConfig().getBoolean("join_settings.firework.flicker", true))
.trail(plugin.getConfig().getBoolean("join_settings.firework.trail", true))
.build();
meta.addEffect(effect);
meta.setPower(plugin.getConfig().getInt("join_settings.firework.power", 1));
firework.setFireworkMeta(meta);
}
private Color parseColor(String colorStr) {
return switch (colorStr.toUpperCase()) {
case "AQUA" -> Color.AQUA;
case "BLACK" -> Color.BLACK;
case "BLUE" -> Color.BLUE;
case "FUCHSIA" -> Color.FUCHSIA;
case "GRAY" -> Color.GRAY;
case "GREEN" -> Color.GREEN;
case "LIME" -> Color.LIME;
case "MAROON" -> Color.MAROON;
case "NAVY" -> Color.NAVY;
case "OLIVE" -> Color.OLIVE;
case "ORANGE" -> Color.ORANGE;
case "PURPLE" -> Color.PURPLE;
case "RED" -> Color.RED;
case "SILVER" -> Color.SILVER;
case "TEAL" -> Color.TEAL;
case "WHITE" -> Color.WHITE;
case "YELLOW" -> Color.YELLOW;
default -> null;
};
return COLOR_MAP.get(colorStr.toUpperCase());
}
private boolean isWorldDisabled(String worldName) {
List<String> disabledWorlds = plugin.getConfig().getStringList("disabled-worlds.worlds");
boolean invert = plugin.getConfig().getBoolean("disabled-worlds.invert", false);
boolean isInList = disabledWorlds.contains(worldName);
return invert ? !isInList : isInList;
}
}

View file

@ -3,7 +3,16 @@ package com.loki.lohub.managers;
import com.loki.lohub.LoHub;
import com.loki.lohub.actions.Action;
import com.loki.lohub.actions.ActionType;
import com.loki.lohub.actions.impl.*;
import com.loki.lohub.actions.impl.ActionbarAction;
import com.loki.lohub.actions.impl.BroadcastAction;
import com.loki.lohub.actions.impl.CloseAction;
import com.loki.lohub.actions.impl.CommandAction;
import com.loki.lohub.actions.impl.ConsoleAction;
import com.loki.lohub.actions.impl.EffectAction;
import com.loki.lohub.actions.impl.GamemodeAction;
import com.loki.lohub.actions.impl.MessageAction;
import com.loki.lohub.actions.impl.SoundAction;
import com.loki.lohub.actions.impl.TitleAction;
import org.bukkit.entity.Player;
import java.util.ArrayList;
@ -12,43 +21,43 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ActionManager {
private final LoHub plugin;
private static final Pattern ACTION_PATTERN = Pattern.compile("\\[([A-Z]+)]\\s*(.*)");
private final LoHub plugin;
public ActionManager(LoHub plugin) {
this.plugin = plugin;
}
public List<Action> parseActions(List<String> actionStrings) {
List<Action> actions = new ArrayList<>();
for (String actionString : actionStrings) {
Action action = parseAction(actionString);
if (action != null) {
actions.add(action);
}
}
return actions;
}
public Action parseAction(String actionString) {
if (actionString == null || actionString.isEmpty()) {
return null;
}
Matcher matcher = ACTION_PATTERN.matcher(actionString);
if (!matcher.matches()) {
plugin.getLogger().warning("Invalid action format: " + actionString);
return null;
}
String typeStr = matcher.group(1);
String data = matcher.group(2);
ActionType type = ActionType.fromString(typeStr);
return switch (type) {
case MESSAGE -> new MessageAction(data);
case BROADCAST -> new BroadcastAction(data);
@ -66,7 +75,7 @@ public class ActionManager {
}
};
}
public void executeActions(Player player, List<Action> actions) {
for (Action action : actions) {
try {
@ -77,7 +86,7 @@ public class ActionManager {
}
}
}
public void executeActions(Player player, List<String> actionStrings, boolean parse) {
if (parse) {
List<Action> actions = parseActions(actionStrings);

View file

@ -5,55 +5,55 @@ import java.util.Map;
import java.util.UUID;
public class CooldownManager {
private final Map<String, Map<UUID, Long>> cooldowns = new HashMap<>();
public void setCooldown(String key, UUID playerId, int seconds) {
cooldowns.computeIfAbsent(key, k -> new HashMap<>())
.put(playerId, System.currentTimeMillis() + (seconds * 1000L));
.put(playerId, System.currentTimeMillis() + (seconds * 1000L));
}
public boolean hasCooldown(String key, UUID playerId) {
Map<UUID, Long> keyCooldowns = cooldowns.get(key);
if (keyCooldowns == null) {
return false;
}
Long expireTime = keyCooldowns.get(playerId);
if (expireTime == null) {
return false;
}
if (System.currentTimeMillis() >= expireTime) {
keyCooldowns.remove(playerId);
return false;
}
return true;
}
public int getRemainingSeconds(String key, UUID playerId) {
Map<UUID, Long> keyCooldowns = cooldowns.get(key);
if (keyCooldowns == null) {
return 0;
}
Long expireTime = keyCooldowns.get(playerId);
if (expireTime == null) {
return 0;
}
long remaining = expireTime - System.currentTimeMillis();
return remaining > 0 ? (int) (remaining / 1000) : 0;
}
public void removeCooldown(String key, UUID playerId) {
Map<UUID, Long> keyCooldowns = cooldowns.get(key);
if (keyCooldowns != null) {
keyCooldowns.remove(playerId);
}
}
public void clearAll() {
cooldowns.clear();
}

View file

@ -4,6 +4,8 @@ import com.loki.lohub.LoHub;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.RegionContainer;
@ -11,105 +13,100 @@ import org.bukkit.Location;
import org.bukkit.World;
public class RegionManager {
private final LoHub plugin;
private static final String HUB_REGION_NAME = "lohub_spawn";
private final LoHub plugin;
public RegionManager(LoHub plugin) {
this.plugin = plugin;
}
public void createHubRegion() {
if (!plugin.getConfig().getBoolean("worldguard.auto-create-region", true)) {
plugin.getLogger().info("WorldGuard region auto-creation is disabled");
return;
}
if (!isWorldGuardAvailable()) {
plugin.getLogger().warning("WorldGuard not found! Region will not be created.");
return;
}
Location spawn = plugin.getSpawnManager().getSpawn();
if (spawn == null || spawn.getWorld() == null) {
plugin.getLogger().warning("Spawn not set! Use /sethub");
return;
}
World world = spawn.getWorld();
int radius = plugin.getConfig().getInt("worldguard.region-radius", 100);
try {
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
com.sk89q.worldguard.protection.managers.RegionManager wgRegionManager = container.get(BukkitAdapter.adapt(world));
if (wgRegionManager == null) {
plugin.getLogger().warning("Failed to get RegionManager for world " + world.getName());
return;
}
ProtectedRegion existingRegion = wgRegionManager.getRegion(HUB_REGION_NAME);
if (existingRegion != null) {
plugin.getLogger().info("Region '" + HUB_REGION_NAME + "' already exists");
return;
}
BlockVector3 min = BlockVector3.at(
spawn.getBlockX() - radius,
world.getMinHeight(),
spawn.getBlockZ() - radius
spawn.getBlockX() - radius,
world.getMinHeight(),
spawn.getBlockZ() - radius
);
BlockVector3 max = BlockVector3.at(
spawn.getBlockX() + radius,
world.getMaxHeight(),
spawn.getBlockZ() + radius
spawn.getBlockX() + radius,
world.getMaxHeight(),
spawn.getBlockZ() + radius
);
ProtectedCuboidRegion region = new ProtectedCuboidRegion(HUB_REGION_NAME, min, max);
region.setFlag(com.sk89q.worldguard.protection.flags.Flags.PVP,
com.sk89q.worldguard.protection.flags.StateFlag.State.DENY);
region.setFlag(com.sk89q.worldguard.protection.flags.Flags.BLOCK_BREAK,
com.sk89q.worldguard.protection.flags.StateFlag.State.DENY);
region.setFlag(com.sk89q.worldguard.protection.flags.Flags.BLOCK_PLACE,
com.sk89q.worldguard.protection.flags.StateFlag.State.DENY);
region.setFlag(com.sk89q.worldguard.protection.flags.Flags.DAMAGE_ANIMALS,
com.sk89q.worldguard.protection.flags.StateFlag.State.DENY);
region.setFlag(com.sk89q.worldguard.protection.flags.Flags.MOB_SPAWNING,
com.sk89q.worldguard.protection.flags.StateFlag.State.DENY);
region.setFlag(com.sk89q.worldguard.protection.flags.Flags.LEAF_DECAY,
com.sk89q.worldguard.protection.flags.StateFlag.State.DENY);
region.setFlag(com.sk89q.worldguard.protection.flags.Flags.ITEM_DROP,
com.sk89q.worldguard.protection.flags.StateFlag.State.DENY);
region.setFlag(com.sk89q.worldguard.protection.flags.Flags.ITEM_PICKUP,
com.sk89q.worldguard.protection.flags.StateFlag.State.DENY);
setRegionFlags(region);
wgRegionManager.addRegion(region);
plugin.getLogger().info("Region '" + HUB_REGION_NAME + "' created around spawn (radius: " + radius + " blocks)");
plugin.getLogger().info("Coordinates: " + min + " -> " + max);
} catch (Exception e) {
plugin.getLogger().severe("Error creating WorldGuard region: " + e.getMessage());
e.printStackTrace();
}
}
private void setRegionFlags(ProtectedCuboidRegion region) {
region.setFlag(Flags.PVP, StateFlag.State.DENY);
region.setFlag(Flags.BLOCK_BREAK, StateFlag.State.DENY);
region.setFlag(Flags.BLOCK_PLACE, StateFlag.State.DENY);
region.setFlag(Flags.DAMAGE_ANIMALS, StateFlag.State.DENY);
region.setFlag(Flags.MOB_SPAWNING, StateFlag.State.DENY);
region.setFlag(Flags.LEAF_DECAY, StateFlag.State.DENY);
region.setFlag(Flags.ITEM_DROP, StateFlag.State.DENY);
region.setFlag(Flags.ITEM_PICKUP, StateFlag.State.DENY);
}
public void deleteHubRegion() {
if (!isWorldGuardAvailable()) {
return;
}
Location spawn = plugin.getSpawnManager().getSpawn();
if (spawn == null || spawn.getWorld() == null) {
return;
}
try {
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
com.sk89q.worldguard.protection.managers.RegionManager wgRegionManager = container.get(BukkitAdapter.adapt(spawn.getWorld()));
if (wgRegionManager != null) {
wgRegionManager.removeRegion(HUB_REGION_NAME);
plugin.getLogger().info("Region '" + HUB_REGION_NAME + "' deleted");
@ -118,7 +115,7 @@ public class RegionManager {
plugin.getLogger().severe("Error deleting region: " + e.getMessage());
}
}
private boolean isWorldGuardAvailable() {
try {
Class.forName("com.sk89q.worldguard.WorldGuard");

View file

@ -12,18 +12,18 @@ import java.io.File;
import java.io.IOException;
public class SpawnManager {
private final LoHub plugin;
private final File spawnFile;
private FileConfiguration spawnConfig;
private Location spawnLocation;
public SpawnManager(LoHub plugin) {
this.plugin = plugin;
this.spawnFile = new File(plugin.getDataFolder(), "spawn.yml");
loadSpawn();
}
private void loadSpawn() {
if (!spawnFile.exists()) {
try {
@ -32,9 +32,9 @@ public class SpawnManager {
plugin.getLogger().severe("Failed to create spawn.yml: " + e.getMessage());
}
}
spawnConfig = YamlConfiguration.loadConfiguration(spawnFile);
if (spawnConfig.contains("spawn")) {
String worldName = spawnConfig.getString("spawn.world");
double x = spawnConfig.getDouble("spawn.x");
@ -42,7 +42,7 @@ public class SpawnManager {
double z = spawnConfig.getDouble("spawn.z");
float yaw = (float) spawnConfig.getDouble("spawn.yaw");
float pitch = (float) spawnConfig.getDouble("spawn.pitch");
World world = Bukkit.getWorld(worldName);
if (world != null) {
spawnLocation = new Location(world, x, y, z, yaw, pitch);
@ -52,35 +52,35 @@ public class SpawnManager {
}
}
}
public Location getSpawn() {
return spawnLocation;
}
public void setSpawn(Location location) {
this.spawnLocation = location;
spawnConfig.set("spawn.world", location.getWorld().getName());
spawnConfig.set("spawn.x", location.getX());
spawnConfig.set("spawn.y", location.getY());
spawnConfig.set("spawn.z", location.getZ());
spawnConfig.set("spawn.yaw", location.getYaw());
spawnConfig.set("spawn.pitch", location.getPitch());
try {
spawnConfig.save(spawnFile);
plugin.getLogger().info("Spawn set: " + location.getWorld().getName() +
" (" + location.getBlockX() + ", " + location.getBlockY() + ", " + location.getBlockZ() + ")");
plugin.getLogger().info("Spawn set: " + location.getWorld().getName() +
" (" + location.getBlockX() + ", " + location.getBlockY() + ", " + location.getBlockZ() + ")");
} catch (IOException e) {
plugin.getLogger().severe("Failed to save spawn.yml: " + e.getMessage());
}
}
public Location getSpawn() {
return spawnLocation;
}
public void teleportToSpawn(Player player) {
if (spawnLocation == null) {
return;
}
player.teleport(spawnLocation);
}
}

View file

@ -9,83 +9,83 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class ItemBuilder {
private final ItemStack itemStack;
public ItemBuilder(Material material) {
this.itemStack = new ItemStack(material);
}
public ItemBuilder(ItemStack itemStack) {
this.itemStack = itemStack.clone();
}
public static ItemBuilder fromConfig(ConfigurationSection section) {
return fromConfig(section, null);
}
public static ItemBuilder fromConfig(ConfigurationSection section, Player player) {
String materialName = section.getString("material", "STONE").toUpperCase();
Material material;
try {
material = Material.valueOf(materialName);
} catch (IllegalArgumentException e) {
material = Material.STONE;
}
ItemBuilder builder = new ItemBuilder(material);
if (section.contains("amount")) {
builder.amount(section.getInt("amount", 1));
}
if (section.contains("display_name")) {
String name = section.getString("display_name");
builder.name(player != null ? PlaceholderUtil.parse(name, player) : name);
}
if (section.contains("lore")) {
List<String> lore = section.getStringList("lore");
builder.lore(player != null ?
lore.stream().map(line -> PlaceholderUtil.parse(line, player)).collect(Collectors.toList()) :
lore);
builder.lore(player != null ?
lore.stream().map(line -> PlaceholderUtil.parse(line, player)).collect(Collectors.toList()) :
lore);
}
if (section.contains("glow") && section.getBoolean("glow")) {
builder.glow();
}
if (section.contains("custom_model_data")) {
builder.customModelData(section.getInt("custom_model_data"));
}
if (section.contains("item_flags")) {
section.getStringList("item_flags").forEach(flagName -> {
try {
builder.flag(ItemFlag.valueOf(flagName.toUpperCase()));
} catch (IllegalArgumentException ignored) {}
} catch (IllegalArgumentException ignored) {
}
});
}
if (material == Material.PLAYER_HEAD && section.contains("skull_owner")) {
String owner = section.getString("skull_owner");
builder.skullOwner(player != null ? owner.replace("%player%", player.getName()) : owner);
}
return builder;
}
public ItemBuilder amount(int amount) {
itemStack.setAmount(Math.max(1, amount));
return this;
}
public ItemBuilder name(String name) {
ItemMeta meta = itemStack.getItemMeta();
if (meta != null) {
@ -94,23 +94,23 @@ public class ItemBuilder {
}
return this;
}
public ItemBuilder lore(List<String> lore) {
ItemMeta meta = itemStack.getItemMeta();
if (meta != null) {
List<String> coloredLore = lore.stream()
.map(TextUtil::colorize)
.collect(Collectors.toList());
.map(TextUtil::colorize)
.collect(Collectors.toList());
meta.setLore(coloredLore);
itemStack.setItemMeta(meta);
}
return this;
}
public ItemBuilder lore(String... lines) {
return lore(List.of(lines));
}
public ItemBuilder flag(ItemFlag... flags) {
ItemMeta meta = itemStack.getItemMeta();
if (meta != null) {
@ -119,17 +119,17 @@ public class ItemBuilder {
}
return this;
}
public ItemBuilder glow() {
ItemMeta meta = itemStack.getItemMeta();
if (meta != null) {
meta.addEnchant(Enchantment.LUCK, 1, true);
meta.addEnchant(Enchantment.UNBREAKING, 1, true);
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
itemStack.setItemMeta(meta);
}
return this;
}
public ItemBuilder customModelData(int data) {
ItemMeta meta = itemStack.getItemMeta();
if (meta != null) {
@ -138,7 +138,7 @@ public class ItemBuilder {
}
return this;
}
public ItemBuilder skullOwner(String owner) {
if (itemStack.getType() == Material.PLAYER_HEAD) {
SkullMeta meta = (SkullMeta) itemStack.getItemMeta();
@ -149,7 +149,7 @@ public class ItemBuilder {
}
return this;
}
public ItemStack build() {
return itemStack;
}

View file

@ -6,49 +6,53 @@ import org.bukkit.Location;
import org.bukkit.entity.Player;
public class PlaceholderUtil {
private static boolean placeholderAPIEnabled = false;
private PlaceholderUtil() {
// Utility class - prevent instantiation
}
public static void init() {
placeholderAPIEnabled = Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI");
}
public static String parse(String text, Player player) {
if (text == null) {
return "";
}
text = parseInternalPlaceholders(text, player);
if (placeholderAPIEnabled && player != null) {
text = PlaceholderAPI.setPlaceholders(player, text);
}
return text;
}
private static String parseInternalPlaceholders(String text, Player player) {
if (player != null) {
text = text.replace("%player%", player.getName());
text = text.replace("%player_displayname%", player.getDisplayName());
if (text.contains("%location%")) {
Location loc = player.getLocation();
text = text.replace("%location%",
loc.getBlockX() + ", " + loc.getBlockY() + ", " + loc.getBlockZ());
text = text.replace("%location%",
loc.getBlockX() + ", " + loc.getBlockY() + ", " + loc.getBlockZ());
}
if (text.contains("%world%")) {
text = text.replace("%world%", player.getWorld().getName());
}
}
text = text.replace("%online%", String.valueOf(Bukkit.getOnlinePlayers().size()));
text = text.replace("%online_max%", String.valueOf(Bukkit.getMaxPlayers()));
return text;
}
public static boolean isPlaceholderAPIEnabled() {
return placeholderAPIEnabled;
}

View file

@ -8,49 +8,53 @@ import java.util.regex.Pattern;
import java.util.stream.Collectors;
public class TextUtil {
private static final Pattern HEX_PATTERN = Pattern.compile("&#([A-Fa-f0-9]{6})");
private TextUtil() {
// Utility class - prevent instantiation
}
public static String colorize(String text) {
if (text == null || text.isEmpty()) {
return text;
}
text = translateHexCodes(text);
text = ChatColor.translateAlternateColorCodes('&', text);
return text;
}
public static List<String> colorize(List<String> lines) {
return lines.stream()
.map(TextUtil::colorize)
.collect(Collectors.toList());
.map(TextUtil::colorize)
.collect(Collectors.toList());
}
private static String translateHexCodes(String text) {
Matcher matcher = HEX_PATTERN.matcher(text);
StringBuffer buffer = new StringBuffer();
while (matcher.find()) {
String hexCode = matcher.group(1);
String replacement = ChatColor.of("#" + hexCode).toString();
matcher.appendReplacement(buffer, replacement);
}
matcher.appendTail(buffer);
return buffer.toString();
}
public static String strip(String text) {
return ChatColor.stripColor(text);
}
public static String joinFrom(int startIndex, String[] args) {
if (args == null || startIndex >= args.length) {
return "";
}
StringBuilder builder = new StringBuilder();
for (int i = startIndex; i < args.length; i++) {
builder.append(args[i]);
@ -58,15 +62,15 @@ public class TextUtil {
builder.append(" ");
}
}
return builder.toString();
}
public static String listToString(List<String> list) {
if (list == null || list.isEmpty()) {
return "";
}
return String.join("\n", list);
}
}

View file

@ -15,13 +15,13 @@ commands:
description: Teleport to spawn
usage: /hub
permission: lohub.hub
aliases: [spawn, хаб, спавн]
aliases: [ spawn, хаб, спавн ]
sethub:
description: Set hub spawn location
usage: /sethub
permission: lohub.admin
aliases: [setspawn, установитьспавн]
aliases: [ setspawn, установитьспавн ]
lohub:
description: LoHub admin command