116 lines
3.0 KiB
Java
116 lines
3.0 KiB
Java
package eu.univento.core.commands;
|
|
|
|
import eu.univento.core.Core;
|
|
import eu.univento.core.api.AutoCommand;
|
|
import eu.univento.core.api.languages.Messages;
|
|
import eu.univento.core.api.player.CustomPlayer;
|
|
import eu.univento.core.api.player.Perms.Ranks;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* command to ban players
|
|
* @author joethei
|
|
* @version 1.0
|
|
*/
|
|
public class Ban extends AutoCommand<Core>{
|
|
|
|
/**
|
|
* @param plugin main class
|
|
* @param command command to execute
|
|
* @param description describes the command
|
|
* @param aliases aliases of command
|
|
*/
|
|
public Ban(Core plugin, String command, String description, String[] aliases) {
|
|
super(plugin, command, description, aliases);
|
|
}
|
|
|
|
@Override
|
|
public boolean execute(CommandSender sender, String label, String[] args) {
|
|
if(sender instanceof Player) {
|
|
CustomPlayer p = CustomPlayer.getPlayer(sender.getName());
|
|
Messages msgs = new Messages(p);
|
|
if(p.isAllowed(Ranks.Moderator)) {
|
|
if(args.length == 2) {
|
|
if(Bukkit.getPlayer(args[0]) != null) {
|
|
CustomPlayer t = CustomPlayer.getPlayer(args[0]);
|
|
if(getReasons().containsValue(args[1])) {
|
|
int id = getKey(args[1]);
|
|
t.ban(getReasons().get(id), p, getBanDurations().get(id));
|
|
}else {
|
|
p.sendMessage(msgs.PREFIX() + msgs.Core_BAN_NO_REASON());
|
|
}
|
|
}else {
|
|
p.sendMessage(msgs.PREFIX() + msgs.NOT_ONLINE(args[0]));
|
|
}
|
|
}else {
|
|
p.sendMessage(msgs.PREFIX() + msgs.Core_BAN_USAGE());
|
|
}
|
|
}else {
|
|
sender.sendMessage(msgs.NO_PERMS());
|
|
}
|
|
}else {
|
|
sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
|
List<String> list = new ArrayList<>();
|
|
for(int i = 0; i >= getReasons().size(); i++) {
|
|
list.add(getReasons().get(i));
|
|
}
|
|
return list;
|
|
}
|
|
|
|
/**
|
|
* @return all possible ban reasons
|
|
*/
|
|
private HashMap<Integer, String> getReasons() {
|
|
HashMap<Integer, String> map = new HashMap<>();
|
|
|
|
map.put(1, "Hacking");
|
|
map.put(2, "Griefing");
|
|
map.put(3, "Bugusing");
|
|
map.put(4, "Insult");
|
|
map.put(5, "Spam");
|
|
map.put(6, "Banumgehung");
|
|
map.put(7, "Advertising");
|
|
map.put(8, "Trolling");
|
|
|
|
return map;
|
|
}
|
|
|
|
/**
|
|
* @return ban durations to reason
|
|
*/
|
|
private HashMap<Integer, Integer> getBanDurations() {
|
|
HashMap<Integer, Integer> map = new HashMap<>();
|
|
|
|
map.put(1, 60);
|
|
map.put(2, 30);
|
|
map.put(3, 20);
|
|
map.put(4, 10);
|
|
map.put(5, 5);
|
|
map.put(6, 120);
|
|
map.put(7, 15);
|
|
map.put(8, 25);
|
|
|
|
return map;
|
|
}
|
|
|
|
private Integer getKey(String value) {
|
|
for(int key : getReasons().keySet()) {
|
|
if(getReasons().get(key).equals(value)) {
|
|
return key;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
} |