Skip to content

Commit

Permalink
Remove some Deprecated code from OreControlService
Browse files Browse the repository at this point in the history
Took 4 minutes
  • Loading branch information
DerFrZocker committed Jul 19, 2020
1 parent 948c4d8 commit 190161c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import org.bukkit.World;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -283,34 +282,4 @@ public interface OreControlService {
*/
void setActivated(@NotNull WorldOreConfig worldOreConfig, @NotNull Ore ore, boolean status);

/**
* Checks if the given String represent an Ore
* If the given String is null, the method return false
*
* @param string to check
* @return true if the given String represent an Ore, otherwise false
*/
@Deprecated
boolean isOre(@Nullable String string);

/**
* Checks if the given String represent a Biome
* If the given String is null, the method return false
*
* @param string to check
* @return true if the given String represent a Biome, otherwise false
*/
@Deprecated
boolean isBiome(@Nullable String string);

/**
* Checks if the given String represent a Setting
* If the given String is null, the method return false
*
* @param string to check
* @return true if the given String represent a Setting, otherwise false
*/
@Deprecated
boolean isSetting(@Nullable String string);

}
Original file line number Diff line number Diff line change
Expand Up @@ -372,46 +372,6 @@ public void setActivated(@NotNull final WorldOreConfig worldOreConfig, @NotNull
oreSettings.setActivated(value);
}

@Override
public boolean isOre(@Nullable final String string) {
if (string == null)
return false;

try {
Ore.valueOf(string.toUpperCase());
return true;
} catch (final IllegalArgumentException e) {
return false;
}

}

@Override
public boolean isBiome(@Nullable final String string) {
if (string == null)
return false;

try {
Biome.valueOf(string.toUpperCase());
return true;
} catch (final IllegalArgumentException e) {
return false;
}
}

@Override
public boolean isSetting(@Nullable final String string) {
if (string == null)
return false;

try {
Setting.valueOf(string.toUpperCase());
return true;
} catch (final IllegalArgumentException e) {
return false;
}
}

@NotNull
private OreSettings getDefault(@NotNull final Ore ore) {
final OreSettings oreSettings = getDefaultOreSetting(ore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@

package de.derfrzocker.ore.control.impl;

import de.derfrzocker.ore.control.api.*;
import de.derfrzocker.ore.control.api.Biome;
import de.derfrzocker.ore.control.api.BiomeOreSettings;
import de.derfrzocker.ore.control.api.Ore;
import de.derfrzocker.ore.control.api.OreSettings;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.SerializableAs;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.*;

Expand Down Expand Up @@ -72,18 +75,27 @@ public static BiomeOreSettingsYamlImpl deserialize(@NotNull final Map<String, Ob

list.forEach(oreSettings1 -> oreSettings.put(oreSettings1.getOre(), oreSettings1));
} else {
final OreControlService service = Bukkit.getServicesManager().load(OreControlService.class);

Validate.notNull(service, "OreControlService can not be null");

// old storage type
map.entrySet().stream().filter(entry -> service.isOre(entry.getKey())).
map.entrySet().stream().filter(entry -> isOre(entry.getKey())).
forEach(entry -> oreSettings.put(Ore.valueOf(entry.getKey().toUpperCase()), (OreSettings) entry.getValue()));
}

return new BiomeOreSettingsYamlImpl(Biome.valueOf(((String) map.get(BIOME_KEY)).toUpperCase()), oreSettings);
}

private static boolean isOre(@Nullable final String string) {
if (string == null)
return false;

try {
Ore.valueOf(string.toUpperCase());
return true;
} catch (final IllegalArgumentException e) {
return false;
}

}

@NotNull
@Override
public Biome getBiome() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static OreSettingsYamlImpl deserialize(@NotNull final Map<String, Object>

Validate.notNull(service, "OreControlService can not be null");

map.entrySet().stream().filter(entry -> service.isSetting(entry.getKey())).
map.entrySet().stream().filter(entry -> isSetting(entry.getKey())).
forEach(entry -> settings.put(Setting.valueOf(entry.getKey().toUpperCase()), NumberConversions.toDouble(entry.getValue())));
}

Expand All @@ -98,6 +98,18 @@ public static OreSettingsYamlImpl deserialize(@NotNull final Map<String, Object>
return oreSettingsYaml;
}

private static boolean isSetting(@Nullable final String string) {
if (string == null)
return false;

try {
Setting.valueOf(string.toUpperCase());
return true;
} catch (final IllegalArgumentException e) {
return false;
}
}

@NotNull
@Override
public Ore getOre() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import de.derfrzocker.ore.control.api.*;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.SerializableAs;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -90,11 +89,7 @@ public static WorldOreConfigYamlImpl deserialize(@NotNull final Map<String, Obje
list.forEach(oreSettings1 -> oreSettings.put(oreSettings1.getOre(), oreSettings1));
} else {
// old storage type
final OreControlService service = Bukkit.getServicesManager().load(OreControlService.class);

Validate.notNull(service, "OreControlService can not be null");

map.entrySet().stream().filter(entry -> service.isOre(entry.getKey())).
map.entrySet().stream().filter(entry -> isOre(entry.getKey())).
forEach(entry -> oreSettings.put(Ore.valueOf(entry.getKey().toUpperCase()), (OreSettings) entry.getValue()));
}

Expand All @@ -108,11 +103,7 @@ public static WorldOreConfigYamlImpl deserialize(@NotNull final Map<String, Obje
list.forEach(biomeOreSettings1 -> biomeOreSettings.put(biomeOreSettings1.getBiome(), biomeOreSettings1));
} else {
// old storage type
final OreControlService service = Bukkit.getServicesManager().load(OreControlService.class);

Validate.notNull(service, "OreControlService can not be null");

map.entrySet().stream().filter(entry -> service.isBiome(entry.getKey())).
map.entrySet().stream().filter(entry -> isBiome(entry.getKey())).
forEach(entry -> biomeOreSettings.put(Biome.valueOf(entry.getKey().toUpperCase()), (BiomeOreSettings) entry.getValue()));
}

Expand All @@ -126,6 +117,31 @@ public static WorldOreConfigYamlImpl deserialize(@NotNull final Map<String, Obje
return new WorldOreConfigYamlImpl(name, (boolean) map.getOrDefault(TEMPLATE_KEY, false), oreSettings, biomeOreSettings);
}

private static boolean isOre(@Nullable final String string) {
if (string == null)
return false;

try {
Ore.valueOf(string.toUpperCase());
return true;
} catch (final IllegalArgumentException e) {
return false;
}

}

private static boolean isBiome(@Nullable final String string) {
if (string == null)
return false;

try {
Biome.valueOf(string.toUpperCase());
return true;
} catch (final IllegalArgumentException e) {
return false;
}
}

@NotNull
@Override
public String getName() {
Expand Down

0 comments on commit 190161c

Please sign in to comment.