Skip to content
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

Add breeding #7110

Open
wants to merge 62 commits into
base: dev/feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
a437ca9
Update aliases I guess?
Fusezion Mar 30, 2023
296a944
Revert "Update aliases I guess?"
Fusezion Mar 30, 2023
2cdf76d
Adding Events
Fusezion Apr 7, 2023
9b3afd9
Breeding Event Expressions
Fusezion Apr 7, 2023
27e1392
More Breeding Related Syntax
Fusezion Apr 7, 2023
07ced16
Pattern Fixes & Class Exist checks
Fusezion Apr 7, 2023
6ab1dba
Test, Test, Test
Fusezion Apr 7, 2023
0423ea7
Merge branch 'master' into enhancement/Breedable
Fusezion Apr 7, 2023
c6acbe9
:purple_heart: Formatting
Fusezion Apr 7, 2023
243d402
Added Adult Syntax
Fusezion Apr 7, 2023
8bcbffb
Apply suggestions from code review
Fusezion Apr 7, 2023
50748f5
ExprLoveTime -> ExprLoveTicks
Fusezion Apr 8, 2023
93059ae
Update ExprBreedingFamily.java
Fusezion Apr 8, 2023
912a300
Update ExprExperience.java
Fusezion Apr 8, 2023
09d1999
Added comment to CondIsAdult and EffMakeAdult
Fusezion Apr 8, 2023
daeb7bf
Merge branch 'master' into enhancement/Breedable
Fusezion Apr 8, 2023
c543ef2
Merge branch 'master' into enhancement/Breedable
TheLimeGlass Apr 8, 2023
34d5453
Syntax description notes
Fusezion Apr 8, 2023
0b894cc
Update ExprLoveTicks and SimpleEvents
Fusezion Apr 8, 2023
0b10f7d
Fix ExprLoveTicks & Update Test
Fusezion Apr 8, 2023
14b7962
LoveTicks -> LoveTime
Fusezion Apr 10, 2023
4ab107e
Merge branch 'master' into enhancement/Breedable
Fusezion Apr 17, 2023
442602a
Apply suggestions from code review
Fusezion Apr 19, 2023
babb7b1
Change CondIsAdult condition checks
Fusezion Apr 19, 2023
60a0500
Apply requested code review changes
Fusezion Apr 19, 2023
a8deec7
Apply more requested changes
Fusezion Apr 19, 2023
f46a502
Merge branch 'enhancement/Breedable' of https://github.com/Fusezion/S…
Fusezion Apr 19, 2023
fcbe57a
Merge branch 'master' into enhancement/Breedable
Fusezion May 1, 2023
a5f894d
Merge branch 'master' into enhancement/Breedable
Fusezion Jul 12, 2023
2556e3b
Merge branch 'SkriptLang:master' into enhancement/Breedable
Fusezion Aug 8, 2023
47301ca
Merge branch 'dev/feature' into enhancement/Breedable
Fusezion Oct 13, 2023
abe6540
Merge branch 'dev/feature' into enhancement/Breedable
sovdeeth Dec 30, 2023
f6e2954
Merge branch 'dev/feature' into enhancement/Breedable
Fusezion Jan 1, 2024
04d4e3a
Merge branch 'dev/feature' into enhancement/Breedable
Fusezion Jan 1, 2024
f14bc73
Merge branch 'dev/feature' into enhancement/Breedable
sovdeeth Jun 28, 2024
485ac5f
Merge branch 'dev/feature' into enhancement/Breedable
sovdeeth Jul 1, 2024
9d98120
update conds
Efnilite Sep 22, 2024
29847db
update exprs
Efnilite Sep 22, 2024
803c718
update effs
Efnilite Sep 22, 2024
fe00590
update event values
Efnilite Sep 22, 2024
668dad6
Merge branch 'fork/Fusezion/enhancement/Breedable' into breeding
Efnilite Sep 22, 2024
91b9ee1
update annot
Efnilite Sep 22, 2024
5018770
update annotations
Efnilite Sep 22, 2024
28c1ac3
update CondIsInLove
Efnilite Sep 22, 2024
f0a12da
renames
Efnilite Sep 22, 2024
987ff80
updates
Efnilite Sep 22, 2024
11dbd44
update tests
Efnilite Sep 22, 2024
7715a65
oops
Efnilite Sep 22, 2024
24e3c2b
fix
Efnilite Sep 22, 2024
05e7627
grr
Efnilite Sep 22, 2024
8b7106f
gahr
Efnilite Sep 22, 2024
d4be4e9
add breeding trigger event
Efnilite Sep 22, 2024
06dd041
more
Efnilite Sep 23, 2024
9ab4f4a
MORE
Efnilite Sep 23, 2024
555c053
MORE!!!!
Efnilite Sep 23, 2024
fb105b4
MORE!!!!!!
Efnilite Sep 23, 2024
fd0baef
Merge branch 'dev/feature' into breeding
Efnilite Sep 23, 2024
d74ddc9
stupid copilot
Efnilite Sep 23, 2024
4f4b5aa
Merge remote-tracking branch 'origin/breeding' into breeding
Efnilite Sep 23, 2024
d43733a
g
Efnilite Sep 23, 2024
eff120d
fixes
Efnilite Sep 26, 2024
43d3769
agag
Efnilite Sep 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityBreedEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityEnterLoveModeEvent;
import org.bukkit.event.entity.EntityDropItemEvent;
import org.bukkit.event.entity.EntityEvent;
import org.bukkit.event.entity.EntityPickupItemEvent;
Expand Down Expand Up @@ -1801,6 +1803,28 @@ public Location get(LootGenerateEvent event) {
}, EventValues.TIME_NOW);
}

// EntityBreedEvent
EventValues.registerEventValue(EntityBreedEvent.class, ItemStack.class, new Getter<>() {
@Override
public @Nullable ItemStack get(EntityBreedEvent event) {
return event.getBredWith();
}
}, EventValues.TIME_NOW);

EventValues.registerEventValue(EntityEnterLoveModeEvent.class, LivingEntity.class, new Getter<>() {
@Override
public LivingEntity get(EntityEnterLoveModeEvent event) {
return event.getEntity();
}
}, EventValues.TIME_NOW);

EventValues.registerEventValue(EntityEnterLoveModeEvent.class, HumanEntity.class, new Getter<>() {
@Override
public @Nullable HumanEntity get(EntityEnterLoveModeEvent event) {
return event.getHumanEntity();
}
}, EventValues.TIME_NOW);

// EntityResurrectEvent
EventValues.registerEventValue(EntityResurrectEvent.class, Slot.class, new Getter<Slot, EntityResurrectEvent>() {
@Override
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondCanAge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ch.njol.skript.conditions;

import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import org.bukkit.entity.Breedable;
import org.bukkit.entity.LivingEntity;

@Name("Can Age")
@Description("Checks whether or not an entity will be able to age/grow up.")
@Examples({
"on breeding:",
"\tentity can't age",
"\tbroadcast \"An immortal has been born!\" to player"
})
@Since("INSERT VERSION")
public class CondCanAge extends PropertyCondition<LivingEntity> {

static {
register(CondCanAge.class, PropertyType.CAN, "(age|grow (up|old[er]))", "livingentities");
}

@Override
public boolean check(LivingEntity entity) {
return entity instanceof Breedable breedable && !breedable.getAgeLock();
}

@Override
protected String getPropertyName() {
return "age";
}

}
36 changes: 36 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondCanBreed.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ch.njol.skript.conditions;

import ch.njol.skript.Skript;
import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import org.bukkit.entity.Breedable;
import org.bukkit.entity.LivingEntity;

@Name("Can Breed")
@Description("Checks whether or not a living entity can be bred.")
@Examples({
"on right click on living entity:",
"\tevent-entity can't breed",
"\tsend \"Turns out %event-entity% is not breedable. Must be a Skript user!\" to player"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💀

})
@Since("INSERT VERSION")
public class CondCanBreed extends PropertyCondition<LivingEntity> {

static {
register(CondCanBreed.class, PropertyType.CAN, "(breed|be bred)", "livingentities");
}

@Override
public boolean check(LivingEntity entity) {
return entity instanceof Breedable breedable && breedable.canBreed();
}

@Override
protected String getPropertyName() {
return "breed";
}

}
35 changes: 35 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondIsAdult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ch.njol.skript.conditions;

import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import org.bukkit.entity.Ageable;
import org.bukkit.entity.LivingEntity;

@Name("Is Adult")
@Description("Checks whether or not a living entity is an adult.")
@Examples({
"on drink:",
"\tevent-entity is not an adult",
"\tkill event-entity"
})
@Since("INSERT VERSION")
public class CondIsAdult extends PropertyCondition<LivingEntity> {

static {
register(CondIsAdult.class, "[an] adult", "livingentities");
}

@Override
public boolean check(LivingEntity entity) {
return entity instanceof Ageable ageable && ageable.isAdult();
}

@Override
protected String getPropertyName() {
return "an adult";
}

}
36 changes: 36 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondIsBaby.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ch.njol.skript.conditions;

import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import org.bukkit.entity.Ageable;
import org.bukkit.entity.LivingEntity;

@Name("Is Baby")
@Description("Checks whether or not a living entity is a baby.")
@Examples({
"on drink:",
"\tevent-entity is a baby",
"\tkill event-entity"
})
@Since("INSERT VERSION")
public class CondIsBaby extends PropertyCondition<LivingEntity> {

static {
register(CondIsBaby.class, "a (child|baby)", "livingentities");
}

@Override
public boolean check(LivingEntity entity) {
return entity instanceof Ageable ageable && !ageable.isAdult();

}

@Override
protected String getPropertyName() {
return "a baby";
}

}
38 changes: 38 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondIsInLove.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package ch.njol.skript.conditions;

import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import org.bukkit.entity.Animals;
import org.bukkit.entity.LivingEntity;

@Name("Is In Love")
@Description("Checks whether or not a living entity is in love.")
@Examples({
"on spawn of living entity:",
"\tif entity is in love:",
"broadcast \"That was quick!\""
})
@Since("INSERT VERSION")
public class CondIsInLove extends PropertyCondition<LivingEntity> {

static {
register(CondIsInLove.class, "in lov(e|ing) [state|mode]", "livingentities");
}

@Override
public boolean check(LivingEntity entity) {
if (entity instanceof Animals animals)
return animals.isLoveMode();

return false;
}

@Override
protected String getPropertyName() {
return "in love";
}

}
63 changes: 63 additions & 0 deletions src/main/java/ch/njol/skript/effects/EffAllowAging.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package ch.njol.skript.effects;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.entity.Breedable;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Allow Aging")
@Description("Sets whether or not living entities will be able to age.")
@Examples({
"on spawn of animal:",
"\tallow aging of entity"
})
@Since("INSERT VERSION")
public class EffAllowAging extends Effect {

static {
Skript.registerEffect(EffAllowAging.class,
"lock age of %livingentities%",
"prevent aging of %livingentities%",
"prevent %livingentities% from aging",
"unlock age of %livingentities%",
"allow aging of %livingentities%",
"allow %livingentities% to age");
}

private boolean unlock;
private Expression<LivingEntity> entities;

@Override
public boolean init(Expression<?>[] expressions, int matchedPattern,
Kleenean isDelayed, ParseResult parseResult) {
//noinspection unchecked
entities = (Expression<LivingEntity>) expressions[0];
unlock = matchedPattern > 2;
return true;
}

@Override
protected void execute(Event event) {
for (LivingEntity livingEntity : entities.getArray(event)) {
if (!(livingEntity instanceof Breedable breedable))
continue;

breedable.setAgeLock(!unlock);
}
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return (unlock ? "allow" : "prevent") + " aging of " + entities.toString(event,debug);
}

}
61 changes: 61 additions & 0 deletions src/main/java/ch/njol/skript/effects/EffBreedable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package ch.njol.skript.effects;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.entity.Breedable;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Make Breedable")
@Description("Sets whether or not entities will be able to breed. Only works on animals.")
@Examples({
"on spawn of animal:",
"\tmake entity unbreedable"
})
@Since("INSERT VERSION")
public class EffBreedable extends Effect {

static {
Skript.registerEffect(EffBreedable.class,
"make %livingentities% breedable",
"unsterilize %livingentities%",
"make %livingentities% (not |non(-| )|un)breedable",
"sterilize %livingentities%");
}

private boolean sterilize;
private Expression<LivingEntity> entities;

@Override
public boolean init(Expression<?>[] expressions, int matchedPattern,
Kleenean isDelayed, ParseResult parseResult) {
sterilize = matchedPattern > 1;
//noinspection unchecked
entities = (Expression<LivingEntity>) expressions[0];
return true;
}

@Override
protected void execute(Event event) {
for (LivingEntity entity : entities.getArray(event)) {
if (!(entity instanceof Breedable breedable))
continue;

breedable.setBreed(!sterilize);
}
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "make " + entities.toString(event, debug) + (sterilize ? " non-" : " ") + "breedable";
}

}
Loading