Skip to content

Commit

Permalink
Add validity check for MVdW Listener
Browse files Browse the repository at this point in the history
  • Loading branch information
APickledWalrus committed May 24, 2024
1 parent fef82b9 commit 1801dcb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class MVdWPlaceholderAPIListener implements PlaceholderListener {
private final String placeholder;

private final Set<PlaceholderEvaluator> evaluators = new HashSet<>();
private boolean isInvalid;

public MVdWPlaceholderAPIListener(Plugin plugin, String placeholder) {
this.plugin = plugin;
Expand All @@ -25,6 +26,9 @@ public MVdWPlaceholderAPIListener(Plugin plugin, String placeholder) {
@Override
public void registerListener() {
PlaceholderAPI.registerPlaceholder(plugin, placeholder, event -> {
if (isInvalid) { // true when the listener has been unregistered
return null;
}
OfflinePlayer player = event.getPlayer();
if (player == null) { // this is for an actual offline player
player = event.getOfflinePlayer();
Expand All @@ -41,7 +45,7 @@ public void registerListener() {

@Override
public void unregisterListener() {
// TODO determine if this is possible
isInvalid = true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"\t# Placeholder is \"{skriptplaceholders_author}\"",
"\tset the result to \"APickledWalrus\""
})
@Since("1.0.0, 1.3.0 (MVdWPlaceholderAPI support)")
@Since("1.0.0, 1.3.0 (MVdWPlaceholderAPI support), 1.7.0 (relational placeholder support)")
public class StructPlaceholder extends Structure implements PlaceholderEvaluator {

static {
Expand Down

0 comments on commit 1801dcb

Please sign in to comment.