Make sure all instances are CloseablePluginResults

This commit is contained in:
Frank van der Heijden 2021-12-20 18:17:10 +01:00
parent 37823c34c5
commit bfce868145
No known key found for this signature in database
GPG key ID: B808721C2DD5B5B8

View file

@ -2,16 +2,24 @@ package net.frankheijden.serverutils.common.entities.results;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.List; import java.util.List;
public class CloseablePluginResults<T> extends PluginResults<T> implements Closeable { public class CloseablePluginResults<T> extends PluginResults<T> implements Closeable {
@Override @Override
public CloseablePluginResults<T> addResult(PluginResult<T> pluginResult) { public CloseablePluginResults<T> addResult(PluginResult<T> pluginResult) {
if (!(pluginResult instanceof CloseablePluginResult)) { if (pluginResult instanceof CloseablePluginResult) {
throw new IllegalArgumentException("Not an instance of CloseablePluginResult: " + pluginResult);
}
results.add(pluginResult); results.add(pluginResult);
} else {
results.add(new CloseablePluginResult<>(
pluginResult.getPluginId(),
pluginResult.getPlugin(),
pluginResult.getResult(),
Collections.emptyList(),
pluginResult.getPlaceholders()
));
}
return this; return this;
} }
@ -28,10 +36,8 @@ public class CloseablePluginResults<T> extends PluginResults<T> implements Close
} }
@Override @Override
protected CloseablePluginResults<T> addResult(String pluginId, T plugin, Result result, String... placeholders protected CloseablePluginResults<T> addResult(String pluginId, T plugin, Result result, String... placeholders) {
) { return addResult(new CloseablePluginResult<>(pluginId, plugin, result, Collections.emptyList(), placeholders));
super.addResult(pluginId, plugin, result, placeholders);
return this;
} }
public CloseablePluginResults<T> addResult( public CloseablePluginResults<T> addResult(