mirror of
https://github.com/ashhhleyyy/player-pronouns.git
synced 2024-11-23 17:48:09 +00:00
Small amount of code cleanup
This commit is contained in:
parent
02dab5525d
commit
ef01f32989
2 changed files with 28 additions and 29 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -31,3 +31,7 @@ bin/
|
||||||
# fabric
|
# fabric
|
||||||
|
|
||||||
run/
|
run/
|
||||||
|
|
||||||
|
# crashes
|
||||||
|
|
||||||
|
*.hprof
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package io.github.ashisbored.playerpronouns;
|
package io.github.ashisbored.playerpronouns;
|
||||||
|
|
||||||
import eu.pb4.placeholders.PlaceholderAPI;
|
import eu.pb4.placeholders.PlaceholderAPI;
|
||||||
|
import eu.pb4.placeholders.PlaceholderContext;
|
||||||
import eu.pb4.placeholders.PlaceholderResult;
|
import eu.pb4.placeholders.PlaceholderResult;
|
||||||
import io.github.ashisbored.playerpronouns.command.PronounsCommand;
|
import io.github.ashisbored.playerpronouns.command.PronounsCommand;
|
||||||
import io.github.ashisbored.playerpronouns.data.PronounDatabase;
|
import io.github.ashisbored.playerpronouns.data.PronounDatabase;
|
||||||
|
@ -62,37 +63,31 @@ public class PlayerPronouns implements ModInitializer {
|
||||||
PronounsCommand.register(dispatcher);
|
PronounsCommand.register(dispatcher);
|
||||||
});
|
});
|
||||||
|
|
||||||
PlaceholderAPI.register(new Identifier(MOD_ID, "pronouns"), ctx -> {
|
PlaceholderAPI.register(new Identifier(MOD_ID, "pronouns"), ctx ->
|
||||||
if (!ctx.hasPlayer()) {
|
PlayerPronouns.fromContext(ctx, false));
|
||||||
return PlaceholderResult.invalid("missing player");
|
|
||||||
}
|
|
||||||
String defaultMessage = ctx.hasArgument() ? ctx.getArgument() : config.getDefaultPlaceholder();
|
|
||||||
ServerPlayerEntity player = ctx.getPlayer();
|
|
||||||
if (pronounDatabase == null) {
|
|
||||||
return PlaceholderResult.value(defaultMessage);
|
|
||||||
}
|
|
||||||
Pronouns pronouns = pronounDatabase.get(player.getUuid());
|
|
||||||
if (pronouns == null) {
|
|
||||||
return PlaceholderResult.value(defaultMessage);
|
|
||||||
}
|
|
||||||
return PlaceholderResult.value(pronouns.formatted());
|
|
||||||
});
|
|
||||||
|
|
||||||
PlaceholderAPI.register(new Identifier(MOD_ID, "raw_pronouns"), ctx -> {
|
PlaceholderAPI.register(new Identifier(MOD_ID, "raw_pronouns"), ctx ->
|
||||||
if (!ctx.hasPlayer()) {
|
PlayerPronouns.fromContext(ctx, false));
|
||||||
return PlaceholderResult.invalid("missing player");
|
}
|
||||||
}
|
|
||||||
String defaultMessage = ctx.hasArgument() ? ctx.getArgument() : config.getDefaultPlaceholder();
|
private static PlaceholderResult fromContext(PlaceholderContext ctx, boolean formatted) {
|
||||||
ServerPlayerEntity player = ctx.getPlayer();
|
if (!ctx.hasPlayer()) {
|
||||||
if (pronounDatabase == null) {
|
return PlaceholderResult.invalid("missing player");
|
||||||
return PlaceholderResult.value(defaultMessage);
|
}
|
||||||
}
|
String defaultMessage = ctx.hasArgument() ? ctx.getArgument() : config.getDefaultPlaceholder();
|
||||||
Pronouns pronouns = pronounDatabase.get(player.getUuid());
|
ServerPlayerEntity player = ctx.getPlayer();
|
||||||
if (pronouns == null) {
|
if (pronounDatabase == null) {
|
||||||
return PlaceholderResult.value(defaultMessage);
|
return PlaceholderResult.value(defaultMessage);
|
||||||
}
|
}
|
||||||
|
Pronouns pronouns = pronounDatabase.get(player.getUuid());
|
||||||
|
if (pronouns == null) {
|
||||||
|
return PlaceholderResult.value(defaultMessage);
|
||||||
|
}
|
||||||
|
if (formatted) {
|
||||||
|
return PlaceholderResult.value(pronouns.formatted());
|
||||||
|
} else {
|
||||||
return PlaceholderResult.value(pronouns.raw());
|
return PlaceholderResult.value(pronouns.raw());
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reloadConfig() {
|
public static void reloadConfig() {
|
||||||
|
|
Loading…
Reference in a new issue