Search in sources :

Example 1 with ForceFieldManager

use of net.sacredlabyrinth.Phaed.PreciousStones.managers.ForceFieldManager in project MagicPlugin by elBukkit.

the class PreciousStonesAPI method getFieldLocations.

@Nullable
public Map<String, Location> getFieldLocations(Player player) {
    if (preciousStones == null || player == null || !canGetFields)
        return null;
    ForceFieldManager manager = preciousStones.getForceFieldManager();
    if (manager == null)
        return null;
    Collection<Field> fields = manager.getAllPlayerFields(player.getName());
    if (fields == null)
        return null;
    Map<String, Location> fieldLocations = new HashMap<>();
    for (Field field : fields) {
        String fieldName = field.getName();
        String fieldType = field.getSettings().getTitle();
        String fieldOwner = field.getOwner();
        List<String> renters = field.getRenters();
        if (fieldName == null || fieldName.isEmpty()) {
            fieldName = fieldType;
        }
        if (!fieldOwner.equalsIgnoreCase(player.getName())) {
            if (renters.contains(player.getName().toLowerCase())) {
                fieldName = fieldName + ChatColor.GRAY + " (Renting)";
            } else {
                fieldName = fieldName + ChatColor.LIGHT_PURPLE + " (" + fieldOwner + ")";
            }
        }
        fieldLocations.put(fieldName, field.getLocation());
    }
    return fieldLocations;
}
Also used : Field(net.sacredlabyrinth.Phaed.PreciousStones.field.Field) ForceFieldManager(net.sacredlabyrinth.Phaed.PreciousStones.managers.ForceFieldManager) HashMap(java.util.HashMap) Location(org.bukkit.Location) Nullable(javax.annotation.Nullable)

Example 2 with ForceFieldManager

use of net.sacredlabyrinth.Phaed.PreciousStones.managers.ForceFieldManager in project MagicPlugin by elBukkit.

the class PreciousStonesAPI method createField.

public boolean createField(Location location, Player player) {
    ForceFieldManager manager = preciousStones.getForceFieldManager();
    Block targetBlock = location.getBlock();
    BlockPlaceEvent event = new BlockPlaceEvent(targetBlock, targetBlock.getState(), targetBlock.getRelative(BlockFace.DOWN), new ItemStack(targetBlock.getType(), CompatibilityLib.getDeprecatedUtils().getData(targetBlock)), player, true, EquipmentSlot.HAND);
    manager.add(location.getBlock(), player, event);
    return !event.isCancelled();
}
Also used : ForceFieldManager(net.sacredlabyrinth.Phaed.PreciousStones.managers.ForceFieldManager) BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent) Block(org.bukkit.block.Block) ItemStack(org.bukkit.inventory.ItemStack)

Example 3 with ForceFieldManager

use of net.sacredlabyrinth.Phaed.PreciousStones.managers.ForceFieldManager in project MagicPlugin by elBukkit.

the class PreciousStonesAPI method getFieldLocations.

@Nullable
public List<PlayerWarp> getFieldLocations(String playerName) {
    if (preciousStones == null || playerName == null)
        return null;
    ForceFieldManager manager = preciousStones.getForceFieldManager();
    if (manager == null)
        return null;
    List<PlayerWarp> fieldLocations = new ArrayList<>();
    for (World world : Bukkit.getWorlds()) {
        Collection<Field> fields = manager.getFields(playerName, world);
        if (fields == null)
            continue;
        for (Field field : fields) {
            String fieldName = field.getName();
            String fieldType = field.getSettings().getTitle();
            String fieldOwner = field.getOwner();
            List<String> renters = field.getRenters();
            if (fieldName == null || fieldName.isEmpty()) {
                fieldName = fieldType;
            }
            if (!fieldOwner.equalsIgnoreCase(playerName)) {
                if (renters.contains(playerName.toLowerCase())) {
                    fieldName = fieldName + ChatColor.GRAY + " (Renting)";
                } else {
                    fieldName = fieldName + ChatColor.LIGHT_PURPLE + " (" + fieldOwner + ")";
                }
            }
            fieldLocations.add(new PlayerWarp(fieldName, field.getLocation()));
        }
    }
    return fieldLocations.isEmpty() ? null : fieldLocations;
}
Also used : Field(net.sacredlabyrinth.Phaed.PreciousStones.field.Field) ForceFieldManager(net.sacredlabyrinth.Phaed.PreciousStones.managers.ForceFieldManager) PlayerWarp(com.elmakers.mine.bukkit.api.protection.PlayerWarp) ArrayList(java.util.ArrayList) World(org.bukkit.World) Nullable(javax.annotation.Nullable)

Aggregations

ForceFieldManager (net.sacredlabyrinth.Phaed.PreciousStones.managers.ForceFieldManager)3 Nullable (javax.annotation.Nullable)2 Field (net.sacredlabyrinth.Phaed.PreciousStones.field.Field)2 PlayerWarp (com.elmakers.mine.bukkit.api.protection.PlayerWarp)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Location (org.bukkit.Location)1 World (org.bukkit.World)1 Block (org.bukkit.block.Block)1 BlockPlaceEvent (org.bukkit.event.block.BlockPlaceEvent)1 ItemStack (org.bukkit.inventory.ItemStack)1