Skip to content

Commit

Permalink
Ensure thread safety for unloading
Browse files Browse the repository at this point in the history
  • Loading branch information
APickledWalrus committed May 26, 2024
1 parent 539f152 commit 0b8afb7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Patrick Miller
Copyright (c) 2024 Patrick Miller

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,24 @@ public boolean load() {
if (Bukkit.isPrimaryThread()) {
registry.registerPlaceholder(plugin, placeholder, this);
} else {
Bukkit.getScheduler().runTask(SkriptPlaceholders.getInstance(), () -> {
registry.registerPlaceholder(plugin, placeholder, this);
});
Bukkit.getScheduler().runTask(SkriptPlaceholders.getInstance(),
() -> registry.registerPlaceholder(plugin, placeholder, this)
);
}

return true;
}

@Override
public void unload() {
registry.unregisterPlaceholder(plugin, placeholder, this);
// to be safe, ensure unregistering is done on the main thread too
if (Bukkit.isPrimaryThread()) {
registry.unregisterPlaceholder(plugin, placeholder, this);
} else {
Bukkit.getScheduler().runTask(SkriptPlaceholders.getInstance(),
() -> registry.unregisterPlaceholder(plugin, placeholder, this)
);
}
}

@Override
Expand Down

0 comments on commit 0b8afb7

Please sign in to comment.