-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to catch entities with fishing (#301)
- Loading branch information
Showing
18 changed files
with
346 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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
19 changes: 19 additions & 0 deletions
19
...ain/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/loot/MythicEntityLootParser.java
This file contains 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,19 @@ | ||
package dev.aurelium.auraskills.bukkit.hooks.mythicmobs.loot; | ||
|
||
import dev.aurelium.auraskills.bukkit.loot.entity.EntityProperties; | ||
import dev.aurelium.auraskills.bukkit.loot.entity.EntitySupplier; | ||
import dev.aurelium.auraskills.bukkit.loot.parser.CustomEntityParser; | ||
import org.spongepowered.configurate.ConfigurationNode; | ||
|
||
public class MythicEntityLootParser implements CustomEntityParser { | ||
|
||
@Override | ||
public EntitySupplier getEntitySupplier(ConfigurationNode config) { | ||
return new MythicEntitySupplier(EntityProperties.fromConfig(config)); | ||
} | ||
|
||
@Override | ||
public boolean shouldUseParser(ConfigurationNode config) { | ||
return config.node("entity").getString("").startsWith("mythicmobs:"); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
.../main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/loot/MythicEntitySupplier.java
This file contains 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,35 @@ | ||
package dev.aurelium.auraskills.bukkit.hooks.mythicmobs.loot; | ||
|
||
import dev.aurelium.auraskills.bukkit.AuraSkills; | ||
import dev.aurelium.auraskills.bukkit.loot.entity.EntityProperties; | ||
import dev.aurelium.auraskills.bukkit.loot.entity.EntitySupplier; | ||
import io.lumine.mythic.bukkit.BukkitAdapter; | ||
import io.lumine.mythic.bukkit.MythicBukkit; | ||
import io.lumine.mythic.core.mobs.ActiveMob; | ||
import org.bukkit.Location; | ||
import org.bukkit.entity.Entity; | ||
|
||
public class MythicEntitySupplier extends EntitySupplier { | ||
|
||
public MythicEntitySupplier(EntityProperties entityProperties) { | ||
super(entityProperties); | ||
} | ||
|
||
@Override | ||
public Entity spawnEntity(AuraSkills plugin, Location location) { | ||
ActiveMob activeMob; | ||
|
||
if (getEntityProperties().level() != null) { | ||
activeMob = MythicBukkit.inst().getMobManager().spawnMob(getEntityProperties().entityId(), location, getEntityProperties().level()); | ||
} else { | ||
activeMob = MythicBukkit.inst().getMobManager().spawnMob(getEntityProperties().entityId(), location); | ||
} | ||
|
||
return BukkitAdapter.adapt(activeMob.getEntity()); | ||
} | ||
|
||
@Override | ||
public void removeEntity(Entity entity) { | ||
MythicBukkit.inst().getMobManager().getActiveMob(entity.getUniqueId()).ifPresent(ActiveMob::remove); | ||
} | ||
} |
This file contains 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 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 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
26 changes: 26 additions & 0 deletions
26
bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/EntityProperties.java
This file contains 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,26 @@ | ||
package dev.aurelium.auraskills.bukkit.loot.entity; | ||
|
||
import org.spongepowered.configurate.ConfigurationNode; | ||
|
||
public record EntityProperties(String entityId, | ||
String name, | ||
Integer level, | ||
Double health, | ||
Double damage, | ||
Float horizontalVelocity, | ||
Float verticalVelocity) { | ||
|
||
public static EntityProperties fromConfig(ConfigurationNode config) { | ||
String[] id = config.node("entity").getString("").split(":"); | ||
|
||
return new EntityProperties( | ||
id.length > 1 ? id[1] : id[0], | ||
config.node("name").getString(), | ||
config.node("level").empty() ? null : config.node("level").getInt(), | ||
config.node("health").empty() ? null : config.node("health").getDouble(), | ||
config.node("damage").empty() ? null : config.node("damage").getDouble(), | ||
config.node("velocity", "horizontal").empty() ? null : config.node("velocity", "horizontal").getFloat(), | ||
config.node("velocity", "vertical").empty() ? null : config.node("velocity", "vertical").getFloat() | ||
); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/EntitySupplier.java
This file contains 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,22 @@ | ||
package dev.aurelium.auraskills.bukkit.loot.entity; | ||
|
||
import dev.aurelium.auraskills.bukkit.AuraSkills; | ||
import org.bukkit.Location; | ||
import org.bukkit.entity.Entity; | ||
|
||
public abstract class EntitySupplier { | ||
|
||
private final EntityProperties entityProperties; | ||
|
||
public EntitySupplier(EntityProperties entityProperties) { | ||
this.entityProperties = entityProperties; | ||
} | ||
|
||
public abstract Entity spawnEntity(AuraSkills plugin, Location location); | ||
|
||
public abstract void removeEntity(Entity entity); | ||
|
||
public EntityProperties getEntityProperties() { | ||
return entityProperties; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntityParser.java
This file contains 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,23 @@ | ||
package dev.aurelium.auraskills.bukkit.loot.entity; | ||
|
||
import dev.aurelium.auraskills.bukkit.loot.parser.CustomEntityParser; | ||
import org.spongepowered.configurate.ConfigurationNode; | ||
|
||
public class VanillaEntityParser implements CustomEntityParser { | ||
|
||
@Override | ||
public EntitySupplier getEntitySupplier(ConfigurationNode config) { | ||
return new VanillaEntitySupplier(EntityProperties.fromConfig(config)); | ||
} | ||
|
||
@Override | ||
public boolean shouldUseParser(ConfigurationNode config) { | ||
String entity = config.node("entity").getString(); | ||
|
||
if (entity == null) return false; | ||
|
||
// If it has a colon, it's a custom entity | ||
// But if it starts with minecraft:, it's a vanilla entity stated explicitly | ||
return !entity.contains(":") || entity.startsWith("minecraft:"); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntitySupplier.java
This file contains 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,58 @@ | ||
package dev.aurelium.auraskills.bukkit.loot.entity; | ||
|
||
import dev.aurelium.auraskills.bukkit.AuraSkills; | ||
import org.bukkit.Location; | ||
import org.bukkit.World; | ||
import org.bukkit.attribute.Attribute; | ||
import org.bukkit.attribute.AttributeInstance; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.EntityType; | ||
import org.bukkit.entity.LivingEntity; | ||
import org.bukkit.metadata.FixedMetadataValue; | ||
|
||
public class VanillaEntitySupplier extends EntitySupplier { | ||
|
||
public VanillaEntitySupplier(EntityProperties entityProperties) { | ||
super(entityProperties); | ||
} | ||
|
||
@Override | ||
public Entity spawnEntity(AuraSkills plugin, Location location) { | ||
World world = location.getWorld(); | ||
if (world == null) return null; | ||
|
||
Entity entity = world.spawnEntity(location, EntityType.valueOf(getEntityProperties().entityId().toUpperCase())); | ||
|
||
if (entity instanceof LivingEntity livingEntity) { | ||
if (getEntityProperties().health() != null) { | ||
AttributeInstance attribute = livingEntity.getAttribute(Attribute.GENERIC_MAX_HEALTH); | ||
if (attribute != null) { | ||
attribute.setBaseValue(getEntityProperties().health()); | ||
livingEntity.setHealth(Math.min(getEntityProperties().health(), attribute.getValue())); | ||
} | ||
} | ||
if (getEntityProperties().damage() != null) { | ||
AttributeInstance attribute = livingEntity.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE); | ||
if (attribute != null) { | ||
attribute.setBaseValue(getEntityProperties().damage()); | ||
} | ||
} | ||
} | ||
|
||
if (getEntityProperties().name() != null) { | ||
entity.setCustomName(plugin.getMessageProvider().applyFormatting(getEntityProperties().name())); | ||
entity.setCustomNameVisible(true); | ||
} | ||
|
||
if (getEntityProperties().level() != null) { | ||
entity.setMetadata("auraskills_level", new FixedMetadataValue(plugin, getEntityProperties().level())); | ||
} | ||
|
||
return entity; | ||
} | ||
|
||
@Override | ||
public void removeEntity(Entity entity) { | ||
entity.remove(); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.