From 4114c36c8c7d8c19f10e785b30aeabb18d2d9875 Mon Sep 17 00:00:00 2001 From: Josh Larson Date: Fri, 8 Feb 2019 08:27:54 -0600 Subject: [PATCH] Fixed bug in prose packet object parsing and added a convenience constructor for string ids --- .../data/encodables/oob/ProsePackage.java | 91 +++++++++++-------- 1 file changed, 52 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/projectswg/common/data/encodables/oob/ProsePackage.java b/src/main/java/com/projectswg/common/data/encodables/oob/ProsePackage.java index 47ec6bf..1c0ee45 100644 --- a/src/main/java/com/projectswg/common/data/encodables/oob/ProsePackage.java +++ b/src/main/java/com/projectswg/common/data/encodables/oob/ProsePackage.java @@ -82,6 +82,19 @@ public class ProsePackage implements OutOfBandData { setProse(proseKey, prose); } + /** + * Creates a new ProsePackage with multiple defined parameters. The first Object must be the prose key, followed by the keys value, and so on. If you're only setting 1 parameter, you should use the ProsePackage(key, prose) constructor instead.
+ *
+ * Example:
+ *      ProsePackage("StringId", new StringId("base_player", "prose_deposit_success"), "DI", 500) + * + * @param objects Key followed by the value. Can either be STF, TU, TT, TO, or DI. + */ + public ProsePackage(StringId stringId, Object ... objects) { + this(objects); + setStringId(stringId); + } + /** * Creates a new ProsePackage with multiple defined parameters. The first Object must be the prose key, followed by the keys value, and so on. If you're only setting 1 parameter, you should use the ProsePackage(key, prose) constructor instead.
*
@@ -93,7 +106,7 @@ public class ProsePackage implements OutOfBandData { public ProsePackage(Object ... objects) { this(); int length = objects.length; - for (int i = 0; i < length - 1; i++) { + for (int i = 0; i < length - 1; i+=2) { if (!(objects[i] instanceof String)) // Make sure that it's a key, chance of it being a customString though continue; @@ -101,6 +114,44 @@ public class ProsePackage implements OutOfBandData { } } + public final void setStringId(Object prose) { + if (prose instanceof StringId) { + base = (StringId) prose; + } else if (prose instanceof String) { + if (((String) prose).startsWith("@")) { + base = new StringId((String) prose); + } else { + Log.w("The base STF cannot be a custom string!"); + } + } else { + Log.w("The base STF must be either a Stf or a String! Received class: " + prose.getClass().getName()); + } + } + + public final void setTU(Object prose) { + setProse(actor, prose); + } + + public final void setTT(Object prose) { + setProse(target, prose); + } + + public final void setTO(Object prose) { + setProse(other, prose); + } + + public final void setDI(Integer prose) { + di = prose; + } + + public final void setDF(Float prose) { + df = prose; + } + + public final void setGrammarFlag(boolean useGrammar) { + grammarFlag = useGrammar; + } + private void setProse(String key, Object prose) { switch (key) { case "StringId": @@ -135,44 +186,6 @@ public class ProsePackage implements OutOfBandData { } } - public void setStringId(Object prose) { - if (prose instanceof StringId) { - base = (StringId) prose; - } else if (prose instanceof String) { - if (((String) prose).startsWith("@")) { - base = new StringId((String) prose); - } else { - Log.w("The base STF cannot be a custom string!"); - } - } else { - Log.w("The base STF must be either a Stf or a String! Received class: " + prose.getClass().getName()); - } - } - - public void setTU(Object prose) { - setProse(actor, prose); - } - - public void setTT(Object prose) { - setProse(target, prose); - } - - public void setTO(Object prose) { - setProse(other, prose); - } - - public void setDI(Integer prose) { - di = prose; - } - - public void setDF(Float prose) { - df = prose; - } - - public void setGrammarFlag(boolean useGrammar) { - grammarFlag = useGrammar; - } - private void setProse(Prose prose, Object obj) { if (obj instanceof StringId) { prose.setStringId((StringId) obj);