-
-
Notifications
You must be signed in to change notification settings - Fork 395
Chicken Variants #7868
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
Absolutionism
wants to merge
9
commits into
SkriptLang:dev/feature
Choose a base branch
from
Absolutionism:dev/ChickenVariants
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.
Open
Chicken Variants #7868
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
04aa925
Initial Commit
Absolutionism f10f2aa
Update ChickenData.java
Absolutionism 41580a4
Update src/main/resources/lang/default.lang
Absolutionism bb5370b
Update
Absolutionism e35784d
Merge branch 'dev/feature' into dev/ChickenVariants
Absolutionism 60d70b1
Merge branch 'dev/feature' into dev/ChickenVariants
Absolutionism 6e53fb8
Merge branch 'dev/feature' into dev/ChickenVariants
sovdeeth c1d8e7a
Merge branch 'dev/feature' into dev/ChickenVariants
Absolutionism 435e8d0
Pickle's Changes
Absolutionism 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package ch.njol.skript.entity; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.lang.Literal; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import ch.njol.skript.registrations.Classes; | ||
import ch.njol.util.coll.CollectionUtils; | ||
import com.google.common.collect.Iterators; | ||
import org.bukkit.entity.Chicken; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Objects; | ||
|
||
public class ChickenData extends EntityData<Chicken> { | ||
|
||
private static final boolean VARIANTS_ENABLED; | ||
private static final Object[] variants; | ||
|
||
static { | ||
register(ChickenData.class, "chicken", Chicken.class, "chicken"); | ||
if (Skript.classExists("org.bukkit.entity.Chicken$Variant")) { | ||
VARIANTS_ENABLED = true; | ||
variants = Iterators.toArray(Classes.getExactClassInfo(Chicken.Variant.class).getSupplier().get(), Chicken.Variant.class); | ||
} else { | ||
VARIANTS_ENABLED = false; | ||
variants = null; | ||
} | ||
} | ||
|
||
private @Nullable Object variant = null; | ||
|
||
public ChickenData() {} | ||
|
||
// TODO: When safe, 'variant' should have the type changed to 'Chicken.Variant' | ||
public ChickenData(@Nullable Object variant) { | ||
this.variant = variant; | ||
} | ||
|
||
@Override | ||
protected boolean init(Literal<?>[] exprs, int matchedPattern, ParseResult parseResult) { | ||
if (VARIANTS_ENABLED) { | ||
Literal<?> expr = null; | ||
if (exprs[0] != null) { // chicken | ||
expr = exprs[0]; | ||
} else if (exprs[1] != null) { // chicks | ||
expr = exprs[1]; | ||
} | ||
if (expr != null) | ||
//noinspection unchecked | ||
variant = ((Literal<Chicken.Variant>) expr).getSingle(); | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
protected boolean init(@Nullable Class<? extends Chicken> entityClass, @Nullable Chicken chicken) { | ||
if (chicken != null) { | ||
if (VARIANTS_ENABLED) | ||
variant = chicken.getVariant(); | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public void set(Chicken chicken) { | ||
if (VARIANTS_ENABLED) { | ||
Object finalVariant = variant != null ? variant : CollectionUtils.getRandom(variants); | ||
assert finalVariant != null; | ||
chicken.setVariant((Chicken.Variant) finalVariant); | ||
} | ||
} | ||
|
||
@Override | ||
protected boolean match(Chicken chicken) { | ||
return variant == null || variant == chicken.getVariant(); | ||
} | ||
|
||
@Override | ||
public Class<? extends Chicken> getType() { | ||
return Chicken.class; | ||
} | ||
|
||
@Override | ||
public EntityData<Chicken> getSuperType() { | ||
return new ChickenData(); | ||
} | ||
|
||
@Override | ||
protected int hashCode_i() { | ||
return Objects.hashCode(variant); | ||
} | ||
|
||
@Override | ||
protected boolean equals_i(EntityData<?> obj) { | ||
if (!(obj instanceof ChickenData other)) | ||
return false; | ||
return variant == other.variant; | ||
} | ||
|
||
@Override | ||
public boolean isSupertypeOf(EntityData<?> entityData) { | ||
if (!(entityData instanceof ChickenData other)) | ||
return false; | ||
return variant == null || variant == other.variant; | ||
} | ||
|
||
/** | ||
* A dummy/placeholder class to ensure working operation on MC versions that do not have `Chicken.Variant` | ||
*/ | ||
public static class ChickenVariantDummy {} | ||
|
||
} |
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
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
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.