use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class CommandDeny method onCommand.
@Override
public void onCommand(CommandData commandData) {
PartyPlayerEntity pp = commandData.getPartyPlayer();
PartyEntity party = commandData.getParty();
/*
* Command starts
*/
party.denyInvite(pp.getPlayerUUID());
LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_DENY.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class CommandHelp method onCommand.
@Override
public void onCommand(CommandData commandData) {
PartyPlayerEntity pp = commandData.getPartyPlayer();
/*
* Command starts
*/
// Get all allowed commands
List<String> list = new ArrayList<String>();
LinkedHashMap<String, String> commands = pp.getAllowedCommands();
for (Entry<String, String> entry : commands.entrySet()) {
list.add(entry.getValue());
}
// Split commands per page
int page = 1;
int maxpages;
if (list.size() == 0)
maxpages = 1;
else if ((list.size() % ConfigMain.COMMANDS_HELP_PERPAGE) == 0)
maxpages = list.size() / ConfigMain.COMMANDS_HELP_PERPAGE;
else
maxpages = (list.size() / ConfigMain.COMMANDS_HELP_PERPAGE) + 1;
if (commandData.getArgs().length > 1) {
try {
page = Integer.parseInt(commandData.getArgs()[1]);
} catch (NumberFormatException ex) {
}
if (page > maxpages || page < 1)
page = maxpages;
}
// Start priting
int commandNumber = 0;
String message = Messages.HELP_HEADER.replace("%page%", Integer.toString(page)).replace("%maxpages%", Integer.toString(maxpages)) + "\n";
for (String string : list) {
int currentChoosenPage = (page - 1) * ConfigMain.COMMANDS_HELP_PERPAGE;
if (commandNumber >= currentChoosenPage && commandNumber < currentChoosenPage + ConfigMain.COMMANDS_HELP_PERPAGE) {
message += string + "\n";
}
commandNumber++;
}
message += Messages.HELP_FOOTER.replace("%page%", Integer.toString(page)).replace("%maxpages%", Integer.toString(maxpages));
pp.sendMessage(message);
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class CommandHome method onCommand.
@Override
public void onCommand(CommandData commandData) {
PartyPlayerEntity pp = commandData.getPartyPlayer();
/*
* Command handling
*/
PartyEntity party;
if (commandData.getArgs().length > 1)
party = plugin.getPartyManager().getParty(commandData.getArgs()[1]);
else
party = plugin.getPartyManager().getParty(pp.getPartyName());
if (party == null) {
if (commandData.getArgs().length > 1)
pp.sendMessage(Messages.ADDCMD_HOME_NOEXISTS);
else
pp.sendMessage(Messages.PARTIES_COMMON_NOTINPARTY);
return;
}
if (commandData.getArgs().length == 1 && !PartiesUtils.checkPlayerRankAlerter(pp, PartiesPermission.PRIVATE_HOME))
return;
if (party.getHome() == null) {
pp.sendMessage(Messages.ADDCMD_HOME_NOHOME, party);
return;
}
if (VaultHandler.payCommand(VaultHandler.VaultCommand.HOME, pp, commandData.getCommandLabel(), commandData.getArgs()))
return;
/*
* Command starts
*/
int delay = ConfigParties.HOME_DELAY;
for (PermissionAttachmentInfo pa : commandData.getPlayer().getEffectivePermissions()) {
String perm = pa.getPermission();
if (perm.startsWith("parties.home.")) {
String[] splitted = perm.split("\\.");
try {
delay = Integer.parseInt(splitted[2]);
} catch (Exception ex) {
}
}
}
if (delay > 0) {
pp.setHomeFrom(commandData.getPlayer().getLocation());
plugin.getPlayerManager().addHomeCount();
BukkitTask it = new HomeTask(plugin, pp, party.getHome()).runTaskLater(plugin, delay * 20);
pp.setHomeTask(it.getTaskId());
pp.sendMessage(Messages.ADDCMD_HOME_TELEPORTIN.replace("%time%", Integer.toString(delay)));
} else {
plugin.getPartiesScheduler().runSync(() -> {
commandData.getPlayer().teleport(party.getHome());
});
pp.sendMessage(Messages.ADDCMD_HOME_TELEPORTED);
}
LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_HOME.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class CommandHome 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.HOME.toString())) {
pp.sendNoPermission(PartiesPermission.HOME);
return false;
}
if (commandData.getArgs().length > 1) {
if (!player.hasPermission(PartiesPermission.HOME_OTHERS.toString())) {
pp.sendMessage(Messages.ADDCMD_HOME_WRONGCMD);
return false;
} else if (commandData.getArgs().length > 2) {
pp.sendMessage(Messages.ADDCMD_HOME_WRONGCMD_ADMIN);
return false;
}
}
commandData.setPlayer(player);
commandData.setPartyPlayer(pp);
return true;
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class MotdTask method run.
@Override
public void run() {
if (pl != null && pl.isOnline()) {
PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(pl.getUniqueId());
if (createID.equals(pp.getCreateID()) && !pp.getPartyName().isEmpty()) {
PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
if (party != null && !party.getMotd().isEmpty()) {
StringBuilder sb = new StringBuilder();
for (String str : Messages.ADDCMD_MOTD_CONTENT) {
sb.append(str.replace(Constants.PLACEHOLDER_PARTY_MOTD, "%temporary_motd%") + "\n");
}
String message = PartiesUtils.convertAllPlaceholders(sb.toString(), party, pp);
sb = new StringBuilder();
for (String str : party.getMotd().split(ConfigParties.MOTD_NEWLINECODE)) {
sb.append(str + "\n");
}
message = message.replace("%temporary_motd%", sb.toString());
pp.sendMessage(message);
}
}
}
}
Aggregations