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

View File

@ -44,7 +44,9 @@ public class FlagBuilder {
}
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 {
TextVariables() {}
public static final String NAME = "[name]";
public static final String DESCRIPTION = "[description]";
public static final String NUMBER = "[number]";

View File

@ -79,51 +79,52 @@ public class FlagTest {
@Test
public void testHashCode() {
Flag flag1 = new Flag(null, null, null, false, null, 0, null, false);
Flag flag2 = 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, null, 0, null, false);
assertTrue(flag1.hashCode() == flag2.hashCode());
}
@Test
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
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());
}
@Test
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());
}
@Test
public void testGetListener() {
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);
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());
}
@Test
public void testIsDefaultSetting() {
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)));
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)));
}
@Test
public void testSetDefaultSetting() {
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)));
id.setDefaultSetting(true);
assertTrue(id.isSetForWorld(mock(World.class)));
@ -135,24 +136,25 @@ public class FlagTest {
@Test
public void testIsDefaultSetting_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)));
// 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)));
}
@Test
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());
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());
}
@Test
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());
}
@ -160,18 +162,18 @@ public class FlagTest {
@Test
public void testEqualsObject() {
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));
int i = 45;
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;
assertTrue(flag1.equals(flag2));
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(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.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);
@ -227,14 +229,14 @@ public class FlagTest {
@Test
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());
}
@Test
public void testCompareTo() {
Flag aaa = new Flag("AAA", Material.ACACIA_DOOR, null, false, Flag.Type.PROTECTION, 0, null, false);
Flag bbb = new Flag("BBB", 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, Flag.Type.PROTECTION, 0, null, false);
assertTrue(aaa.compareTo(bbb) < bbb.compareTo(aaa));
assertTrue(aaa.compareTo(aaa) == 0);
}