mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-22 17:18:37 +01:00
Restore 1.8 compatibility
This commit is contained in:
parent
dcb14170b9
commit
ec1215b227
@ -87,7 +87,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ess3</groupId>
|
||||
<artifactId>BlockMetaProvider</artifactId>
|
||||
<artifactId>UpdatedMetaProvider</artifactId>
|
||||
<version>2.0.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
@ -34,9 +34,12 @@ import com.google.common.collect.Iterables;
|
||||
import net.ess3.api.*;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.ISettings;
|
||||
import net.ess3.nms.PotionMetaProvider;
|
||||
import net.ess3.nms.SpawnEggProvider;
|
||||
import net.ess3.nms.SpawnerProvider;
|
||||
import net.ess3.nms.blockmeta.BlockMetaSpawnerProvider;
|
||||
import net.ess3.nms.legacy.LegacyPotionMetaProvider;
|
||||
import net.ess3.nms.updatedmeta.BasePotionDataProvider;
|
||||
import net.ess3.nms.updatedmeta.BlockMetaSpawnerProvider;
|
||||
import net.ess3.nms.legacy.LegacySpawnEggProvider;
|
||||
import net.ess3.nms.legacy.LegacySpawnerProvider;
|
||||
import net.ess3.nms.v1_8_R1.v1_8_R1SpawnerProvider;
|
||||
@ -102,6 +105,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
private transient Method oldGetOnlinePlayers;
|
||||
private transient SpawnerProvider spawnerProvider;
|
||||
private transient SpawnEggProvider spawnEggProvider;
|
||||
private transient PotionMetaProvider potionMetaProvider;
|
||||
|
||||
public Essentials() {
|
||||
}
|
||||
@ -213,6 +217,11 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
v1_9_R1SpawnEggProvider.class,
|
||||
LegacySpawnEggProvider.class
|
||||
), "spawn egg").getProvider();
|
||||
potionMetaProvider = new ProviderFactory<>(getLogger(),
|
||||
Arrays.asList(
|
||||
BasePotionDataProvider.class,
|
||||
LegacyPotionMetaProvider.class
|
||||
), "potion meta").getProvider();
|
||||
reload();
|
||||
} catch (YAMLException exception) {
|
||||
if (pm.getPlugin("EssentialsUpdate") != null) {
|
||||
@ -790,6 +799,11 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
return spawnEggProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PotionMetaProvider getPotionMetaProvider() {
|
||||
return potionMetaProvider;
|
||||
}
|
||||
|
||||
private static class EssentialsWorldListener implements Listener, Runnable {
|
||||
private transient final IEssentials ess;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.earth2me.essentials.utils.PotionMetaUtil;
|
||||
import net.ess3.nms.updatedmeta.BasePotionDataProvider;
|
||||
import com.earth2me.essentials.utils.StringUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -153,7 +153,7 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb {
|
||||
}
|
||||
retval = ess.getSpawnEggProvider().createEggItem(type);
|
||||
} else if (mat == Material.POTION) {
|
||||
retval = PotionMetaUtil.createPotionItem(metaData);
|
||||
retval = ess.getPotionMetaProvider().createPotionItem(metaData);
|
||||
} else {
|
||||
retval.setDurability(metaData);
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
package net.ess3.api;
|
||||
|
||||
import net.ess3.nms.PotionMetaProvider;
|
||||
import net.ess3.nms.SpawnEggProvider;
|
||||
|
||||
public interface IEssentials extends com.earth2me.essentials.IEssentials {
|
||||
|
||||
SpawnEggProvider getSpawnEggProvider();
|
||||
|
||||
PotionMetaProvider getPotionMetaProvider();
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package net.ess3.nms.legacy;
|
||||
|
||||
import net.ess3.nms.PotionMetaProvider;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class LegacyPotionMetaProvider extends PotionMetaProvider {
|
||||
@Override
|
||||
public ItemStack createPotionItem(int effectId) {
|
||||
ItemStack potion = new ItemStack(Material.POTION, 1);
|
||||
potion.setDurability((short) effectId);
|
||||
return potion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHumanName() {
|
||||
return "legacy potion meta provider";
|
||||
}
|
||||
}
|
18
nms/NMSProvider/src/net/ess3/nms/PotionMetaProvider.java
Normal file
18
nms/NMSProvider/src/net/ess3/nms/PotionMetaProvider.java
Normal file
@ -0,0 +1,18 @@
|
||||
package net.ess3.nms;
|
||||
|
||||
import net.ess3.providers.Provider;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public abstract class PotionMetaProvider implements Provider {
|
||||
public abstract ItemStack createPotionItem(int effectId);
|
||||
|
||||
@Override
|
||||
public boolean tryProvider() {
|
||||
try {
|
||||
createPotionItem(16420); // Poison Level II Splash
|
||||
return true;
|
||||
} catch (Throwable t) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>BlockMetaProvider</artifactId>
|
||||
<artifactId>UpdatedMetaProvider</artifactId>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
@ -1,16 +1,16 @@
|
||||
package com.earth2me.essentials.utils;
|
||||
package net.ess3.nms.updatedmeta;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.ess3.nms.PotionMetaProvider;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.potion.Potion;
|
||||
import org.bukkit.potion.PotionData;
|
||||
import org.bukkit.potion.PotionType;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class PotionMetaUtil {
|
||||
public class BasePotionDataProvider extends PotionMetaProvider {
|
||||
private static Map<Integer, PotionType> damageValueToType = ImmutableMap.<Integer, PotionType>builder()
|
||||
.put(1, PotionType.REGEN)
|
||||
.put(2, PotionType.SPEED)
|
||||
@ -28,7 +28,7 @@ public class PotionMetaUtil {
|
||||
.put(14, PotionType.INVISIBILITY)
|
||||
.build();
|
||||
|
||||
public static ItemStack createPotionItem(int effectId) throws IllegalArgumentException {
|
||||
public ItemStack createPotionItem(int effectId) throws IllegalArgumentException {
|
||||
int damageValue = getBit(effectId, 0) +
|
||||
2 * getBit(effectId, 1) +
|
||||
4 * getBit(effectId, 2) +
|
||||
@ -52,7 +52,7 @@ public class PotionMetaUtil {
|
||||
|
||||
PotionMeta meta = (PotionMeta) potion.getItemMeta();
|
||||
PotionData data = new PotionData(type, extended, upgraded);
|
||||
meta.setBasePotionData(data);
|
||||
meta.setBasePotionData(data); // this method is exclusive to recent 1.9+
|
||||
potion.setItemMeta(meta);
|
||||
|
||||
return potion;
|
||||
@ -61,4 +61,9 @@ public class PotionMetaUtil {
|
||||
private static int getBit(int n, int k) {
|
||||
return (n >> k) & 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHumanName() {
|
||||
return "1.9+ BasePotionData provider";
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package net.ess3.nms.blockmeta;
|
||||
package net.ess3.nms.updatedmeta;
|
||||
|
||||
import net.ess3.nms.SpawnerProvider;
|
||||
import org.bukkit.block.BlockState;
|
2
pom.xml
2
pom.xml
@ -43,7 +43,7 @@
|
||||
<module>EssentialsXMPP</module>
|
||||
<module>EssentialsGroupManager</module>
|
||||
<module>nms/NMSProvider</module>
|
||||
<module>nms/BlockMetaProvider</module>
|
||||
<module>nms/UpdatedMetaProvider</module>
|
||||
<module>nms/1_8_R1Provider</module>
|
||||
<module>nms/1_8_R2Provider</module>
|
||||
<module>nms/LegacyProvider</module>
|
||||
|
Loading…
Reference in New Issue
Block a user