* @param alias
* @return
*/
public static Boolean uninvite(CommandSender sender, String[] args, String command, String alias) {
if (CommandsEX.sqlEnabled) {
Player player = (Player)sender;
// remove the requested invite, if we didn't spam too much :)
if (!Utils.checkCommandSpam(player, "home-uninvite")) {
String pName = player.getName();
if (args.length == 1) {
// no arguments, provide command help
Commands.showCommandHelpAndUsage(sender, "cex_home", "home_uninvite");
return true;
}
try {
ResultSet res;
if (multiHomesEnabled) {
// if multiple homes are enabled, we uninvite from home in player's current world
res = SQLManager.query_res("SELECT id_home, allowed_players FROM " + SQLManager.prefix + "homes WHERE player_name = ? AND world_name = ?", pName, player.getWorld().getName());
} else {
// multiple homes disabled, we uninvite from player's home anywhere
res = SQLManager.query_res("SELECT id_home, allowed_players FROM " + SQLManager.prefix + "homes WHERE player_name = ?", pName);
}
while (res.next()) {
List<Object> newAllowedPlayers = new ArrayList<Object>();
Boolean playerFound = false;
if ((res.getString("allowed_players") != null) && !res.getString("allowed_players").equals("") && !res.wasNull()) {
String[] allowedPlayers = res.getString("allowed_players").split(",");
for (String s : allowedPlayers) {
if (!s.equals(args[1])) {
newAllowedPlayers.add(s);
} else {
playerFound = true;
}
}
// the requested player is not invited to this home
if (!playerFound) {
LogHelper.showInfo("[" + Nicknames.getNick(args[1]) + " #####homePlayerUninviteNotFound", sender);
return true;
}
} else {
// no invited players
LogHelper.showInfo("homeNoPlayersInvited", sender);
return true;
}
// update the DB with new newAllowedPlayers value
SQLManager.query("UPDATE " + SQLManager.prefix + "homes SET allowed_players = ? WHERE id_home = ?", Utils.implode(newAllowedPlayers, ","), res.getInt("id_home"));
// inform user that the player was uninvited
LogHelper.showInfos(sender, "[" + Nicknames.getNick(args[1]) + " #####homePlayerUninvited");
// if the actual player is online, inform him as well
Player p = Bukkit.getServer().getPlayer(args[1]);
if (p != null) {
LogHelper.showInfos(p, "homePlayerUninviteNotify#####[" + Nicknames.getNick(pName) + "#####homeYouHaveBeenInvited2");
}
// return here, since we can only uninvite a single player