Search in sources :

Example 11 with Location

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

the class PrismPlayerEvents method recordCocoaPlantEvent.

/**
     * 
     * @param block
     * @param inhand
     * @param player
     */
protected void recordCocoaPlantEvent(Block block, ItemStack inhand, BlockFace clickedFace, String player) {
    if (!Prism.getIgnore().event("block-place", block))
        return;
    if (block.getType().equals(Material.LOG) && block.getData() >= 3 && inhand.getTypeId() == 351 && inhand.getDurability() == 3) {
        final Location newLoc = block.getRelative(clickedFace).getLocation();
        final Block actualBlock = block.getWorld().getBlockAt(newLoc);
        // This is a lame way to do this
        final BlockAction action = new BlockAction();
        action.setActionType("block-place");
        action.setPlayerName(player);
        action.setX(actualBlock.getX());
        action.setY(actualBlock.getY());
        action.setZ(actualBlock.getZ());
        action.setWorldName(newLoc.getWorld().getName());
        action.setBlockId(127);
        action.setBlockSubId((byte) 1);
        RecordingQueue.addToQueue(action);
    }
}
Also used : BlockAction(me.botsko.prism.actions.BlockAction) Block(org.bukkit.block.Block) Location(org.bukkit.Location)

Example 12 with Location

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

the class RadiusParameter method process.

/**
	 * 
	 */
@Override
public void process(QueryParameters query, String alias, String input, CommandSender sender) {
    Player player = null;
    if (sender instanceof Player) {
        player = (Player) sender;
    }
    String inputValue = input;
    final FileConfiguration config = Bukkit.getPluginManager().getPlugin("Prism").getConfig();
    if (TypeUtils.isNumeric(inputValue) || (inputValue.contains(":") && inputValue.split(":").length >= 1 && TypeUtils.isNumeric(inputValue.split(":")[1]))) {
        int radius, desiredRadius;
        Location coordsLoc = null;
        if (inputValue.contains(":")) {
            desiredRadius = Integer.parseInt(inputValue.split(":")[1]);
            final String radiusLocOrPlayer = inputValue.split(":")[0];
            if (radiusLocOrPlayer.contains(",") && player != null) {
                // Coordinates;
                // x,y,z
                final String[] coordinates = radiusLocOrPlayer.split(",");
                if (coordinates.length != 3) {
                    throw new IllegalArgumentException("Couldn't parse the coordinates '" + radiusLocOrPlayer + "'. Perhaps you have more than two commas?");
                }
                for (final String s : coordinates) {
                    if (!TypeUtils.isNumeric(s)) {
                        throw new IllegalArgumentException("The coordinate '" + s + "' is not a number.");
                    }
                }
                coordsLoc = (new Location(player.getWorld(), Integer.parseInt(coordinates[0]), Integer.parseInt(coordinates[1]), Integer.parseInt(coordinates[2])));
            } else // Try to find an online player
            if (Bukkit.getServer().getPlayer(radiusLocOrPlayer) != null) {
                player = Bukkit.getServer().getPlayer(radiusLocOrPlayer);
            } else {
                throw new IllegalArgumentException("Couldn't find the player named '" + radiusLocOrPlayer + "'. Perhaps they are not online or you misspelled their name?");
            }
        } else {
            desiredRadius = Integer.parseInt(inputValue);
        }
        if (desiredRadius <= 0) {
            throw new IllegalArgumentException("Radius must be greater than zero. Or leave it off to use the default. Use /prism ? for help.");
        }
        // If neither sender or a named player found, die here
        if (player == null) {
            throw new IllegalArgumentException("The radius parameter must be used by a player. Use w:worldname if attempting to limit to a world.");
        }
        // Clamp radius based on perms, configs
        radius = MiscUtils.clampRadius(player, desiredRadius, query.getProcessType(), config);
        if (desiredRadius != radius) {
            if (sender != null)
                sender.sendMessage(Prism.messenger.playerError("Forcing radius to " + radius + " as allowed by config."));
        }
        if (radius > 0) {
            query.setRadius(radius);
            if (coordsLoc != null) {
                // We
                query.setMinMaxVectorsFromPlayerLocation(coordsLoc);
            // need
            // to
            // set
            // this
            // *after*
            // the
            // radius
            // has
            // been
            // set
            // or
            // it
            // won't
            // work.
            } else {
                query.setMinMaxVectorsFromPlayerLocation(player.getLocation());
            }
        }
    } else {
        // If neither sender or a named player found, die here
        if (player == null) {
            throw new IllegalArgumentException("The radius parameter must be used by a player. Use w:worldname if attempting to limit to a world.");
        }
        // User wants an area inside of a worldedit selection
        if (inputValue.equals("we")) {
            if (Prism.plugin_worldEdit == null) {
                throw new IllegalArgumentException("This feature is disabled because Prism couldn't find WorldEdit.");
            } else {
                // Load a selection from world edit as our area.
                final Prism prism = (Prism) Bukkit.getPluginManager().getPlugin("Prism");
                if (!WorldEditBridge.getSelectedArea(prism, player, query)) {
                    throw new IllegalArgumentException("Invalid region selected. Make sure you have a region selected, and that it doesn't exceed the max radius.");
                }
            }
        } else // Confine to the chunk
        if (inputValue.equals("c") || inputValue.equals("chunk")) {
            final Chunk ch = player.getLocation().getChunk();
            query.setWorld(ch.getWorld().getName());
            query.setMinLocation(ChunkUtils.getChunkMinVector(ch));
            query.setMaxLocation(ChunkUtils.getChunkMaxVector(ch));
        } else // User wants no radius, but contained within the current world
        if (inputValue.equals("world")) {
            // Do they have permission to override the global lookup radius
            if (query.getProcessType().equals(PrismProcessType.LOOKUP) && !player.hasPermission("prism.override-max-lookup-radius")) {
                throw new IllegalArgumentException("You do not have permission to override the max radius.");
            }
            // Do they have permission to override the global applier radius
            if (!query.getProcessType().equals(PrismProcessType.LOOKUP) && !player.hasPermission("prism.override-max-applier-radius")) {
                throw new IllegalArgumentException("You do not have permission to override the max radius.");
            }
            // Use the world defined in the w: param
            if (query.getWorld() != null) {
                inputValue = query.getWorld();
            } else // Use the current world
            {
                inputValue = player.getWorld().getName();
            }
            query.setWorld(inputValue);
            query.setAllowNoRadius(true);
        } else // User has asked for a global radius
        if (inputValue.equals("global")) {
            // Do they have permission to override the global lookup radius
            if (query.getProcessType().equals(PrismProcessType.LOOKUP) && !player.hasPermission("prism.override-max-lookup-radius")) {
                throw new IllegalArgumentException("You do not have permission to override the max radius.");
            }
            // Do they have permission to override the global applier radius
            if (!query.getProcessType().equals(PrismProcessType.LOOKUP) && !player.hasPermission("prism.override-max-applier-radius")) {
                throw new IllegalArgumentException("You do not have permission to override the max radius.");
            }
            // Either they have permission or player is null
            query.setWorld(null);
            query.setAllowNoRadius(true);
        } else {
            throw new IllegalArgumentException("Radius is invalid. There's a bunch of choice, so use /prism actions for assistance.");
        }
    }
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) Player(org.bukkit.entity.Player) Chunk(org.bukkit.Chunk) Prism(me.botsko.prism.Prism) Location(org.bukkit.Location)

Example 13 with Location

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

the class LimboServiceHelper method merge.

/**
     * Merges two existing LimboPlayer instances of a player. Merging is done the following way:
     * <ul>
     *  <li><code>isOperator, allowFlight</code>: true if either limbo has true</li>
     *  <li><code>flySpeed, walkSpeed</code>: maximum value of either limbo player</li>
     *  <li><code>group, location</code>: from old limbo if not empty/null, otherwise from new limbo</li>
     * </ul>
     *
     * @param newLimbo the new limbo player
     * @param oldLimbo the old limbo player
     * @return merged limbo player if both arguments are not null, otherwise the first non-null argument
     */
LimboPlayer merge(LimboPlayer newLimbo, LimboPlayer oldLimbo) {
    if (newLimbo == null) {
        return oldLimbo;
    } else if (oldLimbo == null) {
        return newLimbo;
    }
    boolean isOperator = newLimbo.isOperator() || oldLimbo.isOperator();
    boolean canFly = newLimbo.isCanFly() || oldLimbo.isCanFly();
    float flySpeed = Math.max(newLimbo.getFlySpeed(), oldLimbo.getFlySpeed());
    float walkSpeed = Math.max(newLimbo.getWalkSpeed(), oldLimbo.getWalkSpeed());
    String group = firstNotEmpty(newLimbo.getGroup(), oldLimbo.getGroup());
    Location location = firstNotNull(oldLimbo.getLocation(), newLimbo.getLocation());
    return new LimboPlayer(location, isOperator, group, canFly, walkSpeed, flySpeed);
}
Also used : Location(org.bukkit.Location)

Example 14 with Location

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

the class OnShutdownPlayerSaver method saveLoggedinPlayer.

private void saveLoggedinPlayer(Player player) {
    if (settings.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)) {
        Location loc = spawnLoader.getPlayerLocationOrSpawn(player);
        final PlayerAuth auth = PlayerAuth.builder().name(player.getName().toLowerCase()).realName(player.getName()).location(loc).build();
        dataSource.updateQuitLoc(auth);
    }
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Location(org.bukkit.Location)

Example 15 with Location

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

the class SpawnLocationViewer method showPlayerSpawn.

private void showPlayerSpawn(CommandSender sender, String playerName) {
    Player player = bukkitService.getPlayerExact(playerName);
    if (player == null) {
        sender.sendMessage("Player '" + playerName + "' is not online!");
    } else {
        Location spawn = spawnLoader.getSpawnLocation(player);
        sender.sendMessage("Player '" + playerName + "' has spawn location: " + formatLocation(spawn));
        sender.sendMessage("Note: this check excludes the AuthMe firstspawn.");
    }
}
Also used : Player(org.bukkit.entity.Player) DebugSectionUtils.formatLocation(fr.xephi.authme.command.executable.authme.debug.DebugSectionUtils.formatLocation) Location(org.bukkit.Location)

Aggregations

Location (org.bukkit.Location)351 Player (org.bukkit.entity.Player)90 World (org.bukkit.World)56 EventHandler (org.bukkit.event.EventHandler)43 Test (org.junit.Test)43 Vector (org.bukkit.util.Vector)38 ArrayList (java.util.ArrayList)29 Block (org.bukkit.block.Block)18 Entity (org.bukkit.entity.Entity)17 User (com.earth2me.essentials.User)16 ItemStack (org.bukkit.inventory.ItemStack)15 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)14 LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)14 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)14 List (java.util.List)12 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)11 BlockState (org.bukkit.block.BlockState)11 UUID (java.util.UUID)10 LivingEntity (org.bukkit.entity.LivingEntity)10 MinigamePlayer (au.com.mineauz.minigames.MinigamePlayer)9