3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-24 18:10:08 +01:00

Attempt at fixing NamespacedRegistry

Dieser Commit ist enthalten in:
MattBDev 2019-08-19 14:12:28 -04:00
Ursprung 45f947a3b2
Commit 1eec4884c8
4 geänderte Dateien mit 33 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -37,16 +37,24 @@ import com.sk89q.worldedit.bukkit.adapter.BukkitImplLoader;
import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.event.platform.CommandSuggestionEvent;
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.internal.command.CommandUtil;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockCategory;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.FuzzyBlockState;
import com.sk89q.worldedit.world.entity.EntityType;
import com.sk89q.worldedit.world.gamemode.GameModes;
import com.sk89q.worldedit.world.item.ItemCategory;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.weather.WeatherTypes;
import io.papermc.lib.PaperLib;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@ -214,7 +222,7 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
PaperLib.suggestPaper(this);
}
public void setupRegistries() {
private void setupRegistries() {
// Biome
for (Biome biome : Biome.values()) {
String lowerCaseBiomeName = biome.name().toLowerCase(Locale.ROOT);
@ -259,6 +267,9 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
EntityType.REGISTRY.register("minecraft:" + lowerCaseMcId, new EntityType("minecraft:" + lowerCaseMcId));
}
}
// ... :|
GameModes.get("");
WeatherTypes.get("");
}
private void setupTags() {
@ -428,7 +439,7 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
// code of WorldEdit expects it
String[] split = new String[args.length + 1];
System.arraycopy(args, 0, split, 1, args.length);
split[0] = "/" + cmd.getName();
split[0] = "/" + commandLabel;
CommandEvent event = new CommandEvent(wrapCommandSender(sender), Joiner.on(" ").join(split));
getWorldEdit().getEventBus().post(event);
@ -443,7 +454,7 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
// code of WorldEdit expects it
String[] split = new String[args.length + 1];
System.arraycopy(args, 0, split, 1, args.length);
split[0] = "/" + cmd.getName();
split[0] = "/" + commandLabel;
String arguments = Joiner.on(" ").join(split);
CommandSuggestionEvent event = new CommandSuggestionEvent(wrapCommandSender(sender), arguments);
@ -577,9 +588,9 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
if (!event.isCommand()) return;
String buffer = event.getBuffer();
final String[] parts = buffer.split(" ");
if (parts.length < 1) return;
final String label = parts[0];
int firstSpace = buffer.indexOf(' ');
if (firstSpace < 0) return;
final String label = buffer.substring(0, firstSpace);
final Optional<org.enginehub.piston.Command> command
= WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().getCommandManager().getCommand(label);
if (!command.isPresent()) return;

Datei anzeigen

@ -29,7 +29,7 @@ import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;
public final class NamespacedRegistry<V extends RegistryItem & Keyed> extends Registry<V> {
public final class NamespacedRegistry<V extends Keyed> extends Registry<V> {
private static final String MINECRAFT_NAMESPACE = "minecraft";
private final Set<String> knownNamespaces = new HashSet<>();
private final String defaultNamespace;
@ -60,7 +60,9 @@ public final class NamespacedRegistry<V extends RegistryItem & Keyed> extends Re
if (existing != null) {
throw new UnsupportedOperationException("Replacing existing registrations is not supported");
}
value.setInternalId(lastInternalId++);
if (value instanceof RegistryItem) {
((RegistryItem)value).setInternalId(lastInternalId++);
}
values.add(value);
super.register(key, value);
if (key.startsWith(defaultNamespace)) {
@ -78,7 +80,10 @@ public final class NamespacedRegistry<V extends RegistryItem & Keyed> extends Re
}
public int getInternalId(V value) {
return value.getInternalId();
if (value instanceof RegistryItem) {
return ((RegistryItem)value).getInternalId();
}
return 0;
}
public int size() {

Datei anzeigen

@ -29,6 +29,7 @@ import com.sk89q.worldedit.function.mask.SingleBlockTypeMask;
import com.sk89q.worldedit.function.pattern.FawePattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.Keyed;
import com.sk89q.worldedit.registry.NamespacedRegistry;
import com.sk89q.worldedit.registry.state.AbstractProperty;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.registry.state.PropertyKey;
@ -36,15 +37,20 @@ import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javax.annotation.Nullable;
public class BlockType implements FawePattern, Keyed {
public static final NamespacedRegistry<BlockType> REGISTRY = new NamespacedRegistry<>("block type");
private final String id;
private final BlockTypes.Settings settings;

Datei anzeigen

@ -954,15 +954,14 @@ public final class BlockTypes {
try {
Field field = BlockTypes.class.getDeclaredField(enumName);
ReflectionUtils.setFailsafeFieldValue(field, null, existing);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
// register states
if (typeName.startsWith("minecraft:")) $REGISTRY.put(typeName.substring(10), existing);
$REGISTRY.put(typeName, existing);
BlockType.REGISTRY.register(typeName,existing);
String nameSpace = typeName.substring(0, typeName.indexOf(':'));
$NAMESPACES.add(nameSpace);
return existing;