Search in sources :

Example 1 with OfflinePlayer

use of org.bukkit.OfflinePlayer in project Prism-Bukkit by prism.

the class EntityAction method applyRollback.

/**
	 * 
	 */
@Override
public ChangeResult applyRollback(Player player, QueryParameters parameters, boolean is_preview) {
    if (getEntityType() == null) {
        return new ChangeResult(ChangeResultType.SKIPPED, null);
    }
    if (Prism.getIllegalEntities().contains(getEntityType().name().toLowerCase())) {
        return new ChangeResult(ChangeResultType.SKIPPED, null);
    }
    if (!is_preview) {
        final Location loc = getLoc();
        loc.setX(loc.getX() + 0.5);
        loc.setZ(loc.getZ() + 0.5);
        final Entity entity = loc.getWorld().spawnEntity(loc, getEntityType());
        // Get custom name
        if (entity instanceof LivingEntity && getCustomName() != null) {
            final LivingEntity namedEntity = (LivingEntity) entity;
            namedEntity.setCustomName(getCustomName());
        }
        // Get animal age
        if (entity instanceof Ageable) {
            final Ageable age = (Ageable) entity;
            if (!isAdult()) {
                age.setBaby();
            } else {
                age.setAdult();
            }
        }
        // Set sheep color
        if (entity.getType().equals(EntityType.SHEEP) && getColor() != null) {
            final Sheep sheep = ((Sheep) entity);
            sheep.setColor(getColor());
        }
        // Set villager profession
        if (entity instanceof Villager && getProfession() != null) {
            final Villager v = (Villager) entity;
            v.setProfession(getProfession());
        }
        // Set wolf details
        if (entity instanceof Wolf) {
            // Owner
            final Wolf wolf = (Wolf) entity;
            final String tamingOwner = getTamingOwner();
            if (tamingOwner != null) {
                Player owner = plugin.getServer().getPlayer(tamingOwner);
                if (owner == null) {
                    final OfflinePlayer offlinePlayer = plugin.getServer().getOfflinePlayer(tamingOwner);
                    if (offlinePlayer.hasPlayedBefore()) {
                        owner = offlinePlayer.getPlayer();
                    }
                }
                if (owner != null)
                    wolf.setOwner(owner);
            }
            // Collar color
            if (getColor() != null) {
                wolf.setCollarColor(getColor());
            }
            if (isSitting()) {
                wolf.setSitting(true);
            }
        }
        // Set ocelot details
        if (entity instanceof Ocelot) {
            // Owner
            final Ocelot ocelot = (Ocelot) entity;
            final String tamingOwner = getTamingOwner();
            if (tamingOwner != null) {
                Player owner = plugin.getServer().getPlayer(tamingOwner);
                if (owner == null) {
                    final OfflinePlayer offlinePlayer = plugin.getServer().getOfflinePlayer(tamingOwner);
                    if (offlinePlayer.hasPlayedBefore()) {
                        owner = offlinePlayer.getPlayer();
                    }
                }
                if (owner != null) {
                    ocelot.setOwner(owner);
                }
            }
            // Cat type
            if (getCatType() != null) {
                ocelot.setCatType(getCatType());
            }
            // Sitting
            if (isSitting()) {
                ocelot.setSitting(true);
            }
        }
        // Set horse details
        if (entity instanceof Horse) {
            final Horse h = (Horse) entity;
            if (getVariant() != null) {
                h.setVariant(getVariant());
            }
            if (getHorseColor() != null) {
                h.setColor(getHorseColor());
            }
            if (getStyle() != null) {
                h.setStyle(getStyle());
            }
            h.setCarryingChest(this.actionData.chest);
            h.setDomestication(this.actionData.dom);
            h.setMaxDomestication(this.actionData.maxDom);
            h.setJumpStrength(this.actionData.jump);
            h.setMaxHealth(this.actionData.maxHealth);
            // Stuff
            h.getInventory().setSaddle(getSaddle());
            h.getInventory().setArmor(getArmor());
            // Owner
            final String tamingOwner = getTamingOwner();
            if (tamingOwner != null) {
                Player owner = plugin.getServer().getPlayer(tamingOwner);
                if (owner == null) {
                    final OfflinePlayer offlinePlayer = plugin.getServer().getOfflinePlayer(tamingOwner);
                    if (offlinePlayer.hasPlayedBefore()) {
                        owner = offlinePlayer.getPlayer();
                    }
                }
                if (owner != null)
                    h.setOwner(owner);
            }
        }
        return new ChangeResult(ChangeResultType.APPLIED, null);
    }
    return new ChangeResult(ChangeResultType.PLANNED, null);
}
Also used : OfflinePlayer(org.bukkit.OfflinePlayer) ChangeResult(me.botsko.prism.appliers.ChangeResult) OfflinePlayer(org.bukkit.OfflinePlayer) Location(org.bukkit.Location)

Example 2 with OfflinePlayer

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

the class RoyalAuthConverter method execute.

@Override
public void execute(CommandSender sender) {
    for (OfflinePlayer player : plugin.getServer().getOfflinePlayers()) {
        try {
            String name = player.getName().toLowerCase();
            File file = new File(makePath(".", "plugins", "RoyalAuth", "userdata", name + ".yml"));
            if (dataSource.isAuthAvailable(name) || !file.exists()) {
                continue;
            }
            FileConfiguration configuration = YamlConfiguration.loadConfiguration(file);
            PlayerAuth auth = PlayerAuth.builder().name(name).password(configuration.getString(PASSWORD_PATH), null).lastLogin(configuration.getLong(LAST_LOGIN_PATH)).realName(player.getName()).build();
            dataSource.saveAuth(auth);
        } catch (Exception e) {
            ConsoleLogger.logException("Error while trying to import " + player.getName() + " RoyalAuth data", e);
        }
    }
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) OfflinePlayer(org.bukkit.OfflinePlayer) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) File(java.io.File)

Example 3 with OfflinePlayer

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

the class HasPermissionChecker method execute.

@Override
public void execute(CommandSender sender, List<String> arguments) {
    if (arguments.size() < 2) {
        sender.sendMessage("Check if a player has permission:");
        sender.sendMessage("Example: /authme debug perm bobby my.perm.node");
        return;
    }
    final String playerName = arguments.get(0);
    final String permissionNode = arguments.get(1);
    Player player = bukkitService.getPlayerExact(playerName);
    if (player == null) {
        OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(playerName);
        if (offlinePlayer == null) {
            sender.sendMessage(ChatColor.DARK_RED + "Player '" + playerName + "' does not exist");
        } else {
            sender.sendMessage("Player '" + playerName + "' not online; checking with offline player");
            performPermissionCheck(offlinePlayer, permissionNode, permissionsManager::hasPermissionOffline, sender);
        }
    } else {
        performPermissionCheck(player, permissionNode, permissionsManager::hasPermission, sender);
    }
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) OfflinePlayer(org.bukkit.OfflinePlayer)

Example 4 with OfflinePlayer

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

the class PurgeBannedPlayersCommand method executeCommand.

@Override
public void executeCommand(CommandSender sender, List<String> arguments) {
    // Get the list of banned players
    Set<OfflinePlayer> bannedPlayers = bukkitService.getBannedPlayers();
    Set<String> namedBanned = new HashSet<>(bannedPlayers.size());
    for (OfflinePlayer offlinePlayer : bannedPlayers) {
        namedBanned.add(offlinePlayer.getName().toLowerCase());
    }
    purgeService.purgePlayers(sender, namedBanned, bannedPlayers.toArray(new OfflinePlayer[bannedPlayers.size()]));
}
Also used : OfflinePlayer(org.bukkit.OfflinePlayer) HashSet(java.util.HashSet)

Example 5 with OfflinePlayer

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

the class PurgePlayerCommand method executeCommand.

private void executeCommand(CommandSender sender, String name, String option) {
    if ("force".equals(option) || !dataSource.isAuthAvailable(name)) {
        OfflinePlayer offlinePlayer = bukkitService.getOfflinePlayer(name);
        purgeExecutor.executePurge(singletonList(offlinePlayer), singletonList(name.toLowerCase()));
        sender.sendMessage("Purged data for player " + name);
    } else {
        sender.sendMessage("This player is still registered! Are you sure you want to proceed? " + "Use '/authme purgeplayer " + name + " force' to run the command anyway");
    }
}
Also used : OfflinePlayer(org.bukkit.OfflinePlayer)

Aggregations

OfflinePlayer (org.bukkit.OfflinePlayer)52 Player (org.bukkit.entity.Player)19 JobsPlayer (com.gamingmesh.jobs.container.JobsPlayer)10 Job (com.gamingmesh.jobs.container.Job)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 File (java.io.File)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 HashSet (java.util.HashSet)4 World (org.bukkit.World)4 CommandSender (org.bukkit.command.CommandSender)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 JobProgression (com.gamingmesh.jobs.container.JobProgression)2 IOException (java.io.IOException)2 UUID (java.util.UUID)2 net.aufdemrand.denizen.objects.dWorld (net.aufdemrand.denizen.objects.dWorld)2 Element (net.aufdemrand.denizencore.objects.Element)2 GlowOfflinePlayer (net.glowstone.GlowOfflinePlayer)2 User (com.earth2me.essentials.User)1 ImmutableList (com.google.common.collect.ImmutableList)1