Java Code Examples for org.bukkit.configuration.file.FileConfiguration#getBoolean()

The following examples show how to use org.bukkit.configuration.file.FileConfiguration#getBoolean() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArmorListener.java    From MineTinker with GNU General Public License v3.0 6 votes vote down vote up
private void expCalculation(boolean isBlocking, ItemStack tool, EntityDamageEvent event, Player player) {
	//Armor should not get Exp when successfully blocking
	if(isBlocking && !ToolType.SHIELD.contains(tool.getType()) && ToolType.ARMOR.contains(tool.getType())) return;
	//Shield should not get Exp when not successfully blocking when getting attacked
	if(!isBlocking && player.equals(event.getEntity()) && ToolType.SHIELD.contains(tool.getType())) return;
	FileConfiguration config = MineTinker.getPlugin().getConfig();
	int amount = config.getInt("ExpPerEntityHit");

	if (config.getBoolean("EnableDamageExp")) {
		amount = (int) Math.round(event.getDamage());
	}

	if (config.getBoolean("DisableExpFromFalldamage", false)
			&& event.getCause() == EntityDamageEvent.DamageCause.FALL) {
		return;
	}

	modManager.addExp(player, tool, amount);
}
 
Example 2
Source File: GovernmentManager.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
private void loadGovType(FileConfiguration config, String name) {
    if (!config.getBoolean("enabled", false)) {
        return;
    }
    String govTypeString = config.getString("inherit", name);
    GovernmentType governmentType = GovernmentType.valueOf(govTypeString.toUpperCase());
    if (governmentType == GovernmentType.CYBERSYNACY) {
        new AIManager();
    }
    CVItem cvItem = CVItem.createCVItemFromString(config.getString("icon", "STONE"));

    ArrayList<GovTransition> transitions = processTransitionList(config.getConfigurationSection("transition"));
    Government government = new Government(name, governmentType,
            getBuffs(config.getConfigurationSection("buffs")), cvItem, transitions);
    governments.put(name.toUpperCase(), government);
}
 
Example 3
Source File: CommandListener.java    From Carbon with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
  FileConfiguration spigot = YamlConfiguration.loadConfiguration(new File(Bukkit.getServer().getWorldContainer(), "spigot.yml"));
  if (event.getMessage().equalsIgnoreCase("/reload") && event.getPlayer().hasPermission("bukkit.command.reload")) {
    // Restarts server if server is set up for it.
    if (spigot.getBoolean("settings.restart-on-crash")) {
      Bukkit.getLogger().severe("[Carbon] Restarting server due to reload command!");
      Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "restart");
    } else {
      // Call to server shutdown on disable.
      // Won't hurt if server already disables itself, but will prevent plugin unload/reload.
      Bukkit.getLogger().severe("[Carbon] Stopping server due to reload command!");
      Bukkit.shutdown();
    }
  }
  }
 
Example 4
Source File: ListenerResurrect.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority=EventPriority.NORMAL, ignoreCancelled=true)
public void beforeResurrect(EntityResurrectEvent e) {
    FileConfiguration config = this.expansion.getConfig("citizens-compatibility.yml");
    if(!config.getBoolean("npc-options.prevent-resurrect", true)) return;
    
    LivingEntity entity = e.getEntity();
    if(!entity.hasMetadata("NPC")) return;

    NPCRegistry npcRegistry = CitizensAPI.getNPCRegistry();
    NPC npc = npcRegistry.getNPC(entity);

    NPCManager npcManager = this.expansion.getNPCManager();
    if(npcManager.isInvalid(npc)) return;
    
    e.setCancelled(true);
}
 
Example 5
Source File: ListenerNewItemPickup.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority= EventPriority.HIGH, ignoreCancelled=true)
public void onPickupItem(EntityPickupItemEvent e) {
    FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml");
    if(!config.getBoolean("items.prevent-item-pickup")) return;

    LivingEntity entity = e.getEntity();
    if(!(entity instanceof Player)) return;

    Player player = (Player) entity;
    ICombatManager combatManager = this.plugin.getCombatManager();
    if(!combatManager.isInCombat(player)) return;

    e.setCancelled(true);
    sendMessage(player);
}
 
Example 6
Source File: ListenerBlocks.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority=EventPriority.HIGH, ignoreCancelled=true)
public void onInteract(PlayerInteractEvent e) {
    Action action = e.getAction();
    if(action != Action.RIGHT_CLICK_BLOCK) return;

    FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml");
    if(!config.getBoolean("blocks.prevent-interaction")) return;

    Player player = e.getPlayer();
    ICombatManager combatManager = this.plugin.getCombatManager();
    if(!combatManager.isInCombat(player)) return;

    e.setCancelled(true);
    sendMessageWithCooldown(player, "cheat-prevention.blocks.no-interaction");
}
 
Example 7
Source File: BedwarsRel.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
public boolean getBooleanConfig(String key, boolean defaultBool) {
  FileConfiguration config = this.getConfig();
  if (config.contains(key) && config.isBoolean(key)) {
    return config.getBoolean(key);
  }
  return defaultBool;
}
 
Example 8
Source File: ListenerMobCombat.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private Entity linkPet(Entity original) {
    if(original == null) return null;
    
    FileConfiguration config = this.expansion.getPlugin().getConfig("config.yml");
    if(!config.getBoolean("link-pets")) return original;
    
    if(original instanceof Tameable) {
        Tameable pet = (Tameable) original;
        AnimalTamer owner = pet.getOwner();
        if(owner instanceof Entity) return (Entity) owner;
    }
    
    return original;
}
 
Example 9
Source File: NPCManager.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
public void loadTagStatus(Player player) {
    if(player == null) return;

    FileConfiguration config = this.expansion.getConfig("citizens-compatibility.yml");
    if(!config.getBoolean("retag-player-on-login", true)) return;

    ICombatLogX plugin = this.expansion.getPlugin();
    ICombatManager combatManager = plugin.getCombatManager();
    combatManager.tag(player, null, TagType.UNKNOWN, TagReason.UNKNOWN);
}
 
Example 10
Source File: ListenerDamage.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private boolean doesNotTagPlayer(EntityDamageEvent.DamageCause cause) {
    if(cause == null) return true;

    FileConfiguration config = this.expansion.getConfig("damage-tagger.yml");
    boolean allDamage = config.getBoolean("all-damage");
    if(allDamage) return false;

    String causeName = cause.name().toLowerCase().replace("_", "-");
    String configPath = "damage-type." + causeName;
    return !config.getBoolean(configPath, false);
}
 
Example 11
Source File: CrazyCrates.java    From Crazy-Crates with MIT License 5 votes vote down vote up
/**
 * Load the crate preview of a crate.
 * @param crate The crate you wish to load the preview of.
 * @return An Inventory object of the preview.
 */
public Inventory loadPreview(Crate crate) {
    FileConfiguration file = crate.getFile();
    int slots = 9;
    for (int size = file.getConfigurationSection("Crate.Prizes").getKeys(false).size(); size > 9 && slots < crate.getMaxSlots(); size -= 9) {
        slots += 9;
    }
    Inventory inv = Bukkit.createInventory(null, slots, Methods.sanitizeColor(file.getString("Crate.Name")));
    for (String reward : file.getConfigurationSection("Crate.Prizes").getKeys(false)) {
        String id = file.getString("Crate.Prizes." + reward + ".DisplayItem", "Stone");
        String name = file.getString("Crate.Prizes." + reward + ".DisplayName", "");
        List<String> lore = file.getStringList("Crate.Prizes." + reward + ".Lore");
        HashMap<Enchantment, Integer> enchantments = new HashMap<>();
        String player = file.getString("Crate.Prizes." + reward + ".Player", "");
        boolean glowing = file.getBoolean("Crate.Prizes." + reward + ".Glowing");
        int amount = file.getInt("Crate.Prizes." + reward + ".DisplayAmount", 1);
        for (String enchantmentName : file.getStringList("Crate.Prizes." + reward + ".DisplayEnchantments")) {
            Enchantment enchantment = Methods.getEnchantment(enchantmentName.split(":")[0]);
            if (enchantment != null) {
                enchantments.put(enchantment, Integer.parseInt(enchantmentName.split(":")[1]));
            }
        }
        try {
            inv.setItem(inv.firstEmpty(), new ItemBuilder().setMaterial(id).setAmount(amount).setName(name).setLore(lore).setEnchantments(enchantments).setGlowing(glowing).setPlayer(player).build());
        } catch (Exception e) {
            inv.addItem(new ItemBuilder().setMaterial("RED_TERRACOTTA", "STAINED_CLAY:14").setName("&c&lERROR").setLore(Arrays.asList("&cThere is an error", "&cFor the reward: &c" + reward)).build());
        }
    }
    return inv;
}
 
Example 12
Source File: DoubleDamageEvent.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
public DoubleDamageEvent(GameMap map, boolean b) {
	this.gMap = map;
	this.enabled = b;
	File dataDirectory = SkyWarsReloaded.get().getDataFolder();
       File mapDataDirectory = new File(dataDirectory, "mapsData");

       if (!mapDataDirectory.exists() && !mapDataDirectory.mkdirs()) {
       	return;
       }
       
       File mapFile = new File(mapDataDirectory, gMap.getName() + ".yml");
    if (mapFile.exists()) {
    	eventName = "DoubleDamageEvent";
    	slot = 15;
    	material = new ItemStack(Material.DIAMOND_AXE, 1);
        FileConfiguration fc = YamlConfiguration.loadConfiguration(mapFile);
        this.min = fc.getInt("events." + eventName + ".minStart");
        this.max = fc.getInt("events." + eventName + ".maxStart");
        this.length = fc.getInt("events." + eventName + ".length");
        this.chance = fc.getInt("events." + eventName + ".chance");
        this.title = fc.getString("events." + eventName + ".title");
        this.subtitle = fc.getString("events." + eventName + ".subtitle");
        this.startMessage = fc.getString("events." + eventName + ".startMessage");
        this.endMessage = fc.getString("events." + eventName + ".endMessage");
        this.announceEvent = fc.getBoolean("events." + eventName + ".announceTimer");
        this.repeatable = fc.getBoolean("events." + eventName + ".repeatable");
    }
}
 
Example 13
Source File: Directing.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void reload() {
	FileConfiguration config = getConfig();
	config.options().copyDefaults(true);

	config.addDefault("Allowed", true);
	config.addDefault("MaxLevel", 1);
	config.addDefault("SlotCost", 1);
	config.addDefault("WorksOnXP", true);
	config.addDefault("MinimumLevelToGetXP", 1); //Modifier-Level to give Player XP
	config.addDefault("WorkInPVP", true);
	config.addDefault("Color", "%GRAY%");

	config.addDefault("EnchantCost", 10);
	config.addDefault("Enchantable", false);

	config.addDefault("Recipe.Enabled", true);
	config.addDefault("Recipe.Top", "ECE");
	config.addDefault("Recipe.Middle", "CIC");
	config.addDefault("Recipe.Bottom", "ECE");

	Map<String, String> recipeMaterials = new HashMap<>();
	recipeMaterials.put("C", Material.COMPASS.name());
	recipeMaterials.put("E", Material.ENDER_PEARL.name());
	recipeMaterials.put("I", Material.IRON_BLOCK.name());

	config.addDefault("Recipe.Materials", recipeMaterials);

	ConfigurationManager.saveConfig(config);
	ConfigurationManager.loadConfig("Modifiers" + File.separator, getFileName());

	init(Material.COMPASS);

	this.workInPVP = config.getBoolean("WorkInPVP", true);
	this.workOnXP = config.getBoolean("WorksOnXP", true);
	this.minimumLevelForXP = config.getInt("MinimumLevelToGetXP", 1);
}
 
Example 14
Source File: MobSpawnEvent.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
public MobSpawnEvent(GameMap map, boolean b) {
	this.gMap = map;
	this.enabled = b;
	File dataDirectory = SkyWarsReloaded.get().getDataFolder();
       File mapDataDirectory = new File(dataDirectory, "mapsData");

       if (!mapDataDirectory.exists() && !mapDataDirectory.mkdirs()) {
       	return;
       }
       
       File mapFile = new File(mapDataDirectory, gMap.getName() + ".yml");
    if (mapFile.exists()) {
    	eventName = "MobSpawnEvent";
    	slot = 22;
    	material = SkyWarsReloaded.getNMS().getMaterial("MOB_SPAWNER");
        FileConfiguration fc = YamlConfiguration.loadConfiguration(mapFile);
        this.min = fc.getInt("events." + eventName + ".minStart");
        this.max = fc.getInt("events." + eventName + ".maxStart");
        this.length = fc.getInt("events." + eventName + ".length");
        this.chance = fc.getInt("events." + eventName + ".chance");
        this.title = fc.getString("events." + eventName + ".title");
        this.subtitle = fc.getString("events." + eventName + ".subtitle");
        this.startMessage = fc.getString("events." + eventName + ".startMessage");
        this.endMessage = fc.getString("events." + eventName + ".endMessage");
        this.announceEvent = fc.getBoolean("events." + eventName + ".announceTimer");
        this.repeatable = fc.getBoolean("events." + eventName + ".repeatable");
        this.minMobsPerPlayer = fc.getInt("events." + eventName + ".minMobsPerPlayer");
        this.maxMobsPerPlayer = fc.getInt("events." + eventName + ".maxMobsPerPlayer");
        this.mobs = fc.getStringList("events." + eventName + ".mobs");
    }
}
 
Example 15
Source File: ListenerBlocks.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority=EventPriority.HIGH, ignoreCancelled=true)
public void onBlockPlace(BlockPlaceEvent e) {
    FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml");
    if(!config.getBoolean("blocks.prevent-placing")) return;

    Player player = e.getPlayer();
    ICombatManager combatManager = this.plugin.getCombatManager();
    if(!combatManager.isInCombat(player)) return;

    e.setCancelled(true);
    sendMessageWithCooldown(player, "cheat-prevention.blocks.no-placing");
}
 
Example 16
Source File: DeathMatchEvent.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
public DeathMatchEvent(GameMap map, boolean b) {
	this.gMap = map;
	this.enabled = b;
	File dataDirectory = SkyWarsReloaded.get().getDataFolder();
       File mapDataDirectory = new File(dataDirectory, "mapsData");

       if (!mapDataDirectory.exists() && !mapDataDirectory.mkdirs()) {
       	return;
       }
       
       File mapFile = new File(mapDataDirectory, gMap.getName() + ".yml");
    if (mapFile.exists()) {
    	eventName = "DeathMatchEvent";
    	slot = 8;
    	material = new ItemStack(Material.DIAMOND_SWORD, 1);
        FileConfiguration fc = YamlConfiguration.loadConfiguration(mapFile);
        this.min = fc.getInt("events." + eventName + ".minStart");
        this.max = fc.getInt("events." + eventName + ".maxStart");
        this.length = fc.getInt("events." + eventName + ".length");
        this.chance = fc.getInt("events." + eventName + ".chance");
        this.title = fc.getString("events." + eventName + ".title");
        this.subtitle = fc.getString("events." + eventName + ".subtitle");
        this.startMessage = fc.getString("events." + eventName + ".startMessage");
        this.endMessage = fc.getString("events." + eventName + ".endMessage");
        this.announceEvent = fc.getBoolean("events." + eventName + ".announceTimer");
        this.repeatable = fc.getBoolean("events." + eventName + ".repeatable");
       }
}
 
Example 17
Source File: DisableRegenEvent.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
public DisableRegenEvent(GameMap map, boolean b) {
	this.gMap = map;
	this.enabled = b;
	File dataDirectory = SkyWarsReloaded.get().getDataFolder();
       File mapDataDirectory = new File(dataDirectory, "mapsData");

       if (!mapDataDirectory.exists() && !mapDataDirectory.mkdirs()) {
       	return;
       }
       
       File mapFile = new File(mapDataDirectory, gMap.getName() + ".yml");
    if (mapFile.exists()) {
    	eventName = "DisableRegenEvent";
    	slot = 18;
    	material = new ItemStack(Material.GOLDEN_APPLE, 1);
        FileConfiguration fc = YamlConfiguration.loadConfiguration(mapFile);
        this.min = fc.getInt("events." + eventName + ".minStart");
        this.max = fc.getInt("events." + eventName + ".maxStart");
        this.length = fc.getInt("events." + eventName + ".length");
        this.chance = fc.getInt("events." + eventName + ".chance");
        this.title = fc.getString("events." + eventName + ".title");
        this.subtitle = fc.getString("events." + eventName + ".subtitle");
        this.startMessage = fc.getString("events." + eventName + ".startMessage");
        this.endMessage = fc.getString("events." + eventName + ".endMessage");
        this.announceEvent = fc.getBoolean("events." + eventName + ".announceTimer");
        this.repeatable = fc.getBoolean("events." + eventName + ".repeatable");
    }
}
 
Example 18
Source File: CrazyCrates.java    From Crazy-Crates with MIT License 5 votes vote down vote up
private ItemStack getKey(FileConfiguration file) {
    String name = file.getString("Crate.PhysicalKey.Name");
    List<String> lore = file.getStringList("Crate.PhysicalKey.Lore");
    String id = file.getString("Crate.PhysicalKey.Item");
    boolean glowing = false;
    if (file.contains("Crate.PhysicalKey.Glowing")) {
        glowing = file.getBoolean("Crate.PhysicalKey.Glowing");
    }
    return new ItemBuilder().setMaterial(id).setName(name).setLore(lore).setGlowing(glowing).build();
}
 
Example 19
Source File: LevelManager.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
public void loadKillSounds() {
    killSoundList.clear();
    File soundFile = new File(SkyWarsReloaded.get().getDataFolder(), "killsounds.yml");

    if (!soundFile.exists()) {
    	if (SkyWarsReloaded.getNMS().getVersion() < 8) {
            	SkyWarsReloaded.get().saveResource("killsounds18.yml", false);
            	File sf = new File(SkyWarsReloaded.get().getDataFolder(), "killsounds18.yml");
            	if (sf.exists()) {
            		sf.renameTo(new File(SkyWarsReloaded.get().getDataFolder(), "killsounds.yml"));
            	}
    	} else {
        	SkyWarsReloaded.get().saveResource("killsounds.yml", false);
    	}
    }

    if (soundFile.exists()) {
        FileConfiguration storage = YamlConfiguration.loadConfiguration(soundFile);

        if (storage.getConfigurationSection("sounds") != null) {
        	for (String key: storage.getConfigurationSection("sounds").getKeys(false)) {
        		String sound = storage.getString("sounds." + key + ".sound");
            	String name = storage.getString("sounds." + key + ".displayName");
            	int volume = storage.getInt("sounds." + key + ".volume");
            	int pitch = storage.getInt("sounds." + key + ".pitch");
            	String material = storage.getString("sounds." + key + ".icon");
            	int level = storage.getInt("sounds." + key + ".level");
            	int cost = storage.getInt("sounds." + key + ".cost");
            	boolean isCustom = storage.getBoolean("sounds." + key + ".isCustomSound");
            	
            	Material mat = Material.matchMaterial(material);
            	if (mat != null) {
            		if (!isCustom) {
            			try {
            				Sound s = Sound.valueOf(sound);
            				if (s != null) {
            					killSoundList.add(new SoundItem(key, sound, name, level, cost, volume, pitch, mat, isCustom));
            				}
            			} catch (IllegalArgumentException e) {
            				SkyWarsReloaded.get().getServer().getLogger().info(sound + " is not a valid sound in killsounds.yml");
            			}
            		} else {
            			killSoundList.add(new SoundItem(key, sound, name, level, cost, volume, pitch, mat, isCustom));
            		}
            			
                } else {
                	SkyWarsReloaded.get().getServer().getLogger().info(mat + " is not a valid Material in killsounds.yml");
                }
        	}
        }
    }
    
    Collections.<SoundItem>sort(killSoundList);
}
 
Example 20
Source File: Scotopic.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void reload() {
	FileConfiguration config = getConfig();
	config.options().copyDefaults(true);

	config.addDefault("Allowed", true);
	config.addDefault("Color", "%YELLOW%");
	config.addDefault("MaxLevel", 3);
	config.addDefault("SlotCost", 2);
	config.addDefault("RequiredLightLevel", 6);
	config.addDefault("CooldownInSeconds", 120); //in seconds
	config.addDefault("DurationPerLevel", 100); //in ticks
	config.addDefault("CooldownReductionPerLevel", 0.65);
	config.addDefault("GivesImmunityToBlindness", true);

	config.addDefault("EnchantCost", 10);
	config.addDefault("Enchantable", false);

	config.addDefault("Recipe.Enabled", true);
	config.addDefault("Recipe.Top", "S S");
	config.addDefault("Recipe.Middle", " F ");
	config.addDefault("Recipe.Bottom", "S S");

	Map<String, String> recipeMaterials = new HashMap<>();
	recipeMaterials.put("S", Material.SPIDER_EYE.name());
	recipeMaterials.put("F", Material.FERMENTED_SPIDER_EYE.name());

	config.addDefault("Recipe.Materials", recipeMaterials);

	ConfigurationManager.saveConfig(config);
	ConfigurationManager.loadConfig("Modifiers" + File.separator, getFileName());

	init(Material.FERMENTED_SPIDER_EYE);
	this.requiredLightLevel = config.getInt("RequiredLightLevel", 6);
	this.durationPerLevel = config.getInt("DurationPerLevel", 100);
	this.cooldownInSeconds = config.getInt("CooldownInSeconds", 120);
	this.cooldownReductionPerLevel = config.getDouble("CooldownReductionPerLevel", 0.65);
	this.givesImmunity = config.getBoolean("GivesImmunityToEffect", true);

	this.description = this.description
			.replaceAll("%amount", String.valueOf(this.durationPerLevel / 20.0))
			.replaceAll("%light", String.valueOf(this.requiredLightLevel))
			.replaceAll("%cmax", String.valueOf(this.cooldownInSeconds))
			.replaceAll("%cmin", String.valueOf(Math.round(this.cooldownInSeconds * Math.pow(1.0 - this.cooldownReductionPerLevel, this.getMaxLvl() - 1))));
}