mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-03 06:57:39 +01:00
Support custom biomes in random teleport excluded biome list (#5703)
This commit is contained in:
parent
52a638f18f
commit
bd8c792fa4
@ -59,6 +59,7 @@ import net.ess3.nms.refl.providers.ReflServerStateProvider;
|
|||||||
import net.ess3.nms.refl.providers.ReflSpawnEggProvider;
|
import net.ess3.nms.refl.providers.ReflSpawnEggProvider;
|
||||||
import net.ess3.nms.refl.providers.ReflSpawnerBlockProvider;
|
import net.ess3.nms.refl.providers.ReflSpawnerBlockProvider;
|
||||||
import net.ess3.nms.refl.providers.ReflSyncCommandsProvider;
|
import net.ess3.nms.refl.providers.ReflSyncCommandsProvider;
|
||||||
|
import net.ess3.provider.BiomeKeyProvider;
|
||||||
import net.ess3.provider.ContainerProvider;
|
import net.ess3.provider.ContainerProvider;
|
||||||
import net.ess3.provider.DamageEventProvider;
|
import net.ess3.provider.DamageEventProvider;
|
||||||
import net.ess3.provider.FormattedCommandAliasProvider;
|
import net.ess3.provider.FormattedCommandAliasProvider;
|
||||||
@ -95,6 +96,7 @@ import net.ess3.provider.providers.ModernItemUnbreakableProvider;
|
|||||||
import net.ess3.provider.providers.ModernPersistentDataProvider;
|
import net.ess3.provider.providers.ModernPersistentDataProvider;
|
||||||
import net.ess3.provider.providers.ModernPlayerLocaleProvider;
|
import net.ess3.provider.providers.ModernPlayerLocaleProvider;
|
||||||
import net.ess3.provider.providers.ModernSignDataProvider;
|
import net.ess3.provider.providers.ModernSignDataProvider;
|
||||||
|
import net.ess3.provider.providers.PaperBiomeKeyProvider;
|
||||||
import net.ess3.provider.providers.PaperContainerProvider;
|
import net.ess3.provider.providers.PaperContainerProvider;
|
||||||
import net.ess3.provider.providers.PaperKnownCommandsProvider;
|
import net.ess3.provider.providers.PaperKnownCommandsProvider;
|
||||||
import net.ess3.provider.providers.PaperMaterialTagProvider;
|
import net.ess3.provider.providers.PaperMaterialTagProvider;
|
||||||
@ -197,6 +199,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
|||||||
private transient PlayerLocaleProvider playerLocaleProvider;
|
private transient PlayerLocaleProvider playerLocaleProvider;
|
||||||
private transient SignDataProvider signDataProvider;
|
private transient SignDataProvider signDataProvider;
|
||||||
private transient DamageEventProvider damageEventProvider;
|
private transient DamageEventProvider damageEventProvider;
|
||||||
|
private transient BiomeKeyProvider biomeKeyProvider;
|
||||||
private transient Kits kits;
|
private transient Kits kits;
|
||||||
private transient RandomTeleport randomTeleport;
|
private transient RandomTeleport randomTeleport;
|
||||||
private transient UpdateChecker updateChecker;
|
private transient UpdateChecker updateChecker;
|
||||||
@ -485,6 +488,10 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
|||||||
damageEventProvider = new LegacyDamageEventProvider();
|
damageEventProvider = new LegacyDamageEventProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (PaperLib.isPaper() && VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_19_4_R01)) {
|
||||||
|
biomeKeyProvider = new PaperBiomeKeyProvider();
|
||||||
|
}
|
||||||
|
|
||||||
execTimer.mark("Init(Providers)");
|
execTimer.mark("Init(Providers)");
|
||||||
reload();
|
reload();
|
||||||
|
|
||||||
@ -1426,6 +1433,11 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
|||||||
return damageEventProvider;
|
return damageEventProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BiomeKeyProvider getBiomeKeyProvider() {
|
||||||
|
return biomeKeyProvider;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SignDataProvider getSignDataProvider() {
|
public SignDataProvider getSignDataProvider() {
|
||||||
return signDataProvider;
|
return signDataProvider;
|
||||||
|
@ -9,6 +9,7 @@ import com.earth2me.essentials.perm.PermissionsHandler;
|
|||||||
import com.earth2me.essentials.updatecheck.UpdateChecker;
|
import com.earth2me.essentials.updatecheck.UpdateChecker;
|
||||||
import com.earth2me.essentials.userstorage.IUserMap;
|
import com.earth2me.essentials.userstorage.IUserMap;
|
||||||
import net.ess3.nms.refl.providers.ReflOnlineModeProvider;
|
import net.ess3.nms.refl.providers.ReflOnlineModeProvider;
|
||||||
|
import net.ess3.provider.BiomeKeyProvider;
|
||||||
import net.ess3.provider.ContainerProvider;
|
import net.ess3.provider.ContainerProvider;
|
||||||
import net.ess3.provider.DamageEventProvider;
|
import net.ess3.provider.DamageEventProvider;
|
||||||
import net.ess3.provider.FormattedCommandAliasProvider;
|
import net.ess3.provider.FormattedCommandAliasProvider;
|
||||||
@ -186,5 +187,7 @@ public interface IEssentials extends Plugin {
|
|||||||
|
|
||||||
DamageEventProvider getDamageEventProvider();
|
DamageEventProvider getDamageEventProvider();
|
||||||
|
|
||||||
|
BiomeKeyProvider getBiomeKeyProvider();
|
||||||
|
|
||||||
PluginCommand getPluginCommand(String cmd);
|
PluginCommand getPluginCommand(String cmd);
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,12 @@ import com.earth2me.essentials.utils.LocationUtil;
|
|||||||
import com.earth2me.essentials.utils.VersionUtil;
|
import com.earth2me.essentials.utils.VersionUtil;
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import net.ess3.api.InvalidWorldException;
|
import net.ess3.api.InvalidWorldException;
|
||||||
|
import net.ess3.provider.BiomeKeyProvider;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Biome;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -76,14 +75,10 @@ public class RandomTeleport implements IConf {
|
|||||||
config.save();
|
config.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Biome> getExcludedBiomes() {
|
public Set<String> getExcludedBiomes() {
|
||||||
final List<String> biomeNames = config.getList("excluded-biomes", String.class);
|
final Set<String> excludedBiomes = new HashSet<>();
|
||||||
final Set<Biome> excludedBiomes = new HashSet<>();
|
for (final String key : config.getList("excluded-biomes", String.class)) {
|
||||||
for (final String biomeName : biomeNames) {
|
excludedBiomes.add(key.toLowerCase());
|
||||||
try {
|
|
||||||
excludedBiomes.add(Biome.valueOf(biomeName.toUpperCase()));
|
|
||||||
} catch (final IllegalArgumentException ignored) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return excludedBiomes;
|
return excludedBiomes;
|
||||||
}
|
}
|
||||||
@ -204,7 +199,31 @@ public class RandomTeleport implements IConf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isValidRandomLocation(final Location location) {
|
private boolean isValidRandomLocation(final Location location) {
|
||||||
return location.getBlockY() > ess.getWorldInfoProvider().getMinHeight(location.getWorld()) && !this.getExcludedBiomes().contains(location.getBlock().getBiome());
|
return location.getBlockY() > ess.getWorldInfoProvider().getMinHeight(location.getWorld()) && !isExcludedBiome(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exclude biome if enum or namespaced key matches
|
||||||
|
private boolean isExcludedBiome(final Location location) {
|
||||||
|
final Set<String> excluded = getExcludedBiomes();
|
||||||
|
final String enumKey = location.getBlock().getBiome().name().toLowerCase();
|
||||||
|
// Try with good old bukkit enum
|
||||||
|
if (excluded.contains(enumKey)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_14_4_R01)) {
|
||||||
|
// No way to get the biome key on versions below this
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final String biomeKey;
|
||||||
|
final BiomeKeyProvider biomeKeyProvider = ess.getBiomeKeyProvider();
|
||||||
|
if (biomeKeyProvider != null) {
|
||||||
|
// Works with custom biome keys
|
||||||
|
biomeKey = biomeKeyProvider.getBiomeKey(location.getBlock()).toString();
|
||||||
|
} else {
|
||||||
|
// Custom biome keys resolve as "minecraft:custom" which is unfortunate
|
||||||
|
biomeKey = location.getBlock().getBiome().getKey().toString();
|
||||||
|
}
|
||||||
|
return excluded.contains(biomeKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getFile() {
|
public File getFile() {
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
package net.ess3.provider;
|
||||||
|
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
|
public interface BiomeKeyProvider extends Provider {
|
||||||
|
NamespacedKey getBiomeKey(Block block);
|
||||||
|
}
|
@ -11,8 +11,8 @@ dependencies {
|
|||||||
implementation(project(':providers:BaseProviders')) {
|
implementation(project(':providers:BaseProviders')) {
|
||||||
exclude(module: 'spigot-api')
|
exclude(module: 'spigot-api')
|
||||||
}
|
}
|
||||||
compileOnly 'io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT'
|
compileOnly 'io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT'
|
||||||
compileOnly 'io.papermc.paper:paper-mojangapi:1.18.2-R0.1-SNAPSHOT'
|
compileOnly 'io.papermc.paper:paper-mojangapi:1.20.4-R0.1-SNAPSHOT'
|
||||||
}
|
}
|
||||||
|
|
||||||
essentials {
|
essentials {
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
package net.ess3.provider.providers;
|
||||||
|
|
||||||
|
import net.ess3.provider.BiomeKeyProvider;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public class PaperBiomeKeyProvider implements BiomeKeyProvider {
|
||||||
|
@Override
|
||||||
|
public NamespacedKey getBiomeKey(final Block block) {
|
||||||
|
return Bukkit.getUnsafe().getBiomeKey(block.getWorld(), block.getX(), block.getY(), block.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return "Paper Biome Key Provider";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user