diff --git a/src/main/java/org/avarion/graves/Graves.java b/src/main/java/org/avarion/graves/Graves.java index 3bcf587..acec4f2 100644 --- a/src/main/java/org/avarion/graves/Graves.java +++ b/src/main/java/org/avarion/graves/Graves.java @@ -25,6 +25,7 @@ import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.*; import java.nio.charset.StandardCharsets; @@ -495,29 +496,93 @@ public Compatibility getCompatibility() { return compatibility; } + /// startregion: getConfig* + public boolean getConfigBool(String config, Grave grave) { + return getConfig(config, grave.getOwnerType(), grave.getPermissionList()).getBoolean(config); + } + + public int getConfigInt(String config, Grave grave) { + return getConfig(config, grave.getOwnerType(), grave.getPermissionList()).getInt(config); + } + + public int getConfigInt(String config, Grave grave, int defaultValue) { + return getConfig(config, grave.getOwnerType(), grave.getPermissionList()).getInt(config, defaultValue); + } + + public String getConfigString(String config, Grave grave, String defaultValue) { + return getConfig(config, grave.getOwnerType(), grave.getPermissionList()).getString(config, defaultValue); + } + + public String getConfigString(String config, Entity entity, String defaultValue) { + return getConfig(config, entity.getType(), getPermissionList(entity)).getString(config, defaultValue); + } + + public String getConfigString(String config, Grave grave) { + return getConfig(config, grave.getOwnerType(), grave.getPermissionList()).getString(config); + } + + public List getConfigStringList(String config, Grave grave) { + return getConfig(config, grave.getOwnerType(), grave.getPermissionList()).getStringList(config); + } + + public double getConfigDbl(String config, Grave grave) { + return getConfig(config, grave.getOwnerType(), grave.getPermissionList()).getDouble(config); + } + + public boolean getConfigBool(String config, @NotNull Entity entity) { + return getConfig(config, entity.getType(), getPermissionList(entity)).getBoolean(config); + } + + public boolean getConfigBool(String config, Entity entity, @Nullable List permissionList) { + return getConfig(config, entity.getType(), permissionList).getBoolean(config); + } + + public boolean getConfigBool(String config, EntityType entityType, @Nullable List permissionList) { + return getConfig(config, entityType, permissionList).getBoolean(config); + } + + public int getConfigInt(String config, Entity entity, @Nullable List permissionList) { + return getConfig(config, entity.getType(), permissionList).getInt(config); + } + + public String getConfigString(String config, Entity entity, @Nullable List permissionList) { + return getConfig(config, entity.getType(), permissionList).getString(config); + } + + public String getConfigString(String config, Entity entity, @Nullable List permissionList, String defaultValue) { + return getConfig(config, entity.getType(), permissionList).getString(config, defaultValue); + } + + public String getConfigString(String config, EntityType entityType, @Nullable List permissionList) { + return getConfig(config, entityType, permissionList).getString(config); + } + + public List getConfigStringList(String config, Entity entity, @Nullable List permissionList) { + return getConfig(config, entity.getType(), permissionList).getStringList(config); + } + /// endregion: getConfig* + + /// startregion: getConfig public ConfigurationSection getConfig(String config, Grave grave) { return getConfig(config, grave.getOwnerType(), grave.getPermissionList()); } - public ConfigurationSection getConfig(String config, Entity entity) { - return getConfig(config, entity.getType(), getPermissionList(entity)); + private ConfigurationSection getConfig(String config, Entity entity, @Nullable List permissionList) { + return getConfig(config, entity.getType(), permissionList); } - public ConfigurationSection getConfig(String config, Entity entity, List permissionList) { - return getConfig(config, entity.getType(), permissionList); + private ConfigurationSection getConfig(String config, @NotNull Entity entity) { + return getConfig(config, entity.getType(), getPermissionList(entity)); } - public ConfigurationSection getConfig(String config, EntityType entityType, List permissionList) { + private ConfigurationSection getConfig(String config, EntityType entityType, List permissionList) { if (permissionList != null && !permissionList.isEmpty()) { for (String permission : permissionList) { String section = "settings.permission." + permission; - if (getConfig().isConfigurationSection(section)) { - ConfigurationSection configurationSection = getConfig().getConfigurationSection(section); - - if (configurationSection != null && configurationSection.contains(config, true)) { - return configurationSection; - } + ConfigurationSection configurationSection = getConfig().getConfigurationSection(section); + if (configurationSection != null && configurationSection.contains(config, true)) { + return configurationSection; } } } @@ -525,17 +590,15 @@ public ConfigurationSection getConfig(String config, EntityType entityType, List if (entityType != null) { String section = "settings.entity." + entityType.name(); - if (getConfig().isConfigurationSection(section)) { - ConfigurationSection configurationSection = getConfig().getConfigurationSection(section); - - if (configurationSection != null && configurationSection.contains(config, true)) { - return configurationSection; - } + ConfigurationSection configurationSection = getConfig().getConfigurationSection(section); + if (configurationSection != null && configurationSection.contains(config, true)) { + return configurationSection; } } return getConfig().getConfigurationSection("settings.default.default"); } + /// endregion private void loadResourceDefaults(FileConfiguration fileConfiguration, String resource) { InputStream inputStream = getResource(resource); diff --git a/src/main/java/org/avarion/graves/compatibility/CompatibilityBlockData.java b/src/main/java/org/avarion/graves/compatibility/CompatibilityBlockData.java index 1ea3788..13fc543 100644 --- a/src/main/java/org/avarion/graves/compatibility/CompatibilityBlockData.java +++ b/src/main/java/org/avarion/graves/compatibility/CompatibilityBlockData.java @@ -88,9 +88,9 @@ public boolean hasTitleData(Block block) { @SuppressWarnings("deprecation") private void updateSkullBlock(Block block, Grave grave, Graves plugin) { - int headType = plugin.getConfig("block.head.type", grave).getInt("block.head.type"); - String headBase64 = plugin.getConfig("block.head.base64", grave).getString("block.head.base64"); - String headName = plugin.getConfig("block.head.name", grave).getString("block.head.name"); + int headType = plugin.getConfigInt("block.head.type", grave); + String headBase64 = plugin.getConfigString("block.head.base64", grave); + String headName = plugin.getConfigString("block.head.name", grave); Skull skull = (Skull) block.getState(); Rotatable skullRotate = (Rotatable) block.getBlockData(); @@ -104,11 +104,11 @@ private void updateSkullBlock(Block block, Grave grave, Graves plugin) { else if (grave.getOwnerTexture() != null) { SkinUtil.setSkullBlockTexture(skull, grave.getOwnerName(), grave.getOwnerTexture()); } - else if (headBase64 != null && !headBase64.equals("")) { + else if (headBase64 != null && !headBase64.isEmpty()) { SkinUtil.setSkullBlockTexture(skull, grave.getOwnerName(), headBase64); } } - else if (headType == 1 && headBase64 != null && !headBase64.equals("")) { + else if (headType == 1 && headBase64 != null && !headBase64.isEmpty()) { SkinUtil.setSkullBlockTexture(skull, grave.getOwnerName(), headBase64); } else if (headType == 2 && headName != null && headName.length() <= 16) { diff --git a/src/main/java/org/avarion/graves/integration/FurnitureEngine.java b/src/main/java/org/avarion/graves/integration/FurnitureEngine.java index 0a85354..0fc1437 100644 --- a/src/main/java/org/avarion/graves/integration/FurnitureEngine.java +++ b/src/main/java/org/avarion/graves/integration/FurnitureEngine.java @@ -54,8 +54,8 @@ public void unregisterListeners() { } public void createFurniture(Location location, Grave grave) { - if (plugin.getConfig("furnitureengine.enabled", grave).getBoolean("furnitureengine.enabled")) { - String name = plugin.getConfig("furnitureengine.name", grave).getString("furnitureengine.name", ""); + if (plugin.getConfigBool("furnitureengine.enabled", grave)) { + String name = plugin.getConfigString("furnitureengine.name", grave, ""); location.getBlock().setType(Material.AIR); diff --git a/src/main/java/org/avarion/graves/integration/FurnitureLib.java b/src/main/java/org/avarion/graves/integration/FurnitureLib.java index 313dd87..32ff33c 100644 --- a/src/main/java/org/avarion/graves/integration/FurnitureLib.java +++ b/src/main/java/org/avarion/graves/integration/FurnitureLib.java @@ -67,8 +67,8 @@ public boolean canBuild(Location location, Player player) { } public void createFurniture(Location location, Grave grave) { - if (plugin.getConfig("furniturelib.enabled", grave).getBoolean("furniturelib.enabled")) { - String name = plugin.getConfig("furniturelib.name", grave).getString("furniturelib.name", ""); + if (plugin.getConfigBool("furniturelib.enabled", grave)) { + String name = plugin.getConfigString("furniturelib.name", grave, ""); Project project = furnitureLib.getFurnitureManager().getProject(name); if (project != null && project.haveModelSchematic()) { @@ -83,10 +83,9 @@ public void createFurniture(Location location, Grave grave) { objectID.getBlockList() .stream() .filter(signLocation -> signLocation.getBlock().getType().name().contains("SIGN")) - .forEach((signLocation) -> setSign(signLocation.getBlock(), plugin.getConfig("furniturelib.line", grave) - .getStringList("furniturelib.line"), grave)); + .forEach((signLocation) -> setSign(signLocation.getBlock(), plugin.getConfigStringList("furniturelib.line", grave), grave)); - if (plugin.getConfig("furniturelib.head.replace", grave).getBoolean("furniturelib.head.replace")) { + if (plugin.getConfigBool("furniturelib.head.replace", grave)) { objectID.getPacketList().forEach((fEntity) -> setSkull(fEntity, grave)); } @@ -142,8 +141,7 @@ private void setSign(Block block, List stringList, Grave grave) { } private void setSkull(fEntity fEntity, Grave grave) { - List materialList = plugin.getConfig("furniturelib.head.material", grave) - .getStringList("furniturelib.head.material"); + List materialList = plugin.getConfigStringList("furniturelib.head.material", grave); ItemStack itemStack = plugin.getCompatibility().getSkullItemStack(grave, plugin); if (fEntity.getItemInMainHand() != null diff --git a/src/main/java/org/avarion/graves/integration/ItemsAdder.java b/src/main/java/org/avarion/graves/integration/ItemsAdder.java index 5080037..beb9f70 100644 --- a/src/main/java/org/avarion/graves/integration/ItemsAdder.java +++ b/src/main/java/org/avarion/graves/integration/ItemsAdder.java @@ -56,9 +56,8 @@ public void createFurniture(Location location, Grave grave) { .getOppositeFace())); location.setPitch(grave.getPitch()); - if (plugin.getConfig("itemsadder.furniture.enabled", grave).getBoolean("itemsadder.furniture.enabled")) { - String name = plugin.getConfig("itemsadder.furniture.name", grave) - .getString("itemsadder.furniture.name", ""); + if (plugin.getConfigBool("itemsadder.furniture.enabled", grave)) { + String name = plugin.getConfigString("itemsadder.furniture.name", grave, ""); location.getBlock().setType(Material.AIR); CustomFurniture customFurniture = createCustomFurniture(name, location); @@ -105,8 +104,8 @@ public void removeFurniture(Map entityDataMap) { } public void createBlock(Location location, Grave grave) { - if (plugin.getConfig("itemsadder.block.enabled", grave).getBoolean("itemsadder.block.enabled")) { - String name = plugin.getConfig("itemsadder.block.name", grave).getString("itemsadder.block.name", ""); + if (plugin.getConfigBool("itemsadder.block.enabled", grave)) { + String name = plugin.getConfigString("itemsadder.block.name", grave, ""); CustomBlock customBlock = createCustomBlock(name, location); if (customBlock != null) { diff --git a/src/main/java/org/avarion/graves/integration/MultiPaper.java b/src/main/java/org/avarion/graves/integration/MultiPaper.java index fa8c39e..24fc594 100644 --- a/src/main/java/org/avarion/graves/integration/MultiPaper.java +++ b/src/main/java/org/avarion/graves/integration/MultiPaper.java @@ -58,11 +58,9 @@ private void registerListeners() { List itemStackList = (List) Base64Util.base64ToObject(dataSplit[1]); if (grave != null && itemStackList != null) { - String title = StringUtil.parseString(plugin.getConfig("gui.grave.title", grave) - .getString("gui.grave.title"), grave.getLocationDeath(), grave, plugin); + String title = StringUtil.parseString(plugin.getConfigString("gui.grave.title", grave), grave.getLocationDeath(), grave, plugin); Grave.StorageMode storageMode = plugin.getGraveManager() - .getStorageMode(plugin.getConfig("storage.mode", grave) - .getString("storage.mode")); + .getStorageMode(plugin.getConfigString("storage.mode", grave)); grave.setInventory(plugin.getGraveManager() .createGraveInventory(grave, grave.getLocationDeath(), itemStackList, title, storageMode)); diff --git a/src/main/java/org/avarion/graves/integration/Oraxen.java b/src/main/java/org/avarion/graves/integration/Oraxen.java index d6aa04e..0099a9f 100644 --- a/src/main/java/org/avarion/graves/integration/Oraxen.java +++ b/src/main/java/org/avarion/graves/integration/Oraxen.java @@ -79,9 +79,9 @@ public void unregisterListeners() { } public void createFurniture(Location location, Grave grave) { - if (plugin.getConfig("oraxen.furniture.enabled", grave).getBoolean("oraxen.furniture.enabled")) { + if (plugin.getConfigBool("oraxen.furniture.enabled", grave)) { try { - String name = plugin.getConfig("oraxen.furniture.name", grave).getString("oraxen.furniture.name", ""); + String name = plugin.getConfigString("oraxen.furniture.name", grave, ""); FurnitureMechanic furnitureMechanic = getFurnitureMechanic(name); if (furnitureMechanic != null && location.getWorld() != null) { @@ -120,8 +120,8 @@ public void removeFurniture(Grave grave) { } public void createBlock(Location location, Grave grave) { - if (plugin.getConfig("oraxen.block.enabled", grave).getBoolean("oraxen.block.enabled")) { - String name = plugin.getConfig("oraxen.block.name", grave).getString("oraxen.block.name", ""); + if (plugin.getConfigBool("oraxen.block.enabled", grave)) { + String name = plugin.getConfigString("oraxen.block.name", grave, ""); NoteBlockMechanic noteBlockMechanic = getNoteBlockMechanic(name); if (noteBlockMechanic != null && location.getWorld() != null) { diff --git a/src/main/java/org/avarion/graves/integration/PlayerNPC.java b/src/main/java/org/avarion/graves/integration/PlayerNPC.java index f0da228..d15afbc 100644 --- a/src/main/java/org/avarion/graves/integration/PlayerNPC.java +++ b/src/main/java/org/avarion/graves/integration/PlayerNPC.java @@ -72,7 +72,7 @@ public void createCorpse(Location location, Grave grave) { public void createCorpse(UUID uuid, Location location, Grave grave, boolean createEntityData) { plugin.getServer().getScheduler().runTask(plugin, () -> { - if (plugin.getConfig("playernpc.corpse.enabled", grave).getBoolean("playernpc.corpse.enabled") + if (plugin.getConfigBool("playernpc.corpse.enabled", grave) && grave.getOwnerType() == EntityType.PLAYER) { Player player = plugin.getServer().getPlayer(grave.getOwnerUUID()); Location npcLocation = location.clone(); @@ -84,8 +84,7 @@ public void createCorpse(UUID uuid, Location location, Grave grave, boolean crea NPC.Pose pose = NPC.Pose.SWIMMING; try { - pose = NPC.Pose.valueOf(plugin.getConfig("playernpc.corpse.pose", grave) - .getString("playernpc.corpse.pose")); + pose = NPC.Pose.valueOf(plugin.getConfigString("playernpc.corpse.pose", grave)); } catch (IllegalArgumentException ignored) { } @@ -111,10 +110,9 @@ public void createCorpse(UUID uuid, Location location, Grave grave, boolean crea npc.setAutoShow(true); npc.setCustomData("grave_uuid", grave.getUUID().toString()); - npc.setCollidable(plugin.getConfig("playernpc.corpse.collide", grave) - .getBoolean("playernpc.corpse.collide")); + npc.setCollidable(plugin.getConfigBool("playernpc.corpse.collide", grave)); - if (plugin.getConfig("playernpc.corpse.armor", grave).getBoolean("playernpc.corpse.armor")) { + if (plugin.getConfigBool("playernpc.corpse.armor", grave)) { if (grave.getEquipmentMap().containsKey(EquipmentSlot.HEAD)) { npc.setHelmet(grave.getEquipmentMap().get(EquipmentSlot.HEAD)); } @@ -132,7 +130,7 @@ public void createCorpse(UUID uuid, Location location, Grave grave, boolean crea } } - if (plugin.getConfig("playernpc.corpse.hand", grave).getBoolean("playernpc.corpse.hand")) { + if (plugin.getConfigBool("playernpc.corpse.hand", grave)) { if (grave.getEquipmentMap().containsKey(EquipmentSlot.HAND)) { npc.setItemInRightHand(grave.getEquipmentMap().get(EquipmentSlot.HAND)); } @@ -142,11 +140,9 @@ public void createCorpse(UUID uuid, Location location, Grave grave, boolean crea } } - if (plugin.getConfig("playernpc.corpse.glow.enabled", grave) - .getBoolean("playernpc.corpse.glow.enabled")) { + if (plugin.getConfigBool("playernpc.corpse.glow.enabled", grave)) { try { - npc.setGlowing(true, ChatColor.valueOf(plugin.getConfig("playernpc.corpse.glow.color", grave) - .getString("playernpc.corpse.glow.color"))); + npc.setGlowing(true, ChatColor.valueOf(plugin.getConfigString("playernpc.corpse.glow.color", grave))); } catch (IllegalArgumentException ignored) { npc.setGlowing(true); diff --git a/src/main/java/org/avarion/graves/integration/WorldEdit.java b/src/main/java/org/avarion/graves/integration/WorldEdit.java index 04401bd..19df15f 100644 --- a/src/main/java/org/avarion/graves/integration/WorldEdit.java +++ b/src/main/java/org/avarion/graves/integration/WorldEdit.java @@ -84,14 +84,13 @@ public void loadData() { } public void createSchematic(Location location, Grave grave) { - if (location.getWorld() != null && plugin.getConfig("schematic.enabled", grave) - .getBoolean("schematic.enabled")) { - String schematicName = plugin.getConfig("schematic.name", grave).getString("schematic.name"); - - if (schematicName != null && !schematicName.equals("") && hasSchematic(schematicName)) { - int offsetX = plugin.getConfig("schematic.offset.x", grave).getInt("schematic.offset.x"); - int offsetY = plugin.getConfig("schematic.offset.y", grave).getInt("schematic.offset.y"); - int offsetZ = plugin.getConfig("schematic.offset.z", grave).getInt("schematic.offset.z"); + if (location.getWorld() != null && plugin.getConfigBool("schematic.enabled", grave)) { + String schematicName = plugin.getConfigString("schematic.name", grave); + + if (schematicName != null && !schematicName.isEmpty() && hasSchematic(schematicName)) { + int offsetX = plugin.getConfigInt("schematic.offset.x", grave); + int offsetY = plugin.getConfigInt("schematic.offset.y", grave); + int offsetZ = plugin.getConfigInt("schematic.offset.z", grave); pasteSchematic(location.clone().add(offsetX, offsetY, offsetZ), location.getYaw(), schematicName); diff --git a/src/main/java/org/avarion/graves/listener/BlockBreakListener.java b/src/main/java/org/avarion/graves/listener/BlockBreakListener.java index 4db489b..797256c 100644 --- a/src/main/java/org/avarion/graves/listener/BlockBreakListener.java +++ b/src/main/java/org/avarion/graves/listener/BlockBreakListener.java @@ -25,20 +25,19 @@ public void onBlockBreak(BlockBreakEvent event) { Grave grave = plugin.getBlockManager().getGraveFromBlock(block); if (grave != null) { - if (plugin.getConfig("grave.break", grave).getBoolean("grave.break")) { + if (plugin.getConfigBool("grave.break", grave)) { if (plugin.getEntityManager().canOpenGrave(player, grave)) { GraveBreakEvent graveBreakEvent = new GraveBreakEvent(block, player, grave); - graveBreakEvent.setDropItems(plugin.getConfig("drop.break", grave).getBoolean("drop.break")); + graveBreakEvent.setDropItems(plugin.getConfigBool("drop.break", grave)); plugin.getServer().getPluginManager().callEvent(graveBreakEvent); if (!graveBreakEvent.isCancelled()) { - if (plugin.getConfig("drop.auto-loot.enabled", grave).getBoolean("drop.auto-loot.enabled")) { + if (plugin.getConfigBool("drop.auto-loot.enabled", grave)) { player.sendMessage("here"); plugin.getGraveManager().autoLootGrave(player, block.getLocation(), grave); - if (graveBreakEvent.isDropItems() && plugin.getConfig("drop.auto-loot.break", grave) - .getBoolean("drop.auto-loot.break")) { + if (graveBreakEvent.isDropItems() && plugin.getConfigBool("drop.auto-loot.break", grave)) { plugin.getGraveManager().breakGrave(block.getLocation(), grave); } else { diff --git a/src/main/java/org/avarion/graves/listener/BlockExplodeListener.java b/src/main/java/org/avarion/graves/listener/BlockExplodeListener.java index c1cfc3d..8994d8d 100644 --- a/src/main/java/org/avarion/graves/listener/BlockExplodeListener.java +++ b/src/main/java/org/avarion/graves/listener/BlockExplodeListener.java @@ -34,13 +34,13 @@ public void onBlockExplode(BlockExplodeEvent event) { if ((System.currentTimeMillis() - grave.getTimeCreation()) < 1000) { iterator.remove(); } - else if (plugin.getConfig("explode", grave).getBoolean("explode")) { + else if (plugin.getConfigBool("explode", grave)) { GraveExplodeEvent graveExplodeEvent = new GraveExplodeEvent(location, null, grave); plugin.getServer().getPluginManager().callEvent(graveExplodeEvent); if (!graveExplodeEvent.isCancelled()) { - if (plugin.getConfig("drop.explode", grave).getBoolean("drop.explode")) { + if (plugin.getConfigBool("drop.explode", grave)) { plugin.getGraveManager().breakGrave(location, grave); } else { @@ -52,7 +52,7 @@ else if (plugin.getConfig("explode", grave).getBoolean("explode")) { plugin.getEntityManager() .runCommands("event.command.explode", event.getBlock().getType().name(), location, grave); - if (plugin.getConfig("zombie.explode", grave).getBoolean("zombie.explode")) { + if (plugin.getConfigBool("zombie.explode", grave)) { plugin.getEntityManager().spawnZombie(location, grave); } } diff --git a/src/main/java/org/avarion/graves/listener/EntityDeathListener.java b/src/main/java/org/avarion/graves/listener/EntityDeathListener.java index 7d9c6e8..1b9f6d1 100644 --- a/src/main/java/org/avarion/graves/listener/EntityDeathListener.java +++ b/src/main/java/org/avarion/graves/listener/EntityDeathListener.java @@ -38,7 +38,7 @@ public void onEntityDeath(EntityDeathEvent event) { String entityName = plugin.getEntityManager().getEntityName(livingEntity); Location location = LocationUtil.roundLocation(livingEntity.getLocation()); List permissionList = livingEntity instanceof Player ? plugin.getPermissionList(livingEntity) : null; - List worldList = plugin.getConfig("world", livingEntity, permissionList).getStringList("world"); + List worldList = plugin.getConfigStringList("world", livingEntity, permissionList); List removedItemStackList = new ArrayList<>(); // Removed items @@ -70,8 +70,7 @@ public void onEntityDeath(EntityDeathEvent event) { .split("\\|")) : null; - if (!plugin.getConfig("zombie.drop", zombieGraveEntityType, zombieGravePermissionList) - .getBoolean("zombie.drop")) { + if (!plugin.getConfigBool("zombie.drop", zombieGraveEntityType, zombieGravePermissionList)) { event.getDrops().clear(); event.setDroppedExp(0); } @@ -100,7 +99,7 @@ else if (player.hasPermission("essentials.keepinv")) { } // Enabled - if (!plugin.getConfig("grave.enabled", livingEntity, permissionList).getBoolean("grave.enabled")) { + if (!plugin.getConfigBool("grave.enabled", livingEntity, permissionList)) { if (livingEntity instanceof Player) { plugin.debugMessage("Grave not created for " + entityName + " because they have graves disabled", 2); } @@ -130,8 +129,7 @@ else if (player.hasPermission("essentials.keepinv")) { // Creature spawn reason if (livingEntity instanceof Creature) { - List spawnReasonList = plugin.getConfig("spawn.reason", livingEntity, permissionList) - .getStringList("spawn.reason"); + List spawnReasonList = plugin.getConfigStringList("spawn.reason", livingEntity, permissionList); if (plugin.getEntityManager().hasDataString(livingEntity, "spawnReason") && (!spawnReasonList.contains("ALL") && !spawnReasonList.contains(plugin.getEntityManager() @@ -206,23 +204,19 @@ else if (!plugin.getLocationManager().canBuild(livingEntity, location, permissio // PvP, PvE, Environmental if (livingEntity.getLastDamageCause() != null) { EntityDamageEvent.DamageCause damageCause = livingEntity.getLastDamageCause().getCause(); - List damageCauseList = plugin.getConfig("death.reason", livingEntity, permissionList) - .getStringList("death.reason"); + List damageCauseList = plugin.getConfigStringList("death.reason", livingEntity, permissionList); if (!damageCauseList.contains("ALL") && !damageCauseList.contains(damageCause.name()) && (damageCause == EntityDamageEvent.DamageCause.ENTITY_ATTACK && ((livingEntity.getKiller() != null - && !plugin.getConfig("death.player", livingEntity, permissionList) - .getBoolean("death.player")) + && !plugin.getConfigBool("death.player", livingEntity, permissionList)) || (livingEntity.getKiller() == null - && !plugin.getConfig("death.entity", livingEntity, permissionList) - .getBoolean("death.entity"))) + && !plugin.getConfigBool("death.entity", livingEntity, permissionList))) || (damageCause != EntityDamageEvent.DamageCause.ENTITY_ATTACK - && !plugin.getConfig("death.environmental", livingEntity, permissionList) - .getBoolean("death.environmental")))) { + && !plugin.getConfigBool("death.environmental", livingEntity, permissionList)))) { plugin.debugMessage("Grave not created for " + entityName + " because they died to an invalid damage cause", 2); @@ -233,7 +227,7 @@ else if (!plugin.getLocationManager().canBuild(livingEntity, location, permissio // Max if (plugin.getGraveManager().getGraveList(livingEntity).size() - >= plugin.getConfig("grave.max", livingEntity, permissionList).getInt("grave.max")) { + >= plugin.getConfigInt("grave.max", livingEntity, permissionList)) { plugin.getEntityManager() .sendMessage("message.max", livingEntity, livingEntity.getLocation(), permissionList); plugin.debugMessage("Grave not created for " + entityName + " because they reached maximum graves", 2); @@ -242,8 +236,8 @@ else if (!plugin.getLocationManager().canBuild(livingEntity, location, permissio } // Token - if (plugin.getConfig("token.enabled", livingEntity, permissionList).getBoolean("token.enabled")) { - String name = plugin.getConfig("token.name", livingEntity).getString("token.name", "basic"); + if (plugin.getConfigBool("token.enabled", livingEntity, permissionList)) { + String name = plugin.getConfigString("token.name", livingEntity, "basic"); if (plugin.getConfig().isConfigurationSection("settings.token." + name)) { ItemStack itemStack = plugin.getRecipeManager().getGraveTokenFromPlayer(name, event.getDrops()); @@ -277,15 +271,13 @@ else if (!plugin.getLocationManager().canBuild(livingEntity, location, permissio if (itemStack != null) { // Ignore compass if (plugin.getEntityManager().getGraveUUIDFromItemStack(itemStack) != null) { - if (plugin.getConfig("compass.destroy", livingEntity, permissionList) - .getBoolean("compass.destroy")) { + if (plugin.getConfigBool("compass.destroy", livingEntity, permissionList)) { dropItemStackListIterator.remove(); event.getDrops().remove(itemStack); continue; } - else if (plugin.getConfig("compass.ignore", livingEntity, permissionList) - .getBoolean("compass.ignore")) { + else if (plugin.getConfigBool("compass.ignore", livingEntity, permissionList)) { continue; } } diff --git a/src/main/java/org/avarion/graves/listener/EntityExplodeListener.java b/src/main/java/org/avarion/graves/listener/EntityExplodeListener.java index 8dc06c7..b4466d7 100644 --- a/src/main/java/org/avarion/graves/listener/EntityExplodeListener.java +++ b/src/main/java/org/avarion/graves/listener/EntityExplodeListener.java @@ -34,13 +34,13 @@ public void onEntityExplode(EntityExplodeEvent event) { if ((System.currentTimeMillis() - grave.getTimeCreation()) < 1000) { iterator.remove(); } - else if (plugin.getConfig("grave.explode", grave).getBoolean("grave.explode")) { + else if (plugin.getConfigBool("grave.explode", grave)) { GraveExplodeEvent graveExplodeEvent = new GraveExplodeEvent(location, event.getEntity(), grave); plugin.getServer().getPluginManager().callEvent(graveExplodeEvent); if (!graveExplodeEvent.isCancelled()) { - if (plugin.getConfig("drop.explode", grave).getBoolean("drop.explode")) { + if (plugin.getConfigBool("drop.explode", grave)) { plugin.getGraveManager().breakGrave(location, grave); } else { @@ -52,7 +52,7 @@ else if (plugin.getConfig("grave.explode", grave).getBoolean("grave.explode")) { plugin.getEntityManager() .runCommands("event.command.explode", event.getEntity(), location, grave); - if (plugin.getConfig("zombie.explode", grave).getBoolean("zombie.explode")) { + if (plugin.getConfigBool("zombie.explode", grave)) { plugin.getEntityManager().spawnZombie(location, grave); } } diff --git a/src/main/java/org/avarion/graves/listener/InventoryClickListener.java b/src/main/java/org/avarion/graves/listener/InventoryClickListener.java index d462981..7a64d65 100644 --- a/src/main/java/org/avarion/graves/listener/InventoryClickListener.java +++ b/src/main/java/org/avarion/graves/listener/InventoryClickListener.java @@ -42,8 +42,7 @@ else if (event.getWhoClicked() instanceof Player) { if (grave != null) { plugin.getEntityManager() - .runFunction(player, plugin.getConfig("gui.menu.list.function", grave) - .getString("gui.menu.list.function", "menu"), grave); + .runFunction(player, plugin.getConfigString("gui.menu.list.function", grave, "menu"), grave); plugin.getGUIManager().setGraveListItems(graveList.getInventory(), graveList.getUUID()); } @@ -55,12 +54,9 @@ else if (inventoryHolder instanceof GraveMenu) { if (grave != null) { plugin.getEntityManager() - .runFunction(player, plugin.getConfig("gui.menu.grave.slot." - + event.getSlot() - + ".function", grave) - .getString("gui.menu.grave.slot." - + event.getSlot() - + ".function", "none"), grave); + .runFunction(player, plugin.getConfigString("gui.menu.grave.slot." + + event.getSlot() + + ".function", grave, "none"), grave); plugin.getGUIManager().setGraveMenuItems(graveMenu.getInventory(), grave); } diff --git a/src/main/java/org/avarion/graves/listener/PlayerDeathListener.java b/src/main/java/org/avarion/graves/listener/PlayerDeathListener.java index 353c169..95cc1a1 100644 --- a/src/main/java/org/avarion/graves/listener/PlayerDeathListener.java +++ b/src/main/java/org/avarion/graves/listener/PlayerDeathListener.java @@ -29,7 +29,7 @@ public void onPlayerDeathEvent(PlayerDeathEvent event) { if (itemStack != null) { if (plugin.getEntityManager().getGraveUUIDFromItemStack(itemStack) != null - && plugin.getConfig("compass.destroy", event.getEntity()).getBoolean("compass.destroy")) { + && plugin.getConfigBool("compass.destroy", event.getEntity())) { iterator.remove(); } } diff --git a/src/main/java/org/avarion/graves/listener/PlayerMoveListener.java b/src/main/java/org/avarion/graves/listener/PlayerMoveListener.java index f83e8b5..bf75bab 100644 --- a/src/main/java/org/avarion/graves/listener/PlayerMoveListener.java +++ b/src/main/java/org/avarion/graves/listener/PlayerMoveListener.java @@ -60,8 +60,7 @@ else if (chunkData.getBlockDataMap().containsKey(location.clone().subtract(0, 1, .containsKey(blockData.getGraveUUID())) { Grave grave = plugin.getCacheManager().getGraveMap().get(blockData.getGraveUUID()); - if (grave != null - && plugin.getConfig("block.walk-over", grave).getBoolean("block.walk-over") + if (grave != null && plugin.getConfigBool("block.walk-over", grave) && plugin.getEntityManager().canOpenGrave(player, grave)) { plugin.getGraveManager().cleanupCompasses(player, grave); plugin.getGraveManager().autoLootGrave(event.getPlayer(), location, grave); diff --git a/src/main/java/org/avarion/graves/listener/PlayerRespawnListener.java b/src/main/java/org/avarion/graves/listener/PlayerRespawnListener.java index b84a9f5..4bcd4d7 100644 --- a/src/main/java/org/avarion/graves/listener/PlayerRespawnListener.java +++ b/src/main/java/org/avarion/graves/listener/PlayerRespawnListener.java @@ -31,13 +31,11 @@ public void onPlayerRespawn(PlayerRespawnEvent event) { plugin.getServer().getScheduler().runTaskLater(plugin, () -> { plugin.getEntityManager() - .runFunction(player, plugin.getConfig("respawn.function", player, permissionList) - .getString("respawn.function", "none"), grave); + .runFunction(player, plugin.getConfigString("respawn.function", player, permissionList, "none"), grave); }, 1L); - if (plugin.getConfig("respawn.compass", player, permissionList).getBoolean("respawn.compass") - && grave.getLivedTime() - <= plugin.getConfig("respawn.compass-time", player, permissionList).getInt("respawn.compass-time") + if (plugin.getConfigBool("respawn.compass", player, permissionList) + && grave.getLivedTime() <= plugin.getConfigInt("respawn.compass-time", player, permissionList) * 1000L) { List locationList = plugin.getGraveManager() .getGraveLocationList(event.getRespawnLocation(), grave); diff --git a/src/main/java/org/avarion/graves/manager/BlockManager.java b/src/main/java/org/avarion/graves/manager/BlockManager.java index 7fd21ec..10f08cc 100644 --- a/src/main/java/org/avarion/graves/manager/BlockManager.java +++ b/src/main/java/org/avarion/graves/manager/BlockManager.java @@ -47,8 +47,8 @@ public void createBlock(Location location, Grave grave) { if (location.getWorld() != null) { Material material; - if (plugin.getConfig("block.enabled", grave).getBoolean("block.enabled")) { - String materialString = plugin.getConfig("block.material", grave).getString("block.material", "CHEST"); + if (plugin.getConfigBool("block.enabled", grave)) { + String materialString = plugin.getConfigString("block.material", grave, "CHEST"); material = Material.matchMaterial(materialString); } @@ -56,9 +56,9 @@ public void createBlock(Location location, Grave grave) { material = null; } - int offsetX = plugin.getConfig("block.offset.x", grave).getInt("block.offset.x"); - int offsetY = plugin.getConfig("block.offset.y", grave).getInt("block.offset.y"); - int offsetZ = plugin.getConfig("block.offset.z", grave).getInt("block.offset.z"); + int offsetX = plugin.getConfigInt("block.offset.x", grave); + int offsetY = plugin.getConfigInt("block.offset.y", grave); + int offsetZ = plugin.getConfigInt("block.offset.z", grave); location.add(offsetX, offsetY, offsetZ); diff --git a/src/main/java/org/avarion/graves/manager/DataManager.java b/src/main/java/org/avarion/graves/manager/DataManager.java index ac32894..0baaaaa 100644 --- a/src/main/java/org/avarion/graves/manager/DataManager.java +++ b/src/main/java/org/avarion/graves/manager/DataManager.java @@ -692,8 +692,7 @@ public Grave resultSetToGrave(ResultSet resultSet) { grave.setPermissionList(resultSet.getString("permissions") != null ? new ArrayList<>(Arrays.asList(resultSet.getString("permissions").split("\\|"))) : null); - grave.setInventory(InventoryUtil.stringToInventory(grave, resultSet.getString("inventory"), StringUtil.parseString(plugin.getConfig("gui.grave.title", grave.getOwnerType(), grave.getPermissionList()) - .getString("gui.grave.title"), grave.getLocationDeath(), grave, plugin), plugin)); + grave.setInventory(InventoryUtil.stringToInventory(grave, resultSet.getString("inventory"), StringUtil.parseString(plugin.getConfigString("gui.grave.title", grave), grave.getLocationDeath(), grave, plugin), plugin)); if (resultSet.getString("equipment") != null) { Map equipmentMap = (Map) Base64Util.base64ToObject(resultSet.getString("equipment")); diff --git a/src/main/java/org/avarion/graves/manager/EntityManager.java b/src/main/java/org/avarion/graves/manager/EntityManager.java index 09b95c7..6d00aec 100644 --- a/src/main/java/org/avarion/graves/manager/EntityManager.java +++ b/src/main/java/org/avarion/graves/manager/EntityManager.java @@ -42,7 +42,7 @@ public ItemStack createGraveCompass(Player player, Location location, Grave grav if (true) { Material material = Material.COMPASS; - if (plugin.getConfig("compass.recovery", grave).getBoolean("compass.recovery")) { + if (plugin.getConfigBool("compass.recovery", grave)) { try { material = Material.valueOf("RECOVERY_COMPASS"); } @@ -70,24 +70,24 @@ else if (itemStack.getType().name().equals("RECOVERY_COMPASS")) { } List loreList = new ArrayList<>(); - int customModelData = plugin.getConfig("compass.model-data", grave).getInt("compass.model-data", -1); + int customModelData = plugin.getConfigInt("compass.model-data", grave, -1); if (customModelData > -1) { itemMeta.setCustomModelData(customModelData); } - if (plugin.getConfig("compass.glow", grave).getBoolean("compass.glow")) { + if (plugin.getConfigBool("compass.glow", grave)) { itemMeta.addEnchant(Enchantment.DURABILITY, 1, true); itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); } - itemMeta.setDisplayName(ChatColor.WHITE + StringUtil.parseString(plugin.getConfig("compass.name", grave) - .getString("compass.name"), grave, plugin)); + itemMeta.setDisplayName(ChatColor.WHITE + + StringUtil.parseString(plugin.getConfigString("compass.name", grave), grave, plugin)); itemMeta.getPersistentDataContainer() .set(new NamespacedKey(plugin, "graveUUID"), PersistentDataType.STRING, grave.getUUID() .toString()); - for (String string : plugin.getConfig("compass.lore", grave).getStringList("compass.lore")) { + for (String string : plugin.getConfigStringList("compass.lore", grave)) { loreList.add(ChatColor.GRAY + StringUtil.parseString(string, location, grave, plugin)); } @@ -194,11 +194,10 @@ public void teleportEntity(Entity entity, Location location, Grave grave) { } public double getTeleportCost(Location location1, Location location2, Grave grave) { - double cost = plugin.getConfig("teleport.cost", grave).getDouble("teleport.cost"); + double cost = plugin.getConfigDbl("teleport.cost", grave); if (plugin.getConfig("teleport.cost", grave).isString("teleport.cost")) { - String costString = StringUtil.parseString(plugin.getConfig("teleport.cost", grave) - .getString("teleport.cost"), location2, grave, plugin); + String costString = StringUtil.parseString(plugin.getConfigString("teleport.cost", grave), location2, grave, plugin); try { cost = Double.parseDouble(costString); @@ -208,10 +207,9 @@ public double getTeleportCost(Location location1, Location location2, Grave grav } } - double costDifferentWorld = plugin.getConfig("teleport.cost-different-world", grave) - .getDouble("teleport.cost-different-world"); + double costDifferentWorld = plugin.getConfigDbl("teleport.cost-different-world", grave); - if (plugin.getConfig("teleport.cost-distance-increase", grave).getBoolean("teleport.cost-distance-increase")) { + if (plugin.getConfigBool("teleport.cost-distance-increase", grave)) { double distance = Math.sqrt(NumberConversions.square(location1.getBlockX() - location2.getBlockX()) + NumberConversions.square(location1.getBlockZ() - location2.getBlockZ())); cost = Math.round(cost * (distance / 16)); @@ -252,9 +250,9 @@ public void playWorldSound(String string, Location location, Grave grave) { public void playWorldSound(String string, Location location, EntityType entityType, List permissionList, float volume, float pitch) { if (location.getWorld() != null) { - string = plugin.getConfig(string, entityType, permissionList).getString(string); + string = plugin.getConfigString(string, entityType, permissionList); - if (string != null && !string.equals("")) { + if (string != null && !string.isEmpty()) { try { location.getWorld().playSound(location, Sound.valueOf(string.toUpperCase()), volume, pitch); } @@ -284,9 +282,9 @@ public void playPlayerSound(String string, Entity entity, Location location, Lis public void playPlayerSound(String string, Entity entity, Location location, List permissionList, float volume, float pitch) { if (entity instanceof Player) { Player player = (Player) entity; - string = plugin.getConfig(string, entity, permissionList).getString(string); + string = plugin.getConfigString(string, entity, permissionList); - if (string != null && !string.equals("")) { + if (string != null && !string.isEmpty()) { try { player.playSound(location, Sound.valueOf(string.toUpperCase()), volume, pitch); } @@ -334,20 +332,19 @@ private void sendMessage(String string, Entity entity, String name, Location loc Player player = (Player) entity; if (grave != null) { - string = plugin.getConfig(string, grave).getString(string); + string = plugin.getConfigString(string, grave); } else { - string = plugin.getConfig(string, entity.getType(), permissionList).getString(string); + string = plugin.getConfigString(string, entity.getType(), permissionList); } - String prefix = plugin.getConfig("message.prefix", entity.getType(), permissionList) - .getString("message.prefix"); + String prefix = plugin.getConfigString("message.prefix", entity.getType(), permissionList); - if (prefix != null && !prefix.equals("")) { + if (prefix != null && !prefix.isEmpty()) { string = prefix + string; } - if (string != null && !string.equals("")) { + if (string != null && !string.isEmpty()) { player.sendMessage(StringUtil.parseString(string, entity, name, location, grave, plugin)); } } @@ -362,15 +359,15 @@ public void runCommands(String string, String name, Location location, Grave gra } private void runCommands(String string, Entity entity, String name, Location location, Grave grave) { - for (String command : plugin.getConfig(string, grave).getStringList(string)) { - if (command != null && !command.equals("")) { + for (String command : plugin.getConfigStringList(string, grave)) { + if (command != null && !command.isEmpty()) { runConsoleCommand(StringUtil.parseString(command, entity, name, location, grave, plugin)); } } } private void runConsoleCommand(String string) { - if (string != null && !string.equals("")) { + if (string != null && !string.isEmpty()) { ServerCommandEvent serverCommandEvent = new ServerCommandEvent(plugin.getServer() .getConsoleSender(), string); @@ -404,7 +401,7 @@ public boolean runFunction(Entity entity, String function, Grave grave) { } case "teleport": case "teleportation": { - if (plugin.getConfig("teleport.enabled", grave).getBoolean("teleport.enabled") + if (plugin.getConfigBool("teleport.enabled", grave) && (EntityUtil.hasPermission(entity, "graves.teleport") || EntityUtil.hasPermission(entity, "graves.bypass"))) { plugin.getEntityManager() @@ -446,7 +443,7 @@ public boolean runFunction(Entity entity, String function, Grave grave) { case "open": case "loot": case "virtual": { - double distance = plugin.getConfig("virtual.distance", grave).getDouble("virtual.distance"); + double distance = plugin.getConfigDbl("virtual.distance", grave); if (distance < 0) { plugin.getGraveManager().openGrave(entity, entity.getLocation(), grave); @@ -481,30 +478,28 @@ public boolean canOpenGrave(Player player, Grave grave) { return true; } else if (grave.getProtection() && grave.getOwnerUUID() != null) { - if (grave.getOwnerUUID().equals(player.getUniqueId()) && plugin.getConfig("protection.open.owner", grave) - .getBoolean("protection.open.owner")) { + if (grave.getOwnerUUID().equals(player.getUniqueId()) + && plugin.getConfigBool("protection.open.owner", grave)) { return true; } else { if (grave.getKillerUUID() != null) { if (grave.getKillerUUID().equals(player.getUniqueId()) - && plugin.getConfig("protection.open.killer", grave).getBoolean("protection.open.killer")) { + && plugin.getConfigBool("protection.open.killer", grave)) { return true; } else { return !grave.getOwnerUUID().equals(player.getUniqueId()) && !grave.getKillerUUID() .equals(player.getUniqueId()) - && plugin.getConfig("protection.open.other", grave).getBoolean("protection.open.other"); + && plugin.getConfigBool("protection.open.other", grave); } } else { return (grave.getOwnerUUID().equals(player.getUniqueId()) - && plugin.getConfig("protection.open.missing.owner", grave) - .getBoolean("protection.open.missing.owner")) || (!grave.getOwnerUUID() + && plugin.getConfigBool("protection.open.missing.owner", grave)) || (!grave.getOwnerUUID() .equals(player.getUniqueId()) - && plugin.getConfig("protection.open.missing.other", grave) - .getBoolean("protection.open.missing.other")); + && plugin.getConfigBool("protection.open.missing.other", grave)); } } } @@ -514,9 +509,9 @@ else if (grave.getProtection() && grave.getOwnerUUID() != null) { } public void spawnZombie(Location location, Entity entity, LivingEntity targetEntity, Grave grave) { - if ((plugin.getConfig("zombie.spawn-owner", grave).getBoolean("zombie.spawn-owner") && grave.getOwnerUUID() + if ((plugin.getConfigBool("zombie.spawn-owner", grave) && grave.getOwnerUUID() .equals(entity.getUniqueId()) - || plugin.getConfig("zombie.spawn-other", grave).getBoolean("zombie.spawn-other") && !grave.getOwnerUUID() + || plugin.getConfigBool("zombie.spawn-other", grave) && !grave.getOwnerUUID() .equals(entity.getUniqueId()))) { spawnZombie(location, targetEntity, grave); } @@ -529,7 +524,7 @@ public void spawnZombie(Location location, Grave grave) { @SuppressWarnings("deprecation") private void spawnZombie(Location location, LivingEntity targetEntity, Grave grave) { if (location != null && location.getWorld() != null && grave.getOwnerType() == EntityType.PLAYER) { - String zombieType = plugin.getConfig("zombie.type", grave).getString("zombie.type", "ZOMBIE").toUpperCase(); + String zombieType = plugin.getConfigString("zombie.type", grave, "ZOMBIE").toUpperCase(); EntityType entityType = EntityType.ZOMBIE; try { @@ -553,7 +548,7 @@ private void spawnZombie(Location location, LivingEntity targetEntity, Grave gra LivingEntity livingEntity = (LivingEntity) entity; if (livingEntity.getEquipment() != null) { - if (plugin.getConfig("zombie.owner-head", grave).getBoolean("zombie.owner-head")) { + if (plugin.getConfigBool("zombie.owner-head", grave)) { livingEntity.getEquipment() .setHelmet(plugin.getCompatibility().getSkullItemStack(grave, plugin)); } @@ -563,21 +558,20 @@ private void spawnZombie(Location location, LivingEntity targetEntity, Grave gra livingEntity.getEquipment().setBoots(null); } - double zombieHealth = plugin.getConfig("zombie.health", grave).getDouble("zombie.health"); + double zombieHealth = plugin.getConfigDbl("zombie.health", grave); if (zombieHealth >= 0.5) { livingEntity.setMaxHealth(zombieHealth); livingEntity.setHealth(zombieHealth); } - if (!plugin.getConfig("zombie.pickup", grave).getBoolean("zombie.pickup")) { + if (!plugin.getConfigBool("zombie.pickup", grave)) { livingEntity.setCanPickupItems(false); } - String zombieName = StringUtil.parseString(plugin.getConfig("zombie.name", grave) - .getString("zombie.name"), location, grave, plugin); + String zombieName = StringUtil.parseString(plugin.getConfigString("zombie.name", grave), location, grave, plugin); - if (!zombieName.equals("")) { + if (!zombieName.isEmpty()) { livingEntity.setCustomName(zombieName); } @@ -611,25 +605,23 @@ private void spawnZombie(Location location, LivingEntity targetEntity, Grave gra } public void createArmorStand(Location location, Grave grave) { - if (plugin.getConfig("armor-stand.enabled", grave).getBoolean("armor-stand.enabled")) { - double offsetX = plugin.getConfig("armor-stand.offset.x", grave).getDouble("armor-stand.offset.x"); - double offsetY = plugin.getConfig("armor-stand.offset.y", grave).getDouble("armor-stand.offset.y"); - double offsetZ = plugin.getConfig("armor-stand.offset.z", grave).getDouble("armor-stand.offset.z"); - boolean marker = plugin.getConfig("armor-stand.marker", grave).getBoolean("armor-stand.marker"); + if (plugin.getConfigBool("armor-stand.enabled", grave)) { + double offsetX = plugin.getConfigDbl("armor-stand.offset.x", grave); + double offsetY = plugin.getConfigDbl("armor-stand.offset.y", grave); + double offsetZ = plugin.getConfigDbl("armor-stand.offset.z", grave); + boolean marker = plugin.getConfigBool("armor-stand.marker", grave); location = LocationUtil.roundLocation(location).add(offsetX + 0.5, offsetY, offsetZ + 0.5); location.setYaw(grave.getYaw()); location.setPitch(grave.getPitch()); if (location.getWorld() != null) { - Material material = Material.matchMaterial(plugin.getConfig("armor-stand.material", grave) - .getString("armor-stand.material", "AIR")); + Material material = Material.matchMaterial(plugin.getConfigString("armor-stand.material", grave, "AIR")); if (material != null && !MaterialUtil.isAir(material)) { ItemStack itemStack = new ItemStack(material, 1); ItemMeta itemMeta = itemStack.getItemMeta(); - int customModelData = plugin.getConfig("armor-stand.model-data", grave) - .getInt("armor-stand.model-data", -1); + int customModelData = plugin.getConfigInt("armor-stand.model-data", grave, -1); if (itemMeta != null) { if (customModelData > -1) { @@ -663,15 +655,13 @@ public void createArmorStand(Location location, Grave grave) { armorStand.setVisible(false); armorStand.setGravity(false); armorStand.setCustomNameVisible(false); - armorStand.setSmall(plugin.getConfig("armor-stand.small", grave) - .getBoolean("armor-stand.small")); + armorStand.setSmall(plugin.getConfigBool("armor-stand.small", grave)); if (armorStand.getEquipment() != null) { EquipmentSlot equipmentSlot = EquipmentSlot.HEAD; try { - equipmentSlot = EquipmentSlot.valueOf(plugin.getConfig("armor-stand.slot", grave) - .getString("armor-stand.slot", "HEAD")); + equipmentSlot = EquipmentSlot.valueOf(plugin.getConfigString("armor-stand.slot", grave, "HEAD")); } catch (IllegalArgumentException ignored) { } @@ -685,24 +675,22 @@ public void createArmorStand(Location location, Grave grave) { } public void createItemFrame(Location location, Grave grave) { - if (plugin.getConfig("item-frame.enabled", grave).getBoolean("item-frame.enabled")) { - double offsetX = plugin.getConfig("item-frame.offset.x", grave).getDouble("item-frame.offset.x"); - double offsetY = plugin.getConfig("item-frame.offset.y", grave).getDouble("item-frame.offset.y"); - double offsetZ = plugin.getConfig("item-frame.offset.z", grave).getDouble("item-frame.offset.z"); + if (plugin.getConfigBool("item-frame.enabled", grave)) { + double offsetX = plugin.getConfigDbl("item-frame.offset.x", grave); + double offsetY = plugin.getConfigDbl("item-frame.offset.y", grave); + double offsetZ = plugin.getConfigDbl("item-frame.offset.z", grave); location = LocationUtil.roundLocation(location).add(offsetX + 0.5, offsetY, offsetZ + 0.5); location.setYaw(grave.getYaw()); location.setPitch(grave.getPitch()); if (location.getWorld() != null) { - Material material = Material.matchMaterial(plugin.getConfig("item-frame.material", grave) - .getString("item-frame.material", "AIR")); + Material material = Material.matchMaterial(plugin.getConfigString("item-frame.material", grave, "AIR")); if (material != null && !MaterialUtil.isAir(material)) { ItemStack itemStack = new ItemStack(material, 1); ItemMeta itemMeta = itemStack.getItemMeta(); - int customModelData = plugin.getConfig("item-frame.model-data", grave) - .getInt("item-frame.model-data", -1); + int customModelData = plugin.getConfigInt("item-frame.model-data", grave, -1); if (itemMeta != null) { if (customModelData > -1) { diff --git a/src/main/java/org/avarion/graves/manager/GUIManager.java b/src/main/java/org/avarion/graves/manager/GUIManager.java index 2cec170..e449820 100644 --- a/src/main/java/org/avarion/graves/manager/GUIManager.java +++ b/src/main/java/org/avarion/graves/manager/GUIManager.java @@ -67,8 +67,7 @@ public void openGraveList(Entity entity, UUID uuid, boolean sound) { if (!playerGraveList.isEmpty()) { GraveList graveList = new GraveList(uuid, playerGraveList); Inventory inventory = plugin.getServer() - .createInventory(graveList, InventoryUtil.getInventorySize(playerGraveList.size()), StringUtil.parseString(plugin.getConfig("gui.menu.list.title", player, permissionList) - .getString("gui.menu.list.title", "Graves Main Menu"), player, plugin)); + .createInventory(graveList, InventoryUtil.getInventorySize(playerGraveList.size()), StringUtil.parseString(plugin.getConfigString("gui.menu.list.title", player, permissionList, "Graves Main Menu"), player, plugin)); setGraveListItems(inventory, playerGraveList); graveList.setInventory(inventory); @@ -107,8 +106,7 @@ public void openGraveMenu(Entity entity, Grave grave, boolean sound) { if (entity instanceof Player) { Player player = (Player) entity; GraveMenu graveMenu = new GraveMenu(grave); - String title = StringUtil.parseString(plugin.getConfig("gui.menu.grave.title", player, grave.getPermissionList()) - .getString("gui.menu.grave.title", "Grave"), player, plugin); + String title = StringUtil.parseString(plugin.getConfigString("gui.menu.grave.title", player, grave.getPermissionList(), "Grave"), player, plugin); Inventory inventory = plugin.getServer() .createInventory(graveMenu, InventoryUtil.getInventorySize(5), title); diff --git a/src/main/java/org/avarion/graves/manager/GraveManager.java b/src/main/java/org/avarion/graves/manager/GraveManager.java index 5a65c06..76fd139 100644 --- a/src/main/java/org/avarion/graves/manager/GraveManager.java +++ b/src/main/java/org/avarion/graves/manager/GraveManager.java @@ -50,8 +50,7 @@ private void startGraveTimer() { plugin.getServer().getPluginManager().callEvent(graveTimeoutEvent); if (!graveTimeoutEvent.isCancelled()) { - if (graveTimeoutEvent.getLocation() != null && plugin.getConfig("drop.timeout", grave) - .getBoolean("drop.timeout")) { + if (graveTimeoutEvent.getLocation() != null && plugin.getConfigBool("drop.timeout", grave)) { dropGraveItems(graveTimeoutEvent.getLocation(), grave); dropGraveExperience(graveTimeoutEvent.getLocation(), grave); } @@ -91,8 +90,7 @@ private void startGraveTimer() { Grave grave = plugin.getCacheManager().getGraveMap().get(hologramData.getUUIDGrave()); if (grave != null) { - List lineList = plugin.getConfig("hologram.line", grave) - .getStringList("hologram.line"); + List lineList = plugin.getConfigStringList("hologram.line", grave); Collections.reverse(lineList); @@ -169,31 +167,30 @@ public void toggleGraveProtection(Grave grave) { } public void graveParticle(Location location, Grave grave) { - if (location.getWorld() != null && plugin.getConfig("particle.enabled", grave).getBoolean("particle.enabled")) { + if (location.getWorld() != null && plugin.getConfigBool("particle.enabled", grave)) { Particle particle = Particle.REDSTONE; - String particleType = plugin.getConfig("particle.type", grave).getString("particle.type"); + String particleType = plugin.getConfigString("particle.type", grave); - if (particleType != null && !particleType.equals("")) { + if (particleType != null && !particleType.isEmpty()) { try { - particle = Particle.valueOf(plugin.getConfig("particle.type", grave).getString("particle.type")); + particle = Particle.valueOf(plugin.getConfigString("particle.type", grave)); } catch (IllegalArgumentException ignored) { plugin.debugMessage(particleType + " is not a Particle ENUM", 1); } } - int count = plugin.getConfig("particle.count", grave).getInt("particle.count"); - double offsetX = plugin.getConfig("particle.offset.x", grave).getDouble("particle.offset.x"); - double offsetY = plugin.getConfig("particle.offset.y", grave).getDouble("particle.offset.y"); - double offsetZ = plugin.getConfig("particle.offset.z", grave).getDouble("particle.offset.z"); + int count = plugin.getConfigInt("particle.count", grave); + double offsetX = plugin.getConfigDbl("particle.offset.x", grave); + double offsetY = plugin.getConfigDbl("particle.offset.y", grave); + double offsetZ = plugin.getConfigDbl("particle.offset.z", grave); location = location.clone().add(offsetX + 0.5, offsetY + 0.5, offsetZ + 0.5); if (location.getWorld() != null) { switch (particle.name()) { case "REDSTONE": - int size = plugin.getConfig("particle.dust-size", grave).getInt("particle.dust-size"); - Color color = ColorUtil.getColor(plugin.getConfig("particle.dust-color", grave) - .getString("particle.dust-color", "RED")); + int size = plugin.getConfigInt("particle.dust-size", grave); + Color color = ColorUtil.getColor(plugin.getConfigString("particle.dust-color", grave, "RED")); if (color == null) { color = Color.RED; @@ -356,10 +353,8 @@ public void placeGrave(Location location, Grave grave) { public Inventory getGraveInventory(Grave grave, LivingEntity livingEntity, List graveItemStackList, List removedItemStackList, List permissionList) { List filterGraveItemStackList = filterGraveItemStackList(graveItemStackList, removedItemStackList, livingEntity, permissionList); - String title = StringUtil.parseString(plugin.getConfig("gui.grave.title", grave) - .getString("gui.grave.title"), livingEntity, grave.getLocationDeath(), grave, plugin); - Grave.StorageMode storageMode = getStorageMode(plugin.getConfig("storage.mode", grave) - .getString("storage.mode")); + String title = StringUtil.parseString(plugin.getConfigString("gui.grave.title", grave), livingEntity, grave.getLocationDeath(), grave, plugin); + Grave.StorageMode storageMode = getStorageMode(plugin.getConfigString("storage.mode", grave)); return plugin.getGraveManager() .createGraveInventory(grave, grave.getLocationDeath(), filterGraveItemStackList, title, storageMode); @@ -452,7 +447,7 @@ public List filterGraveItemStackList(List itemStackList, L itemStackList = new ArrayList<>(itemStackList); if (livingEntity instanceof Player - && getStorageMode(plugin.getConfig("storage.mode", livingEntity, permissionList).getString("storage.mode")) + && getStorageMode(plugin.getConfigString("storage.mode", livingEntity, permissionList)) == Grave.StorageMode.EXACT) { Player player = (Player) livingEntity; List playerInventoryContentList = Arrays.asList(player.getInventory().getContents()); @@ -708,8 +703,8 @@ public void autoLootGrave(Entity entity, Location location, Grave grave) { } public String getDamageReason(EntityDamageEvent.DamageCause damageCause, Grave grave) { - return plugin.getConfig("message.death-reason." + damageCause.name(), grave) - .getString("message.death-reason." + damageCause.name(), StringUtil.format(damageCause.name())); + return plugin.getConfigString("message.death-reason." + + damageCause.name(), grave, StringUtil.format(damageCause.name())); } public void playEffect(String string, Location location) { @@ -726,7 +721,7 @@ public void playEffect(String string, Location location, int data, Grave grave) string = plugin.getConfig(string, grave).getString(string); } - if (string != null && !string.equals("")) { + if (string != null && !string.isEmpty()) { try { location.getWorld().playEffect(location, Effect.valueOf(string.toUpperCase()), data); } @@ -742,8 +737,7 @@ public boolean shouldIgnoreItemStack(ItemStack itemStack, Entity entity, Grave g } public boolean shouldIgnoreItemStack(ItemStack itemStack, Entity entity, List permissionList) { - if (plugin.getConfig("ignore.item.material", entity, permissionList) - .getStringList("ignore.item.material") + if (plugin.getConfigStringList("ignore.item.material", entity, permissionList) .contains(itemStack.getType().name())) { return true; } @@ -753,17 +747,15 @@ public boolean shouldIgnoreItemStack(ItemStack itemStack, Entity entity, List permissionList) { - List stringList = plugin.getConfig("ignore.block.material", entity, permissionList) - .getStringList("ignore.block.material"); + List stringList = plugin.getConfigStringList("ignore.block.material", entity, permissionList); for (String string : stringList) { - if (!string.equals("") && string.equals(block.getType().name())) { + if (!string.isEmpty() && string.equals(block.getType().name())) { return true; } } diff --git a/src/main/java/org/avarion/graves/manager/HologramManager.java b/src/main/java/org/avarion/graves/manager/HologramManager.java index b0ddfbf..d9c9c0f 100644 --- a/src/main/java/org/avarion/graves/manager/HologramManager.java +++ b/src/main/java/org/avarion/graves/manager/HologramManager.java @@ -23,15 +23,15 @@ public HologramManager(Graves plugin) { } public void createHologram(Location location, Grave grave) { - if (plugin.getConfig("hologram.enabled", grave).getBoolean("hologram.enabled")) { - double offsetX = plugin.getConfig("hologram.offset.x", grave).getDouble("hologram.offset.x"); - double offsetY = plugin.getConfig("hologram.offset.y", grave).getDouble("hologram.offset.y"); - double offsetZ = plugin.getConfig("hologram.offset.z", grave).getDouble("hologram.offset.z"); - boolean marker = plugin.getConfig("hologram.marker", grave).getBoolean("hologram.marker"); + if (plugin.getConfigBool("hologram.enabled", grave)) { + double offsetX = plugin.getConfigDbl("hologram.offset.x", grave); + double offsetY = plugin.getConfigDbl("hologram.offset.y", grave); + double offsetZ = plugin.getConfigDbl("hologram.offset.z", grave); + boolean marker = plugin.getConfigBool("hologram.marker", grave); location = LocationUtil.roundLocation(location) .add(offsetX + 0.5, offsetY + (marker ? 0.49 : -0.49), offsetZ + 0.5); - List lineList = plugin.getConfig("hologram.line", grave).getStringList("hologram.line"); - double lineHeight = plugin.getConfig("hologram.height-line", grave).getDouble("hologram.height-line"); + List lineList = plugin.getConfigStringList("hologram.line", grave); + double lineHeight = plugin.getConfigDbl("hologram.height-line", grave); int lineNumber = 0; Collections.reverse(lineList); diff --git a/src/main/java/org/avarion/graves/manager/ImportManager.java b/src/main/java/org/avarion/graves/manager/ImportManager.java index 818cb5b..9c536f3 100644 --- a/src/main/java/org/avarion/graves/manager/ImportManager.java +++ b/src/main/java/org/avarion/graves/manager/ImportManager.java @@ -103,7 +103,7 @@ public Grave convertAngelChestToGrave(File file) { //grave.setTimeCreation(angelChest.getLong("created", System.currentTimeMillis())); grave.setTimeCreation(System.currentTimeMillis()); //grave.setTimeAlive(angelChest.getInt("secondsLeft", 0) * 10000L); - grave.setTimeAlive(plugin.getConfig("grave.time", grave).getInt("grave.time") * 1000L); + grave.setTimeAlive(plugin.getConfigInt("grave.time", grave) * 1000L); grave.setProtection(angelChest.getBoolean("isProtected", false)); grave.setExperience(angelChest.getInt("experience", 0)); @@ -132,11 +132,9 @@ public Grave convertAngelChestToGrave(File file) { } if (!itemStackList.isEmpty()) { - String title = StringUtil.parseString(plugin.getConfig("gui.grave.title", grave) - .getString("gui.grave.title"), grave.getLocationDeath(), grave, plugin); + String title = StringUtil.parseString(plugin.getConfigString("gui.grave.title", grave), grave.getLocationDeath(), grave, plugin); Grave.StorageMode storageMode = plugin.getGraveManager() - .getStorageMode(plugin.getConfig("storage.mode", grave) - .getString("storage.mode")); + .getStorageMode(plugin.getConfigString("storage.mode", grave)); Inventory inventory = plugin.getGraveManager() .createGraveInventory(grave, grave.getLocationDeath(), itemStackList, title, storageMode); diff --git a/src/main/java/org/avarion/graves/manager/ItemStackManager.java b/src/main/java/org/avarion/graves/manager/ItemStackManager.java index 1a30d4c..b04e677 100644 --- a/src/main/java/org/avarion/graves/manager/ItemStackManager.java +++ b/src/main/java/org/avarion/graves/manager/ItemStackManager.java @@ -31,21 +31,21 @@ public ItemStack getGraveObituary(Grave grave) { List lineList = new ArrayList<>(); List loreList = new ArrayList<>(); - for (String lore : plugin.getConfig("obituary.line", grave).getStringList("obituary.line")) { + for (String lore : plugin.getConfigStringList("obituary.line", grave)) { lineList.add(StringUtil.parseString(lore, grave.getLocationDeath(), grave, plugin)); } - for (String string : plugin.getConfig("obituary.lore", grave).getStringList("obituary.lore")) { + for (String string : plugin.getConfigStringList("obituary.lore", grave)) { loreList.add(ChatColor.GRAY + StringUtil.parseString(string, grave.getLocationDeath(), grave, plugin)); } - int customModelData = plugin.getConfig("obituary.model-data", grave).getInt("obituary.model-data", -1); + int customModelData = plugin.getConfigInt("obituary.model-data", grave, -1); if (customModelData > -1) { bookMeta.setCustomModelData(customModelData); } - if (plugin.getConfig("obituary.glow", grave).getBoolean("obituary.glow")) { + if (plugin.getConfigBool("obituary.glow", grave)) { bookMeta.addEnchant(Enchantment.DURABILITY, 1, true); bookMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); @@ -54,10 +54,9 @@ public ItemStack getGraveObituary(Grave grave) { bookMeta.setGeneration(null); bookMeta.setPages(String.join("\n", lineList)); bookMeta.setLore(loreList); - bookMeta.setTitle(ChatColor.WHITE + StringUtil.parseString(plugin.getConfig("obituary.title", grave) - .getString("obituary.title"), grave, plugin)); - bookMeta.setAuthor(StringUtil.parseString(plugin.getConfig("obituary.author", grave) - .getString("obituary.author"), grave, plugin)); + bookMeta.setTitle(ChatColor.WHITE + + StringUtil.parseString(plugin.getConfigString("obituary.title", grave), grave, plugin)); + bookMeta.setAuthor(StringUtil.parseString(plugin.getConfigString("obituary.author", grave), grave, plugin)); itemStack.setItemMeta(bookMeta); } @@ -71,19 +70,19 @@ public ItemStack getGraveHead(Grave grave) { if (itemMeta != null) { List loreList = new ArrayList<>(); - for (String string : plugin.getConfig("head.lore", grave).getStringList("head.lore")) { + for (String string : plugin.getConfigStringList("head.lore", grave)) { loreList.add(ChatColor.GRAY + StringUtil.parseString(string, grave.getLocationDeath(), grave, plugin)); } - int customModelData = plugin.getConfig("head.model-data", grave).getInt("head.model-data", -1); + int customModelData = plugin.getConfigInt("head.model-data", grave, -1); if (customModelData > -1) { itemMeta.setCustomModelData(customModelData); } itemMeta.setLore(loreList); - itemMeta.setDisplayName(ChatColor.WHITE + StringUtil.parseString(plugin.getConfig("head.name", grave) - .getString("head.name"), grave, plugin)); + itemMeta.setDisplayName(ChatColor.WHITE + + StringUtil.parseString(plugin.getConfigString("head.name", grave), grave, plugin)); itemStack.setItemMeta(itemMeta); } @@ -93,8 +92,8 @@ public ItemStack getGraveHead(Grave grave) { public ItemStack createGraveListItemStack(int number, Grave grave) { Material material; - if (plugin.getConfig("gui.menu.list.item.block", grave).getBoolean("gui.menu.list.item.block")) { - String materialString = plugin.getConfig("block.material", grave).getString("block.material", "CHEST"); + if (plugin.getConfigBool("gui.menu.list.item.block", grave)) { + String materialString = plugin.getConfigString("block.material", grave, "CHEST"); material = Material.matchMaterial(materialString); } @@ -115,14 +114,13 @@ public ItemStack createGraveListItemStack(int number, Grave grave) { if (itemStack.getItemMeta() != null) { ItemMeta itemMeta = itemStack.getItemMeta(); - String name = ChatColor.WHITE + StringUtil.parseString(plugin.getConfig("gui.menu.list.name", grave) - .getString("gui.menu.list.name"), grave, plugin) + String name = ChatColor.WHITE + + StringUtil.parseString(plugin.getConfigString("gui.menu.list.name", grave), grave, plugin) .replace("%number%", String.valueOf(number)); List loreList = new ArrayList<>(); - int customModelData = plugin.getConfig("gui.menu.list.model-data", grave) - .getInt("gui.menu.list.model-data", -1); + int customModelData = plugin.getConfigInt("gui.menu.list.model-data", grave, -1); - for (String string : plugin.getConfig("gui.menu.list.lore", grave).getStringList("gui.menu.list.lore")) { + for (String string : plugin.getConfigStringList("gui.menu.list.lore", grave)) { loreList.add(ChatColor.GRAY + StringUtil.parseString(string, grave.getLocationDeath(), grave, plugin)); } @@ -144,8 +142,7 @@ public ItemStack createGraveListItemStack(int number, Grave grave) { } public ItemStack createGraveMenuItemStack(int slot, Grave grave) { - String materialString = plugin.getConfig("gui.menu.grave.slot." + slot + ".material", grave) - .getString("gui.menu.grave.slot." + slot + ".material", "PAPER"); + String materialString = plugin.getConfigString("gui.menu.grave.slot." + slot + ".material", grave, "PAPER"); Material material = Material.matchMaterial(materialString); if (material == null) { @@ -158,18 +155,13 @@ public ItemStack createGraveMenuItemStack(int slot, Grave grave) { if (itemStack.getItemMeta() != null) { ItemMeta itemMeta = itemStack.getItemMeta(); - String name = ChatColor.WHITE + StringUtil.parseString(plugin.getConfig("gui.menu.grave.slot." + String name = ChatColor.WHITE + StringUtil.parseString(plugin.getConfigString("gui.menu.grave.slot." + slot - + ".name", grave) - .getString("gui.menu.grave.slot." - + slot - + ".name"), grave, plugin); + + ".name", grave), grave, plugin); List loreList = new ArrayList<>(); - int customModelData = plugin.getConfig("gui.menu.grave.slot." + slot + ".model-data", grave) - .getInt("gui.menu.grave.slot." + slot + ".model-data", -1); + int customModelData = plugin.getConfigInt("gui.menu.grave.slot." + slot + ".model-data", grave, -1); - for (String string : plugin.getConfig("gui.menu.grave.slot." + slot + ".lore", grave) - .getStringList("gui.menu.grave.slot." + slot + ".lore")) { + for (String string : plugin.getConfigStringList("gui.menu.grave.slot." + slot + ".lore", grave)) { loreList.add(ChatColor.GRAY + StringUtil.parseString(string, grave.getLocationDeath(), grave, plugin)); } diff --git a/src/main/java/org/avarion/graves/manager/LocationManager.java b/src/main/java/org/avarion/graves/manager/LocationManager.java index 058440b..6d1220f 100644 --- a/src/main/java/org/avarion/graves/manager/LocationManager.java +++ b/src/main/java/org/avarion/graves/manager/LocationManager.java @@ -40,11 +40,11 @@ public void removeLastSolidLocation(Entity entity) { public Location getSafeTeleportLocation(Entity entity, Location location, Grave grave, Graves plugin) { if (location.getWorld() != null) { - if (plugin.getConfig("teleport.unsafe", grave).getBoolean("teleport.unsafe") + if (plugin.getConfigBool("teleport.unsafe", grave) || isLocationSafePlayer(location)) { return location; } - else if (plugin.getConfig("teleport.top", grave).getBoolean("teleport.top")) { + else if (plugin.getConfigBool("teleport.top", grave)) { Location topLocation = getTop(location, entity, grave); if (topLocation != null && isLocationSafePlayer(topLocation) && topLocation.getWorld() != null) { @@ -76,12 +76,10 @@ else if (MaterialUtil.isLava(block.getType())) { } else { Location graveLocation = (MaterialUtil.isAir(block.getType()) - || MaterialUtil.isWater(block.getType())) - ? (plugin.getConfig("placement.ground", grave) - .getBoolean("placement.ground") - ? getGround(location, livingEntity, grave) - : null) - : getRoof(location, livingEntity, grave); + || MaterialUtil.isWater(block.getType())) ? ( + plugin.getConfigBool("placement.ground", grave) + ? getGround(location, livingEntity, grave) + : null) : getRoof(location, livingEntity, grave); if (graveLocation != null) { return graveLocation; @@ -154,10 +152,10 @@ else if (isLocationSafeGrave(location) && !hasGrave(location)) { } public Location getVoid(Location location, Entity entity, Grave grave) { - if (plugin.getConfig("placement.void", grave).getBoolean("placement.void")) { + if (plugin.getConfigBool("placement.void", grave)) { location = location.clone(); - if (plugin.getConfig("placement.void-smart", grave).getBoolean("placement.void-smart")) { + if (plugin.getConfigBool("placement.void-smart", grave)) { Location solidLocation = plugin.getLocationManager().getLastSolidLocation(entity); if (solidLocation != null) { @@ -182,7 +180,7 @@ public Location getVoid(Location location, Entity entity, Grave grave) { } public Location getLavaTop(Location location, Entity entity, Grave grave) { - if (plugin.getConfig("placement.lava-smart", grave).getBoolean("placement.lava-smart")) { + if (plugin.getConfigBool("placement.lava-smart", grave)) { Location solidLocation = plugin.getLocationManager().getLastSolidLocation(entity); if (solidLocation != null) { @@ -190,7 +188,7 @@ public Location getLavaTop(Location location, Entity entity, Grave grave) { } } - if (plugin.getConfig("placement.lava-top", grave).getBoolean("placement.lava-top")) { + if (plugin.getConfigBool("placement.lava-top", grave)) { location = location.clone(); if (location.getWorld() != null) { @@ -199,7 +197,7 @@ public Location getLavaTop(Location location, Entity entity, Grave grave) { while (counter <= location.getWorld().getMaxHeight()) { Block block = location.getBlock(); - if ((MaterialUtil.isAir(block.getType())) + if (MaterialUtil.isAir(block.getType()) && !plugin.getCompatibility().hasTitleData(block) && !MaterialUtil.isLava(block.getType())) { return location; @@ -216,14 +214,12 @@ public Location getLavaTop(Location location, Entity entity, Grave grave) { @SuppressWarnings("BooleanMethodIsAlwaysInverted") public boolean canBuild(LivingEntity livingEntity, Location location, List permissionList) { - if (livingEntity instanceof Player) { - Player player = (Player) livingEntity; + if (livingEntity instanceof Player player) { - return (!plugin.getConfig("placement.can-build", player, permissionList).getBoolean("placement.can-build") + return (!plugin.getConfigBool("placement.can-build", player, permissionList) || plugin.getCompatibility().canBuild(player, location, plugin)) && (!plugin.getIntegrationManager() .hasProtectionLib() || ( - !plugin.getConfig("placement.can-build-protectionlib", player, permissionList) - .getBoolean("placement.can-build-protectionlib") + !plugin.getConfigBool("placement.can-build-protectionlib", player, permissionList) || plugin.getIntegrationManager() .getProtectionLib() .canBuild(location, player))); diff --git a/src/main/java/org/avarion/graves/util/InventoryUtil.java b/src/main/java/org/avarion/graves/util/InventoryUtil.java index 9b322da..4a7b3ab 100644 --- a/src/main/java/org/avarion/graves/util/InventoryUtil.java +++ b/src/main/java/org/avarion/graves/util/InventoryUtil.java @@ -169,7 +169,7 @@ public static String inventoryToString(Inventory inventory) { public static Inventory stringToInventory(InventoryHolder inventoryHolder, String string, String title, Graves plugin) { String[] strings = string.split("\\|"); - if (strings.length > 0 && !strings[0].equals("")) { + if (strings.length > 0 && !strings[0].isEmpty()) { Inventory inventory = plugin.getServer() .createInventory(inventoryHolder, InventoryUtil.getInventorySize(strings.length), title); diff --git a/src/main/java/org/avarion/graves/util/SkinUtil.java b/src/main/java/org/avarion/graves/util/SkinUtil.java index 0203bac..6f4f0dc 100644 --- a/src/main/java/org/avarion/graves/util/SkinUtil.java +++ b/src/main/java/org/avarion/graves/util/SkinUtil.java @@ -96,7 +96,7 @@ public static String getTexture(Entity entity) { try { String base64 = SkullTextureAPI.getTexture(entity); - if (base64 != null && !base64.equals("")) { + if (base64 != null && !base64.isEmpty()) { return base64; } } @@ -119,7 +119,7 @@ public static GameProfile getPlayerGameProfile(Player player) { findGameProfileMethod(playerObject); } - if (GAMEPROFILE_METHOD != null && !GAMEPROFILE_METHOD.equals("")) { + if (GAMEPROFILE_METHOD != null && !GAMEPROFILE_METHOD.isEmpty()) { Method gameProfile = playerObject.getClass().getMethod(GAMEPROFILE_METHOD); gameProfile.setAccessible(true); diff --git a/src/main/java/org/avarion/graves/util/StringUtil.java b/src/main/java/org/avarion/graves/util/StringUtil.java index 52132e3..25a4bda 100644 --- a/src/main/java/org/avarion/graves/util/StringUtil.java +++ b/src/main/java/org/avarion/graves/util/StringUtil.java @@ -97,10 +97,8 @@ public static String parseString(String string, Entity entity, String name, Loca > 0 || grave.getTimeProtectionRemaining() < 0) - ? plugin.getConfig("protection.state.protected", grave) - .getString("protection.state.protected", "Protected") - : plugin.getConfig("protection.state.unprotected", grave) - .getString("protection.state.unprotected", "Unprotected")) + ? plugin.getConfigString("protection.state.protected", grave, "Protected") + : plugin.getConfigString("protection.state.unprotected", grave, "Unprotected")) .replace("%item%", String.valueOf(grave.getItemAmount())); if (grave.getExperience() > 0) { string = string.replace("%level%", String.valueOf(ExperienceUtil.getLevelFromExperience(grave.getExperience()))) @@ -117,15 +115,9 @@ public static String parseString(String string, Entity entity, String name, Loca } if (location != null && location.getWorld() != null && grave != null) { - string = string.replace("%world_formatted%", location.getWorld() != null - ? plugin.getConfig("message.world." - + location.getWorld() - .getName(), grave) - .getString("message.world." - + location.getWorld() - .getName(), StringUtil.format(location.getWorld() - .getName())) - : ""); + string = string.replace("%world_formatted%", location.getWorld() != null ? plugin.getConfigString( + "message.world." + + location.getWorld().getName(), grave, StringUtil.format(location.getWorld().getName())) : ""); } else { string = string.replace("%world_formatted%", ""); @@ -195,11 +187,10 @@ public static String parseTime(String string, Grave grave) { public static String getDateString(Grave grave, long time, Graves plugin) { if (time > 0) { - return new SimpleDateFormat(plugin.getConfig("time.date", grave) - .getString("time.date", "dd-MM-yyyy")).format(new Date(time)); + return new SimpleDateFormat(plugin.getConfigString("time.date", grave, "dd-MM-yyyy")).format(new Date(time)); } - return plugin.getConfig("time.infinite", grave).getString("time.infinite"); + return plugin.getConfigString("time.infinite", grave); } public static String getTimeString(Grave grave, long time, Graves plugin) { @@ -216,33 +207,25 @@ public static String getTimeString(Grave grave, long time, Graves plugin) { String timeSecond = ""; if (day > 0) { - timeDay = plugin.getConfig("time.day", grave) - .getString("time.day") - .replace("%day%", String.valueOf(day)); + timeDay = plugin.getConfigString("time.day", grave).replace("%day%", String.valueOf(day)); } if (hour > 0) { - timeHour = plugin.getConfig("time.hour", grave) - .getString("time.hour") - .replace("%hour%", String.valueOf(hour)); + timeHour = plugin.getConfigString("time.hour", grave).replace("%hour%", String.valueOf(hour)); } if (minute > 0) { - timeMinute = plugin.getConfig("time.minute", grave) - .getString("time.minute") - .replace("%minute%", String.valueOf(minute)); + timeMinute = plugin.getConfigString("time.minute", grave).replace("%minute%", String.valueOf(minute)); } if (second > 0) { - timeSecond = plugin.getConfig("time.second", grave) - .getString("time.second") - .replace("%second%", String.valueOf(second)); + timeSecond = plugin.getConfigString("time.second", grave).replace("%second%", String.valueOf(second)); } return normalizeSpace(timeDay + timeHour + timeMinute + timeSecond); } - return plugin.getConfig("time.infinite", grave).getString("time.infinite"); + return plugin.getConfigString("time.infinite", grave); } private static String normalizeSpace(String string) {