Reduced complexity of Flag constructor.

Added constructor to TextVariables.
This commit is contained in:
tastybento 2018-06-23 17:06:17 -07:00
parent f12bc17ca3
commit 729706f69d
5 changed files with 82 additions and 32 deletions

View File

@ -279,61 +279,79 @@ protection:
ANVIL: ANVIL:
description: "Toggle interaction" description: "Toggle interaction"
name: Anvils name: Anvils
hint: "Anvil use disabled"
ARMOR_STAND: ARMOR_STAND:
description: "Toggle interaction" description: "Toggle interaction"
name: "Armor stands" name: "Armor stands"
hint: "Armor stand use disabled"
BEACON: BEACON:
description: "Toggle interaction" description: "Toggle interaction"
name: Beacons name: Beacons
hint: "Beacon use disabled"
BED: BED:
description: "Toggle interaction" description: "Toggle interaction"
name: Beds name: Beds
hint: "Bed use disabled"
BREAK_BLOCKS: BREAK_BLOCKS:
description: "Toggle breaking" description: "Toggle breaking"
name: "Break blocks" name: "Break blocks"
hint: "Block breaking disabled"
BREEDING: BREEDING:
description: "Toggle breeding" description: "Toggle breeding"
name: "Breed animals" name: "Breed animals"
hint: "Animal breeding protected"
BREWING: BREWING:
description: "Toggle interaction" description: "Toggle interaction"
name: "Brewing stands" name: "Brewing stands"
hint: "No brewing allowed"
BUCKET: BUCKET:
description: "Toggle interaction" description: "Toggle interaction"
name: Buckets name: Buckets
hint: "No bucket use allowed"
CHEST: CHEST:
description: "Toggle chest access" description: "Toggle chest access"
name: Chests name: Chests
hint: "Chest access disabled"
CHORUS_FRUIT: CHORUS_FRUIT:
description: "Toggle teleportation" description: "Toggle teleportation"
name: "Chorus fruits" name: "Chorus fruits"
hint: "No teleporting"
COLLECT_LAVA: COLLECT_LAVA:
description: | description: |
Toggle collecting lava Toggle collecting lava
(override Buckets) (override Buckets)
name: "Collect lava" name: "Collect lava"
hint: "No lava collection"
COLLECT_WATER: COLLECT_WATER:
description: | description: |
Toggle collecting water Toggle collecting water
(override Buckets) (override Buckets)
name: "Collect water" name: "Collect water"
hint: "No water collection"
CRAFTING: CRAFTING:
description: "Toggle use" description: "Toggle use"
name: Workbenches name: Workbenches
hint: "No workbench use"
CROP_TRAMPLE: CROP_TRAMPLE:
description: "Toggle crop trampling" description: "Toggle crop trampling"
name: "Trample crops" name: "Trample crops"
hint: "Crops are protected"
DOOR: DOOR:
description: "Toggle door usage" description: "Toggle door usage"
name: "Use doors" name: "Use doors"
hint: "No door use"
EGGS: EGGS:
description: "Toggle egg throwing" description: "Toggle egg throwing"
name: "Egg throwing" name: "Egg throwing"
hint: "No egg throwing"
ELYTRA: ELYTRA:
description: "Toggle use on island" description: "Toggle use on island"
name: "Elytras" name: "Elytra"
hint: "No elytra flying allowed"
ENCHANTING: ENCHANTING:
description: "Toggle use" description: "Toggle use"
name: "Enchanting table" name: "Enchanting table"
hint: "No table use"
ENDER_CHEST: ENDER_CHEST:
description: "Toggle use/crafting" description: "Toggle use/crafting"
name: "Ender Chests" name: "Ender Chests"
@ -341,6 +359,7 @@ protection:
ENDER_PEARL: ENDER_PEARL:
description: "Toggle use" description: "Toggle use"
name: "EnderPearls" name: "EnderPearls"
hint: "No enderpearl use"
ENTER_EXIT_MESSAGES: ENTER_EXIT_MESSAGES:
description: "Display entry and exit messages" description: "Display entry and exit messages"
island: "[name]'s island" island: "[name]'s island"
@ -350,27 +369,35 @@ protection:
FIRE: FIRE:
description: "Allow fire to exist or not" description: "Allow fire to exist or not"
name: Fire name: Fire
hint: "No fire allowed"
FIRE_EXTINGUISH: FIRE_EXTINGUISH:
description: "Toggle extinguishing" description: "Toggle extinguishing"
name: "Fire extinguish" name: "Fire extinguish"
hint: "No fire extinguishing allowed"
FIRE_SPREAD: FIRE_SPREAD:
description: "Toggle spread" description: "Toggle spread"
name: "Fire spread" name: "Fire spread"
hint: "No fire spread allowed"
FURNACE: FURNACE:
description: "Toggle use" description: "Toggle use"
name: Furnace name: Furnace
hint: "No furnace use"
GATE: GATE:
description: "Toggle use" description: "Toggle use"
name: Gates name: Gates
hint: "No gate use"
HURT_ANIMALS: HURT_ANIMALS:
description: "Toggle hurting" description: "Toggle hurting"
name: "Hurt animals" name: "Hurt animals"
hint: "No animal hurting allowed"
HURT_MONSTERS: HURT_MONSTERS:
description: "Toggle hurting" description: "Toggle hurting"
name: "Hurt monsters" name: "Hurt monsters"
hint: "No monster hurting"
HURT_VILLAGERS: HURT_VILLAGERS:
description: "Toggle hurting" description: "Toggle hurting"
name: "Hurt villagers" name: "Hurt villagers"
hint: "No villager hurting"
INVINCIBLE_VISITORS: INVINCIBLE_VISITORS:
description: | description: |
&aConfigure invincible visitor &aConfigure invincible visitor
@ -385,21 +412,25 @@ protection:
ITEM_DROP: ITEM_DROP:
description: "Toggle dropping" description: "Toggle dropping"
name: "Item drop" name: "Item drop"
hint: "Items cannot be dropped"
ITEM_PICKUP: ITEM_PICKUP:
description: "Toggle pickup" description: "Toggle pickup"
name: "Item pickup" name: "Item pickup"
hint: "Items cannot be picked up"
LEASH: LEASH:
description: "Toggle use" description: "Toggle use"
name: "Leash use" name: "Leash use"
LEVER_BUTTON: LEVER_BUTTON:
description: "Toggle use" description: "Toggle use"
name: "Leaver or button use" name: "Leaver or button use"
hint: "No leash use"
LOCK: LOCK:
description: "Toggle lock" description: "Toggle lock"
name: "Lock island" name: "Lock island"
MILKING: MILKING:
description: "Toggle cow milking" description: "Toggle cow milking"
name: Milking name: Milking
hint: "No milking allowed"
MONSTER_SPAWN: MONSTER_SPAWN:
description: "Toggle spawning" description: "Toggle spawning"
name: "Monster spawning" name: "Monster spawning"
@ -408,9 +439,11 @@ protection:
&aToggle access &aToggle access
&ato mount inventory &ato mount inventory
name: "Mount inventory" name: "Mount inventory"
hint: "No access to mount inventory"
MUSIC: MUSIC:
description: "Toggle access" description: "Toggle access"
name: Music name: Music
hint: "No jukebox use"
PISTON_PUSH: PISTON_PUSH:
description: | description: |
&aAllow pistons to push &aAllow pistons to push
@ -419,34 +452,42 @@ protection:
PLACE_BLOCKS: PLACE_BLOCKS:
description: "Toggle placing" description: "Toggle placing"
name: "Place blocks" name: "Place blocks"
hint: "Not allowed to place blocks"
PORTAL: PORTAL:
description: "Toggle use" description: "Toggle use"
name: Portal name: Portal
hint: "Portal use is disallowed"
PRESSURE_PLATE: PRESSURE_PLATE:
description: "Toggle usage" description: "Toggle usage"
name: "Pressure Plates" name: "Pressure Plates"
hint: "No pressure plate use"
PVP_END: PVP_END:
description: | description: |
&cEnable/Disable PVP &cEnable/Disable PVP
&cin the End. &cin the End.
name: "End PVP" name: "End PVP"
hint: "No PVP allowed in the End"
PVP_NETHER: PVP_NETHER:
description: | description: |
&cEnable/Disable PVP &cEnable/Disable PVP
&cin nether. &cin nether.
name: "Nether PVP" name: "Nether PVP"
hint: "No PVP allowed in the Nether"
PVP_OVERWORLD: PVP_OVERWORLD:
description: | description: |
&cEnable/Disable PVP &cEnable/Disable PVP
&con island. &con island.
name: "Overworld PVP" name: "Overworld PVP"
pvp-not-allowed: "&cPVP is not allowed" pvp-not-allowed: "&cPVP is not allowed"
hint: "No PVP allowed in this world"
REDSTONE: REDSTONE:
description: "Toggle use" description: "Toggle use"
name: "Redstone items" name: "Redstone items"
hint: "No redstone item use"
RIDING: RIDING:
description: "Toggle riding" description: "Toggle riding"
name: "Animal riding" name: "Animal riding"
hint: "No animal riding allowed"
REMOVE_MOBS: REMOVE_MOBS:
description: | description: |
&aRemove monsters when &aRemove monsters when
@ -455,15 +496,19 @@ protection:
SHEARING: SHEARING:
description: "Toggle sheering" description: "Toggle sheering"
name: Shearing name: Shearing
hint: "No shearing"
SPAWN_EGGS: SPAWN_EGGS:
description: "Toggle use" description: "Toggle use"
name: "Spawn eggs" name: "Spawn eggs"
hint: "No throwing spawn eggs"
TRADING: TRADING:
description: "Toggle trading" description: "Toggle trading"
name: "Village trading" name: "Village trading"
hint: "No villager trading"
TRAPDOOR: TRAPDOOR:
description: "Toggle access" description: "Toggle access"
name: "Trap doors" name: "Trap doors"
hint: "No trapdoor use"
locked: "&cThis island is locked!" locked: "&cThis island is locked!"
protected: "&cIsland protected: [description]" protected: "&cIsland protected: [description]"

View File

@ -34,6 +34,8 @@ public class Flag implements Comparable<Flag> {
} }
} }
private static final String PROTECTION_FLAGS = "protection.flags.";
private final String id; private final String id;
private final Material icon; private final Material icon;
private final Listener listener; private final Listener listener;
@ -43,11 +45,10 @@ public class Flag implements Comparable<Flag> {
private final PanelItem.ClickHandler clickHandler; private final PanelItem.ClickHandler clickHandler;
private final boolean subPanel; private final boolean subPanel;
Flag(String id, Material icon, Listener listener, boolean defaultSetting, Type type, int defaultRank, PanelItem.ClickHandler clickListener, boolean subPanel) { Flag(String id, Material icon, Listener listener, Type type, int defaultRank, PanelItem.ClickHandler clickListener, boolean subPanel) {
this.id = id; this.id = id;
this.icon = icon; this.icon = icon;
this.listener = listener; this.listener = listener;
this.setting = defaultSetting;
this.type = type; this.type = type;
this.defaultRank = defaultRank; this.defaultRank = defaultRank;
this.clickHandler = clickListener; this.clickHandler = clickListener;
@ -165,15 +166,15 @@ public class Flag implements Comparable<Flag> {
} }
public String getNameReference() { public String getNameReference() {
return "protection.flags." + this.id + ".name"; return PROTECTION_FLAGS + this.id + ".name";
} }
public String getDescriptionReference() { public String getDescriptionReference() {
return "protection.flags." + this.id + ".description"; return PROTECTION_FLAGS + this.id + ".description";
} }
public String getHintReference() { public String getHintReference() {
return "protection.flags." + this.id + ".hint"; return PROTECTION_FLAGS + this.id + ".hint";
} }
/** /**
@ -246,6 +247,4 @@ public class Flag implements Comparable<Flag> {
public int compareTo(Flag o) { public int compareTo(Flag o) {
return getID().compareTo(o.getID()); return getID().compareTo(o.getID());
} }
} }

View File

@ -44,7 +44,9 @@ public class FlagBuilder {
} }
public Flag build() { public Flag build() {
return new Flag(id, icon, listener, setting, type, defaultRank, onClick, subPanel); Flag f = new Flag(id, icon, listener, type, defaultRank, onClick, subPanel);
f.setDefaultSetting(setting);
return f;
} }
/** /**

View File

@ -6,6 +6,8 @@ package us.tastybento.bskyblock.api.localization;
*/ */
public class TextVariables { public class TextVariables {
TextVariables() {}
public static final String NAME = "[name]"; public static final String NAME = "[name]";
public static final String DESCRIPTION = "[description]"; public static final String DESCRIPTION = "[description]";
public static final String NUMBER = "[number]"; public static final String NUMBER = "[number]";

View File

@ -79,51 +79,52 @@ public class FlagTest {
@Test @Test
public void testHashCode() { public void testHashCode() {
Flag flag1 = new Flag(null, null, null, false, null, 0, null, false); Flag flag1 = new Flag(null, null, null, null, 0, null, false);
Flag flag2 = new Flag(null, null, null, false, null, 0, null, false); Flag flag2 = new Flag(null, null, null, null, 0, null, false);
assertTrue(flag1.hashCode() == flag2.hashCode()); assertTrue(flag1.hashCode() == flag2.hashCode());
} }
@Test @Test
public void testFlag() { public void testFlag() {
assertNotNull(new Flag(null, null, null, false, null, 0, null, false)); assertNotNull(new Flag(null, null, null, null, 0, null, false));
} }
@Test @Test
public void testGetID() { public void testGetID() {
Flag id = new Flag("id", null, null, false, null, 0, null, false); Flag id = new Flag("id", null, null, null, 0, null, false);
assertEquals("id", id.getID()); assertEquals("id", id.getID());
} }
@Test @Test
public void testGetIcon() { public void testGetIcon() {
Flag id = new Flag("id", Material.ACACIA_DOOR, null, false, null, 0, null, false); Flag id = new Flag("id", Material.ACACIA_DOOR, null, null, 0, null, false);
assertEquals(Material.ACACIA_DOOR, id.getIcon()); assertEquals(Material.ACACIA_DOOR, id.getIcon());
} }
@Test @Test
public void testGetListener() { public void testGetListener() {
Listener l = mock(Listener.class); Listener l = mock(Listener.class);
Flag id = new Flag("id", Material.ACACIA_DOOR, l, false, null, 0, null, false); Flag id = new Flag("id", Material.ACACIA_DOOR, l, null, 0, null, false);
Optional<Listener> ol = Optional.ofNullable(l); Optional<Listener> ol = Optional.ofNullable(l);
assertEquals(ol, id.getListener()); assertEquals(ol, id.getListener());
id = new Flag("id", Material.ACACIA_DOOR, null, false, null, 0, null, false); id = new Flag("id", Material.ACACIA_DOOR, null, null, 0, null, false);
assertEquals(Optional.empty(), id.getListener()); assertEquals(Optional.empty(), id.getListener());
} }
@Test @Test
public void testIsDefaultSetting() { public void testIsDefaultSetting() {
Type type = Type.SETTING; Type type = Type.SETTING;
Flag id = new Flag("id", Material.ACACIA_DOOR, null, false, type , 0, null, false); Flag id = new Flag("id", Material.ACACIA_DOOR, null, type , 0, null, false);
assertFalse(id.isSetForWorld(mock(World.class))); assertFalse(id.isSetForWorld(mock(World.class)));
id = new Flag("id", Material.ACACIA_DOOR, null, true, type, 0, null, false); id = new Flag("id", Material.ACACIA_DOOR, null, type, 0, null, false);
id.setDefaultSetting(true);
assertTrue(id.isSetForWorld(mock(World.class))); assertTrue(id.isSetForWorld(mock(World.class)));
} }
@Test @Test
public void testSetDefaultSetting() { public void testSetDefaultSetting() {
Type type = Type.SETTING; Type type = Type.SETTING;
Flag id = new Flag("id", Material.ACACIA_DOOR, null, false, type, 0, null, false); Flag id = new Flag("id", Material.ACACIA_DOOR, null, type, 0, null, false);
assertFalse(id.isSetForWorld(mock(World.class))); assertFalse(id.isSetForWorld(mock(World.class)));
id.setDefaultSetting(true); id.setDefaultSetting(true);
assertTrue(id.isSetForWorld(mock(World.class))); assertTrue(id.isSetForWorld(mock(World.class)));
@ -135,24 +136,25 @@ public class FlagTest {
@Test @Test
public void testIsDefaultSetting_World_Setting() { public void testIsDefaultSetting_World_Setting() {
Type type = Type.WORLD_SETTING; Type type = Type.WORLD_SETTING;
Flag id = new Flag("id", Material.ACACIA_DOOR, null, false, type , 0, null, false); Flag id = new Flag("id", Material.ACACIA_DOOR, null, type , 0, null, false);
assertFalse(id.isSetForWorld(mock(World.class))); assertFalse(id.isSetForWorld(mock(World.class)));
// Default can only be set once with world settings, so use a new id for flag // Default can only be set once with world settings, so use a new id for flag
id = new Flag("id2", Material.ACACIA_DOOR, null, true, type, 0, null, false); id = new Flag("id2", Material.ACACIA_DOOR, null, type, 0, null, false);
id.setDefaultSetting(true);
assertTrue(id.isSetForWorld(mock(World.class))); assertTrue(id.isSetForWorld(mock(World.class)));
} }
@Test @Test
public void testGetType() { public void testGetType() {
Flag id = new Flag("id", Material.ACACIA_DOOR, null, false, Flag.Type.PROTECTION, 0, null, false); Flag id = new Flag("id", Material.ACACIA_DOOR, null, Flag.Type.PROTECTION, 0, null, false);
assertEquals(Flag.Type.PROTECTION,id.getType()); assertEquals(Flag.Type.PROTECTION,id.getType());
id = new Flag("id", Material.ACACIA_DOOR, null, false, Flag.Type.SETTING, 0, null, false); id = new Flag("id", Material.ACACIA_DOOR, null, Flag.Type.SETTING, 0, null, false);
assertEquals(Flag.Type.SETTING,id.getType()); assertEquals(Flag.Type.SETTING,id.getType());
} }
@Test @Test
public void testGetDefaultRank() { public void testGetDefaultRank() {
Flag id = new Flag("id", Material.ACACIA_DOOR, null, false, Flag.Type.PROTECTION, 100, null, false); Flag id = new Flag("id", Material.ACACIA_DOOR, null, Flag.Type.PROTECTION, 100, null, false);
assertEquals(100, id.getDefaultRank()); assertEquals(100, id.getDefaultRank());
} }
@ -160,18 +162,18 @@ public class FlagTest {
@Test @Test
public void testEqualsObject() { public void testEqualsObject() {
Flag flag1 = null; Flag flag1 = null;
Flag flag2 = new Flag(null, null, null, false, null, 0, null, false); Flag flag2 = new Flag(null, null, null, null, 0, null, false);
assertFalse(flag2.equals(null)); assertFalse(flag2.equals(null));
int i = 45; int i = 45;
assertFalse(flag2.equals(i)); assertFalse(flag2.equals(i));
flag1 = new Flag(null, null, null, false, null, 0, null, false); flag1 = new Flag(null, null, null, null, 0, null, false);
flag2 = flag1; flag2 = flag1;
assertTrue(flag1.equals(flag2)); assertTrue(flag1.equals(flag2));
assertTrue(flag2.equals(flag1)); assertTrue(flag2.equals(flag1));
flag2 = new Flag("id", Material.ACACIA_DOOR, null, false, Flag.Type.PROTECTION, 0, null, false); flag2 = new Flag("id", Material.ACACIA_DOOR, null, Flag.Type.PROTECTION, 0, null, false);
assertFalse(flag1.equals(flag2)); assertFalse(flag1.equals(flag2));
assertFalse(flag2.equals(flag1)); assertFalse(flag2.equals(flag1));
@ -214,7 +216,7 @@ public class FlagTest {
when(rm.getRank(Mockito.eq(RanksManager.VISITOR_RANK))).thenReturn("Visitor"); when(rm.getRank(Mockito.eq(RanksManager.VISITOR_RANK))).thenReturn("Visitor");
when(rm.getRank(Mockito.eq(RanksManager.OWNER_RANK))).thenReturn("Owner"); when(rm.getRank(Mockito.eq(RanksManager.OWNER_RANK))).thenReturn("Owner");
Flag id = new Flag("id", Material.ACACIA_DOOR, null, false, Flag.Type.PROTECTION, 0, null, false); Flag id = new Flag("id", Material.ACACIA_DOOR, null, Flag.Type.PROTECTION, 0, null, false);
PanelItem pi = id.toPanelItem(plugin, user); PanelItem pi = id.toPanelItem(plugin, user);
@ -227,14 +229,14 @@ public class FlagTest {
@Test @Test
public void testToString() { public void testToString() {
Flag id = new Flag("id", Material.ACACIA_DOOR, null, false, Flag.Type.PROTECTION, 0, null, false); Flag id = new Flag("id", Material.ACACIA_DOOR, null, Flag.Type.PROTECTION, 0, null, false);
assertEquals("Flag [id=id, icon=ACACIA_DOOR, listener=null, type=PROTECTION, defaultSetting=false, defaultRank=0, clickHandler=null, subPanel=false]", id.toString()); assertEquals("Flag [id=id, icon=ACACIA_DOOR, listener=null, type=PROTECTION, defaultSetting=false, defaultRank=0, clickHandler=null, subPanel=false]", id.toString());
} }
@Test @Test
public void testCompareTo() { public void testCompareTo() {
Flag aaa = new Flag("AAA", Material.ACACIA_DOOR, null, false, Flag.Type.PROTECTION, 0, null, false); Flag aaa = new Flag("AAA", Material.ACACIA_DOOR, null, Flag.Type.PROTECTION, 0, null, false);
Flag bbb = new Flag("BBB", Material.ACACIA_DOOR, null, false, Flag.Type.PROTECTION, 0, null, false); Flag bbb = new Flag("BBB", Material.ACACIA_DOOR, null, Flag.Type.PROTECTION, 0, null, false);
assertTrue(aaa.compareTo(bbb) < bbb.compareTo(aaa)); assertTrue(aaa.compareTo(bbb) < bbb.compareTo(aaa));
assertTrue(aaa.compareTo(aaa) == 0); assertTrue(aaa.compareTo(aaa) == 0);
} }