Search in sources :

Example 51 with MaterialData

use of org.bukkit.material.MaterialData in project acidisland by tastybento.

the class PluginConfig method loadPluginConfig.

/**
 * Loads the various settings from the config.yml file into the plugin
 * @param plugin - ASkyBlock plugin object - askyblock
 * @return true if plugin config is loaded correctly
 */
public static boolean loadPluginConfig(ASkyBlock plugin) {
    try {
        plugin.getConfig();
    } catch (final Exception e) {
        e.printStackTrace();
    }
    // The order in this file should match the order in config.yml so that it is easy to check that everything is covered
    // ********************** Island settings **************************
    Settings.islandDistance = plugin.getConfig().getInt("island.distance", 200);
    if (Settings.islandDistance < 50) {
        Settings.islandDistance = 50;
        plugin.getLogger().info("Setting minimum island distance to 50");
    }
    if (Settings.islandDistance % 2 != 0) {
        plugin.getLogger().warning("Island distance should be even!");
    }
    Settings.islandProtectionRange = plugin.getConfig().getInt("island.protectionRange", 100);
    if (Settings.islandProtectionRange > Settings.islandDistance) {
        plugin.getLogger().warning("Protection range cannot be > island distance. Setting them to be equal.");
        Settings.islandProtectionRange = Settings.islandDistance;
    }
    if (Settings.islandProtectionRange <= 0) {
        plugin.getLogger().warning("Protection range of 0 in config.yml: To disable protection, the range should");
        plugin.getLogger().warning("equal the island distance and then you should allow all island protection flags");
        plugin.getLogger().warning("in config.yml. Protection range will be set to island distance (" + Settings.islandDistance + ")");
        Settings.islandProtectionRange = Settings.islandDistance;
    }
    if (Settings.islandProtectionRange % 2 != 0) {
        Settings.islandProtectionRange--;
        plugin.getLogger().warning("Protection range must be even, using " + Settings.islandProtectionRange);
    }
    // xoffset and zoffset are not public and only used for IslandWorld compatibility
    Settings.islandXOffset = plugin.getConfig().getInt("island.xoffset", 0);
    if (Settings.islandXOffset < 0) {
        Settings.islandXOffset = 0;
        plugin.getLogger().info("Setting minimum island X Offset to 0");
    } else if (Settings.islandXOffset > Settings.islandDistance) {
        Settings.islandXOffset = Settings.islandDistance;
        plugin.getLogger().info("Setting maximum island X Offset to " + Settings.islandDistance);
    }
    Settings.islandZOffset = plugin.getConfig().getInt("island.zoffset", 0);
    if (Settings.islandZOffset < 0) {
        Settings.islandZOffset = 0;
        plugin.getLogger().info("Setting minimum island Z Offset to 0");
    } else if (Settings.islandZOffset > Settings.islandDistance) {
        Settings.islandZOffset = Settings.islandDistance;
        plugin.getLogger().info("Setting maximum island Z Offset to " + Settings.islandDistance);
    }
    // This is the origin of new islands
    long x = plugin.getConfig().getLong("island.startx", 0);
    // Check this is a multiple of island distance
    long z = plugin.getConfig().getLong("island.startz", 0);
    Settings.islandStartX = Math.round((double) x / Settings.islandDistance) * Settings.islandDistance + Settings.islandXOffset;
    Settings.islandStartZ = Math.round((double) z / Settings.islandDistance) * Settings.islandDistance + Settings.islandZOffset;
    // ASkyBlock and AcidIsland difference
    if (Settings.GAMETYPE.equals(Settings.GameType.ACIDISLAND)) {
        Settings.islandHeight = plugin.getConfig().getInt("island.islandlevel", 50) - 5;
        // The island's center is actually 5 below sea level
        Settings.seaHeight = plugin.getConfig().getInt("island.sealevel", 50);
    } else {
        // ASkyBlock
        Settings.islandHeight = plugin.getConfig().getInt("island.islandlevel", 120) - 5;
        // The island's center is actually 5 below sea level
        Settings.seaHeight = plugin.getConfig().getInt("island.sealevel", 0);
    }
    if (Settings.islandHeight < 0) {
        Settings.islandHeight = 0;
    }
    if (Settings.seaHeight < 0) {
        Settings.seaHeight = 0;
    }
    // Island reset settings
    Settings.resetLimit = plugin.getConfig().getInt("island.resetlimit", 2);
    if (Settings.resetWait < 0) {
        Settings.resetWait = -1;
    }
    Settings.resetWait = plugin.getConfig().getInt("island.resetwait", 300);
    if (Settings.resetWait < 0) {
        Settings.resetWait = 0;
    }
    // Seconds to wait for a confirmation of reset
    Settings.resetConfirmWait = plugin.getConfig().getInt("island.resetconfirmwait", 10);
    if (Settings.resetConfirmWait < 0) {
        Settings.resetConfirmWait = 0;
    }
    // Timeout required between duplicate team join/leaves
    Settings.inviteWait = plugin.getConfig().getInt("island.invitewait", 60);
    if (Settings.inviteWait < 0) {
        Settings.inviteWait = 0;
    }
    // Invite timeout before accept/reject timesout
    Settings.inviteTimeout = plugin.getConfig().getInt("island.invitetimeout", 60);
    // Convert to ticks
    Settings.inviteTimeout *= 20;
    // Max team size
    Settings.maxTeamSize = plugin.getConfig().getInt("island.maxteamsize", 4);
    // Deprecated settings - use permission askyblock.team.maxsize.<number> instead
    /*
        Settings.maxTeamSizeVIP = plugin.getConfig().getInt("island.vipteamsize", 0);
        Settings.maxTeamSizeVIP2 = plugin.getConfig().getInt("island.vip2teamsize", 0);
        if (Settings.maxTeamSizeVIP > 0 || Settings.maxTeamSizeVIP2 > 0) {
            plugin.getLogger().warning(Settings.PERMPREFIX + "team.vip and " + Settings.PERMPREFIX + "team.vip2 are deprecated!");
            plugin.getLogger().warning("Use permission " + Settings.PERMPREFIX + "team.maxsize.<number> instead.");
        }
         */
    // Island level cool down time
    Settings.levelWait = plugin.getConfig().getInt("island.levelwait", 60);
    if (Settings.levelWait < 0) {
        Settings.levelWait = 0;
    }
    // Get chest items
    String chestItems = plugin.getConfig().getString("island.chestItems", "");
    if (!chestItems.isEmpty()) {
        final String[] chestItemString = chestItems.split(" ");
        // plugin.getLogger().info("DEBUG: chest items = " + chestItemString);
        final ItemStack[] tempChest = new ItemStack[chestItemString.length];
        for (int i = 0; i < tempChest.length; i++) {
            String[] amountdata = chestItemString[i].split(":");
            try {
                if (amountdata.length == 3 && amountdata[0].equalsIgnoreCase("MONSTER_EGG")) {
                    try {
                        EntityType type = EntityType.valueOf(amountdata[1].toUpperCase());
                        if (Bukkit.getServer().getVersion().contains("(MC: 1.8") || Bukkit.getServer().getVersion().contains("(MC: 1.7")) {
                            tempChest[i] = new SpawnEgg(type).toItemStack(Integer.parseInt(amountdata[2]));
                        } else {
                            try {
                                tempChest[i] = new SpawnEgg1_9(type).toItemStack(Integer.parseInt(amountdata[2]));
                            } catch (Exception ex) {
                                tempChest[i] = new ItemStack(Material.MONSTER_EGG);
                                plugin.getLogger().severe("Monster eggs not supported with this server version.");
                            }
                        }
                    } catch (Exception e) {
                        plugin.getLogger().severe("Spawn eggs must be described by name. Try one of these (not all are possible):");
                        for (EntityType type : EntityType.values()) {
                            if (type.isSpawnable() && type.isAlive()) {
                                plugin.getLogger().severe(type.toString());
                            }
                        }
                    }
                } else if (amountdata[0].equals("POTION")) {
                    // amountdata.length);
                    if (amountdata.length == 6) {
                        tempChest[i] = Challenges.getPotion(amountdata, Integer.parseInt(amountdata[5]), "config.yml");
                    } else {
                        plugin.getLogger().severe("Problem loading chest item from config.yml so skipping it: " + chestItemString[i]);
                        plugin.getLogger().severe("Potions for the chest must be fully defined as POTION:NAME:<LEVEL>:<EXTENDED>:<SPLASH/LINGER>:QTY");
                    }
                } else {
                    Material mat;
                    if (StringUtils.isNumeric(amountdata[0])) {
                        mat = Material.getMaterial(Integer.parseInt(amountdata[0]));
                    } else {
                        mat = Material.getMaterial(amountdata[0].toUpperCase());
                    }
                    if (amountdata.length == 2) {
                        tempChest[i] = new ItemStack(mat, Integer.parseInt(amountdata[1]));
                    } else if (amountdata.length == 3) {
                        tempChest[i] = new ItemStack(mat, Integer.parseInt(amountdata[2]), Short.parseShort(amountdata[1]));
                    }
                }
            } catch (java.lang.IllegalArgumentException ex) {
                ex.printStackTrace();
                plugin.getLogger().severe("Problem loading chest item from config.yml so skipping it: " + chestItemString[i]);
                plugin.getLogger().severe("Error is : " + ex.getMessage());
                plugin.getLogger().info("Potential potion types are: ");
                for (PotionType c : PotionType.values()) plugin.getLogger().info(c.name());
            } catch (Exception e) {
                e.printStackTrace();
                plugin.getLogger().severe("Problem loading chest item from config.yml so skipping it: " + chestItemString[i]);
                plugin.getLogger().info("Potential material types are: ");
                for (Material c : Material.values()) plugin.getLogger().info(c.name());
            // e.printStackTrace();
            }
        }
        Settings.chestItems = tempChest;
    } else {
        // Nothing in the chest
        Settings.chestItems = new ItemStack[0];
    }
    // Defaul companion
    String companion = plugin.getConfig().getString("island.companion", "COW").toUpperCase();
    Settings.islandCompanion = null;
    if (!companion.equalsIgnoreCase("NOTHING")) {
        String commaList = "NOTHING, ";
        for (EntityType type : EntityType.values()) {
            if (companion.equalsIgnoreCase(type.toString())) {
                Settings.islandCompanion = type;
                break;
            }
            commaList += ", " + type.toString();
        }
        if (Settings.islandCompanion == null) {
            plugin.getLogger().warning("Island companion is not recognized. Pick from " + commaList);
        }
    }
    // Companion names
    List<String> companionNames = plugin.getConfig().getStringList("island.companionnames");
    Settings.companionNames = new ArrayList<String>();
    for (String name : companionNames) {
        Settings.companionNames.add(ChatColor.translateAlternateColorCodes('&', name));
    }
    // Island name length
    Settings.minNameLength = plugin.getConfig().getInt("island.minnamelength", 1);
    Settings.maxNameLength = plugin.getConfig().getInt("island.maxnamelength", 20);
    if (Settings.minNameLength < 0) {
        Settings.minNameLength = 0;
    }
    if (Settings.maxNameLength < 1) {
        Settings.maxNameLength = 1;
    }
    if (Settings.minNameLength > Settings.maxNameLength) {
        Settings.minNameLength = Settings.maxNameLength;
    }
    // Flymode expiration while flying oustide island boundaries
    Settings.flyTimeOutside = plugin.getConfig().getInt("island.flytimeoutside", 0);
    if (Settings.flyTimeOutside < 0) {
        Settings.flyTimeOutside = 0;
    }
    // Temporary Permissions while inside island
    Settings.temporaryPermissions = plugin.getConfig().getStringList("island.islandtemporaryperms");
    // System settings
    Settings.allowEndermanGriefing = plugin.getConfig().getBoolean("island.allowendermangriefing", true);
    Settings.endermanDeathDrop = plugin.getConfig().getBoolean("island.endermandeathdrop", true);
    Settings.allowCreeperDamage = plugin.getConfig().getBoolean("island.allowcreeperdamage", true);
    Settings.allowCreeperGriefing = plugin.getConfig().getBoolean("island.allowcreepergriefing", false);
    Settings.allowTNTDamage = plugin.getConfig().getBoolean("island.allowtntdamage", false);
    Settings.allowFireExtinguish = plugin.getConfig().getBoolean("island.allowfireextinguish", false);
    Settings.allowChestDamage = plugin.getConfig().getBoolean("island.allowchestdamage", false);
    Settings.allowVisitorKeepInvOnDeath = plugin.getConfig().getBoolean("island.allowvisitorkeepinvondeath", false);
    Settings.allowPistonPush = plugin.getConfig().getBoolean("island.allowpistonpush", true);
    Settings.allowMobDamageToItemFrames = plugin.getConfig().getBoolean("island.allowitemframedamage", false);
    // Clean up blocks around edges when deleting islands - this is a hidden setting not in the config.yml
    // Add if admins complain about slow cleaning.
    Settings.cleanRate = plugin.getConfig().getInt("island.cleanrate", 2);
    if (Settings.cleanRate < 1) {
        Settings.cleanRate = 1;
    }
    // ******** General Settings **********
    // Load world name
    Settings.worldName = plugin.getConfig().getString("general.worldName");
    // Check if the world name matches island.yml info
    File islandFile = new File(plugin.getDataFolder(), "islands.yml");
    if (islandFile.exists()) {
        YamlConfiguration islandYaml = new YamlConfiguration();
        try {
            islandYaml.load(islandFile);
            if (!islandYaml.contains(Settings.worldName)) {
                // Bad news, stop everything and tell the admin
                plugin.getLogger().severe("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+");
                plugin.getLogger().severe("More set up is required. Go to config.yml and edit it.");
                plugin.getLogger().severe("");
                plugin.getLogger().severe("Check island world name is same as world in islands.yml.");
                plugin.getLogger().severe("If you are resetting and changing world, delete island.yml and restart.");
                plugin.getLogger().severe("");
                plugin.getLogger().severe("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+");
                return false;
            }
        } catch (Exception e) {
        }
    }
    // Get the default language
    Settings.defaultLanguage = plugin.getConfig().getString("general.defaultlanguage", "en-US");
    // Load languages
    HashMap<String, ASLocale> availableLocales = new HashMap<String, ASLocale>();
    FileLister fl = new FileLister(plugin);
    try {
        int index = 1;
        for (String code : fl.list()) {
            // plugin.getLogger().info("DEBUG: lang file = " + code);
            availableLocales.put(code, new ASLocale(plugin, code, index++));
        }
    } catch (IOException e1) {
        plugin.getLogger().severe("Could not add locales!");
    }
    if (!availableLocales.containsKey(Settings.defaultLanguage)) {
        plugin.getLogger().severe("'" + Settings.defaultLanguage + ".yml' not found in /locale folder. Using /locale/en-US.yml");
        Settings.defaultLanguage = "en-US";
        availableLocales.put(Settings.defaultLanguage, new ASLocale(plugin, Settings.defaultLanguage, 0));
    }
    plugin.setAvailableLocales(availableLocales);
    // Check for updates
    Settings.updateCheck = plugin.getConfig().getBoolean("general.checkupdates", true);
    // Silence command feedback
    Settings.silenceCommandFeedback = plugin.getConfig().getBoolean("general.silencecommandfeedback", true);
    // Action bar settings
    Settings.showInActionBar = plugin.getConfig().getBoolean("general.showinactionbar", true);
    // Max Islands
    Settings.maxIslands = plugin.getConfig().getInt("general.maxIslands", 0);
    // Use control panel
    Settings.useControlPanel = plugin.getConfig().getBoolean("general.usecontrolpanel", false);
    // Create nether or not
    Settings.createNether = plugin.getConfig().getBoolean("general.createnether", true);
    if (!Settings.createNether) {
        plugin.getLogger().info("The Nether is disabled");
    }
    // Use the island nether
    Settings.newNether = plugin.getConfig().getBoolean("general.newnether", true);
    // Nether trees
    Settings.netherTrees = plugin.getConfig().getBoolean("general.nethertrees", true);
    // Nether roof option
    Settings.netherRoof = plugin.getConfig().getBoolean("general.netherroof", true);
    // Nether spawn protection radius
    Settings.netherSpawnRadius = plugin.getConfig().getInt("general.netherspawnradius", 25);
    if (Settings.netherSpawnRadius < 0) {
        Settings.netherSpawnRadius = 0;
    } else if (Settings.netherSpawnRadius > 100) {
        Settings.netherSpawnRadius = 100;
    }
    // Nether roof option
    Settings.netherRoof = plugin.getConfig().getBoolean("general.netherroof", true);
    // Run level calc at login
    Settings.loginLevel = plugin.getConfig().getBoolean("general.loginlevel", false);
    // Island reset commands
    Settings.resetCommands = plugin.getConfig().getStringList("general.resetcommands");
    Settings.leaveCommands = plugin.getConfig().getStringList("general.leavecommands");
    Settings.startCommands = plugin.getConfig().getStringList("general.startcommands");
    Settings.teamStartCommands = plugin.getConfig().getStringList("general.teamstartcommands");
    Settings.visitorCommandBlockList = plugin.getConfig().getStringList("general.visitorbannedcommands");
    // How long a player has to wait after deactivating PVP until they can activate PVP again
    Settings.pvpRestartCooldown = plugin.getConfig().getLong("general.pvpcooldown", 60);
    // Invincible visitors
    Settings.invincibleVisitors = plugin.getConfig().getBoolean("general.invinciblevisitors", false);
    if (Settings.invincibleVisitors) {
        Settings.visitorDamagePrevention = new HashSet<DamageCause>();
        List<String> damageSettings = plugin.getConfig().getStringList("general.invinciblevisitorsoptions");
        for (DamageCause cause : DamageCause.values()) {
            if (damageSettings.contains(cause.toString())) {
                Settings.visitorDamagePrevention.add(cause);
            }
        }
    }
    // ASkyBlock and AcidIsland difference
    if (Settings.GAMETYPE.equals(Settings.GameType.ACIDISLAND)) {
        Settings.acidDamage = plugin.getConfig().getDouble("general.aciddamage", 5D);
        if (Settings.acidDamage > 100D) {
            Settings.acidDamage = 100D;
        } else if (Settings.acidDamage < 0D) {
            Settings.acidDamage = 0D;
        }
        Settings.mobAcidDamage = plugin.getConfig().getDouble("general.mobaciddamage", 10D);
        if (Settings.mobAcidDamage > 100D) {
            Settings.mobAcidDamage = 100D;
        } else if (Settings.mobAcidDamage < 0D) {
            Settings.mobAcidDamage = 0D;
        }
        Settings.rainDamage = plugin.getConfig().getDouble("general.raindamage", 0.5D);
        if (Settings.rainDamage > 100D) {
            Settings.rainDamage = 100D;
        } else if (Settings.rainDamage < 0D) {
            Settings.rainDamage = 0D;
        }
    } else {
        Settings.acidDamage = plugin.getConfig().getDouble("general.aciddamage", 0D);
        if (Settings.acidDamage > 100D) {
            Settings.acidDamage = 100D;
        } else if (Settings.acidDamage < 0D) {
            Settings.acidDamage = 0D;
        }
        Settings.mobAcidDamage = plugin.getConfig().getDouble("general.mobaciddamage", 0D);
        if (Settings.mobAcidDamage > 100D) {
            Settings.mobAcidDamage = 100D;
        } else if (Settings.mobAcidDamage < 0D) {
            Settings.mobAcidDamage = 0D;
        }
        Settings.rainDamage = plugin.getConfig().getDouble("general.raindamage", 0D);
        if (Settings.rainDamage > 100D) {
            Settings.rainDamage = 100D;
        } else if (Settings.rainDamage < 0D) {
            Settings.rainDamage = 0D;
        }
    }
    Settings.animalAcidDamage = plugin.getConfig().getDouble("general.animaldamage", 0D);
    if (Settings.animalAcidDamage > 100D) {
        Settings.animalAcidDamage = 100D;
    } else if (Settings.animalAcidDamage < 0D) {
        Settings.animalAcidDamage = 0D;
    }
    Settings.damageChickens = plugin.getConfig().getBoolean("general.damagechickens", false);
    // Destroy items in acid timer
    Settings.acidItemDestroyTime = plugin.getConfig().getLong("general.itemdestroyafter", 0L) * 20L;
    Settings.damageOps = plugin.getConfig().getBoolean("general.damageops", false);
    // Helmet and full armor acid protection options
    Settings.helmetProtection = plugin.getConfig().getBoolean("general.helmetprotection", true);
    Settings.fullArmorProtection = plugin.getConfig().getBoolean("general.fullarmorprotection", false);
    // Damage Type
    List<String> acidDamageType = plugin.getConfig().getStringList("general.damagetype");
    Settings.acidDamageType.clear();
    if (acidDamageType != null) {
        for (String effect : acidDamageType) {
            PotionEffectType newPotionType = PotionEffectType.getByName(effect);
            if (newPotionType != null) {
                // Check if it is a valid addition
                if (newPotionType.equals(PotionEffectType.BLINDNESS) || newPotionType.equals(PotionEffectType.CONFUSION) || newPotionType.equals(PotionEffectType.HUNGER) || newPotionType.equals(PotionEffectType.POISON) || newPotionType.equals(PotionEffectType.SLOW) || newPotionType.equals(PotionEffectType.SLOW_DIGGING) || newPotionType.equals(PotionEffectType.WEAKNESS)) {
                    Settings.acidDamageType.add(newPotionType);
                }
            } else {
                plugin.getLogger().warning("Could not interpret acid damage modifier: " + effect + " - skipping");
                plugin.getLogger().warning("Types can be : SLOW, SLOW_DIGGING, CONFUSION,");
                plugin.getLogger().warning("BLINDNESS, HUNGER, WEAKNESS and POISON");
            }
        }
    }
    Settings.logInRemoveMobs = plugin.getConfig().getBoolean("general.loginremovemobs", true);
    Settings.islandRemoveMobs = plugin.getConfig().getBoolean("general.islandremovemobs", false);
    List<String> mobWhiteList = plugin.getConfig().getStringList("general.mobwhitelist");
    Settings.mobWhiteList.clear();
    for (String mobName : mobWhiteList) {
        boolean mobFound = false;
        for (EntityType type : EntityType.values()) {
            if (mobName.toUpperCase().equals(type.toString())) {
                try {
                    Settings.mobWhiteList.add(EntityType.valueOf(mobName.toUpperCase()));
                } catch (Exception e) {
                    plugin.getLogger().severe("Error in config.yml, mobwhitelist value '" + mobName + "' is invalid.");
                }
                mobFound = true;
                break;
            }
        }
        if (!mobFound) {
            plugin.getLogger().severe("Error in config.yml, mobwhitelist value '" + mobName + "' is invalid.");
            plugin.getLogger().severe("Possible values are : ");
            for (EntityType e : EntityType.values()) {
                if (e.isAlive()) {
                    plugin.getLogger().severe(e.name());
                }
            }
        }
    }
    Settings.monsterSpawnLimit = plugin.getConfig().getInt("general.monsterspawnlimit", 100);
    if (Settings.monsterSpawnLimit < -1) {
        Settings.monsterSpawnLimit = -1;
    }
    Settings.animalSpawnLimit = plugin.getConfig().getInt("general.animalspawnlimit", 15);
    if (Settings.animalSpawnLimit < -1) {
        Settings.animalSpawnLimit = -1;
    }
    Settings.breedingLimit = plugin.getConfig().getInt("general.breedinglimit", 0);
    Settings.waterAnimalSpawnLimit = plugin.getConfig().getInt("general.wateranimalspawnlimit", 15);
    if (Settings.waterAnimalSpawnLimit < -1) {
        Settings.waterAnimalSpawnLimit = -1;
    }
    Settings.villagerLimit = plugin.getConfig().getInt("general.villagerlimit", 0);
    Settings.limitedBlocks = new HashMap<String, Integer>();
    Settings.entityLimits = new HashMap<EntityType, Integer>();
    plugin.getLogger().info("Loading entity limits");
    ConfigurationSection entityLimits = plugin.getConfig().getConfigurationSection("general.entitylimits");
    if (entityLimits != null) {
        for (String entity : entityLimits.getKeys(false)) {
            int limit = entityLimits.getInt(entity.toUpperCase(), -1);
            // Check if this is an entity
            for (EntityType type : EntityType.values()) {
                // plugin.getLogger().info("DEBUG: is " + entity + " = " + type.name() + "?");
                if (type.name().equals(entity.toUpperCase())) {
                    // plugin.getLogger().info("DEBUG: yes");
                    Settings.entityLimits.put(type, limit);
                    if (limit > 0) {
                        plugin.getLogger().info(entity.toUpperCase() + " will be limited to " + limit);
                    }
                    break;
                }
            }
            if (Material.getMaterial(entity.toUpperCase()) != null && limit > -1) {
                Settings.limitedBlocks.put(entity.toUpperCase(), limit);
                plugin.getLogger().info(entity.toUpperCase() + " will be limited to " + limit);
                if (entity.equalsIgnoreCase("REDSTONE_COMPARATOR")) {
                    // Player can only ever place a redstone comparator in the OFF state
                    Settings.limitedBlocks.put("REDSTONE_COMPARATOR_OFF", limit);
                } else if (entity.equalsIgnoreCase("BANNER")) {
                    // To simplify banners, the banner is allowed and automatically made wall and standing banner
                    Settings.limitedBlocks.put("WALL_BANNER", limit);
                    Settings.limitedBlocks.put("STANDING_BANNER", limit);
                } else if (entity.equalsIgnoreCase("SIGN")) {
                    // To simplify signs, the sign is allowed and automatically made wall and standing signs
                    Settings.limitedBlocks.put("WALL_SIGN", limit);
                    Settings.limitedBlocks.put("SIGN_POST", limit);
                }
            }
        }
    }
    // Level to purge
    Settings.abandonedIslandLevel = plugin.getConfig().getInt("general.abandonedislandlevel", 10);
    if (Settings.abandonedIslandLevel < 0) {
        Settings.abandonedIslandLevel = 0;
    }
    Settings.maxPurge = plugin.getConfig().getInt("general.maxpurge", 500);
    if (Settings.maxPurge < 0) {
        Settings.maxPurge = 0;
    }
    // Use economy or not
    // In future expand to include internal economy
    Settings.useEconomy = plugin.getConfig().getBoolean("general.useeconomy", true);
    // Reset money when an island is started
    Settings.resetMoney = plugin.getConfig().getBoolean("general.resetmoney", true);
    // Use the minishop or not
    Settings.useMinishop = plugin.getConfig().getBoolean("general.useminishop", true);
    // Starting money - default $0
    Settings.startingMoney = plugin.getConfig().getDouble("general.startingmoney", 0D);
    // Things to reset when an island is reset
    Settings.resetChallenges = plugin.getConfig().getBoolean("general.resetchallenges", true);
    Settings.clearInventory = plugin.getConfig().getBoolean("general.resetinventory", true);
    // Kicked players keep inventory
    Settings.kickedKeepInv = plugin.getConfig().getBoolean("general.kickedkeepinv", false);
    // Leavers lose resets
    Settings.leaversLoseReset = plugin.getConfig().getBoolean("general.leaversloseresets", true);
    // Reset the ender chest
    Settings.resetEnderChest = plugin.getConfig().getBoolean("general.resetenderchest", false);
    // Check if /island command is allowed when falling
    Settings.allowTeleportWhenFalling = plugin.getConfig().getBoolean("general.allowfallingteleport", true);
    Settings.fallingCommandBlockList = plugin.getConfig().getStringList("general.blockingcommands");
    // Challenges
    Settings.broadcastMessages = plugin.getConfig().getBoolean("general.broadcastmessages", true);
    Settings.removeCompleteOntimeChallenges = plugin.getConfig().getBoolean("general.removecompleteonetimechallenges", false);
    Settings.addCompletedGlow = plugin.getConfig().getBoolean("general.addcompletedglow", true);
    // Max home number
    Settings.maxHomes = plugin.getConfig().getInt("general.maxhomes", 1);
    if (Settings.maxHomes < 1) {
        Settings.maxHomes = 1;
    }
    // Make island automatically
    Settings.makeIslandIfNone = plugin.getConfig().getBoolean("general.makeislandifnone", false);
    // Immediate teleport
    Settings.immediateTeleport = plugin.getConfig().getBoolean("general.immediateteleport", false);
    // Respawn on island
    Settings.respawnOnIsland = plugin.getConfig().getBoolean("general.respawnonisland", false);
    // Team chat
    Settings.teamChat = plugin.getConfig().getBoolean("general.teamchat", true);
    Settings.logTeamChat = plugin.getConfig().getBoolean("general.logteamchat", true);
    // Chat prefixes
    Settings.chatLevelPrefix = plugin.getConfig().getString("general.chatlevelprefix", "{ISLAND_LEVEL}");
    Settings.chatChallengeLevelPrefix = plugin.getConfig().getString("general.chatchallanegelevelprefix", "{ISLAND_CHALLENGE_LEVEL}");
    Settings.chatIslandPlayer = plugin.getConfig().getString("general.chatislandplayer", "{ISLAND_PLAYER}");
    // Chat team suffixes - Not public right now
    Settings.setTeamName = plugin.getConfig().getBoolean("general.setteamsuffix", false);
    Settings.teamSuffix = plugin.getConfig().getString("general.teamsuffix", "([level])");
    // Restrict wither
    Settings.restrictWither = plugin.getConfig().getBoolean("general.restrictwither", true);
    // Warp Restriction
    Settings.warpLevelsRestriction = plugin.getConfig().getInt("general.warplevelrestriction", 10);
    // Warp panel
    Settings.useWarpPanel = plugin.getConfig().getBoolean("general.usewarppanel", true);
    // Mute death messages
    Settings.muteDeathMessages = plugin.getConfig().getBoolean("general.mutedeathmessages", false);
    // How often the grid will be saved to file. Default is 5 minutes
    Settings.backupDuration = (plugin.getConfig().getLong("general.backupduration", 5) * 20 * 60);
    // Allow pushing
    Settings.allowPushing = plugin.getConfig().getBoolean("general.allowpushing", true);
    // try to remove the team from the scoreboard
    if (Settings.allowPushing) {
        try {
            ScoreboardManager manager = plugin.getServer().getScoreboardManager();
            if (manager != null) {
                Scoreboard scoreboard = manager.getMainScoreboard();
                if (scoreboard != null) {
                    Team pTeam = scoreboard.getTeam(NO_PUSH_TEAM_NAME);
                    if (pTeam != null) {
                        pTeam.unregister();
                    }
                }
            }
        } catch (Exception e) {
            plugin.getLogger().warning("Problem removing no push from scoreboard.");
        }
    }
    // Recover superflat
    Settings.recoverSuperFlat = plugin.getConfig().getBoolean("general.recoversuperflat");
    if (Settings.recoverSuperFlat) {
        plugin.getLogger().warning("*********************************************************");
        plugin.getLogger().warning("WARNING: Recover super flat mode is enabled");
        plugin.getLogger().warning("This will regenerate any chunks with bedrock at y=0 when they are loaded");
        plugin.getLogger().warning("Switch off when superflat chunks are cleared");
        plugin.getLogger().warning("You should back up your world before running this");
        plugin.getLogger().warning("*********************************************************");
    }
    // Persistent coops
    Settings.persistantCoops = plugin.getConfig().getBoolean("general.persistentcoops");
    // Only leader can coop
    Settings.onlyLeaderCanCoop = plugin.getConfig().getBoolean("general.onlyleadercancoop", false);
    // Fake players
    Settings.allowedFakePlayers = plugin.getConfig().getStringList("general.fakeplayers");
    // Allow Obsidian Scooping
    Settings.allowObsidianScooping = plugin.getConfig().getBoolean("general.allowobsidianscooping", true);
    // Use old display (chat instead of GUI) for Island top ten
    Settings.displayIslandTopTenInChat = plugin.getConfig().getBoolean("general.islandtopteninchat", false);
    // Magic Cobble Generator
    Settings.useMagicCobbleGen = plugin.getConfig().getBoolean("general.usemagiccobblegen", false);
    if (Settings.useMagicCobbleGen) {
        Settings.magicCobbleGenOnlyAtSpawn = plugin.getConfig().getBoolean("general.magiccobblegenonlyatspawn", false);
        if (plugin.getConfig().isSet("general.magiccobblegenchances")) {
            // plugin.getLogger().info("DEBUG: magic cobble gen enabled and chances section found");
            // Clear the cobble gen chances so they can be reloaded
            LavaCheck.clearChances();
            Settings.magicCobbleGenChances = new TreeMap<Long, TreeMap<Double, Material>>();
            for (String level : plugin.getConfig().getConfigurationSection("general.magiccobblegenchances").getKeys(false)) {
                long levelLong = 0;
                try {
                    if (level.equals("default")) {
                        levelLong = Long.MIN_VALUE;
                    } else {
                        levelLong = Long.parseLong(level);
                    }
                    TreeMap<Double, Material> blockMapTree = new TreeMap<Double, Material>();
                    double chanceTotal = 0;
                    for (String block : plugin.getConfig().getConfigurationSection("general.magiccobblegenchances." + level).getKeys(false)) {
                        double chance = plugin.getConfig().getDouble("general.magiccobblegenchances." + level + "." + block, 0D);
                        if (chance > 0 && Material.getMaterial(block) != null && Material.getMaterial(block).isBlock()) {
                            // Store the cumulative chance in the treemap. It does not need to add up to 100%
                            chanceTotal += chance;
                            blockMapTree.put(chanceTotal, Material.getMaterial(block));
                        }
                    }
                    if (!blockMapTree.isEmpty() && chanceTotal > 0) {
                        Settings.magicCobbleGenChances.put(levelLong, blockMapTree);
                        // Store the requested values as a % chance
                        Map<Material, Double> chances = new HashMap<Material, Double>();
                        for (Entry<Double, Material> en : blockMapTree.entrySet()) {
                            double chance = plugin.getConfig().getDouble("general.magiccobblegenchances." + level + "." + en.getValue(), 0D);
                            chances.put(en.getValue(), (chance / chanceTotal) * 100);
                        }
                        LavaCheck.storeChances(levelLong, chances);
                    }
                } catch (NumberFormatException e) {
                    // Putting the catch here means that an invalid level is skipped completely
                    plugin.getLogger().severe("Unknown level '" + level + "' listed in magiccobblegenchances section! Must be an integer or 'default'. Skipping...");
                }
            }
        }
    }
    // Disable offline redstone
    Settings.disableOfflineRedstone = plugin.getConfig().getBoolean("general.disableofflineredstone", false);
    // Allow/disallow TNT pusing
    Settings.allowTNTPushing = plugin.getConfig().getBoolean("general.allowTNTpushing", true);
    // Fancy island level display
    Settings.fancyIslandLevelDisplay = plugin.getConfig().getBoolean("general.fancylevelinchat", false);
    // Check config.yml version
    String configVersion = plugin.getConfig().getString("general.version", "");
    // Ignore last digit if it is 4 digits long
    if (configVersion.split("\\.").length == 4) {
        configVersion = configVersion.substring(0, configVersion.lastIndexOf('.'));
    }
    // Save for plugin version
    String version = plugin.getDescription().getVersion();
    // plugin.getLogger().info("DEBUG: version length " + version.split("\\.").length);
    if (version.split("\\.").length == 4) {
        version = version.substring(0, version.lastIndexOf('.'));
    }
    if (configVersion.isEmpty() || !configVersion.equalsIgnoreCase(version)) {
        // Check to see if this has already been shared
        File newConfig = new File(plugin.getDataFolder(), "config.new.yml");
        plugin.getLogger().warning("***********************************************************");
        plugin.getLogger().warning("Config file is out of date. See config.new.yml for updates!");
        plugin.getLogger().warning("config.yml version is '" + configVersion + "'");
        plugin.getLogger().warning("Latest config version is '" + version + "'");
        plugin.getLogger().warning("***********************************************************");
        if (!newConfig.exists()) {
            File oldConfig = new File(plugin.getDataFolder(), "config.yml");
            File bakConfig = new File(plugin.getDataFolder(), "config.bak");
            if (oldConfig.renameTo(bakConfig)) {
                plugin.saveResource("config.yml", false);
                oldConfig.renameTo(newConfig);
                bakConfig.renameTo(oldConfig);
            }
        }
    }
    // *** Non-Public Settings - these are "secret" settings that may not be used anymore
    // Level logging
    Settings.levelLogging = plugin.getConfig().getBoolean("general.levellogging");
    // Custom generator
    Settings.useOwnGenerator = plugin.getConfig().getBoolean("general.useowngenerator", false);
    // Use physics when pasting island block schematics
    Settings.usePhysics = plugin.getConfig().getBoolean("general.usephysics", false);
    // Legacy setting support for hopper limiting
    if (Settings.limitedBlocks.isEmpty()) {
        Settings.hopperLimit = plugin.getConfig().getInt("general.hopperlimit", -1);
        if (Settings.hopperLimit > 0) {
            Settings.limitedBlocks.put("HOPPER", Settings.hopperLimit);
        }
    }
    // No acid bottles or buckets
    Settings.acidBottle = plugin.getConfig().getBoolean("general.acidbottles", true);
    // ************ Protection Settings ****************
    // Default settings hashmaps - make sure this is kept up to date with new settings
    // If a setting is not listed, the world default is used
    Settings.defaultWorldSettings.clear();
    Settings.defaultIslandSettings.clear();
    Settings.defaultSpawnSettings.clear();
    Settings.visitorSettings.clear();
    ConfigurationSection protectionWorld = plugin.getConfig().getConfigurationSection("protection.world");
    for (String setting : protectionWorld.getKeys(false)) {
        try {
            SettingsFlag flag = SettingsFlag.valueOf(setting.toUpperCase());
            boolean value = plugin.getConfig().getBoolean("protection.world." + flag.name());
            Settings.defaultWorldSettings.put(flag, value);
            Settings.defaultSpawnSettings.put(flag, value);
            Settings.defaultIslandSettings.put(flag, value);
        } catch (Exception e) {
            plugin.getLogger().severe("Unknown setting in config.yml:protection.world " + setting.toUpperCase() + " skipping...");
        }
    }
    // Establish defaults if they are missing in the config file.
    for (SettingsFlag flag : SettingsFlag.values()) {
        if (!Settings.defaultWorldSettings.containsKey(flag)) {
            plugin.getLogger().warning("config.yml:protection.world." + flag.name() + " is missing. You should add it to the config file. Setting to false by default");
            Settings.defaultWorldSettings.put(flag, false);
        }
        if (!Settings.defaultIslandSettings.containsKey(flag)) {
            Settings.defaultIslandSettings.put(flag, false);
        }
        if (!Settings.defaultSpawnSettings.containsKey(flag)) {
            Settings.defaultSpawnSettings.put(flag, false);
        }
    }
    ConfigurationSection protectionIsland = plugin.getConfig().getConfigurationSection("protection.island");
    for (String setting : protectionIsland.getKeys(false)) {
        try {
            SettingsFlag flag = SettingsFlag.valueOf(setting.toUpperCase());
            // Only items in the config.yml can be per island customized
            Settings.visitorSettings.put(flag, protectionIsland.getBoolean(setting));
            // plugin.getLogger().info("DEBUG: visitor flag added " + flag);
            Settings.defaultIslandSettings.put(flag, Settings.visitorSettings.get(flag));
        } catch (Exception e) {
            plugin.getLogger().severe("Unknown setting in config.yml:island.world " + setting.toUpperCase() + " skipping...");
        }
    }
    // ******************** Biome Settings *********************
    Settings.biomeCost = plugin.getConfig().getDouble("biomesettings.defaultcost", 100D);
    if (Settings.biomeCost < 0D) {
        Settings.biomeCost = 0D;
        plugin.getLogger().warning("Biome default cost is < $0, so set to zero.");
    }
    String defaultBiome = plugin.getConfig().getString("biomesettings.defaultbiome", "PLAINS");
    try {
        Settings.defaultBiome = Biome.valueOf(defaultBiome);
    } catch (Exception e) {
        plugin.getLogger().severe("Could not parse biome " + defaultBiome + " using PLAINS instead.");
        Settings.defaultBiome = Biome.PLAINS;
    }
    // ******************** Schematic Section *******************
    // Hack skeleton spawners for 1.11
    Settings.hackSkeletonSpawners = plugin.getConfig().getBoolean("schematicsection.hackskeletonspawners", true);
    // ****************** Levels blockvalues.yml ****************
    // Get the blockvalues.yml file
    YamlConfiguration blockValuesConfig = Util.loadYamlFile("blockvalues.yml");
    // Get the under water multiplier
    Settings.deathpenalty = blockValuesConfig.getInt("deathpenalty", 0);
    Settings.sumTeamDeaths = blockValuesConfig.getBoolean("sumteamdeaths");
    Settings.maxDeaths = blockValuesConfig.getInt("maxdeaths", 10);
    Settings.islandResetDeathReset = blockValuesConfig.getBoolean("islandresetdeathreset", true);
    Settings.teamJoinDeathReset = blockValuesConfig.getBoolean("teamjoindeathreset", true);
    Settings.underWaterMultiplier = blockValuesConfig.getDouble("underwater", 1D);
    Settings.levelCost = blockValuesConfig.getInt("levelcost", 100);
    if (Settings.levelCost < 1) {
        Settings.levelCost = 1;
        plugin.getLogger().warning("levelcost in blockvalues.yml cannot be less than 1. Setting to 1.");
    }
    Settings.blockLimits = new HashMap<MaterialData, Integer>();
    if (blockValuesConfig.isSet("limits")) {
        for (String material : blockValuesConfig.getConfigurationSection("limits").getKeys(false)) {
            try {
                String[] split = material.split(":");
                byte data = 0;
                if (split.length > 1) {
                    data = Byte.valueOf(split[1]);
                }
                Material mat;
                if (StringUtils.isNumeric(split[0])) {
                    mat = Material.getMaterial(Integer.parseInt(split[0]));
                } else {
                    mat = Material.valueOf(split[0].toUpperCase());
                }
                MaterialData materialData = new MaterialData(mat);
                materialData.setData(data);
                Settings.blockLimits.put(materialData, blockValuesConfig.getInt("limits." + material, 0));
                if (DEBUG) {
                    plugin.getLogger().info("Maximum number of " + materialData + " will be " + Settings.blockLimits.get(materialData));
                }
            } catch (Exception e) {
                plugin.getLogger().warning("Unknown material (" + material + ") in blockvalues.yml Limits section. Skipping...");
            }
        }
    }
    Settings.blockValues = new HashMap<MaterialData, Integer>();
    if (blockValuesConfig.isSet("blocks")) {
        for (String material : blockValuesConfig.getConfigurationSection("blocks").getKeys(false)) {
            try {
                String[] split = material.split(":");
                byte data = 0;
                if (split.length > 1) {
                    data = Byte.valueOf(split[1]);
                }
                MaterialData materialData = null;
                if (StringUtils.isNumeric(split[0])) {
                    materialData = new MaterialData(Integer.parseInt(split[0]));
                } else {
                    materialData = new MaterialData(Material.valueOf(split[0].toUpperCase()));
                }
                materialData.setData(data);
                Settings.blockValues.put(materialData, blockValuesConfig.getInt("blocks." + material, 0));
                if (DEBUG) {
                    plugin.getLogger().info(materialData.toString());
                }
            } catch (Exception e) {
                // e.printStackTrace();
                plugin.getLogger().warning("Unknown material (" + material + ") in blockvalues.yml blocks section. Skipping...");
            }
        }
    } else {
        plugin.getLogger().severe("No block values in blockvalues.yml! All island levels will be zero!");
    }
    // All done
    return true;
}
Also used : HashMap(java.util.HashMap) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) SettingsFlag(com.wasteofplastic.acidisland.Island.SettingsFlag) Scoreboard(org.bukkit.scoreboard.Scoreboard) ScoreboardManager(org.bukkit.scoreboard.ScoreboardManager) Team(org.bukkit.scoreboard.Team) PotionEffectType(org.bukkit.potion.PotionEffectType) SpawnEgg1_9(com.wasteofplastic.acidisland.util.SpawnEgg1_9) Material(org.bukkit.Material) SpawnEgg(org.bukkit.material.SpawnEgg) IOException(java.io.IOException) TreeMap(java.util.TreeMap) IOException(java.io.IOException) EntityType(org.bukkit.entity.EntityType) PotionType(org.bukkit.potion.PotionType) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) MaterialData(org.bukkit.material.MaterialData) ItemStack(org.bukkit.inventory.ItemStack) File(java.io.File) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 52 with MaterialData

use of org.bukkit.material.MaterialData in project HawkEye by oliverwoodings.

the class MonitorBlockListener method onBlockFromTo.

@HawkEvent(dataType = { DataType.LAVA_FLOW, DataType.WATER_FLOW })
public void onBlockFromTo(BlockFromToEvent event) {
    List<Integer> fluidBlocks = Arrays.asList(0, 27, 28, 31, 32, 37, 38, 39, 40, 50, 51, 55, 59, 66, 69, 70, 75, 76, 78, 93, 94);
    //Only interested in liquids flowing
    if (!event.getBlock().isLiquid())
        return;
    Location loc = event.getToBlock().getLocation();
    BlockState from = event.getBlock().getState();
    BlockState to = event.getToBlock().getState();
    MaterialData data = from.getData();
    //Lava
    if (from.getTypeId() == 10 || from.getTypeId() == 11) {
        //Flowing into a normal block
        if (fluidBlocks.contains(to.getTypeId())) {
            data.setData((byte) (from.getRawData() + 1));
            from.setData(data);
        } else //Flowing into water
        if (to.getTypeId() == 8 || to.getTypeId() == 9) {
            from.setTypeId(event.getFace() == BlockFace.DOWN ? 10 : 4);
            data.setData((byte) 0);
            from.setData(data);
        }
        DataManager.addEntry(new BlockChangeEntry("Environment", DataType.LAVA_FLOW, loc, to, from));
    } else //Water
    if (from.getTypeId() == 8 || from.getTypeId() == 9) {
        //Normal block
        if (fluidBlocks.contains(to.getTypeId())) {
            data.setData((byte) (from.getRawData() + 1));
            from.setData(data);
            DataManager.addEntry(new BlockChangeEntry("Environment", DataType.WATER_FLOW, loc, to, from));
        }
        //If we are flowing over lava, cobble or obsidian will form
        BlockState lower = event.getToBlock().getRelative(BlockFace.DOWN).getState();
        if (lower.getTypeId() == 10 || lower.getTypeId() == 11) {
            from.setTypeId(lower.getData().getData() == 0 ? 49 : 4);
            loc.setY(loc.getY() - 1);
            DataManager.addEntry(new BlockChangeEntry("Environment", DataType.WATER_FLOW, loc, lower, from));
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) BlockChangeEntry(uk.co.oliwali.HawkEye.entry.BlockChangeEntry) MaterialData(org.bukkit.material.MaterialData) Location(org.bukkit.Location) HawkEvent(uk.co.oliwali.HawkEye.HawkEvent)

Example 53 with MaterialData

use of org.bukkit.material.MaterialData in project Denizen-For-Bukkit by DenizenScript.

the class dLocation method getAttribute.

@Override
public String getAttribute(Attribute attribute) {
    if (attribute == null) {
        return null;
    }
    // -->
    if (attribute.startsWith("above")) {
        return new dLocation(this.clone().add(0, 1, 0)).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("below")) {
        return new dLocation(this.clone().add(0, -1, 0)).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("block")) {
        return new dLocation(getWorld(), getBlockX(), getBlockY(), getBlockZ()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("center")) {
        return new dLocation(getWorld(), getBlockX() + 0.5, getBlockY() + 0.5, getBlockZ() + 0.5).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("highest")) {
        return new dLocation(getWorld().getHighestBlockAt(this).getLocation().add(0, -1, 0)).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("base_color")) {
        DyeColor color = ((Banner) getBlock().getState()).getBaseColor();
        return new Element(color != null ? color.name() : "BLACK").getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("has_inventory")) {
        return new Element(getBlock().getState() instanceof InventoryHolder).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("inventory")) {
        dObject obj = Element.handleNull(identify() + ".inventory", getInventory(), "dInventory", attribute.hasAlternative());
        return obj == null ? null : obj.getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("material")) {
        return dMaterial.getMaterialFrom(getBlock().getType(), getBlock().getData()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("patterns")) {
        dList list = new dList();
        for (org.bukkit.block.banner.Pattern pattern : ((Banner) getBlock().getState()).getPatterns()) {
            list.add(pattern.getColor().name() + "/" + pattern.getPattern().name());
        }
        return list.getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("head_rotation")) {
        return new Element(getSkullRotation(((Skull) getBlock().getState()).getRotation()) + 1).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("switched")) {
        Material type = getBlock().getType();
        if (type == Material.IRON_DOOR_BLOCK || type == Material.WOODEN_DOOR || type == Material.DARK_OAK_DOOR || type == Material.BIRCH_DOOR || type == Material.ACACIA_DOOR || type == Material.JUNGLE_DOOR || type == Material.SPRUCE_DOOR) {
            Location location = this;
            int data = getBlock().getData();
            if (data >= 8) {
                location = clone().add(0, -1, 0);
            }
            return new Element((location.getBlock().getData() & 0x4) > 0).getAttribute(attribute.fulfill(1));
        } else if (type == Material.TRAP_DOOR || type == Material.IRON_TRAPDOOR) {
            return new Element((getBlock().getData() & 0x4) > 0).getAttribute(attribute.fulfill(1));
        } else {
            return new Element((getBlock().getData() & 0x8) > 0).getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("sign_contents")) {
        if (getBlock().getState() instanceof Sign) {
            return new dList(Arrays.asList(((Sign) getBlock().getState()).getLines())).getAttribute(attribute.fulfill(1));
        } else {
            return null;
        }
    }
    // -->
    if (attribute.startsWith("spawner_type")) {
        if (getBlock().getState() instanceof CreatureSpawner) {
            return new dEntity(DenizenEntityType.getByName(((CreatureSpawner) getBlock().getState()).getSpawnedType().name())).getAttribute(attribute.fulfill(1));
        } else {
            return null;
        }
    }
    // -->
    if (attribute.startsWith("drops")) {
        Collection<ItemStack> its = getBlock().getDrops();
        dList list = new dList();
        for (ItemStack it : its) {
            list.add(new dItem(it).identify());
        }
        return list.getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("skull_type")) {
        BlockState blockState = getBlock().getState();
        if (blockState instanceof Skull) {
            String t = ((Skull) blockState).getSkullType().name();
            return new Element(t).getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("skull_name")) {
        BlockState blockState = getBlock().getState();
        if (blockState instanceof Skull) {
            PlayerProfile profile = NMSHandler.getInstance().getBlockHelper().getPlayerProfile((Skull) blockState);
            String n = profile.getName();
            if (n == null) {
                n = ((Skull) blockState).getOwningPlayer().getName();
            }
            return new Element(n).getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("skull_skin")) {
        BlockState blockState = getBlock().getState();
        if (blockState instanceof Skull) {
            PlayerProfile profile = NMSHandler.getInstance().getBlockHelper().getPlayerProfile((Skull) blockState);
            String name = profile.getName();
            UUID uuid = profile.getUniqueId();
            String texture = profile.getTexture();
            attribute = attribute.fulfill(1);
            // -->
            if (attribute.startsWith("full")) {
                return new Element((uuid != null ? uuid : name != null ? name : null) + (texture != null ? "|" + texture : "")).getAttribute(attribute.fulfill(1));
            }
            return new Element(uuid != null ? uuid.toString() : name != null ? name : null).getAttribute(attribute);
        } else {
            return null;
        }
    }
    // -->
    if (attribute.startsWith("simple.formatted")) {
        return new Element("X '" + getBlockX() + "', Y '" + getBlockY() + "', Z '" + getBlockZ() + "', in world '" + getWorld().getName() + "'").getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("simple")) {
        if (getWorld() == null) {
            return new Element(getBlockX() + "," + getBlockY() + "," + getBlockZ()).getAttribute(attribute.fulfill(1));
        } else {
            return new Element(getBlockX() + "," + getBlockY() + "," + getBlockZ() + "," + getWorld().getName()).getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("precise_impact_normal")) {
        int range = attribute.getIntContext(1);
        if (range < 1) {
            range = 200;
        }
        double xzLen = Math.cos((getPitch() % 360) * (Math.PI / 180));
        double nx = xzLen * Math.sin(-getYaw() * (Math.PI / 180));
        double ny = Math.sin(getPitch() * (Math.PI / 180));
        double nz = xzLen * Math.cos(getYaw() * (Math.PI / 180));
        Location location = NMSHandler.getInstance().getEntityHelper().getImpactNormal(this, new org.bukkit.util.Vector(nx, -ny, nz), range);
        if (location != null) {
            return new dLocation(location).getAttribute(attribute.fulfill(1));
        } else {
            return null;
        }
    }
    // -->
    if (attribute.startsWith("precise_cursor_on")) {
        int range = attribute.getIntContext(1);
        if (range < 1) {
            range = 200;
        }
        double xzLen = Math.cos((getPitch() % 360) * (Math.PI / 180));
        double nx = xzLen * Math.sin(-getYaw() * (Math.PI / 180));
        double ny = Math.sin(getPitch() * (Math.PI / 180));
        double nz = xzLen * Math.cos(getYaw() * (Math.PI / 180));
        Location location = NMSHandler.getInstance().getEntityHelper().rayTrace(this, new org.bukkit.util.Vector(nx, -ny, nz), range);
        if (location != null) {
            return new dLocation(location).getAttribute(attribute.fulfill(1));
        } else {
            return null;
        }
    }
    // -->
    if (attribute.startsWith("points_between")) {
        dLocation target = dLocation.valueOf(attribute.getContext(1));
        if (target == null) {
            return null;
        }
        attribute = attribute.fulfill(1);
        // <--[tag]
        // @attribute <l@location.points_between[<location>].distance[<#.#>]>
        // @returns dList(dLocation)
        // @description
        // Finds all locations between this location and another, separated by the specified distance each.
        // -->
        double rad = 1d;
        if (attribute.startsWith("distance")) {
            rad = attribute.getDoubleContext(1);
            attribute = attribute.fulfill(1);
        }
        dList list = new dList();
        org.bukkit.util.Vector rel = target.toVector().subtract(this.toVector());
        double len = rel.length();
        rel = rel.multiply(1d / len);
        for (double i = 0d; i < len; i += rad) {
            list.add(new dLocation(this.clone().add(rel.clone().multiply(i))).identify());
        }
        return list.getAttribute(attribute);
    }
    // -->
    if (attribute.startsWith("facing_blocks")) {
        int range = attribute.getIntContext(1);
        if (range < 1) {
            range = 100;
        }
        dList list = new dList();
        BlockIterator iterator = new BlockIterator(this, 0, range);
        while (iterator.hasNext()) {
            list.add(new dLocation(iterator.next().getLocation()).identify());
        }
        return list.getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("line_of_sight") && attribute.hasContext(1)) {
        dLocation location = dLocation.valueOf(attribute.getContext(1));
        if (location != null) {
            return new Element(NMSHandler.getInstance().getEntityHelper().canTrace(getWorld(), toVector(), location.toVector())).getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("direction.vector")) {
        double xzLen = Math.cos((getPitch() % 360) * (Math.PI / 180));
        double nx = xzLen * Math.sin(-getYaw() * (Math.PI / 180));
        double ny = Math.sin(getPitch() * (Math.PI / 180));
        double nz = xzLen * Math.cos(getYaw() * (Math.PI / 180));
        return new dLocation(getWorld(), nx, -ny, nz).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("direction")) {
        // Get the cardinal direction from this location to another
        if (attribute.hasContext(1) && dLocation.matches(attribute.getContext(1))) {
            // Subtract this location's vector from the other location's vector,
            // not the other way around
            dLocation target = dLocation.valueOf(attribute.getContext(1));
            attribute = attribute.fulfill(1);
            EntityHelper entityHelper = NMSHandler.getInstance().getEntityHelper();
            // -->
            if (attribute.startsWith("yaw")) {
                return new Element(entityHelper.normalizeYaw(entityHelper.getYaw(target.toVector().subtract(this.toVector()).normalize()))).getAttribute(attribute.fulfill(1));
            } else {
                return new Element(entityHelper.getCardinal(entityHelper.getYaw(target.toVector().subtract(this.toVector()).normalize()))).getAttribute(attribute);
            }
        } else // Get a cardinal direction from this location's yaw
        {
            return new Element(NMSHandler.getInstance().getEntityHelper().getCardinal(getYaw())).getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("face") && attribute.hasContext(1)) {
        Location two = dLocation.valueOf(attribute.getContext(1));
        return new dLocation(NMSHandler.getInstance().getEntityHelper().faceLocation(this, two)).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("facing")) {
        if (attribute.hasContext(1)) {
            // The default number of degrees if there is no degrees attribute
            int degrees = 45;
            // The attribute to fulfill from
            int attributePos = 1;
            // -->
            if (attribute.getAttribute(2).startsWith("degrees") && attribute.hasContext(2) && aH.matchesInteger(attribute.getContext(2))) {
                degrees = attribute.getIntContext(2);
                attributePos++;
            }
            if (dLocation.matches(attribute.getContext(1))) {
                return new Element(NMSHandler.getInstance().getEntityHelper().isFacingLocation(this, dLocation.valueOf(attribute.getContext(1)), degrees)).getAttribute(attribute.fulfill(attributePos));
            } else if (dEntity.matches(attribute.getContext(1))) {
                return new Element(NMSHandler.getInstance().getEntityHelper().isFacingLocation(this, dEntity.valueOf(attribute.getContext(1)).getBukkitEntity().getLocation(), degrees)).getAttribute(attribute.fulfill(attributePos));
            }
        }
    }
    // -->
    if (attribute.startsWith("pitch")) {
        return new Element(getPitch()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("with_pose")) {
        String context = attribute.getContext(1);
        Float pitch = 0f;
        Float yaw = 0f;
        if (dEntity.matches(context)) {
            dEntity ent = dEntity.valueOf(context);
            if (ent.isSpawned()) {
                pitch = ent.getBukkitEntity().getLocation().getPitch();
                yaw = ent.getBukkitEntity().getLocation().getYaw();
            }
        } else if (context.split(",").length == 2) {
            String[] split = context.split(",");
            pitch = Float.valueOf(split[0]);
            yaw = Float.valueOf(split[1]);
        }
        dLocation loc = dLocation.valueOf(identify());
        loc.setPitch(pitch);
        loc.setYaw(yaw);
        return loc.getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("yaw.simple")) {
        float yaw = NMSHandler.getInstance().getEntityHelper().normalizeYaw(getYaw());
        if (yaw < 45) {
            return new Element("South").getAttribute(attribute.fulfill(2));
        } else if (yaw < 135) {
            return new Element("West").getAttribute(attribute.fulfill(2));
        } else if (yaw < 225) {
            return new Element("North").getAttribute(attribute.fulfill(2));
        } else if (yaw < 315) {
            return new Element("East").getAttribute(attribute.fulfill(2));
        } else {
            return new Element("South").getAttribute(attribute.fulfill(2));
        }
    }
    // -->
    if (attribute.startsWith("yaw.raw")) {
        return new Element(getYaw()).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("yaw")) {
        return new Element(NMSHandler.getInstance().getEntityHelper().normalizeYaw(getYaw())).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("rotate_around_x") && attribute.hasContext(1)) {
        double angle = attribute.getDoubleContext(1);
        double cos = Math.cos(angle);
        double sin = Math.sin(angle);
        double y = (getY() * cos) - (getZ() * sin);
        double z = (getY() * sin) + (getZ() * cos);
        Location location = clone();
        location.setY(y);
        location.setZ(z);
        return new dLocation(location).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("rotate_around_y") && attribute.hasContext(1)) {
        double angle = attribute.getDoubleContext(1);
        double cos = Math.cos(angle);
        double sin = Math.sin(angle);
        double x = (getX() * cos) + (getZ() * sin);
        double z = (getX() * -sin) + (getZ() * cos);
        Location location = clone();
        location.setX(x);
        location.setZ(z);
        return new dLocation(location).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("rotate_around_z") && attribute.hasContext(1)) {
        double angle = attribute.getDoubleContext(1);
        double cos = Math.cos(angle);
        double sin = Math.sin(angle);
        double x = (getX() * cos) - (getY() * sin);
        double y = (getZ() * sin) + (getY() * cos);
        Location location = clone();
        location.setX(x);
        location.setY(y);
        return new dLocation(location).getAttribute(attribute.fulfill(1));
    }
    if (attribute.matches("find") || attribute.startsWith("nearest")) {
        attribute.fulfill(1);
        // -->
        if (attribute.startsWith("blocks") && attribute.getAttribute(2).startsWith("within") && attribute.hasContext(2)) {
            ArrayList<dLocation> found = new ArrayList<dLocation>();
            int radius = aH.matchesInteger(attribute.getContext(2)) ? attribute.getIntContext(2) : 10;
            List<dMaterial> materials = new ArrayList<dMaterial>();
            if (attribute.hasContext(1)) {
                materials = dList.valueOf(attribute.getContext(1)).filter(dMaterial.class);
            }
            // Avoid NPE from invalid materials
            if (materials == null) {
                return null;
            }
            int max = Settings.blockTagsMaxBlocks();
            int index = 0;
            attribute.fulfill(2);
            Location tstart = getBlock().getLocation();
            double tstartY = tstart.getY();
            fullloop: for (int x = -(radius); x <= radius; x++) {
                for (int y = -(radius); y <= radius; y++) {
                    double newY = y + tstartY;
                    if (newY < 0 || newY > 255) {
                        continue;
                    }
                    for (int z = -(radius); z <= radius; z++) {
                        index++;
                        if (index > max) {
                            break fullloop;
                        }
                        if (Utilities.checkLocation(this, tstart.clone().add(x + 0.5, y + 0.5, z + 0.5), radius)) {
                            if (!materials.isEmpty()) {
                                for (dMaterial material : materials) {
                                    if (material.hasData() && material.getData() != 0) {
                                        // TODO: less arbitrary matching
                                        if (material.matchesMaterialData(tstart.clone().add(x, y, z).getBlock().getState().getData())) {
                                            found.add(new dLocation(tstart.clone().add(x, y, z)));
                                        }
                                    } else if (material.getMaterial() == tstart.clone().add(x, y, z).getBlock().getType()) {
                                        found.add(new dLocation(tstart.clone().add(x, y, z)));
                                    }
                                }
                            } else {
                                found.add(new dLocation(tstart.clone().add(x, y, z)));
                            }
                        }
                    }
                }
            }
            Collections.sort(found, new Comparator<dLocation>() {

                @Override
                public int compare(dLocation loc1, dLocation loc2) {
                    return dLocation.this.compare(loc1, loc2);
                }
            });
            return new dList(found).getAttribute(attribute);
        } else // -->
        if (attribute.startsWith("surface_blocks") && attribute.getAttribute(2).startsWith("within") && attribute.hasContext(2)) {
            ArrayList<dLocation> found = new ArrayList<dLocation>();
            double radius = aH.matchesDouble(attribute.getContext(2)) ? attribute.getDoubleContext(2) : 10;
            List<dMaterial> materials = new ArrayList<dMaterial>();
            if (attribute.hasContext(1)) {
                materials = dList.valueOf(attribute.getContext(1)).filter(dMaterial.class);
            }
            // Avoid NPE from invalid materials
            if (materials == null) {
                return null;
            }
            int max = Settings.blockTagsMaxBlocks();
            int index = 0;
            attribute.fulfill(2);
            Location loc = getBlock().getLocation().add(0.5f, 0.5f, 0.5f);
            fullloop: for (double x = -(radius); x <= radius; x++) {
                for (double y = -(radius); y <= radius; y++) {
                    for (double z = -(radius); z <= radius; z++) {
                        index++;
                        if (index > max) {
                            break fullloop;
                        }
                        if (Utilities.checkLocation(loc, getBlock().getLocation().add(x + 0.5, y + 0.5, z + 0.5), radius)) {
                            Location l = getBlock().getLocation().clone().add(x, y, z);
                            if (!materials.isEmpty()) {
                                for (dMaterial material : materials) {
                                    if (material.matchesMaterialData(getBlock().getLocation().clone().add(x, y, z).getBlock().getType().getNewData(getBlock().getLocation().clone().add(x, y, z).getBlock().getData()))) {
                                        if (l.clone().add(0, 1, 0).getBlock().getType() == Material.AIR && l.clone().add(0, 2, 0).getBlock().getType() == Material.AIR && l.getBlock().getType() != Material.AIR) {
                                            found.add(new dLocation(getBlock().getLocation().clone().add(x + 0.5, y, z + 0.5)));
                                        }
                                    }
                                }
                            } else {
                                if (l.clone().add(0, 1, 0).getBlock().getType() == Material.AIR && l.clone().add(0, 2, 0).getBlock().getType() == Material.AIR && l.getBlock().getType() != Material.AIR) {
                                    found.add(new dLocation(getBlock().getLocation().clone().add(x + 0.5, y, z + 0.5)));
                                }
                            }
                        }
                    }
                }
            }
            Collections.sort(found, new Comparator<dLocation>() {

                @Override
                public int compare(dLocation loc1, dLocation loc2) {
                    return dLocation.this.compare(loc1, loc2);
                }
            });
            return new dList(found).getAttribute(attribute);
        } else // -->
        if (attribute.startsWith("players") && attribute.getAttribute(2).startsWith("within") && attribute.hasContext(2)) {
            ArrayList<dPlayer> found = new ArrayList<dPlayer>();
            double radius = aH.matchesDouble(attribute.getContext(2)) ? attribute.getDoubleContext(2) : 10;
            attribute.fulfill(2);
            for (Player player : Bukkit.getOnlinePlayers()) {
                if (!player.isDead() && Utilities.checkLocation(this, player.getLocation(), radius)) {
                    found.add(new dPlayer(player));
                }
            }
            Collections.sort(found, new Comparator<dPlayer>() {

                @Override
                public int compare(dPlayer pl1, dPlayer pl2) {
                    return dLocation.this.compare(pl1.getLocation(), pl2.getLocation());
                }
            });
            return new dList(found).getAttribute(attribute);
        } else // -->
        if (attribute.startsWith("npcs") && attribute.getAttribute(2).startsWith("within") && attribute.hasContext(2)) {
            ArrayList<dNPC> found = new ArrayList<dNPC>();
            double radius = aH.matchesDouble(attribute.getContext(2)) ? attribute.getDoubleContext(2) : 10;
            attribute.fulfill(2);
            for (dNPC npc : DenizenAPI.getSpawnedNPCs()) {
                if (Utilities.checkLocation(this.getBlock().getLocation(), npc.getLocation(), radius)) {
                    found.add(npc);
                }
            }
            Collections.sort(found, new Comparator<dNPC>() {

                @Override
                public int compare(dNPC npc1, dNPC npc2) {
                    return dLocation.this.compare(npc1.getLocation(), npc2.getLocation());
                }
            });
            return new dList(found).getAttribute(attribute);
        } else // -->
        if (attribute.startsWith("entities") && attribute.getAttribute(2).startsWith("within") && attribute.hasContext(2)) {
            dList ent_list = new dList();
            if (attribute.hasContext(1)) {
                ent_list = dList.valueOf(attribute.getContext(1));
            }
            ArrayList<dEntity> found = new ArrayList<dEntity>();
            double radius = aH.matchesDouble(attribute.getContext(2)) ? attribute.getDoubleContext(2) : 10;
            attribute.fulfill(2);
            for (Entity entity : getWorld().getEntities()) {
                if (Utilities.checkLocation(this, entity.getLocation(), radius)) {
                    dEntity current = new dEntity(entity);
                    if (!ent_list.isEmpty()) {
                        for (String ent : ent_list) {
                            if (current.comparedTo(ent)) {
                                found.add(current);
                                break;
                            }
                        }
                    } else {
                        found.add(current);
                    }
                }
            }
            Collections.sort(found, new Comparator<dEntity>() {

                @Override
                public int compare(dEntity ent1, dEntity ent2) {
                    return dLocation.this.compare(ent1.getLocation(), ent2.getLocation());
                }
            });
            return new dList(found).getAttribute(attribute);
        } else // -->
        if (attribute.startsWith("living_entities") && attribute.getAttribute(2).startsWith("within") && attribute.hasContext(2)) {
            ArrayList<dEntity> found = new ArrayList<dEntity>();
            double radius = aH.matchesDouble(attribute.getContext(2)) ? attribute.getDoubleContext(2) : 10;
            attribute.fulfill(2);
            for (Entity entity : getWorld().getEntities()) {
                if (entity instanceof LivingEntity && Utilities.checkLocation(this, entity.getLocation(), radius)) {
                    found.add(new dEntity(entity));
                }
            }
            Collections.sort(found, new Comparator<dEntity>() {

                @Override
                public int compare(dEntity ent1, dEntity ent2) {
                    return dLocation.this.compare(ent1.getLocation(), ent2.getLocation());
                }
            });
            return new dList(found).getAttribute(attribute);
        }
    }
    // -->
    if (attribute.startsWith("find_path") && attribute.hasContext(1)) {
        dLocation two = dLocation.valueOf(attribute.getContext(1));
        if (two == null) {
            return null;
        }
        List<dLocation> locs = PathFinder.getPath(this, two);
        dList list = new dList();
        for (dLocation loc : locs) {
            list.add(loc.identify());
        }
        return list.getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("formatted.citizens")) {
        return new Element(getX() + ":" + getY() + ":" + getZ() + ":" + getWorld().getName()).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("formatted")) {
        return new Element("X '" + getX() + "', Y '" + getY() + "', Z '" + getZ() + "', in world '" + getWorld().getName() + "'").getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("chunk") || attribute.startsWith("get_chunk")) {
        return new dChunk(this).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("raw")) {
        dLocation rawLocation = new dLocation(this);
        rawLocation.setRaw(true);
        return rawLocation.getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("world")) {
        return dWorld.mirrorBukkitWorld(getWorld()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("x")) {
        return new Element(getX()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("y")) {
        return new Element(getY()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("z")) {
        return new Element(getZ()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("notable_name")) {
        String notname = NotableManager.getSavedId(this);
        if (notname == null) {
            return null;
        }
        return new Element(notname).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("add") && attribute.hasContext(1)) {
        // TODO: Just dLocation.valueOf?
        String[] ints = attribute.getContext(1).replace("l@", "").split(",", 4);
        if (ints.length >= 3) {
            if ((aH.matchesDouble(ints[0]) || aH.matchesInteger(ints[0])) && (aH.matchesDouble(ints[1]) || aH.matchesInteger(ints[1])) && (aH.matchesDouble(ints[2]) || aH.matchesInteger(ints[2]))) {
                return new dLocation(this.clone().add(Double.valueOf(ints[0]), Double.valueOf(ints[1]), Double.valueOf(ints[2]))).getAttribute(attribute.fulfill(1));
            }
        } else if (dLocation.matches(attribute.getContext(1))) {
            return new dLocation(this.clone().add(dLocation.valueOf(attribute.getContext(1)))).getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("sub") && attribute.hasContext(1)) {
        // TODO: Just dLocation.valueOf?
        String[] ints = attribute.getContext(1).replace("l@", "").split(",", 4);
        if (ints.length == 3 || ints.length == 4) {
            if ((aH.matchesDouble(ints[0]) || aH.matchesInteger(ints[0])) && (aH.matchesDouble(ints[1]) || aH.matchesInteger(ints[1])) && (aH.matchesDouble(ints[2]) || aH.matchesInteger(ints[2]))) {
                return new dLocation(this.clone().subtract(Double.valueOf(ints[0]), Double.valueOf(ints[1]), Double.valueOf(ints[2]))).getAttribute(attribute.fulfill(1));
            }
        } else if (dLocation.matches(attribute.getContext(1))) {
            return new dLocation(this.clone().subtract(dLocation.valueOf(attribute.getContext(1)))).getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("mul") && attribute.hasContext(1)) {
        return new dLocation(this.clone().multiply(Double.parseDouble(attribute.getContext(1)))).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("div") && attribute.hasContext(1)) {
        return new dLocation(this.clone().multiply(1D / Double.parseDouble(attribute.getContext(1)))).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("normalize")) {
        double len = Math.sqrt(Math.pow(getX(), 2) + Math.pow(getY(), 2) + Math.pow(getZ(), 2));
        if (len == 0) {
            return this.getAttribute(attribute.fulfill(1));
        } else {
            return new dLocation(this.clone().multiply(1D / len)).getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("vector_length")) {
        return new Element(Math.sqrt(Math.pow(getX(), 2) + Math.pow(getY(), 2) + Math.pow(getZ(), 2))).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("distance_squared") && attribute.hasContext(1)) {
        if (dLocation.matches(attribute.getContext(1))) {
            dLocation toLocation = dLocation.valueOf(attribute.getContext(1));
            if (!getWorld().getName().equalsIgnoreCase(toLocation.getWorld().getName())) {
                if (!attribute.hasAlternative()) {
                    dB.echoError("Can't measure distance between two different worlds!");
                }
                return null;
            }
            return new Element(this.distanceSquared(toLocation)).getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("distance") && attribute.hasContext(1)) {
        if (dLocation.matches(attribute.getContext(1))) {
            dLocation toLocation = dLocation.valueOf(attribute.getContext(1));
            // -->
            if (attribute.getAttribute(2).startsWith("horizontal")) {
                // -->
                if (attribute.getAttribute(3).startsWith("multiworld")) {
                    return new Element(Math.sqrt(Math.pow(this.getX() - toLocation.getX(), 2) + Math.pow(this.getZ() - toLocation.getZ(), 2))).getAttribute(attribute.fulfill(3));
                } else if (this.getWorld() == toLocation.getWorld()) {
                    return new Element(Math.sqrt(Math.pow(this.getX() - toLocation.getX(), 2) + Math.pow(this.getZ() - toLocation.getZ(), 2))).getAttribute(attribute.fulfill(2));
                }
            } else // -->
            if (attribute.getAttribute(2).startsWith("vertical")) {
                // -->
                if (attribute.getAttribute(3).startsWith("multiworld")) {
                    return new Element(Math.abs(this.getY() - toLocation.getY())).getAttribute(attribute.fulfill(3));
                } else if (this.getWorld() == toLocation.getWorld()) {
                    return new Element(Math.abs(this.getY() - toLocation.getY())).getAttribute(attribute.fulfill(2));
                }
            }
            if (!getWorld().getName().equalsIgnoreCase(toLocation.getWorld().getName())) {
                if (!attribute.hasAlternative()) {
                    dB.echoError("Can't measure distance between two different worlds!");
                }
                return null;
            } else {
                return new Element(this.distance(toLocation)).getAttribute(attribute.fulfill(1));
            }
        }
    }
    // -->
    if (attribute.startsWith("is_within") && attribute.hasContext(1)) {
        if (dEllipsoid.matches(attribute.getContext(1))) {
            dEllipsoid ellipsoid = dEllipsoid.valueOf(attribute.getContext(1));
            if (ellipsoid != null) {
                return new Element(ellipsoid.contains(this)).getAttribute(attribute.fulfill(1));
            }
        } else {
            dCuboid cuboid = dCuboid.valueOf(attribute.getContext(1));
            if (cuboid != null) {
                return new Element(cuboid.isInsideCuboid(this)).getAttribute(attribute.fulfill(1));
            }
        }
    }
    // -->
    if (attribute.startsWith("biome.formatted")) {
        return new Element(CoreUtilities.toLowerCase(getBlock().getBiome().name()).replace('_', ' ')).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("biome")) {
        return new dBiome(getBlock().getBiome()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("cuboids")) {
        List<dCuboid> cuboids = dCuboid.getNotableCuboidsContaining(this);
        dList cuboid_list = new dList();
        for (dCuboid cuboid : cuboids) {
            cuboid_list.add(cuboid.identify());
        }
        return cuboid_list.getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("ellipsoids")) {
        List<dEllipsoid> ellipsoids = dEllipsoid.getNotableEllipsoidsContaining(this);
        dList ellipsoid_list = new dList();
        for (dEllipsoid ellipsoid : ellipsoids) {
            ellipsoid_list.add(ellipsoid.identify());
        }
        return ellipsoid_list.getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("is_liquid")) {
        return new Element(getBlock().isLiquid()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("light.from_blocks") || attribute.startsWith("light.blocks")) {
        return new Element(getBlock().getLightFromBlocks()).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("light.from_sky") || attribute.startsWith("light.sky")) {
        return new Element(getBlock().getLightFromSky()).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("light")) {
        return new Element(getBlock().getLightLevel()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("power")) {
        return new Element(getBlock().getBlockPower()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("type")) {
        return new Element("Location").getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("command_block_name") && getBlock().getType() == Material.COMMAND) {
        return new Element(((CommandBlock) getBlock().getState()).getName()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("command_block") && getBlock().getType() == Material.COMMAND) {
        return new Element(((CommandBlock) getBlock().getState()).getCommand()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("furnace_burn_time")) {
        return new Element(((Furnace) getBlock().getState()).getBurnTime()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("furnace_cook_time")) {
        return new Element(((Furnace) getBlock().getState()).getCookTime()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("attached_to")) {
        BlockFace face = BlockFace.SELF;
        MaterialData data = getBlock().getState().getData();
        if (data instanceof Attachable) {
            face = ((Attachable) data).getAttachedFace();
        }
        if (face != BlockFace.SELF) {
            return new dLocation(getBlock().getRelative(face).getLocation()).getAttribute(attribute.fulfill(1));
        }
    }
    // Iterate through this object's properties' attributes
    for (Property property : PropertyParser.getProperties(this)) {
        String returned = property.getAttribute(attribute);
        if (returned != null) {
            return returned;
        }
    }
    return new Element(identify()).getAttribute(attribute);
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Comparator(java.util.Comparator) Player(org.bukkit.entity.Player) PlayerProfile(net.aufdemrand.denizen.nms.util.PlayerProfile) DyeColor(org.bukkit.DyeColor) java.util(java.util) MaterialData(org.bukkit.material.MaterialData) ItemStack(org.bukkit.inventory.ItemStack) BlockIterator(org.bukkit.util.BlockIterator) LivingEntity(org.bukkit.entity.LivingEntity) InventoryHolder(org.bukkit.inventory.InventoryHolder) Property(net.aufdemrand.denizencore.objects.properties.Property) EntityHelper(net.aufdemrand.denizen.nms.interfaces.EntityHelper) Material(org.bukkit.Material) Vector(org.bukkit.util.Vector) Attachable(org.bukkit.material.Attachable) Location(org.bukkit.Location)

Example 54 with MaterialData

use of org.bukkit.material.MaterialData in project Denizen-For-Bukkit by DenizenScript.

the class dCuboid method getBlocks_internal.

public List<dLocation> getBlocks_internal(List<dMaterial> materials) {
    int max = Settings.blockTagsMaxBlocks();
    dLocation loc;
    List<dLocation> list = new ArrayList<dLocation>();
    int index = 0;
    for (LocationPair pair : pairs) {
        dLocation loc_1 = pair.low;
        int y_distance = pair.y_distance;
        int z_distance = pair.z_distance;
        int x_distance = pair.x_distance;
        for (int x = 0; x != x_distance + 1; x++) {
            for (int y = 0; y != y_distance + 1; y++) {
                for (int z = 0; z != z_distance + 1; z++) {
                    loc = new dLocation(loc_1.clone().add(x, y, z));
                    if (loc.getY() < 0 || loc.getY() > 255) {
                        // TODO: Why is this ever possible?
                        continue;
                    }
                    if (!filter.isEmpty()) {
                        // Check filter
                        for (dObject material : filter) {
                            if (((dMaterial) material).matchesMaterialData(new MaterialData(loc.getBlock().getType(), loc.getBlock().getData()))) {
                                if (matchesMaterialList(loc, materials)) {
                                    list.add(loc);
                                }
                            }
                        }
                    } else {
                        if (matchesMaterialList(loc, materials)) {
                            list.add(loc);
                        }
                    }
                    index++;
                    if (index > max) {
                        return list;
                    }
                }
            }
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) MaterialData(org.bukkit.material.MaterialData)

Example 55 with MaterialData

use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.

the class BlockChest method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    super.placeBlock(player, state, face, holding, clickedLoc);
    MaterialData data = state.getData();
    if (data instanceof Chest) {
        Chest chest = (Chest) data;
        GlowBlock chestBlock = state.getBlock();
        BlockFace normalFacing = getOppositeBlockFace(player.getLocation(), false);
        Collection<BlockFace> attachedChests = searchChests(chestBlock);
        if (attachedChests.isEmpty()) {
            chest.setFacingDirection(normalFacing);
            state.setData(chest);
            return;
        } else if (attachedChests.size() > 1) {
            GlowServer.logger.warning("Chest placed near two other chests!");
            return;
        }
        BlockFace otherPart = attachedChests.iterator().next();
        GlowBlock otherPartBlock = chestBlock.getRelative(otherPart);
        if (getAttachedChest(otherPartBlock) != null) {
            GlowServer.logger.warning("Chest placed near already attached chest!");
            return;
        }
        BlockState otherPartState = otherPartBlock.getState();
        MaterialData otherPartData = otherPartState.getData();
        if (otherPartData instanceof Chest) {
            Chest otherChest = (Chest) otherPartData;
            BlockFace facing = getFacingDirection(normalFacing, otherChest.getFacing(), otherPart, player);
            chest.setFacingDirection(facing);
            state.setData(chest);
            otherChest.setFacingDirection(facing);
            otherPartState.setData(otherChest);
            otherPartState.update();
        } else {
            warnMaterialData(Chest.class, otherPartData);
        }
    } else {
        warnMaterialData(Chest.class, data);
    }
}
Also used : Chest(org.bukkit.material.Chest) GlowBlock(net.glowstone.block.GlowBlock) BlockState(org.bukkit.block.BlockState) GlowBlockState(net.glowstone.block.GlowBlockState) BlockFace(org.bukkit.block.BlockFace) MaterialData(org.bukkit.material.MaterialData)

Aggregations

MaterialData (org.bukkit.material.MaterialData)93 GlowBlockState (net.glowstone.block.GlowBlockState)20 ItemStack (org.bukkit.inventory.ItemStack)20 Material (org.bukkit.Material)13 Block (org.bukkit.block.Block)12 BlockState (org.bukkit.block.BlockState)12 GlowBlock (net.glowstone.block.GlowBlock)10 BlockFace (org.bukkit.block.BlockFace)10 MyPetBaby (de.Keyle.MyPet.api.entity.MyPetBaby)9 TagCompound (de.keyle.knbt.TagCompound)9 ArrayList (java.util.ArrayList)6 DoublePlant (org.bukkit.material.DoublePlant)6 Bed (org.bukkit.material.Bed)5 IOException (java.io.IOException)3 GlowDispenser (net.glowstone.block.state.GlowDispenser)3 Location (org.bukkit.Location)3 Player (org.bukkit.entity.Player)3 CocoaPlant (org.bukkit.material.CocoaPlant)3 Dispenser (org.bukkit.material.Dispenser)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3