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(); @NotNull Collection<Hologram> getHolograms();
void deleteHolograms();
/** /**
* @since 1 * @since 1
*/ */

View File

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

View File

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

View File

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