-
-
Notifications
You must be signed in to change notification settings - Fork 452
Add X/Z support for Chunks #8809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
APickledWalrus
wants to merge
2
commits into
dev/feature
Choose a base branch
from
feature/chunk-coordinates
base: dev/feature
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+119
−74
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
src/main/java/org/skriptlang/skript/bukkit/types/ChunkClassInfo.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| package org.skriptlang.skript.bukkit.types; | ||
|
|
||
| import ch.njol.skript.Skript; | ||
| import ch.njol.skript.classes.ClassInfo; | ||
| import ch.njol.skript.classes.Parser; | ||
| import ch.njol.skript.classes.Serializer; | ||
| import ch.njol.skript.lang.ParseContext; | ||
| import ch.njol.yggdrasil.Fields; | ||
| import org.bukkit.Chunk; | ||
| import org.bukkit.World; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.skriptlang.skript.lang.properties.Property; | ||
| import org.skriptlang.skript.lang.properties.handlers.WXYZHandler; | ||
| import org.skriptlang.skript.lang.properties.handlers.base.PropertyHandler; | ||
|
|
||
| import java.io.StreamCorruptedException; | ||
|
|
||
| @ApiStatus.Internal | ||
| public class ChunkClassInfo extends ClassInfo<Chunk> { | ||
|
|
||
| public ChunkClassInfo() { | ||
| super(Chunk.class, "chunk"); | ||
| user("chunks?") | ||
| .name("Chunk") | ||
| .description(""" | ||
| A chunk is a 16 by 16 segment of a world, stretching from the world's bottom to its top. \ | ||
| Chunks are spread on a fixed rectangular grid in their world.\ | ||
| """) | ||
| .since("2.0") | ||
| .parser(new ChunkParser()) | ||
| .serializer(new ChunkSerializer()) | ||
| .property(Property.WXYZ, | ||
| "The X or Z coordinate of the chunk. Added in INSERT VERSION.", | ||
| Skript.instance(), | ||
| new ChunkWXYZHandler()); | ||
| } | ||
|
|
||
| private static class ChunkParser extends Parser<Chunk> { | ||
| //<editor-fold desc="chunk parser" defaultstate="collapsed"> | ||
| @Override | ||
| public boolean canParse(ParseContext context) { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString(Chunk chunk, int flags) { | ||
| return "chunk (" + chunk.getX() + "," + chunk.getZ() + ") of " + chunk.getWorld().getName(); | ||
| } | ||
|
|
||
| @Override | ||
| public String toVariableNameString(final Chunk c) { | ||
| return c.getWorld().getName() + ":" + c.getX() + "," + c.getZ(); | ||
| } | ||
| //</editor-fold> | ||
| } | ||
|
|
||
| private static class ChunkSerializer extends Serializer<Chunk> { | ||
| //<editor-fold desc="chunk serializer" defaultstate="collapsed"> | ||
| @Override | ||
| public Fields serialize(Chunk chunk) { | ||
| Fields fields = new Fields(); | ||
| fields.putObject("world", chunk.getWorld()); | ||
| fields.putPrimitive("x", chunk.getX()); | ||
| fields.putPrimitive("z", chunk.getZ()); | ||
| return fields; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean canBeInstantiated() { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| protected Chunk deserialize(Fields fields) throws StreamCorruptedException { | ||
| World world = fields.getObject("world", World.class); | ||
| if (world == null) { | ||
| throw new StreamCorruptedException("Missing world"); | ||
| } | ||
| int x = fields.getPrimitive("x", int.class); | ||
| int z = fields.getPrimitive("z", int.class); | ||
| return world.getChunkAt(x, z); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean mustSyncDeserialization() { | ||
| return true; | ||
| } | ||
| //</editor-fold> | ||
| } | ||
|
|
||
| private static class ChunkWXYZHandler extends WXYZHandler<Chunk, Integer> { | ||
| //<editor-fold desc="chunk wxyz handler" defaultstate="collapsed"> | ||
| @Override | ||
| public PropertyHandler<Chunk> newInstance() { | ||
| var instance = new ChunkClassInfo.ChunkWXYZHandler(); | ||
| instance.axis(axis); | ||
| return instance; | ||
| } | ||
|
|
||
| @Override | ||
| public Integer convert(Chunk chunk) { | ||
| return axis == Axis.X ? chunk.getX() : chunk.getZ(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean supportsAxis(Axis axis) { | ||
| return axis == Axis.X || axis == Axis.Z; | ||
| } | ||
|
|
||
| @Override | ||
| public @NotNull Class<Integer> returnType() { | ||
| return Integer.class; | ||
| } | ||
| //</editor-fold> | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.