Skip to content

Commit 5b36188

Browse files
committed
change settings to align with morphia deserialization
1 parent 1d4cc3a commit 5b36188

File tree

7 files changed

+127
-79
lines changed

7 files changed

+127
-79
lines changed

src/main/java/net/oceanias/opal/setting/OSetting.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,41 @@
99

1010
@SuppressWarnings({ "unused", "UnusedReturnValue" })
1111
@Getter
12+
@Setter
13+
@Accessors(fluent = true)
1214
public abstract class OSetting<T> {
13-
@Accessors(fluent = true)
14-
protected transient final String pretty;
15+
protected transient String name = "Unspecified Name";
1516

16-
@Accessors(fluent = true)
17-
protected transient final T initial;
17+
protected transient T initial;
1818

19-
@Accessors(fluent = true)
2019
protected transient List<String> description;
2120

22-
@Accessors(fluent = true)
2321
protected transient Material material;
2422

25-
@Setter
26-
@Accessors(fluent = true)
2723
protected T value;
2824

29-
protected OSetting(final String pretty, final T initial) {
25+
protected OSetting(final T initial) {
3026
if (initial == null) {
3127
throw new IllegalArgumentException("Error creating setting; initial value must not be null.");
3228
}
3329

34-
this.pretty = pretty;
3530
this.initial = initial;
3631

3732
value = initial;
3833
}
3934

35+
public OSetting<T> name(final String name) {
36+
this.name = name;
37+
38+
return this;
39+
}
40+
41+
public OSetting<T> initial(final T initial) {
42+
this.initial = initial;
43+
44+
return this;
45+
}
46+
4047
public OSetting<T> description(final List<String> description) {
4148
this.description = description;
4249

src/main/java/net/oceanias/opal/setting/impl/OBooleanSetting.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,22 @@
2020
@SuppressWarnings("unused")
2121
@ExtensionMethod(OCommandSenderExtension.class)
2222
public final class OBooleanSetting extends OSetting<Boolean> {
23-
public OBooleanSetting(final String pretty, final boolean initial) {
24-
super(pretty, initial);
23+
public OBooleanSetting() {
24+
super(false);
25+
}
26+
27+
@Override
28+
public OBooleanSetting name(final String name) {
29+
super.name(name);
30+
31+
return this;
32+
}
33+
34+
@Override
35+
public OBooleanSetting initial(final Boolean initial) {
36+
super.initial(initial);
37+
38+
return this;
2539
}
2640

2741
@Override
@@ -79,7 +93,7 @@ public ItemProvider getItemProvider(final Player viewer) {
7993
lore.add("&eClick &7to toggle!");
8094

8195
return new OItemBuilder(type)
82-
.setName("&e" + setting.pretty)
96+
.setName("&e" + setting.name)
8397
.addLore(lore)
8498
.hideFlags();
8599
}

src/main/java/net/oceanias/opal/setting/impl/OChoiceSetting.java

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,36 @@
1414
import xyz.xenondevs.invui.item.impl.AbstractItem;
1515
import lombok.Getter;
1616
import lombok.RequiredArgsConstructor;
17+
import lombok.Setter;
18+
import lombok.experimental.Accessors;
1719
import lombok.experimental.ExtensionMethod;
1820
import org.jetbrains.annotations.Contract;
1921
import org.jetbrains.annotations.NotNull;
2022

2123
@ExtensionMethod(OCommandSenderExtension.class)
2224
@SuppressWarnings("unused")
2325
@Getter
26+
@Setter
27+
@Accessors(fluent = true)
2428
public final class OChoiceSetting extends OSetting<String> {
25-
private transient final List<String> choices;
29+
private transient List<String> choices;
2630

27-
public OChoiceSetting(final String pretty, final String initial, final @NotNull List<String> choices) {
28-
super(pretty, initial);
31+
public OChoiceSetting() {
32+
super("Option 1");
33+
}
2934

30-
this.choices = choices;
35+
@Override
36+
public OChoiceSetting name(final String name) {
37+
super.name(name);
3138

32-
if (choices.contains(initial)) {
33-
return;
34-
}
39+
return this;
40+
}
41+
42+
@Override
43+
public OChoiceSetting initial(final String initial) {
44+
super.initial(initial);
3545

36-
throw new IllegalArgumentException("Error creating setting; initial value must be in choices list.");
46+
return this;
3747
}
3848

3949
@Override
@@ -52,8 +62,12 @@ public OChoiceSetting material(final Material material) {
5262

5363
@Override
5464
public OChoiceSetting value(final String value) {
65+
if (choices == null) {
66+
throw new IllegalArgumentException("Error updating setting; the choices list is null.");
67+
}
68+
5569
if (!choices.contains(value)) {
56-
throw new IllegalArgumentException("Error updating setting; new value must be in choices list.");
70+
throw new IllegalArgumentException("Error updating setting; new value must be in the choices list.");
5771
}
5872

5973
this.value = value;
@@ -73,6 +87,12 @@ public static class Item extends AbstractItem {
7387

7488
@Override
7589
public ItemProvider getItemProvider(final Player viewer) {
90+
final List<String> choices = setting.choices;
91+
92+
if (choices == null) {
93+
throw new IllegalArgumentException("Error constructing item; the choices list is null.");
94+
}
95+
7696
final Material material = setting.material;
7797

7898
final List<String> description = setting.description;
@@ -91,7 +111,7 @@ public ItemProvider getItemProvider(final Player viewer) {
91111
lore.add("");
92112
lore.add("&eChoices:");
93113

94-
for (final String choice : setting.choices) {
114+
for (final String choice : choices) {
95115
final String colour = choice.equals(setting.value) ? "&a" : "&7";
96116

97117
lore.add(colour + "• " + choice);
@@ -102,7 +122,7 @@ public ItemProvider getItemProvider(final Player viewer) {
102122
lore.add("&eRight-click &7to cycle backwards.");
103123

104124
return new OItemBuilder(type)
105-
.setName("&e" + setting.pretty)
125+
.setName("&e" + setting.name)
106126
.addLore(lore)
107127
.hideFlags();
108128
}

src/main/java/net/oceanias/opal/setting/impl/ODoubleSetting.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,37 @@
1313
import xyz.xenondevs.invui.item.ItemProvider;
1414
import xyz.xenondevs.invui.item.impl.AbstractItem;
1515
import lombok.Getter;
16+
import lombok.Setter;
17+
import lombok.experimental.Accessors;
1618
import lombok.experimental.ExtensionMethod;
1719
import org.jetbrains.annotations.Contract;
1820
import org.jetbrains.annotations.NotNull;
1921

2022
@SuppressWarnings("unused")
2123
@ExtensionMethod(OCommandSenderExtension.class)
2224
@Getter
25+
@Setter
26+
@Accessors(fluent = true)
2327
public final class ODoubleSetting extends OSetting<Double> {
24-
private transient final Double min;
25-
private transient final Double max;
28+
private transient Double min;
29+
private transient Double max;
2630

27-
public ODoubleSetting(final String pretty, final double initial) {
28-
this(pretty, initial, null, null);
31+
public ODoubleSetting() {
32+
super(0.0);
2933
}
3034

31-
public ODoubleSetting(final String pretty, final double initial, final Double min, final Double max) {
32-
super(pretty, initial);
35+
@Override
36+
public ODoubleSetting name(final String name) {
37+
super.name(name);
38+
39+
return this;
40+
}
3341

34-
this.min = min;
35-
this.max = max;
42+
@Override
43+
public ODoubleSetting initial(final Double initial) {
44+
super.initial(initial);
45+
46+
return this;
3647
}
3748

3849
@Override
@@ -103,27 +114,16 @@ public ItemProvider getItemProvider(final Player viewer) {
103114
}
104115

105116
lore.add("&fCurrent: &6" + String.format("%.2f", setting.value));
106-
107-
if (min != null) {
108-
lore.add("");
109-
lore.add("&fMinimum: &c" + String.format("%.2f", min));
110-
}
111-
112-
if (max != null) {
113-
if (min == null) {
114-
lore.add("");
115-
}
116-
117-
lore.add("&fMaximum: &c" + (max == Double.MAX_VALUE ? "None" : String.format("%.2f", max)));
118-
}
119-
117+
lore.add("");
118+
lore.add("&fMinimum: &c" + (max == null ? "None" : String.format("%.2f", min)));
119+
lore.add("&fMaximum: &c" + (max == null ? "None" : String.format("%.2f", max)));
120120
lore.add("");
121121
lore.add("&eLeft-click &7to add &n" + change + "&7.");
122122
lore.add("&eRight-click &7to subtract &n" + change + "&7.");
123123
lore.add("&eShift-click &7to change by &n" + (change * 10.0) + "&7.");
124124

125125
return new OItemBuilder(type)
126-
.setName("&e" + setting.pretty)
126+
.setName("&e" + setting.name)
127127
.addLore(lore)
128128
.hideFlags();
129129
}

src/main/java/net/oceanias/opal/setting/impl/OIntegerSetting.java

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import net.oceanias.opal.setting.OSetting;
44
import net.oceanias.opal.utility.builder.OItemBuilder;
55
import net.oceanias.opal.utility.extension.OCommandSenderExtension;
6-
import java.beans.Transient;
76
import java.util.ArrayList;
87
import java.util.List;
98
import org.bukkit.Material;
@@ -14,26 +13,37 @@
1413
import xyz.xenondevs.invui.item.ItemProvider;
1514
import xyz.xenondevs.invui.item.impl.AbstractItem;
1615
import lombok.Getter;
16+
import lombok.Setter;
17+
import lombok.experimental.Accessors;
1718
import lombok.experimental.ExtensionMethod;
1819
import org.jetbrains.annotations.Contract;
1920
import org.jetbrains.annotations.NotNull;
2021

2122
@SuppressWarnings("unused")
2223
@ExtensionMethod(OCommandSenderExtension.class)
2324
@Getter
25+
@Setter
26+
@Accessors(fluent = true)
2427
public final class OIntegerSetting extends OSetting<Integer> {
25-
private transient final Integer min;
26-
private transient final Integer max;
28+
private transient Integer min;
29+
private transient Integer max;
2730

28-
public OIntegerSetting(final String pretty, final int initial) {
29-
this(pretty, initial, null, null);
31+
public OIntegerSetting() {
32+
super(0);
3033
}
3134

32-
public OIntegerSetting(final String pretty, final int initial, final Integer min, final Integer max) {
33-
super(pretty, initial);
35+
@Override
36+
public OIntegerSetting name(final String name) {
37+
super.name(name);
38+
39+
return this;
40+
}
3441

35-
this.min = min;
36-
this.max = max;
42+
@Override
43+
public OIntegerSetting initial(final Integer initial) {
44+
super.initial(initial);
45+
46+
return this;
3747
}
3848

3949
@Override
@@ -104,27 +114,16 @@ public ItemProvider getItemProvider(final Player viewer) {
104114
}
105115

106116
lore.add("&fCurrent: &6" + setting.value);
107-
108-
if (min != null) {
109-
lore.add("");
110-
lore.add("&fMinimum: &c" + min);
111-
}
112-
113-
if (max != null) {
114-
if (min == null) {
115-
lore.add("");
116-
}
117-
118-
lore.add("&fMaximum: &c" + (max == Integer.MAX_VALUE ? "None" : max));
119-
}
120-
117+
lore.add("");
118+
lore.add("&fMinimum: &c" + (max == null ? "None" : min));
119+
lore.add("&fMaximum: &c" + (max == null ? "None" : max));
121120
lore.add("");
122121
lore.add("&eLeft-click &7to add &n" + change + "&7.");
123122
lore.add("&eRight-click &7to subtract &n" + change + "&7.");
124123
lore.add("&eShift-click &7to change by &n" + (change * 10) + "&7.");
125124

126125
return new OItemBuilder(type)
127-
.setName("&e" + setting.pretty)
126+
.setName("&e" + setting.name)
128127
.addLore(lore)
129128
.hideFlags();
130129
}

src/main/java/net/oceanias/opal/setting/impl/OStringSetting.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,24 @@
4040
@ExtensionMethod({ OComponentExtension.class, OCommandSenderExtension.class })
4141
@Getter
4242
public final class OStringSetting extends OSetting<String> {
43-
private transient final Integer limit;
43+
private transient Integer limit;
4444

45-
public OStringSetting(final String pretty, final String initial) {
46-
this(pretty, initial, null);
45+
public OStringSetting() {
46+
super("");
4747
}
4848

49-
public OStringSetting(final String pretty, final String initial, final Integer limit) {
50-
super(pretty, initial);
49+
@Override
50+
public OStringSetting name(final String name) {
51+
super.name(name);
52+
53+
return this;
54+
}
5155

52-
this.limit = limit;
56+
@Override
57+
public OStringSetting initial(final String initial) {
58+
super.initial(initial);
59+
60+
return this;
5361
}
5462

5563
@Override
@@ -116,7 +124,7 @@ public ItemProvider getItemProvider(final Player viewer) {
116124
lore.add("&eClick &7to change!");
117125

118126
return new OItemBuilder(type)
119-
.setName("&e" + setting.pretty)
127+
.setName("&e" + setting.name)
120128
.addLore(lore)
121129
.hideFlags();
122130
}

src/main/java/net/oceanias/opal/utility/helper/OLocationHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import org.bukkit.Location;
44
import org.jetbrains.annotations.NotNull;
55

6-
@SuppressWarnings("unused")
6+
@SuppressWarnings({ "unused", "BooleanMethodIsAlwaysInverted" })
77
public final class OLocationHelper {
88
public static boolean hasMovedExact(final @NotNull Location from, final @NotNull Location to) {
99
return from.getX() != to.getX()

0 commit comments

Comments
 (0)