49 lines
1.7 KiB
Java
49 lines
1.7 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 UnblockCommand implements CommandExecutor {
|
|
|
|
private final BlockManager blockManager;
|
|
private final FileConfiguration config;
|
|
|
|
public UnblockCommand(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.unblock.usage"));
|
|
return true;
|
|
}
|
|
|
|
Player target = Bukkit.getPlayerExact(args[0]);
|
|
if (target == null || target == player) {
|
|
player.sendMessage(config.getString("messages.unblock.invalid_player"));
|
|
return true;
|
|
}
|
|
|
|
if (blockManager.hasBlocked(player, target)) {
|
|
blockManager.unblockPlayer(player, target);
|
|
player.sendMessage(config.getString("messages.unblock.unblocked").replace("%player%", target.getName()));
|
|
target.sendMessage(config.getString("messages.unblock.unblocked_by").replace("%player%", player.getName()));
|
|
} else {
|
|
player.sendMessage(config.getString("messages.unblock.not_blocked").replace("%player%", target.getName()));
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|