mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-08 17:38:20 +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";
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class ReflUtil {
|
||||
}
|
||||
return nmsVersion;
|
||||
}
|
||||
|
||||
|
||||
public static NMSVersion getNmsVersionObject() {
|
||||
if (nmsVersionObject == null) {
|
||||
nmsVersionObject = NMSVersion.fromString(getNMSVersion());
|
||||
@ -224,7 +224,7 @@ public class ReflUtil {
|
||||
|
||||
/**
|
||||
* https://gist.github.com/SupaHam/dad1db6406596c5f8e4b221ff473831c
|
||||
*
|
||||
*
|
||||
* @author SupaHam (<a href="https://github.com/SupaHam">https://github.com/SupaHam</a>)
|
||||
*/
|
||||
public static class NMSVersion implements Comparable<NMSVersion> {
|
||||
@ -232,7 +232,7 @@ public class ReflUtil {
|
||||
private final int major;
|
||||
private final int minor;
|
||||
private final int release;
|
||||
|
||||
|
||||
public static NMSVersion fromString(String string) {
|
||||
Preconditions.checkNotNull(string, "string cannot be null.");
|
||||
Matcher matcher = VERSION_PATTERN.matcher(string);
|
||||
@ -251,19 +251,19 @@ public class ReflUtil {
|
||||
this.minor = minor;
|
||||
this.release = release;
|
||||
}
|
||||
|
||||
|
||||
public boolean isHigherThan(NMSVersion o) {
|
||||
return compareTo(o) > 0;
|
||||
}
|
||||
|
||||
|
||||
public boolean isHigherThanOrEqualTo(NMSVersion o) {
|
||||
return compareTo(o) >= 0;
|
||||
}
|
||||
|
||||
|
||||
public boolean isLowerThan(NMSVersion o) {
|
||||
return compareTo(o) < 0;
|
||||
}
|
||||
|
||||
|
||||
public boolean isLowerThanOrEqualTo(NMSVersion o) {
|
||||
return compareTo(o) <= 0;
|
||||
}
|
||||
@ -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;
|
||||
@ -95,7 +95,7 @@ public class SpawnEggRefl {
|
||||
}
|
||||
Object id = NBTTagCompoundConstructor.newInstance();
|
||||
Method tagSetString = ReflUtil.getMethodCached(NBTTagCompoundClass, "setString", String.class, String.class);
|
||||
|
||||
|
||||
String idString = type.getName();
|
||||
if (ReflUtil.getNmsVersionObject().isHigherThanOrEqualTo(ReflUtil.V1_11_R1)) {
|
||||
// 1.11 requires domain prefix of minecraft.
|
||||
@ -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