Add deleteHolograms method to API

This commit is contained in:
filoghost 2021-08-23 14:09:51 +02:00
parent 087105ccd1
commit ca5644153e
4 changed files with 23 additions and 4 deletions

View File

@ -72,6 +72,8 @@ public interface HolographicDisplaysAPI {
*/
@NotNull Collection<Hologram> getHolograms();
void deleteHolograms();
/**
* @since 1
*/

View File

@ -163,7 +163,7 @@ public class HolographicDisplays extends FCommonsPlugin {
}
public void load(ErrorCollector errorCollector) {
internalHologramManager.clearAll();
internalHologramManager.deleteHolograms();
configManager.reloadStaticReplacements(errorCollector);
configManager.reloadMainSettings(errorCollector);

View File

@ -71,6 +71,11 @@ class DefaultHolographicDisplaysAPI implements HolographicDisplaysAPI {
return apiHologramManager.getHologramsByPlugin(plugin);
}
@Override
public void deleteHolograms() {
apiHologramManager.deleteHologramsIf(apiHologram -> apiHologram.getCreatorPlugin().equals(plugin));
}
@Override
public @NotNull Collection<String> getRegisteredPlaceholders() {
return placeholderRegistry.getRegisteredIdentifiers(plugin);

View File

@ -12,6 +12,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.function.Predicate;
public abstract class BaseHologramManager<H extends BaseHologram> {
@ -22,16 +23,27 @@ public abstract class BaseHologramManager<H extends BaseHologram> {
holograms.add(hologram);
}
public List<H> getHolograms() {
return unmodifiableHologramsView;
}
public void deleteHologram(H hologram) {
hologram.setDeleted();
holograms.remove(hologram);
}
public List<H> getHolograms() {
return unmodifiableHologramsView;
public void deleteHologramsIf(Predicate<H> condition) {
Iterator<H> iterator = holograms.iterator();
while (iterator.hasNext()) {
H hologram = iterator.next();
if (condition.test(hologram)) {
iterator.remove();
hologram.setDeleted();
}
}
}
public void clearAll() {
public void deleteHolograms() {
Iterator<H> iterator = holograms.iterator();
while (iterator.hasNext()) {
H hologram = iterator.next();