48 lines
1.6 KiB
Java
48 lines
1.6 KiB
Java
package de.viper.survivalplus.commands;
|
|
|
|
import de.viper.survivalplus.Manager.BlockManager;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.command.*;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
|
|
public class BlockCommand implements CommandExecutor {
|
|
|
|
private final BlockManager blockManager;
|
|
private final FileConfiguration config;
|
|
|
|
public BlockCommand(BlockManager blockManager, FileConfiguration config) {
|
|
this.blockManager = blockManager;
|
|
this.config = config;
|
|
}
|
|
|
|
@Override
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
|
|
if (!(sender instanceof Player player)) {
|
|
sender.sendMessage(config.getString("messages.general.only_players"));
|
|
return true;
|
|
}
|
|
|
|
if (args.length != 1) {
|
|
player.sendMessage(config.getString("messages.block.usage"));
|
|
return true;
|
|
}
|
|
|
|
Player target = Bukkit.getPlayerExact(args[0]);
|
|
if (target == null || target == player) {
|
|
player.sendMessage(config.getString("messages.block.invalid_player"));
|
|
return true;
|
|
}
|
|
|
|
if (blockManager.hasBlocked(player, target)) {
|
|
player.sendMessage(config.getString("messages.block.already_blocked").replace("%player%", target.getName()));
|
|
} else {
|
|
blockManager.blockPlayer(player, target);
|
|
player.sendMessage(config.getString("messages.block.blocked").replace("%player%", target.getName()));
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|