mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-03 06:57:39 +01:00
Reflect Banner API Changes
This commit is contained in:
parent
84d3138b21
commit
b9b3e4430e
@ -59,6 +59,7 @@ import net.ess3.nms.refl.providers.ReflServerStateProvider;
|
||||
import net.ess3.nms.refl.providers.ReflSpawnEggProvider;
|
||||
import net.ess3.nms.refl.providers.ReflSpawnerBlockProvider;
|
||||
import net.ess3.nms.refl.providers.ReflSyncCommandsProvider;
|
||||
import net.ess3.provider.BannerDataProvider;
|
||||
import net.ess3.provider.BiomeKeyProvider;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import net.ess3.provider.DamageEventProvider;
|
||||
@ -78,6 +79,7 @@ import net.ess3.provider.SpawnerBlockProvider;
|
||||
import net.ess3.provider.SpawnerItemProvider;
|
||||
import net.ess3.provider.SyncCommandsProvider;
|
||||
import net.ess3.provider.WorldInfoProvider;
|
||||
import net.ess3.provider.providers.BaseBannerDataProvider;
|
||||
import net.ess3.provider.providers.BaseLoggerProvider;
|
||||
import net.ess3.provider.providers.BasePotionDataProvider;
|
||||
import net.ess3.provider.providers.BlockMetaSpawnerItemProvider;
|
||||
@ -85,6 +87,7 @@ import net.ess3.provider.providers.BukkitMaterialTagProvider;
|
||||
import net.ess3.provider.providers.BukkitSpawnerBlockProvider;
|
||||
import net.ess3.provider.providers.FixedHeightWorldInfoProvider;
|
||||
import net.ess3.provider.providers.FlatSpawnEggProvider;
|
||||
import net.ess3.provider.providers.LegacyBannerDataProvider;
|
||||
import net.ess3.provider.providers.LegacyDamageEventProvider;
|
||||
import net.ess3.provider.providers.LegacyItemUnbreakableProvider;
|
||||
import net.ess3.provider.providers.LegacyPlayerLocaleProvider;
|
||||
@ -185,6 +188,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
private transient SpawnerBlockProvider spawnerBlockProvider;
|
||||
private transient SpawnEggProvider spawnEggProvider;
|
||||
private transient PotionMetaProvider potionMetaProvider;
|
||||
private transient BannerDataProvider bannerDataProvider;
|
||||
private transient ServerStateProvider serverStateProvider;
|
||||
private transient ContainerProvider containerProvider;
|
||||
private transient SerializationProvider serializationProvider;
|
||||
@ -411,6 +415,13 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
potionMetaProvider = new BasePotionDataProvider();
|
||||
}
|
||||
|
||||
//Banner Meta Provider
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_20_6_R01)) {
|
||||
bannerDataProvider = new BaseBannerDataProvider();
|
||||
} else {
|
||||
bannerDataProvider = new LegacyBannerDataProvider();
|
||||
}
|
||||
|
||||
//Server State Provider
|
||||
//Container Provider
|
||||
if (PaperLib.isPaper() && VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_15_2_R01)) {
|
||||
@ -1366,6 +1377,11 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
return potionMetaProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BannerDataProvider getBannerDataProvider() {
|
||||
return bannerDataProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomItemResolver getCustomItemResolver() {
|
||||
return customItemResolver;
|
||||
|
@ -9,6 +9,7 @@ import com.earth2me.essentials.perm.PermissionsHandler;
|
||||
import com.earth2me.essentials.updatecheck.UpdateChecker;
|
||||
import com.earth2me.essentials.userstorage.IUserMap;
|
||||
import net.ess3.nms.refl.providers.ReflOnlineModeProvider;
|
||||
import net.ess3.provider.BannerDataProvider;
|
||||
import net.ess3.provider.BiomeKeyProvider;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import net.ess3.provider.DamageEventProvider;
|
||||
@ -189,5 +190,7 @@ public interface IEssentials extends Plugin {
|
||||
|
||||
BiomeKeyProvider getBiomeKeyProvider();
|
||||
|
||||
BannerDataProvider getBannerDataProvider();
|
||||
|
||||
PluginCommand getPluginCommand(String cmd);
|
||||
}
|
||||
|
@ -640,7 +640,7 @@ public class MetaItemStack {
|
||||
final BannerMeta meta = (BannerMeta) stack.getItemMeta();
|
||||
if (split[0].equalsIgnoreCase("basecolor")) {
|
||||
final Color color = Color.fromRGB(Integer.parseInt(split[1]));
|
||||
meta.setBaseColor(DyeColor.getByColor(color));
|
||||
ess.getBannerDataProvider().setBaseColor(stack, DyeColor.getByColor(color));
|
||||
} else if (patternType != null) {
|
||||
final PatternType type = PatternType.getByIdentifier(split[0]);
|
||||
final DyeColor color = DyeColor.getByColor(Color.fromRGB(Integer.parseInt(split[1])));
|
||||
|
@ -317,6 +317,7 @@ public abstract class AbstractItemDb implements IConf, net.ess3.api.IItemDb {
|
||||
sb.append("basecolor:").append(basecolor).append(" ");
|
||||
}
|
||||
for (final org.bukkit.block.banner.Pattern p : shieldBannerMeta.getPatterns()) {
|
||||
//noinspection removal
|
||||
final String type = p.getPattern().getIdentifier();
|
||||
final int color = p.getColor().getColor().asRGB();
|
||||
sb.append(type).append(",").append(color).append(" ");
|
||||
@ -324,7 +325,7 @@ public abstract class AbstractItemDb implements IConf, net.ess3.api.IItemDb {
|
||||
} else {
|
||||
final BannerMeta bannerMeta = (BannerMeta) is.getItemMeta();
|
||||
if (bannerMeta != null) {
|
||||
DyeColor baseDyeColor = bannerMeta.getBaseColor();
|
||||
DyeColor baseDyeColor = ess.getBannerDataProvider().getBaseColor(is);
|
||||
if (baseDyeColor == null) {
|
||||
baseDyeColor = MaterialUtil.getColorOf(material);
|
||||
}
|
||||
@ -335,6 +336,7 @@ public abstract class AbstractItemDb implements IConf, net.ess3.api.IItemDb {
|
||||
sb.append("basecolor:").append(basecolor).append(" ");
|
||||
}
|
||||
for (final org.bukkit.block.banner.Pattern p : bannerMeta.getPatterns()) {
|
||||
//noinspection removal
|
||||
final String type = p.getPattern().getIdentifier();
|
||||
final int color = p.getColor().getColor().asRGB();
|
||||
sb.append(type).append(",").append(color).append(" ");
|
||||
|
@ -3,6 +3,9 @@ plugins {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(':providers:BaseProviders')) {
|
||||
exclude group: "org.spigotmc", module: "spigot-api"
|
||||
}
|
||||
api project(':providers:NMSReflectionProvider')
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,26 @@
|
||||
package net.ess3.provider.providers;
|
||||
|
||||
import net.ess3.provider.BannerDataProvider;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BannerMeta;
|
||||
|
||||
public class LegacyBannerDataProvider implements BannerDataProvider {
|
||||
@Override
|
||||
public DyeColor getBaseColor(ItemStack stack) {
|
||||
final BannerMeta bannerMeta = (BannerMeta) stack.getItemMeta();
|
||||
return bannerMeta.getBaseColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBaseColor(ItemStack stack, DyeColor color) {
|
||||
final BannerMeta bannerMeta = (BannerMeta) stack.getItemMeta();
|
||||
bannerMeta.setBaseColor(color);
|
||||
stack.setItemMeta(bannerMeta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Legacy Banner Meta Provider";
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package net.ess3.provider;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface BannerDataProvider extends Provider {
|
||||
DyeColor getBaseColor(ItemStack stack);
|
||||
|
||||
void setBaseColor(ItemStack stack, DyeColor color);
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package net.ess3.provider.providers;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import net.ess3.provider.BannerDataProvider;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class BaseBannerDataProvider implements BannerDataProvider {
|
||||
private final BiMap<Material, DyeColor> materialToDyeMap = HashBiMap.create();
|
||||
|
||||
public BaseBannerDataProvider() {
|
||||
materialToDyeMap.put(Material.WHITE_BANNER, DyeColor.WHITE);
|
||||
materialToDyeMap.put(Material.LIGHT_GRAY_BANNER, DyeColor.LIGHT_GRAY);
|
||||
materialToDyeMap.put(Material.GRAY_BANNER, DyeColor.GRAY);
|
||||
materialToDyeMap.put(Material.BLACK_BANNER, DyeColor.BLACK);
|
||||
materialToDyeMap.put(Material.RED_BANNER, DyeColor.RED);
|
||||
materialToDyeMap.put(Material.ORANGE_BANNER, DyeColor.ORANGE);
|
||||
materialToDyeMap.put(Material.YELLOW_BANNER, DyeColor.YELLOW);
|
||||
materialToDyeMap.put(Material.LIME_BANNER, DyeColor.LIME);
|
||||
materialToDyeMap.put(Material.GREEN_BANNER, DyeColor.GREEN);
|
||||
materialToDyeMap.put(Material.CYAN_BANNER, DyeColor.CYAN);
|
||||
materialToDyeMap.put(Material.LIGHT_BLUE_BANNER, DyeColor.LIGHT_BLUE);
|
||||
materialToDyeMap.put(Material.BLUE_BANNER, DyeColor.BLUE);
|
||||
materialToDyeMap.put(Material.PURPLE_BANNER, DyeColor.PURPLE);
|
||||
materialToDyeMap.put(Material.MAGENTA_BANNER, DyeColor.MAGENTA);
|
||||
materialToDyeMap.put(Material.PINK_BANNER, DyeColor.PINK);
|
||||
materialToDyeMap.put(Material.BROWN_BANNER, DyeColor.BROWN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DyeColor getBaseColor(ItemStack stack) {
|
||||
return materialToDyeMap.get(stack.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBaseColor(ItemStack stack, DyeColor color) {
|
||||
final Material material = materialToDyeMap.inverse().get(color);
|
||||
if (material != null) {
|
||||
stack.setType(material);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "1.20.5+ Banner Data Provider.";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user