mirror of
https://bitbucket.org/projectswg/pswgcommon.git
synced 2026-01-16 23:04:32 -05:00
Fixed bug in prose packet object parsing and added a convenience constructor for string ids
This commit is contained in:
@@ -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. <br>
|
||||
* <br>
|
||||
* Example: <br>
|
||||
*      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. <br>
|
||||
* <br>
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user