Skip to content

Commit

Permalink
Combine all calls to getConfig().get<type> into singular calls. (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
svaningelgem committed May 29, 2024
1 parent 7675b33 commit 759965a
Show file tree
Hide file tree
Showing 29 changed files with 299 additions and 319 deletions.
97 changes: 80 additions & 17 deletions src/main/java/org/avarion/graves/Graves.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -495,47 +496,109 @@ 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<String> 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<String> permissionList) {
return getConfig(config, entity.getType(), permissionList).getBoolean(config);
}

public boolean getConfigBool(String config, EntityType entityType, @Nullable List<String> permissionList) {
return getConfig(config, entityType, permissionList).getBoolean(config);
}

public int getConfigInt(String config, Entity entity, @Nullable List<String> permissionList) {
return getConfig(config, entity.getType(), permissionList).getInt(config);
}

public String getConfigString(String config, Entity entity, @Nullable List<String> permissionList) {
return getConfig(config, entity.getType(), permissionList).getString(config);
}

public String getConfigString(String config, Entity entity, @Nullable List<String> permissionList, String defaultValue) {
return getConfig(config, entity.getType(), permissionList).getString(config, defaultValue);
}

public String getConfigString(String config, EntityType entityType, @Nullable List<String> permissionList) {
return getConfig(config, entityType, permissionList).getString(config);
}

public List<String> getConfigStringList(String config, Entity entity, @Nullable List<String> 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<String> permissionList) {
return getConfig(config, entity.getType(), permissionList);
}

public ConfigurationSection getConfig(String config, Entity entity, List<String> 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<String> permissionList) {
private ConfigurationSection getConfig(String config, EntityType entityType, List<String> 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;
}
}
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
12 changes: 5 additions & 7 deletions src/main/java/org/avarion/graves/integration/FurnitureLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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));
}

Expand Down Expand Up @@ -142,8 +141,7 @@ private void setSign(Block block, List<String> stringList, Grave grave) {
}

private void setSkull(fEntity fEntity, Grave grave) {
List<String> materialList = plugin.getConfig("furniturelib.head.material", grave)
.getStringList("furniturelib.head.material");
List<String> materialList = plugin.getConfigStringList("furniturelib.head.material", grave);
ItemStack itemStack = plugin.getCompatibility().getSkullItemStack(grave, plugin);

if (fEntity.getItemInMainHand() != null
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/org/avarion/graves/integration/ItemsAdder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -105,8 +104,8 @@ public void removeFurniture(Map<EntityData, Entity> 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) {
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/avarion/graves/integration/MultiPaper.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,9 @@ private void registerListeners() {
List<ItemStack> itemStackList = (List<ItemStack>) 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));
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/avarion/graves/integration/Oraxen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 7 additions & 11 deletions src/main/java/org/avarion/graves/integration/PlayerNPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
}
Expand All @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -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);
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/org/avarion/graves/integration/WorldEdit.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 759965a

Please sign in to comment.