Skip to content

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
imDMK committed Aug 27, 2023
1 parent a71b94c commit b211631
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
8 changes: 6 additions & 2 deletions src/main/java/com/github/imdmk/spenttime/SpentTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,12 @@ public SpentTime(Plugin plugin) {

/* PlaceholderAPI */
if (this.server.getPluginManager().getPlugin("PlaceholderAPI") != null) {
this.placeholderRegistry = new PlaceholderRegistry(plugin.getDescription());
this.placeholderRegistry.registerAll();
this.placeholderRegistry = new PlaceholderRegistry();

Stream.of(
new SpentTimeFormattedPlaceholder(plugin.getDescription()),
new SpentTimePlaceholder(plugin.getDescription())
).forEach(this.placeholderRegistry::register);
}

/* Update check */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package com.github.imdmk.spenttime.placeholder;

import com.github.imdmk.spenttime.placeholder.implementation.SpentTimeFormattedPlaceholder;
import com.github.imdmk.spenttime.placeholder.implementation.SpentTimePlaceholder;
import org.bukkit.plugin.PluginDescriptionFile;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;

import java.util.HashSet;
import java.util.Set;

public class PlaceholderRegistry {

private final SpentTimeFormattedPlaceholder spentTimeFormattedPlaceholder;
private final SpentTimePlaceholder spentTimePlaceholder;
private final Set<PlaceholderExpansion> placeholderExpansions = new HashSet<>();

public void register(PlaceholderExpansion placeholder) {
this.placeholderExpansions.add(placeholder);

public PlaceholderRegistry(PluginDescriptionFile pluginDescriptionFile) {
this.spentTimeFormattedPlaceholder = new SpentTimeFormattedPlaceholder(pluginDescriptionFile);
this.spentTimePlaceholder = new SpentTimePlaceholder(pluginDescriptionFile);
placeholder.register();
}

public void registerAll() {
this.spentTimeFormattedPlaceholder.register();
this.spentTimePlaceholder.register();
public void unregister(PlaceholderExpansion placeholderExpansion) {
this.placeholderExpansions.remove(placeholderExpansion);

placeholderExpansion.unregister();
}

public void unregisterAll() {
this.spentTimeFormattedPlaceholder.unregister();
this.spentTimePlaceholder.unregister();
this.placeholderExpansions.forEach(this::unregister);
}
}

0 comments on commit b211631

Please sign in to comment.