mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-24 09:01:56 +01:00
Clean up providers a bit (#3279)
This commit is contained in:
parent
9e01a1a427
commit
9f3c2683ae
@ -24,7 +24,7 @@ public class FlatSpawnEggProvider extends SpawnEggProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHumanName() {
|
||||
public String getDescription() {
|
||||
return "1.13+ flat spawn egg provider";
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ public class LegacyPotionMetaProvider extends PotionMetaProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHumanName() {
|
||||
public String getDescription() {
|
||||
return "legacy potion meta provider";
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ public class LegacySpawnEggProvider extends SpawnEggProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHumanName() {
|
||||
public String getDescription() {
|
||||
return "legacy item data provider";
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ public class LegacySpawnerProvider extends SpawnerProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHumanName() {
|
||||
public String getDescription() {
|
||||
return "legacy item data provider";
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public abstract class SpawnEggProvider implements Provider {
|
||||
public abstract ItemStack createEggItem(EntityType type) throws IllegalArgumentException;
|
||||
|
||||
public abstract EntityType getSpawnedType(ItemStack eggItem) throws IllegalArgumentException;
|
||||
|
||||
@Override
|
||||
|
@ -25,6 +25,7 @@ public abstract class SpawnerProvider implements Provider {
|
||||
.build();
|
||||
|
||||
public abstract ItemStack setEntityType(ItemStack is, EntityType type) throws IllegalArgumentException;
|
||||
|
||||
public abstract EntityType getEntityType(ItemStack is) throws IllegalArgumentException;
|
||||
|
||||
@Override
|
||||
|
@ -3,5 +3,5 @@ package net.ess3.providers;
|
||||
public interface Provider {
|
||||
boolean tryProvider();
|
||||
|
||||
String getHumanName();
|
||||
String getDescription();
|
||||
}
|
||||
|
@ -5,25 +5,24 @@ import java.util.logging.Logger;
|
||||
public class ProviderFactory<T extends Provider> {
|
||||
private Logger logger;
|
||||
private String providerType;
|
||||
private Iterable<Class <? extends T>> availableProviders;
|
||||
private Iterable<Class<? extends T>> providers;
|
||||
|
||||
public ProviderFactory(Logger logger, Iterable<Class <? extends T>> availableProviders, String providerType) {
|
||||
public ProviderFactory(Logger logger, Iterable<Class<? extends T>> providers, String providerType) {
|
||||
this.logger = logger;
|
||||
this.providerType = providerType;
|
||||
this.availableProviders = availableProviders;
|
||||
this.providers = providers;
|
||||
}
|
||||
|
||||
public T getProvider() {
|
||||
T finalProvider = null;
|
||||
for (Class<? extends T> providerClass : availableProviders) {
|
||||
finalProvider = loadProvider(providerClass);
|
||||
if (finalProvider != null && finalProvider.tryProvider()) {
|
||||
break;
|
||||
for (Class<? extends T> providerClass : providers) {
|
||||
T provider = loadProvider(providerClass);
|
||||
if (provider != null && provider.tryProvider()) {
|
||||
logger.info("Using " + provider.getDescription() + " as " + providerType + " provider.");
|
||||
return provider;
|
||||
}
|
||||
}
|
||||
assert finalProvider != null;
|
||||
logger.info("Using " + finalProvider.getHumanName() + " as " + providerType + " provider.");
|
||||
return finalProvider;
|
||||
logger.severe("The " + providerType + " provider failed to load! Some parts of Essentials may not function correctly.");
|
||||
return null;
|
||||
}
|
||||
|
||||
private T loadProvider(Class<? extends T> providerClass) {
|
||||
|
@ -30,7 +30,7 @@ public class ReflSpawnEggProvider extends SpawnEggProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHumanName() {
|
||||
public String getDescription() {
|
||||
return "Reflection based provider";
|
||||
}
|
||||
}
|
||||
|
@ -290,8 +290,8 @@ public class ReflUtil {
|
||||
}
|
||||
NMSVersion that = (NMSVersion) o;
|
||||
return major == that.major &&
|
||||
minor == that.minor &&
|
||||
release == that.release;
|
||||
minor == that.minor &&
|
||||
release == that.release;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -301,7 +301,7 @@ public class ReflUtil {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "v" + major + "_" + minor + "_R" + release;
|
||||
return "v" + major + "_" + minor + "_R" + release;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ASkyBlock. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************
|
||||
*/
|
||||
*/
|
||||
package net.ess3.nms.refl;
|
||||
|
||||
import org.bukkit.Material;
|
||||
@ -152,4 +152,3 @@ public class SpawnEggRefl {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ public class BasePotionDataProvider extends PotionMetaProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHumanName() {
|
||||
public String getDescription() {
|
||||
return "1.9+ BasePotionData provider";
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ public class BlockMetaSpawnerProvider extends SpawnerProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHumanName() {
|
||||
public String getDescription() {
|
||||
return "1.8.3+ BlockStateMeta provider";
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user