Search in sources :

Example 1 with HomeTask

use of com.alessiodp.parties.tasks.HomeTask 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);
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) BukkitTask(org.bukkit.scheduler.BukkitTask) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) PermissionAttachmentInfo(org.bukkit.permissions.PermissionAttachmentInfo) HomeTask(com.alessiodp.parties.tasks.HomeTask)

Aggregations

PartyEntity (com.alessiodp.parties.parties.objects.PartyEntity)1 PartyPlayerEntity (com.alessiodp.parties.players.objects.PartyPlayerEntity)1 HomeTask (com.alessiodp.parties.tasks.HomeTask)1 PermissionAttachmentInfo (org.bukkit.permissions.PermissionAttachmentInfo)1 BukkitTask (org.bukkit.scheduler.BukkitTask)1