@@ -0,0 +1,52 @@
|
||||
package org.bukkit.craftbukkit.map;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.level.saveddata.maps.MapDecorationType;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.map.MapCursor;
|
||||
|
||||
public final class CraftMapCursor {
|
||||
|
||||
public static final class CraftType {
|
||||
|
||||
public static MapCursor.Type minecraftToBukkit(MapDecorationType minecraft) {
|
||||
Preconditions.checkArgument(minecraft != null);
|
||||
|
||||
IRegistry<MapDecorationType> registry = CraftRegistry.getMinecraftRegistry(Registries.MAP_DECORATION_TYPE);
|
||||
MapCursor.Type bukkit = Registry.MAP_DECORATION_TYPE.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location()));
|
||||
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return bukkit;
|
||||
}
|
||||
|
||||
public static MapCursor.Type minecraftHolderToBukkit(Holder<MapDecorationType> minecraft) {
|
||||
return minecraftToBukkit(minecraft.value());
|
||||
}
|
||||
|
||||
public static MapDecorationType bukkitToMinecraft(MapCursor.Type bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return CraftRegistry.getMinecraftRegistry(Registries.MAP_DECORATION_TYPE)
|
||||
.getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow();
|
||||
}
|
||||
|
||||
public static Holder<MapDecorationType> bukkitToMinecraftHolder(MapCursor.Type bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
IRegistry<MapDecorationType> registry = CraftRegistry.getMinecraftRegistry(Registries.MAP_DECORATION_TYPE);
|
||||
|
||||
if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c<MapDecorationType> holder) {
|
||||
return holder;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("No Reference holder found for " + bukkit
|
||||
+ ", this can happen if a plugin creates its own map cursor type without properly registering it.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.util.CraftChatMessage;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.map.MapCanvas;
|
||||
import org.bukkit.map.MapCursor;
|
||||
import org.bukkit.map.MapCursorCollection;
|
||||
import org.bukkit.map.MapRenderer;
|
||||
import org.bukkit.map.MapView;
|
||||
@@ -42,7 +43,7 @@ public class CraftMapRenderer extends MapRenderer {
|
||||
}
|
||||
|
||||
MapIcon decoration = worldMap.decorations.get(key);
|
||||
cursors.addCursor(decoration.x(), decoration.y(), (byte) (decoration.rot() & 15), decoration.type().getIcon(), true, CraftChatMessage.fromComponent(decoration.name()));
|
||||
cursors.addCursor(new MapCursor(decoration.x(), decoration.y(), (byte) (decoration.rot() & 15), CraftMapCursor.CraftType.minecraftHolderToBukkit(decoration.type()), true, CraftChatMessage.fromComponent(decoration.name().orElse(null))));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.bukkit.craftbukkit.map;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -32,13 +31,7 @@ public final class CraftMapView implements MapView {
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
String text = worldMap.id;
|
||||
Preconditions.checkState(text.startsWith("map_"), "Map has a invalid ID");
|
||||
try {
|
||||
return Integer.parseInt(text.substring("map_".length()));
|
||||
} catch (NumberFormatException ex) {
|
||||
throw new IllegalStateException("Map has non-numeric ID");
|
||||
}
|
||||
return worldMap.id.id();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user