Search in sources :

Example 21 with OfflinePlayer

use of org.bukkit.OfflinePlayer in project Jobs by GamingMesh.

the class JobsCommands method fire.

@JobCommand
public boolean fire(CommandSender sender, String[] args) {
    if (args.length < 2) {
        sendUsage(sender, "fire");
        return true;
    }
    OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[0]);
    JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(offlinePlayer);
    Job job = Jobs.getJob(args[1]);
    if (job == null) {
        sender.sendMessage(ChatColor.RED + Language.getMessage("command.error.job"));
        return true;
    }
    if (!jPlayer.isInJob(job)) {
        String message = ChatColor.RED + Language.getMessage("command.fire.error.nojob");
        message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.RED);
        sender.sendMessage(message);
        return true;
    }
    try {
        Jobs.getPlayerManager().leaveJob(jPlayer, job);
        Player player = Bukkit.getServer().getPlayer(offlinePlayer.getUniqueId());
        if (player != null) {
            String message = Language.getMessage("command.fire.output.target");
            message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE);
            player.sendMessage(message);
        }
        sender.sendMessage(Language.getMessage("command.admin.success"));
    } catch (Exception e) {
        sender.sendMessage(ChatColor.RED + Language.getMessage("command.admin.error"));
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) OfflinePlayer(org.bukkit.OfflinePlayer) Job(com.gamingmesh.jobs.container.Job) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 22 with OfflinePlayer

use of org.bukkit.OfflinePlayer in project Jobs by GamingMesh.

the class JobsCommands method removexp.

@JobCommand
public boolean removexp(CommandSender sender, String[] args) {
    if (args.length < 3) {
        sendUsage(sender, "removexp");
        return true;
    }
    OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[0]);
    JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(offlinePlayer);
    Job job = Jobs.getJob(args[1]);
    if (job == null) {
        sender.sendMessage(ChatColor.RED + Language.getMessage("command.error.job"));
        return true;
    }
    double xpLost;
    try {
        xpLost = Double.parseDouble(args[2]);
    } catch (Exception e) {
        sender.sendMessage(ChatColor.RED + Language.getMessage("command.admin.error"));
        return true;
    }
    if (xpLost <= 0) {
        sender.sendMessage(ChatColor.RED + Language.getMessage("command.admin.error"));
        return true;
    }
    // check if player already has the job
    if (jPlayer.isInJob(job)) {
        Jobs.getPlayerManager().removeExperience(jPlayer, job, xpLost);
        Player player = Bukkit.getServer().getPlayer(offlinePlayer.getUniqueId());
        if (player != null) {
            String message = Language.getMessage("command.removexp.output.target");
            message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE);
            message = message.replace("%xplost%", Double.valueOf(xpLost).toString());
            player.sendMessage(message);
        }
        sender.sendMessage(Language.getMessage("command.admin.success"));
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) OfflinePlayer(org.bukkit.OfflinePlayer) Job(com.gamingmesh.jobs.container.Job) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 23 with OfflinePlayer

use of org.bukkit.OfflinePlayer in project Jobs by GamingMesh.

the class JobsCommands method employ.

@JobCommand
public boolean employ(CommandSender sender, String[] args) {
    if (args.length < 2) {
        sendUsage(sender, "employ");
        return true;
    }
    OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[0]);
    JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(offlinePlayer);
    Job job = Jobs.getJob(args[1]);
    if (job == null) {
        sender.sendMessage(ChatColor.RED + Language.getMessage("command.error.job"));
        return true;
    }
    if (jPlayer.isInJob(job)) {
        // already in job message
        String message = ChatColor.RED + Language.getMessage("command.employ.error.alreadyin");
        message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.RED);
        sender.sendMessage(message);
        return true;
    }
    try {
        // check if player already has the job
        Jobs.getPlayerManager().joinJob(jPlayer, job);
        Player player = Bukkit.getServer().getPlayer(offlinePlayer.getUniqueId());
        if (player != null) {
            String message = Language.getMessage("command.employ.output.target");
            message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE);
            player.sendMessage(message);
        }
        sender.sendMessage(Language.getMessage("command.admin.success"));
    } catch (Exception e) {
        sender.sendMessage(ChatColor.RED + Language.getMessage("command.admin.error"));
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) OfflinePlayer(org.bukkit.OfflinePlayer) Job(com.gamingmesh.jobs.container.Job) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 24 with OfflinePlayer

use of org.bukkit.OfflinePlayer in project AuthMeReloaded by AuthMe.

the class PurgeTask method run.

@Override
public void run() {
    if (toPurge.isEmpty()) {
        //everything was removed
        finish();
        return;
    }
    Set<OfflinePlayer> playerPortion = new HashSet<>(INTERVAL_CHECK);
    Set<String> namePortion = new HashSet<>(INTERVAL_CHECK);
    for (int i = 0; i < INTERVAL_CHECK; i++) {
        int nextPosition = (currentPage * INTERVAL_CHECK) + i;
        if (offlinePlayers.length <= nextPosition) {
            //no more offline players on this page
            break;
        }
        OfflinePlayer offlinePlayer = offlinePlayers[nextPosition];
        if (offlinePlayer.getName() != null && toPurge.remove(offlinePlayer.getName().toLowerCase())) {
            if (!permissionsManager.hasPermissionOffline(offlinePlayer, PlayerStatePermission.BYPASS_PURGE)) {
                playerPortion.add(offlinePlayer);
                namePortion.add(offlinePlayer.getName());
            }
        }
    }
    if (!toPurge.isEmpty() && playerPortion.isEmpty()) {
        ConsoleLogger.info("Finished lookup of offlinePlayers. Begin looking purging player names only");
        //we went through all offlineplayers but there are still names remaining
        for (String name : toPurge) {
            if (!permissionsManager.hasPermissionOffline(name, PlayerStatePermission.BYPASS_PURGE)) {
                namePortion.add(name);
            }
        }
        toPurge.clear();
    }
    currentPage++;
    purgeService.executePurge(playerPortion, namePortion);
    if (currentPage % 20 == 0) {
        int completed = totalPurgeCount - toPurge.size();
        sendMessage("[AuthMe] Purge progress " + completed + '/' + totalPurgeCount);
    }
}
Also used : OfflinePlayer(org.bukkit.OfflinePlayer) HashSet(java.util.HashSet)

Example 25 with OfflinePlayer

use of org.bukkit.OfflinePlayer in project AuthMeReloaded by AuthMe.

the class PurgeExecutor method purgeDat.

/**
     * Removes the .dat file of the given players.
     *
     * @param cleared list of players to clear
     */
synchronized void purgeDat(Collection<OfflinePlayer> cleared) {
    if (!settings.getProperty(PurgeSettings.REMOVE_PLAYER_DAT)) {
        return;
    }
    int i = 0;
    File dataFolder = new File(server.getWorldContainer(), makePath(settings.getProperty(PurgeSettings.DEFAULT_WORLD), "players"));
    for (OfflinePlayer offlinePlayer : cleared) {
        File playerFile = new File(dataFolder, PlayerUtils.getUuidOrName(offlinePlayer) + ".dat");
        if (playerFile.delete()) {
            i++;
        }
    }
    ConsoleLogger.info("AutoPurge: Removed " + i + " .dat Files");
}
Also used : OfflinePlayer(org.bukkit.OfflinePlayer) File(java.io.File)

Aggregations

OfflinePlayer (org.bukkit.OfflinePlayer)55 Player (org.bukkit.entity.Player)21 JobsPlayer (com.gamingmesh.jobs.container.JobsPlayer)10 Job (com.gamingmesh.jobs.container.Job)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 ArrayList (java.util.ArrayList)6 File (java.io.File)5 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 World (org.bukkit.World)4 CommandSender (org.bukkit.command.CommandSender)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 UUID (java.util.UUID)3 Location (org.bukkit.Location)3 JobProgression (com.gamingmesh.jobs.container.JobProgression)2 Island (com.wasteofplastic.acidisland.Island)2 List (java.util.List)2 Set (java.util.Set)2 net.aufdemrand.denizen.objects.dWorld (net.aufdemrand.denizen.objects.dWorld)2