Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-17 00:20:09 +01:00
Use Bukkit Registry API where possible (#2573)
(cherry picked from commit 292dae65cb01929dc2158f09bdb19fdc82b3669f)
Dieser Commit ist enthalten in:
Ursprung
8b18dbcdbd
Commit
f260e19d29
@ -62,9 +62,8 @@ import org.bstats.bukkit.Metrics;
|
|||||||
import org.bstats.charts.SimplePie;
|
import org.bstats.charts.SimplePie;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.Registry;
|
||||||
import org.bukkit.Tag;
|
import org.bukkit.Tag;
|
||||||
import org.bukkit.block.Biome;
|
|
||||||
import org.bukkit.command.BlockCommandSender;
|
import org.bukkit.command.BlockCommandSender;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -89,7 +88,6 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
@ -250,21 +248,23 @@ public class WorldEditPlugin extends JavaPlugin {
|
|||||||
// datapacks aren't loaded until just before the world is, and bukkit has no event for this
|
// datapacks aren't loaded until just before the world is, and bukkit has no event for this
|
||||||
// so the earliest we can do this is in WorldInit
|
// so the earliest we can do this is in WorldInit
|
||||||
setupTags();
|
setupTags();
|
||||||
setupBiomes(false); // FAWE - load biomes later. Initialize biomes twice to allow for the registry to be present for
|
|
||||||
// plugins requiring WE biomes during startup, as well as allowing custom biomes loaded later on to be present in WE.
|
// plugins requiring WE biomes during startup, as well as allowing custom biomes loaded later on to be present in WE.
|
||||||
WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent(platform));
|
WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent(platform));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"deprecation", "unchecked"})
|
@SuppressWarnings({"deprecation", "unchecked"})
|
||||||
private void initializeRegistries() {
|
private void initializeRegistries() {
|
||||||
// FAWE start - move Biomes to their own method. Initialize biomes twice to allow for the registry to be present for
|
// Biome
|
||||||
// plugins requiring WE biomes during startup, as well as allowing custom biomes loaded later on to be present in WE.
|
Registry.BIOME.forEach(biome -> {
|
||||||
setupBiomes(true);
|
if (!biome.name().equals("CUSTOM")) {
|
||||||
// FAWE end
|
String key = biome.getKey().toString();
|
||||||
|
BiomeType.REGISTRY.register(key, new BiomeType(key));
|
||||||
|
}
|
||||||
|
});
|
||||||
/*
|
/*
|
||||||
|
|
||||||
// Block & Item
|
// Block & Item
|
||||||
for (Material material : Material.values()) {
|
Registry.MATERIAL.forEach(material -> {
|
||||||
if (material.isBlock() && !material.isLegacy()) {
|
if (material.isBlock() && !material.isLegacy()) {
|
||||||
BlockType.REGISTRY.register(material.getKey().toString(), new BlockType(material.getKey().toString(), blockState -> {
|
BlockType.REGISTRY.register(material.getKey().toString(), new BlockType(material.getKey().toString(), blockState -> {
|
||||||
// TODO Use something way less hacky than this.
|
// TODO Use something way less hacky than this.
|
||||||
@ -291,17 +291,14 @@ public class WorldEditPlugin extends JavaPlugin {
|
|||||||
if (material.isItem() && !material.isLegacy()) {
|
if (material.isItem() && !material.isLegacy()) {
|
||||||
ItemType.REGISTRY.register(material.getKey().toString(), new ItemType(material.getKey().toString()));
|
ItemType.REGISTRY.register(material.getKey().toString(), new ItemType(material.getKey().toString()));
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Entity
|
// Entity
|
||||||
for (org.bukkit.entity.EntityType entityType : org.bukkit.entity.EntityType.values()) {
|
Registry.ENTITY_TYPE.forEach(entityType -> {
|
||||||
String mcid = entityType.getName();
|
String key = entityType.getKey().toString();
|
||||||
if (mcid != null) {
|
EntityType.REGISTRY.register(key, new EntityType(key));
|
||||||
String lowerCaseMcId = mcid.toLowerCase(Locale.ROOT);
|
});
|
||||||
EntityType.REGISTRY.register("minecraft:" + lowerCaseMcId, new EntityType("minecraft:" + lowerCaseMcId));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// ... :|
|
// ... :|
|
||||||
GameModes.get("");
|
GameModes.get("");
|
||||||
WeatherTypes.get("");
|
WeatherTypes.get("");
|
||||||
@ -322,38 +319,6 @@ public class WorldEditPlugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FAWE start
|
|
||||||
private void setupBiomes(boolean expectFail) {
|
|
||||||
if (this.adapter.value().isPresent()) {
|
|
||||||
// Biomes are stored globally in the server. Registries are not kept per-world in Minecraft.
|
|
||||||
// The WorldServer get-registries method simply delegates to the MinecraftServer method.
|
|
||||||
for (final NamespacedKey biome : ((BukkitImplAdapter<?>) adapter.value().get()).getRegisteredBiomes()) {
|
|
||||||
BiomeType biomeType;
|
|
||||||
if ((biomeType = BiomeType.REGISTRY.get(biome.toString())) == null) { // only register once
|
|
||||||
biomeType = new BiomeType(biome.toString());
|
|
||||||
BiomeType.REGISTRY.register(biome.toString(), biomeType);
|
|
||||||
}
|
|
||||||
biomeType.setLegacyId(adapter.value().get().getInternalBiomeId(biomeType));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!expectFail) {
|
|
||||||
LOGGER.warn("Failed to load biomes via adapter (not present). Will load via bukkit");
|
|
||||||
}
|
|
||||||
for (Biome biome : Biome.values()) {
|
|
||||||
// Custom is bad
|
|
||||||
if (biome.name().equals("CUSTOM")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String lowerCaseBiome = biome.getKey().toString().toLowerCase(Locale.ROOT);
|
|
||||||
// only register once
|
|
||||||
if (BiomeType.REGISTRY.get(lowerCaseBiome) == null) {
|
|
||||||
BiomeType.REGISTRY.register(lowerCaseBiome, new BiomeType(lowerCaseBiome));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// FAWE end
|
|
||||||
|
|
||||||
private void loadAdapter() {
|
private void loadAdapter() {
|
||||||
WorldEdit worldEdit = WorldEdit.getInstance();
|
WorldEdit worldEdit = WorldEdit.getInstance();
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren