use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class CommandKick method onCommand.
@Override
public void onCommand(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
// Command handling
String playerName = commandData.getArgs()[1];
UUID playerUUID = null;
Set<UUID> matchingPlayers = LLAPIHandler.getPlayerByName(playerName);
List<UUID> listPlayers = new LinkedList<>(matchingPlayers);
listPlayers.removeIf((uuid) -> !getPlugin().getPlayerManager().getPlayer(uuid).isInParty());
Collections.sort(listPlayers);
if (listPlayers.size() > 1) {
// Check if the player have selected someone
if (commandData.getArgs().length > 2) {
try {
int sel = Integer.parseInt(commandData.getArgs()[2]);
playerUUID = listPlayers.get(sel - 1);
} catch (Exception ignored) {
}
}
// The player didn't select a player
if (playerUUID == null) {
for (String str : Messages.MAINCMD_KICK_CONFLICT_CONTENT) {
if (str.contains("%list_players%")) {
int i = 1;
for (UUID uuid : listPlayers) {
PartyPlayerImpl pp = getPlugin().getPlayerManager().getPlayer(uuid);
sendMessage(sender, partyPlayer, Messages.MAINCMD_KICK_CONFLICT_PLAYER.replace("%number%", Integer.toString(i)).replace("%username%", playerName), pp, getPlugin().getPartyManager().getPartyOfPlayer(pp));
i++;
}
} else {
sendMessage(sender, partyPlayer, str);
}
}
return;
}
} else if (listPlayers.size() == 1) {
// Player found
playerUUID = listPlayers.get(0);
} else {
// Not found
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PLAYER_NOT_FOUND.replace("%player%", playerName));
return;
}
OfflineUser kickedPlayer = plugin.getOfflinePlayer(playerUUID);
Objects.requireNonNull(kickedPlayer);
PartyPlayerImpl kickedPp = getPlugin().getPlayerManager().getPlayer(playerUUID);
PartyImpl party = partyPlayer != null ? getPlugin().getPartyManager().getParty(partyPlayer.getPartyId()) : null;
boolean otherParty = false;
if (party == null || !party.getMembers().contains(kickedPlayer.getUUID())) {
// Other party
otherParty = true;
if (commandData.havePermission(PartiesPermission.ADMIN_KICK_OTHERS)) {
party = getPlugin().getPartyManager().getParty(kickedPp.getPartyId());
if (party == null) {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PLAYER_NOT_IN_PARTY, kickedPp);
return;
}
} else {
sendMessage(sender, partyPlayer, Messages.MAINCMD_KICK_PLAYERNOTINPARTY, kickedPp);
return;
}
} else {
// Same party
if (partyPlayer.getRank() < kickedPp.getRank() && !commandData.havePermission(PartiesPermission.ADMIN_KICK_OTHERS)) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_KICK_PLAYERHIGHERRANK, kickedPp);
return;
}
}
// Command starts
// Calling API event
IPlayerPreLeaveEvent partiesPreLeaveEvent = getPlugin().getEventManager().preparePlayerPreLeaveEvent(kickedPp, party, LeaveCause.KICK, partyPlayer);
getPlugin().getEventManager().callEvent(partiesPreLeaveEvent);
if (!partiesPreLeaveEvent.isCancelled()) {
if (party.getLeader() != null && party.getLeader().equals(kickedPlayer.getUUID())) {
// Leader
boolean mustDelete = true;
// Check if leader can be changed
if (ConfigParties.GENERAL_MEMBERS_ON_PARTY_LEAVE_CHANGE_LEADER && party.getMembers().size() > 1) {
PartyPlayerImpl newLeader = party.findNewLeader();
if (newLeader != null) {
// Found a new leader
mustDelete = false;
party.changeLeader(newLeader);
party.removeMember(kickedPp, LeaveCause.KICK, partyPlayer);
sendMessage(sender, partyPlayer, Messages.MAINCMD_KICK_SENT, kickedPp);
party.broadcastMessage(Messages.MAINCMD_KICK_BROADCAST_LEADER_CHANGED, newLeader);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_KICK_LEADER_CHANGE, sender.getName(), kickedPp.getName(), party.getName() != null ? party.getName() : "_", newLeader.getName()), true);
}
}
if (mustDelete) {
// Calling Pre API event
IPartyPreDeleteEvent partiesPreDeleteEvent = getPlugin().getEventManager().preparePartyPreDeleteEvent(party, DeleteCause.KICK, kickedPp, partyPlayer);
getPlugin().getEventManager().callEvent(partiesPreDeleteEvent);
if (!partiesPreDeleteEvent.isCancelled()) {
// Disbanding party
sendMessage(sender, partyPlayer, Messages.MAINCMD_KICK_SENT, kickedPp);
party.broadcastMessage(Messages.MAINCMD_KICK_BROADCAST_DISBAND, kickedPp);
party.delete(DeleteCause.KICK, kickedPp, partyPlayer);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_KICK, sender.getName(), kickedPp.getName(), party.getName() != null ? party.getName() : "_", otherParty, true), true);
} else
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_DELETEEVENT_DENY, party.getId(), sender.getName(), sender.getUUID().toString()), true);
}
} else {
// Normal
if (kickedPlayer.isOnline()) {
// Online
kickedPp.sendMessage(Messages.MAINCMD_KICK_PLAYERKICKED, partyPlayer);
}
party.removeMember(kickedPp, LeaveCause.KICK, partyPlayer);
sendMessage(sender, partyPlayer, Messages.MAINCMD_KICK_SENT, kickedPp);
party.broadcastMessage(Messages.MAINCMD_KICK_BROADCAST, kickedPp);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_KICK, sender.getName(), kickedPp.getName(), party.getName() != null ? party.getName() : "_", otherParty, false), true);
}
} else
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_LEAVEEVENT_DENY, sender.getUUID().toString(), party.getId()), true);
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class CommandMotd method onCommand.
@Override
public void onCommand(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
PartyImpl party = ((PartiesCommandData) commandData).getParty();
// Command handling
boolean isRemove = false;
String motd = "";
if (commandData.getArgs()[1].equalsIgnoreCase(ConfigMain.COMMANDS_MISC_REMOVE)) {
// Remove command
isRemove = true;
} else {
motd = plugin.getCommandManager().getCommandUtils().handleCommandString(commandData.getArgs(), 1);
if (!CensorUtils.checkAllowedCharacters(ConfigParties.ADDITIONAL_MOTD_ALLOWEDCHARS, motd, PartiesConstants.DEBUG_CMD_MOTD_REGEXERROR_ALLOWEDCHARS) || (motd.length() > ConfigParties.ADDITIONAL_MOTD_MAXLENGTH) || (motd.length() < ConfigParties.ADDITIONAL_MOTD_MINLENGTH)) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_MOTD_INVALID);
return;
}
if (CensorUtils.checkCensor(ConfigParties.ADDITIONAL_MOTD_CENSORREGEX, motd, PartiesConstants.DEBUG_CMD_MOTD_REGEXERROR_CENSORED)) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_MOTD_CENSORED);
return;
}
if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.MOTD, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
return;
}
// Command starts
party.setMotd(motd);
if (isRemove) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_MOTD_REMOVED);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_MOTD, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
} else {
sendMessage(sender, partyPlayer, Messages.ADDCMD_MOTD_CHANGED);
party.broadcastMessage(Messages.ADDCMD_MOTD_BROADCAST, partyPlayer);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_MOTD_REM, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
}
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class CommandNickname method onCommand.
@Override
public void onCommand(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl senderPp = ((PartiesCommandData) commandData).getPartyPlayer();
// Command handling
String playerName = commandData.getArgs()[1];
UUID playerUUID;
Set<UUID> matchingPlayers;
if (LLAPIHandler.isEnabled()) {
// Use LastLoginAPI to get a list of players with the same name
matchingPlayers = LLAPIHandler.getPlayerByName(playerName);
} else {
// Get only the online player with the same name
matchingPlayers = new HashSet<>();
User user = plugin.getPlayerByName(playerName);
if (user != null)
matchingPlayers.add(user.getUUID());
}
List<UUID> listPlayers = new LinkedList<>(matchingPlayers);
if (listPlayers.size() == 0) {
sendMessage(sender, senderPp, Messages.PARTIES_COMMON_PLAYER_NOT_FOUND.replace("%player%", playerName));
return;
}
listPlayers.removeIf((uuid) -> !getPlugin().getPlayerManager().getPlayer(uuid).isInParty());
playerUUID = listPlayers.stream().findAny().orElse(null);
if (playerUUID == null) {
sendMessage(sender, senderPp, Messages.PARTIES_COMMON_PLAYER_NOT_IN_PARTY.replace("%player%", playerName));
return;
}
OfflineUser targetPlayer = plugin.getOfflinePlayer(playerUUID);
Objects.requireNonNull(targetPlayer);
PartyPlayerImpl targetPp = getPlugin().getPlayerManager().getPlayer(playerUUID);
PartyImpl party = getPlugin().getPartyManager().getParty(targetPp.getPartyId());
boolean isOwn = senderPp != null && senderPp.getPlayerUUID().equals(targetPp.getPlayerUUID());
if (party == null) {
sendMessage(sender, senderPp, Messages.PARTIES_COMMON_NOTINPARTY);
return;
}
if (senderPp != null) {
if (isOwn) {
if (!getPlugin().getRankManager().checkPlayerRank(senderPp, RankPermission.EDIT_NICKNAME_OWN)) {
sendMessage(sender, senderPp, Messages.ADDCMD_NICKNAME_OWN_NO_PERMISSION);
return;
}
} else {
if (!party.getId().equals(senderPp.getPartyId()) && !commandData.havePermission(PartiesPermission.ADMIN_NICKNAME_OTHERS)) {
sendMessage(sender, senderPp, Messages.ADDCMD_NICKNAME_OTHERS_NO_PERMISSION);
return;
}
if (!getPlugin().getRankManager().checkPlayerRank(senderPp, RankPermission.EDIT_NICKNAME_OTHERS)) {
sendMessage(sender, senderPp, Messages.ADDCMD_NICKNAME_OTHERS_NO_PERMISSION);
return;
}
}
}
if (commandData.getArgs().length == 2) {
if (targetPp.getNickname() != null) {
sendMessage(sender, senderPp, isOwn ? Messages.ADDCMD_NICKNAME_SHOW_OWN : Messages.ADDCMD_NICKNAME_SHOW_OTHER, targetPp);
} else {
sendMessage(sender, senderPp, isOwn ? Messages.ADDCMD_NICKNAME_SHOW_OWN_NONE : Messages.ADDCMD_NICKNAME_SHOW_OTHER_NONE, targetPp);
}
} else if (commandData.getArgs().length >= 3) {
// Set/remove
boolean isRemove = false;
String nickname = "";
if (commandData.getArgs()[2].equalsIgnoreCase(ConfigMain.COMMANDS_MISC_REMOVE)) {
// Remove command
isRemove = true;
} else {
nickname = plugin.getCommandManager().getCommandUtils().handleCommandString(commandData.getArgs(), 2);
if (!CensorUtils.checkAllowedCharacters(ConfigParties.ADDITIONAL_NICKNAME_ALLOWEDCHARS, nickname, PartiesConstants.DEBUG_CMD_NICKNAME_REGEXERROR_ALLOWEDCHARS) || (nickname.length() > ConfigParties.ADDITIONAL_NICKNAME_MAXLENGTH) || (nickname.length() < ConfigParties.ADDITIONAL_NICKNAME_MINLENGTH)) {
sendMessage(sender, senderPp, Messages.ADDCMD_NICKNAME_INVALID);
return;
}
if (CensorUtils.checkCensor(ConfigParties.ADDITIONAL_NICKNAME_CENSORREGEX, nickname, PartiesConstants.DEBUG_CMD_NICKNAME_REGEXERROR_CENSORED)) {
sendMessage(sender, senderPp, Messages.ADDCMD_NICKNAME_CENSORED);
return;
}
if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.NICKNAME, senderPp, commandData.getCommandLabel(), commandData.getArgs()))
return;
}
// Command starts
if (isRemove) {
targetPp.setNickname(null);
if (isOwn) {
sendMessage(sender, senderPp, Messages.ADDCMD_NICKNAME_OWN_REMOVED, targetPp);
} else {
sendMessage(sender, senderPp, Messages.ADDCMD_NICKNAME_OTHERS_REMOVED, targetPp);
if (senderPp != null && targetPlayer.isOnline())
targetPp.sendMessage(Messages.ADDCMD_NICKNAME_OTHERS_TARGET_REMOVED, senderPp);
}
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_NICKNAME, sender.getName(), targetPp.getName()), true);
} else {
targetPp.setNickname(nickname);
if (isOwn) {
sendMessage(sender, senderPp, Messages.ADDCMD_NICKNAME_OWN_CHANGED, targetPp);
} else {
sendMessage(sender, senderPp, Messages.ADDCMD_NICKNAME_OTHERS_CHANGED, targetPp);
if (senderPp != null && targetPlayer.isOnline())
targetPp.sendMessage(Messages.ADDCMD_NICKNAME_OTHERS_TARGET_CHANGED.replace("%nickname%", nickname), senderPp);
}
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_NICKNAME_REM, sender.getName(), targetPp.getName()), true);
}
}
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class CommandPassword method onCommand.
@Override
public void onCommand(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
PartyImpl party = ((PartiesCommandData) commandData).getParty();
// Command handling
boolean isRemove = false;
String password;
if (commandData.getArgs()[1].equalsIgnoreCase(ConfigMain.COMMANDS_MISC_REMOVE)) {
// Remove command
isRemove = true;
password = null;
} else {
// Normal command
if (!PasswordUtils.isValid(commandData.getArgs()[1])) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_PASSWORD_INVALID);
return;
}
password = PasswordUtils.hashText(commandData.getArgs()[1]);
if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.PASSWORD, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
return;
}
// Command starts
party.setPassword(password);
if (isRemove) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_PASSWORD_REMOVED);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_PASSWORD_REM, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
} else {
sendMessage(sender, partyPlayer, Messages.ADDCMD_PASSWORD_CHANGED);
party.broadcastMessage(Messages.ADDCMD_PASSWORD_BROADCAST, partyPlayer);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_PASSWORD, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
}
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class CommandDebug method onCommand.
@Override
public void onCommand(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
// Command handling
String playerName;
PartyImpl targetParty = null;
PartyPlayerImpl targetPlayer = null;
CommandType commandType = CommandType.parse(commandData.getArgs()[1]);
if (commandType == null) {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntax));
return;
}
switch(commandType) {
case CONFIG:
if (commandData.getArgs().length != 2) {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntaxConfig));
return;
}
break;
case EXP:
if (commandData.getArgs().length != 2) {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntaxExp));
return;
}
break;
case PARTY:
if (commandData.getArgs().length == 3) {
targetParty = getPlugin().getPartyManager().getParty(commandData.getArgs()[2]);
if (targetParty == null) {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", commandData.getArgs()[2]));
return;
}
} else {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntaxParty));
return;
}
break;
case PLAYER:
if (commandData.getArgs().length == 2) {
if (partyPlayer != null)
targetPlayer = partyPlayer;
else {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntaxPlayer));
return;
}
} else if (commandData.getArgs().length == 3) {
playerName = commandData.getArgs()[2];
User targetUser = plugin.getPlayerByName(playerName);
if (targetUser != null) {
targetPlayer = getPlugin().getPlayerManager().getPlayer(targetUser.getUUID());
} else {
Set<UUID> targetPlayersUuid = LLAPIHandler.getPlayerByName(playerName);
if (targetPlayersUuid.size() > 0) {
targetPlayer = getPlugin().getPlayerManager().getPlayer(targetPlayersUuid.iterator().next());
} else {
// Not found
sendMessage(sender, partyPlayer, Messages.ADDCMD_DEBUG_PLAYER_PLAYER_OFFLINE.replace("%player%", playerName));
return;
}
}
} else {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntaxPlayer));
return;
}
break;
default:
if (commandHandleExtra(commandType, commandData, sender, partyPlayer)) {
// Command handle extra stopped, return
return;
}
}
// Command starts
commandStart(commandType, sender, partyPlayer, targetParty, targetPlayer);
}
Aggregations