mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-09-07 12:58:02 +02:00
Hides deprecated flags from the flags list.
Related to https://github.com/BentoBoxWorld/BentoBox/issues/680 Redoes commit 095237cd5db3b7169df1275759c885b42d9d8d45#diff-fee448dd4d94f3c5faaab7655c47682c Unknown flags in the database are now handled correctly. Added a test to confirm correct operation.
This commit is contained in:
parent
ffd151c881
commit
607d92868e
@ -1,7 +1,12 @@
|
|||||||
package world.bentobox.bentobox.lists;
|
package world.bentobox.bentobox.lists;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.flags.Flag;
|
import world.bentobox.bentobox.api.flags.Flag;
|
||||||
import world.bentobox.bentobox.api.flags.Flag.Type;
|
import world.bentobox.bentobox.api.flags.Flag.Type;
|
||||||
import world.bentobox.bentobox.api.flags.clicklisteners.CycleClick;
|
import world.bentobox.bentobox.api.flags.clicklisteners.CycleClick;
|
||||||
@ -52,10 +57,6 @@ import world.bentobox.bentobox.listeners.flags.worldsettings.RemoveMobsListener;
|
|||||||
import world.bentobox.bentobox.listeners.flags.worldsettings.TreesGrowingOutsideRangeListener;
|
import world.bentobox.bentobox.listeners.flags.worldsettings.TreesGrowingOutsideRangeListener;
|
||||||
import world.bentobox.bentobox.managers.RanksManager;
|
import world.bentobox.bentobox.managers.RanksManager;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains built-in {@link Flag Flags} that are registered by default into the {@link world.bentobox.bentobox.managers.FlagsManager FlagsManager} at startup.
|
* Contains built-in {@link Flag Flags} that are registered by default into the {@link world.bentobox.bentobox.managers.FlagsManager FlagsManager} at startup.
|
||||||
*/
|
*/
|
||||||
@ -424,6 +425,7 @@ public final class Flags {
|
|||||||
*/
|
*/
|
||||||
public static List<Flag> values() {
|
public static List<Flag> values() {
|
||||||
return Arrays.stream(Flags.class.getFields())
|
return Arrays.stream(Flags.class.getFields())
|
||||||
|
.filter(field -> field.getAnnotation(Deprecated.class) == null) // Ensures it is not deprecated
|
||||||
.map(field -> {
|
.map(field -> {
|
||||||
try {
|
try {
|
||||||
return (Flag)field.get(null);
|
return (Flag)field.get(null);
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package world.bentobox.bentobox.database.json.adapters;
|
package world.bentobox.bentobox.database.json.adapters;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@ -106,4 +108,16 @@ public class FlagAdapterTest {
|
|||||||
Mockito.verify(reader).nextString();
|
Mockito.verify(reader).nextString();
|
||||||
assertEquals(Flags.ANIMAL_SPAWN, flag);
|
assertEquals(Flags.ANIMAL_SPAWN, flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReadJsonReaderNoSuchFlag() throws IOException {
|
||||||
|
FlagTypeAdapter fa = new FlagTypeAdapter(plugin);
|
||||||
|
JsonReader reader = mock(JsonReader.class);
|
||||||
|
Mockito.when(reader.peek()).thenReturn(JsonToken.STRING);
|
||||||
|
Mockito.when(reader.nextString()).thenReturn("MUMBO_JUMBO");
|
||||||
|
Flag flag = fa.read(reader);
|
||||||
|
Mockito.verify(reader).nextString();
|
||||||
|
assertNotNull(flag);
|
||||||
|
assertTrue(flag.getID().startsWith("NULL_FLAG_"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user