src/main/java/de/viper/survivalplus/commands/BlockCommand.java aktualisiert
This commit is contained in:
@@ -1,45 +1,47 @@
|
||||
package de.viper.survivalplus.commands;
|
||||
|
||||
import de.viper.survivalplus.Manager.BlockManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class BlockCommand implements CommandExecutor {
|
||||
|
||||
private final BlockManager blockManager;
|
||||
|
||||
public BlockCommand(BlockManager blockManager) {
|
||||
this.blockManager = blockManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
if (!(sender instanceof Player player)) {
|
||||
sender.sendMessage("Dieser Befehl ist nur für Spieler.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length != 1) {
|
||||
player.sendMessage("§cBenutze: /block <Spieler>");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player target = Bukkit.getPlayerExact(args[0]);
|
||||
if (target == null || target == player) {
|
||||
player.sendMessage("§cUngültiger Spieler.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (blockManager.hasBlocked(player, target)) {
|
||||
blockManager.unblockPlayer(player, target);
|
||||
player.sendMessage("§aDu hast §e" + target.getName() + "§a entblockt.");
|
||||
} else {
|
||||
blockManager.blockPlayer(player, target);
|
||||
player.sendMessage("§cDu hast §e" + target.getName() + "§c blockiert.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user