use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class CommandInfo method onCommand.
@Override
public void onCommand(CommandData commandData) {
PartyPlayerEntity pp = commandData.getPartyPlayer();
/*
* Command handling
*/
String partyName;
if (commandData.getArgs().length > 1) {
if (!commandData.havePermission(PartiesPermission.INFO_OTHERS)) {
pp.sendNoPermission(PartiesPermission.INFO_OTHERS);
return;
}
partyName = commandData.getArgs()[1];
} else if (!pp.getPartyName().isEmpty()) {
partyName = pp.getPartyName();
} else {
pp.sendMessage(Messages.PARTIES_COMMON_NOTINPARTY);
return;
}
PartyEntity party = plugin.getPartyManager().getParty(partyName);
if (party == null) {
pp.sendMessage(Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", partyName));
return;
}
/*
* Command starts
*/
StringBuilder sb = new StringBuilder();
for (String str : Messages.MAINCMD_INFO_CONTENT) sb.append(str + "\n");
String text = sb.toString();
Matcher mat = Pattern.compile("%list_(.*?)%").matcher(text);
while (mat.find()) {
Rank rr = plugin.getRankManager().searchRankByHardName(mat.group().substring(6, mat.group().length() - 1));
if (rr != null) {
StringBuilder list = new StringBuilder();
int counter = 0;
for (UUID playerUUID : party.getMembers()) {
PartyPlayer pl = plugin.getPlayerManager().getPlayer(playerUUID);
// Check rank level
if (pl.getRank() == rr.getLevel()) {
if (list.length() > 0) {
list.append(Messages.MAINCMD_INFO_LIST_SEPARATOR);
}
OfflinePlayer op = Bukkit.getOfflinePlayer(pl.getPlayerUUID());
if (op != null)
list.append((op.isOnline() && !PartiesUtils.isVanished((Player) op) ? Messages.MAINCMD_INFO_LIST_ONLINEPREFIX : Messages.MAINCMD_INFO_LIST_OFFLINEPREFIX) + pl.getName());
else
list.append(Messages.MAINCMD_INFO_LIST_UNKNOWN);
counter++;
}
}
text = text.replace(mat.group(), list.toString().isEmpty() ? Messages.MAINCMD_INFO_LIST_EMPTY : list.toString());
text = text.replace("%number_" + mat.group().substring(6, mat.group().length() - 1) + "%", Integer.toString(counter));
}
}
int numOnlinePlayers = party.getNumberOnlinePlayers();
sb = new StringBuilder();
if (text.contains("%online%")) {
if (numOnlinePlayers == 0)
sb.append(Messages.MAINCMD_INFO_LIST_EMPTY);
else {
for (Player pl : party.getOnlinePlayers()) {
if (sb.length() > 0) {
sb.append(Messages.MAINCMD_INFO_LIST_SEPARATOR);
}
if (!PartiesUtils.isVanished(pl))
sb.append(Messages.MAINCMD_INFO_LIST_ONLINEPREFIX + pl.getName());
}
}
text = text.replace("%online%", sb.toString());
}
text = PartiesUtils.convertPartyPlaceholders(text, party, Messages.MAINCMD_INFO_LIST_EMPTY);
pp.sendMessage(text);
LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_INFO.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class CommandInvite method preRequisites.
@Override
public boolean preRequisites(CommandData commandData) {
Player player = (Player) commandData.getSender();
PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(player.getUniqueId());
/*
* Checks for command prerequisites
*/
if (!player.hasPermission(PartiesPermission.INVITE.toString())) {
pp.sendNoPermission(PartiesPermission.INVITE);
return false;
}
PartyEntity party = pp.getPartyName().isEmpty() ? null : plugin.getPartyManager().getParty(pp.getPartyName());
if (party == null) {
pp.sendMessage(Messages.PARTIES_COMMON_NOTINPARTY);
return false;
}
if (!PartiesUtils.checkPlayerRankAlerter(pp, PartiesPermission.PRIVATE_INVITE))
return false;
if (commandData.getArgs().length != 2) {
pp.sendMessage(Messages.MAINCMD_INVITE_WRONGCMD);
return false;
}
if ((ConfigParties.GENERAL_MEMBERSLIMIT != -1) && (party.getMembers().size() >= ConfigParties.GENERAL_MEMBERSLIMIT)) {
pp.sendMessage(Messages.PARTIES_COMMON_PARTYFULL);
return false;
}
commandData.setPlayer(player);
commandData.setPartyPlayer(pp);
commandData.setParty(party);
return true;
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class CommandLeave method onCommand.
@Override
public void onCommand(CommandData commandData) {
PartyPlayerEntity pp = commandData.getPartyPlayer();
PartyEntity party = commandData.getParty();
/*
* Command starts
*/
// Calling API event
PartiesPlayerLeaveEvent partiesLeaveEvent = new PartiesPlayerLeaveEvent(pp, party, false, null);
Bukkit.getServer().getPluginManager().callEvent(partiesLeaveEvent);
if (!partiesLeaveEvent.isCancelled()) {
if (party.getLeader().equals(pp.getPlayerUUID())) {
// Is leader
// Calling Pre API event
PartiesPartyPreDeleteEvent partiesPreDeleteEvent = new PartiesPartyPreDeleteEvent(party, PartiesPartyPreDeleteEvent.DeleteCause.LEAVE, null, pp);
Bukkit.getServer().getPluginManager().callEvent(partiesPreDeleteEvent);
if (!partiesPreDeleteEvent.isCancelled()) {
// Disbanding party
pp.sendMessage(Messages.MAINCMD_LEAVE_LEFT, party);
party.sendBroadcast(pp, Messages.MAINCMD_LEAVE_DISBANDED);
party.removeParty();
party.callChange();
// Calling Post API event
PartiesPartyPostDeleteEvent partiesPostDeleteEvent = new PartiesPartyPostDeleteEvent(party.getName(), PartiesPartyPostDeleteEvent.DeleteCause.LEAVE, null, pp);
Bukkit.getServer().getPluginManager().callEvent(partiesPostDeleteEvent);
LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_CMD_LEAVE_DISBAND.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
} else
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_DELETEEVENT_DENY.replace("{party}", party.getName()).replace("{player}", pp.getName()), true);
} else {
party.getMembers().remove(pp.getPlayerUUID());
party.getOnlinePlayers().remove(commandData.getPlayer());
pp.cleanupPlayer(true);
pp.sendMessage(Messages.MAINCMD_LEAVE_LEFT, party);
party.sendBroadcast(pp, Messages.MAINCMD_LEAVE_BROADCAST);
party.updateParty();
party.callChange();
LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_CMD_LEAVE.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
}
} else
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_LEAVEEVENT_DENY.replace("{party}", party.getName()).replace("{player}", pp.getName()), true);
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class CommandList method preRequisites.
@Override
public boolean preRequisites(CommandData commandData) {
Player player = (Player) commandData.getSender();
PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(player.getUniqueId());
/*
* Checks for command prerequisites
*/
if (!player.hasPermission(PartiesPermission.LIST.toString())) {
pp.sendNoPermission(PartiesPermission.LIST);
return false;
}
if (commandData.getArgs().length > 2) {
pp.sendMessage(Messages.ADDCMD_LIST_WRONGCMD);
return false;
}
commandData.setPlayer(player);
commandData.setPartyPlayer(pp);
commandData.addPermission(PartiesPermission.KICK_OTHERS);
return true;
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class CommandList method onCommand.
@Override
public void onCommand(CommandData commandData) {
PartyPlayerEntity pp = commandData.getPartyPlayer();
/*
* Command handling
*/
int selectedPage = 1;
if (commandData.getArgs().length == 2) {
try {
selectedPage = Integer.parseInt(commandData.getArgs()[1]);
} catch (NumberFormatException ex) {
pp.sendMessage(Messages.ADDCMD_LIST_WRONGCMD);
return;
}
}
/*
* Command starts
*/
// Get all parties
List<PartyEntity> parties = new ArrayList<PartyEntity>();
for (Party party : plugin.getDatabaseManager().getAllParties().join()) {
if (party != null) {
PartyEntity partyImpl = new PartyEntity(party, plugin);
partyImpl.reloadOnlinePlayers();
if (partyImpl.getNumberOnlinePlayers() >= ConfigParties.LIST_FILTERMIN)
parties.add(partyImpl);
}
}
// Order parties
switch(ConfigParties.LIST_ORDEREDBY.toLowerCase()) {
case "kills":
if (!ConfigParties.KILLS_ENABLE)
parties = orderName(parties);
else
parties = orderKills(parties);
break;
case "players":
parties = orderPlayers(parties);
break;
case "allplayers":
parties = orderAllPlayers(parties);
break;
default:
parties = orderName(parties);
}
// Group up parties
parties = limitList(parties);
int maxPages;
if (parties.size() == 0)
maxPages = 1;
else if (parties.size() % ConfigParties.LIST_PERPAGE == 0)
maxPages = parties.size() / ConfigParties.LIST_PERPAGE;
else
maxPages = (parties.size() / ConfigParties.LIST_PERPAGE) + 1;
if (selectedPage > maxPages)
selectedPage = maxPages;
else if (selectedPage < 1)
selectedPage = 1;
int currentPage = 0;
StringBuilder sb = new StringBuilder();
sb.append(Messages.ADDCMD_LIST_HEADER).append("\n");
for (PartyEntity party : parties) {
int currentChoosenPage = (selectedPage - 1) * ConfigParties.LIST_PERPAGE;
if (currentPage >= currentChoosenPage && currentPage < (currentChoosenPage + ConfigParties.LIST_PERPAGE)) {
sb.append(PartiesUtils.convertPartyPlaceholders(Messages.ADDCMD_LIST_FORMATPARTY, party)).append("\n");
}
currentPage++;
}
if (parties.size() == 0)
sb.append(Messages.ADDCMD_LIST_NOONE).append("\n");
sb.append(Messages.ADDCMD_LIST_FOOTER);
pp.sendMessage(sb.toString().replace("%number%", Integer.toString(parties.size())).replace("%page%", Integer.toString(selectedPage)).replace("%maxpages%", Integer.toString(maxPages)));
LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_IGNORE_STOP.replace("{player}", pp.getName()), true);
}
Aggregations