From d97d15d47a74985eaa54b3c62b4780ffcb5671e9 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 14 Mar 2021 10:18:33 -0700 Subject: [PATCH] Added locale strings for the DamageCause enum. Used in InvincibleVistors Fixes https://github.com/BentoBoxWorld/BentoBox/issues/1705 --- .../InvincibleVisitorsListener.java | 5 +- src/main/resources/locales/en-US.yml | 87 +++++++++++++++++++ .../InvincibleVisitorsListenerTest.java | 19 ++-- 3 files changed, 100 insertions(+), 11 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListener.java index 23f219924..e880a5f0a 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListener.java @@ -82,9 +82,8 @@ public class InvincibleVisitorsListener extends FlagListener implements ClickHan private PanelItem getPanelItem(DamageCause c, User user) { PanelItemBuilder pib = new PanelItemBuilder(); - // todo: Please consider adding translation fields for each entry - // of "DamageCause" in the language file in the future. - pib.name(Util.prettifyText(c.toString())); + String translation = user.getTranslationOrNothing("enums.DamageCause." + c.name()); + pib.name(translation.isEmpty() ? Util.prettifyText(c.toString()) : translation); pib.clickHandler(this); if (getIWM().getIvSettings(user.getWorld()).contains(c.name())) { pib.icon(Material.GREEN_SHULKER_BOX); diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index b98168511..5f8381b0d 100644 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -1470,6 +1470,93 @@ catalog: &a Allow BentoBox to connect to GitHub in &a the configuration or try again later. +enums: + DamageCause: + CONTACT: Contact + ENTITY_ATTACK: Entity Attack + ENTITY_SWEEP_ATTACK: Entity Sweep Attack + PROJECTILE: Projectile + SUFFOCATION: Suffocation + FALL: Fall + FIRE: Fire + FIRE_TICK: Fire Tick + MELTING: Melting + LAVA: Lava + DROWNING: Drowning + BLOCK_EXPLOSION: Block Explosion + ENTITY_EXPLOSION: Entity Explosion + VOID: Void + LIGHTNING: Lightning + SUICIDE: Suicide + STARVATION: Starvation + POISON: Poison + MAGIC: Magic + WITHER: Wither + FALLING_BLOCK: Falling Block + THORNS: Thorns + DRAGON_BREATH: Dragon Breath + CUSTOM: Custom + FLY_INTO_WALL: Fly Into Wall + HOT_FLOOR: Hot Floor + CRAMMING: Cramming + DRYOUT: Dryout + CONTACT: Contact + ENTITY_ATTACK: Entity Attack + ENTITY_SWEEP_ATTACK: Entity Sweep Attack + PROJECTILE: Projectile + SUFFOCATION: Suffocation + FALL: Fall + FIRE: Fire + FIRE_TICK: Fire Tick + MELTING: Melting + LAVA: Lava + DROWNING: Drowning + BLOCK_EXPLOSION: Block Explosion + ENTITY_EXPLOSION: Entity Explosion + VOID: Void + LIGHTNING: Lightning + SUICIDE: Suicide + STARVATION: Starvation + POISON: Poison + MAGIC: Magic + WITHER: Wither + FALLING_BLOCK: Falling Block + THORNS: Thorns + DRAGON_BREATH: Dragon Breath + CUSTOM: Custom + FLY_INTO_WALL: Fly Into Wall + HOT_FLOOR: Hot Floor + CRAMMING: Cramming + DRYOUT: Dryout + CONTACT: Contact + ENTITY_ATTACK: Entity Attack + ENTITY_SWEEP_ATTACK: Entity Sweep Attack + PROJECTILE: Projectile + SUFFOCATION: Suffocation + FALL: Fall + FIRE: Fire + FIRE_TICK: Fire Tick + MELTING: Melting + LAVA: Lava + DROWNING: Drowning + BLOCK_EXPLOSION: Block Explosion + ENTITY_EXPLOSION: Entity Explosion + VOID: Void + LIGHTNING: Lightning + SUICIDE: Suicide + STARVATION: Starvation + POISON: Poison + MAGIC: Magic + WITHER: Wither + FALLING_BLOCK: Falling Block + THORNS: Thorns + DRAGON_BREATH: Dragon Breath + CUSTOM: Custom + FLY_INTO_WALL: Fly Into Wall + HOT_FLOOR: Hot Floor + CRAMMING: Cramming + DRYOUT: Dryout + panel: credits: title: "&8 [name] &2 Credits" diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListenerTest.java index 7fd61eb3f..ada063750 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListenerTest.java @@ -3,7 +3,10 @@ package world.bentobox.bentobox.listeners.flags.worldsettings; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.framework; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; @@ -38,7 +41,6 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.Mockito; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; @@ -88,7 +90,7 @@ public class InvincibleVisitorsListenerTest { // Island World Manager when(iwm.inWorld(any(World.class))).thenReturn(true); when(iwm.inWorld(any(Location.class))).thenReturn(true); - when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("bskyblock."); + when(iwm.getPermissionPrefix(any())).thenReturn("bskyblock."); Optional optionalAddon = Optional.of(addon); when(iwm.getAddon(any())).thenReturn(optionalAddon); when(plugin.getIWM()).thenReturn(iwm); @@ -104,8 +106,9 @@ public class InvincibleVisitorsListenerTest { when(user.getLocation()).thenReturn(mock(Location.class)); when(player.getLocation()).thenReturn(mock(Location.class)); when(user.getPlayer()).thenReturn(player); - when(user.hasPermission(Mockito.anyString())).thenReturn(true); - when(user.getTranslation(Mockito.anyString())).thenReturn("panel"); + when(user.hasPermission(anyString())).thenReturn(true); + when(user.getTranslation(anyString())).thenReturn("panel"); + when(user.getTranslationOrNothing(anyString())).thenReturn(""); UUID uuid = UUID.randomUUID(); when(user.getUniqueId()).thenReturn(uuid); when(player.getUniqueId()).thenReturn(uuid); @@ -118,7 +121,7 @@ public class InvincibleVisitorsListenerTest { PanelItem item = mock(PanelItem.class); when(item.getItem()).thenReturn(mock(ItemStack.class)); when(flag.toPanelItem(any(), eq(user), any(), eq(false))).thenReturn(item); - when(fm.getFlag(Mockito.anyString())).thenReturn(Optional.of(flag)); + when(fm.getFlag(anyString())).thenReturn(Optional.of(flag)); when(plugin.getFlagsManager()).thenReturn(fm); // Island Manager @@ -151,13 +154,13 @@ public class InvincibleVisitorsListenerTest { when(top.getSize()).thenReturn(9); when(panel.getInventory()).thenReturn(top); - when(Bukkit.createInventory(any(), Mockito.anyInt(), any())).thenReturn(top); + when(Bukkit.createInventory(any(), anyInt(), any())).thenReturn(top); } @After public void tearDown() { User.clearUsers(); - Mockito.framework().clearInlineMocks(); + framework().clearInlineMocks(); } @Test @@ -169,7 +172,7 @@ public class InvincibleVisitorsListenerTest { @Test public void testOnClickNoPermission() { - when(user.hasPermission(Mockito.anyString())).thenReturn(false); + when(user.hasPermission(anyString())).thenReturn(false); listener.onClick(panel, user, ClickType.LEFT, 0); verify(user).sendMessage("general.errors.no-permission", "[permission]", "bskyblock.admin.settings.INVINCIBLE_VISITORS"); }