Skip to content

Commit

Permalink
Golem, Leech, Protection Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Sefiraat committed Oct 28, 2021
1 parent 820f7c0 commit 3650d0c
Show file tree
Hide file tree
Showing 14 changed files with 312 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,30 @@ public class RemovalBlocksListener implements Listener {

@EventHandler
public void onRemovableBlockBreak(BlockBreakEvent event) {
event.setCancelled(processBlockRemoval(event.getBlock()));
if (processBlockRemoval(event.getBlock())) {
event.setCancelled(true);
}
}

@EventHandler
public void onBucketUse(PlayerBucketFillEvent event) {
event.setCancelled(processBlockRemoval(event.getBlock()));
if (processBlockRemoval(event.getBlock())) {
event.setCancelled(true);
}
}

@EventHandler
public void onBlockForm(BlockFormEvent event) {
event.setCancelled(processBlockRemoval(event.getBlock()));
if (processBlockRemoval(event.getBlock())) {
event.setCancelled(true);
}
}

@EventHandler
public void onBlockExplode(BlockExplodeEvent event) {
event.setCancelled(processBlockRemoval(event.getBlock()));
if (processBlockRemoval(event.getBlock())) {
event.setCancelled(true);
}
}

private boolean processBlockRemoval(Block block) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import io.github.sefiraat.crystamaehistoria.magic.CastInformation;
import io.github.sefiraat.crystamaehistoria.magic.spells.core.MagicProjectile;
import io.github.sefiraat.crystamaehistoria.utils.Keys;
import io.github.sefiraat.crystamaehistoria.utils.datatypes.DataTypeMethods;
import io.github.sefiraat.crystamaehistoria.utils.datatypes.PersistentUUIDDataType;
import io.github.thebusybiscuit.slimefun4.libraries.dough.data.persistent.PersistentDataAPI;
import org.bukkit.Bukkit;
import org.bukkit.Location;
Expand All @@ -18,9 +20,11 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.player.PlayerEggThrowEvent;
import org.bukkit.event.weather.LightningStrikeEvent;
import org.bukkit.inventory.ItemStack;

Expand Down Expand Up @@ -66,6 +70,13 @@ public void onProjectileHit(ProjectileHitEvent event) {
magicProjectile.kill();
}

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEggThrow(PlayerEggThrowEvent event) {
if (CrystamaeHistoria.getProjectileMap().containsKey(event.getEgg().getUniqueId())) {
event.setHatching(false);
}
}

private boolean entityHitAllowed(CastInformation castInformation, Entity hitEntity) {
final Player player = Bukkit.getPlayer(castInformation.getCaster());
return hitEntity instanceof LivingEntity
Expand Down Expand Up @@ -132,13 +143,17 @@ public void onWitherWeatherDeath(EntityDeathEvent event) {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onMagicSummonDeath(EntityDeathEvent event) {
NamespacedKey key = Keys.PDC_IS_SPAWN_OWNER;
if (PersistentDataAPI.hasBoolean(event.getEntity(), key)) {
if (DataTypeMethods.hasCustom(event.getEntity(), key, PersistentUUIDDataType.TYPE)) {
event.setCancelled(true);
event.getEntity().remove();
}
}




@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onMagicSummonChangeBlock(EntityChangeBlockEvent event) {
NamespacedKey key = Keys.PDC_IS_SPAWN_OWNER;
if (DataTypeMethods.hasCustom(event.getEntity(), key, PersistentUUIDDataType.TYPE)) {
event.setCancelled(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.HolyCow;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.KnowledgeShare;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.LavaLake;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.LeechBomb;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.LovePotion;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.Oviparous;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.PoisonNova;
Expand All @@ -38,6 +39,7 @@
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.SpawnFiends;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.Squall;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.StarFall;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.SummonGolem;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.Teleport;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.Tempest;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.TimeCompression;
Expand Down Expand Up @@ -78,6 +80,7 @@ public enum SpellType {
GYROSCOPIC(new Gyroscopic()),
KNOWLEDGE_SHARE(new KnowledgeShare()),
LAVA_LAKE(new LavaLake()),
LEECH_BOMB(new LeechBomb()),
LOVE_POTION(new LovePotion()),
OVIPAROUS(new Oviparous()),
POISON_NOVA(new PoisonNova()),
Expand All @@ -91,6 +94,7 @@ public enum SpellType {
SPAWN_FIENDS(new SpawnFiends()),
SQUALL(new Squall()),
STAR_FALL(new StarFall()),
SUMMON_GOLEM(new SummonGolem()),
TELEPORT(new Teleport()),
TEMPEST(new Tempest()),
TIME_COMPRESSION(new TimeCompression()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.Projectile;
import org.bukkit.util.Vector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.entity.Mob;
import org.bukkit.entity.Player;

import javax.annotation.Nullable;
import java.util.UUID;
Expand All @@ -15,18 +16,26 @@ public class MagicSummon {
@Getter
public final UUID mobUUID;
@Getter
public final UUID ownerUUID;
@Getter
@Setter
public Consumer<MagicSummon> tickConsumer;

public MagicSummon(Mob mob) {
this.mobUUID = mob.getUniqueId();
public MagicSummon(UUID mobUUID, UUID ownerUUID) {
this.mobUUID = mobUUID;
this.ownerUUID = ownerUUID;
}

@Nullable
public Mob getMob() {
return (Mob) Bukkit.getEntity(mobUUID);
}

@Nullable
public Player getPlayer() {
return (Player) Bukkit.getEntity(ownerUUID);
}

public void kill() {
CrystamaeHistoria.getSummonedEntityMap().remove(this);
Mob mob = (Mob) Bukkit.getEntity(mobUUID);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package io.github.sefiraat.crystamaehistoria.magic.spells.tier1;

import io.github.sefiraat.crystamaehistoria.magic.CastInformation;
import io.github.sefiraat.crystamaehistoria.magic.spells.core.MagicProjectile;
import io.github.sefiraat.crystamaehistoria.magic.spells.core.MagicSummon;
import io.github.sefiraat.crystamaehistoria.magic.spells.core.Spell;
import io.github.sefiraat.crystamaehistoria.magic.spells.core.SpellCoreBuilder;
import io.github.sefiraat.crystamaehistoria.slimefun.machines.liquefactionbasin.SpellRecipe;
import io.github.sefiraat.crystamaehistoria.stories.definition.StoryType;
import io.github.sefiraat.crystamaehistoria.utils.SpellUtils;
import io.github.sefiraat.crystamaehistoria.utils.mobgoals.FiendGoal;
import io.github.sefiraat.crystamaehistoria.utils.mobgoals.LeechGoal;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Mob;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

public class LeechBomb extends Spell {

public LeechBomb() {
SpellCoreBuilder spellCoreBuilder = new SpellCoreBuilder(5, true, 0, false, 50, true)
.makeProjectileSpell(this::fireProjectile, 0, false, 0, false)
.makeProjectileVsEntitySpell(this::eggHit)
.makeProjectileVsBlockSpell(this::eggHit);
setSpellCore(spellCoreBuilder.build());
}

@ParametersAreNonnullByDefault
public void fireProjectile(CastInformation castInformation) {
Location location = castInformation.getCastLocation();
Location aimLocation = location.clone().add(0, 1.5, 0).add(location.getDirection().multiply(1));
MagicProjectile magicProjectile = SpellUtils.summonMagicProjectile(castInformation, EntityType.EGG, aimLocation);
magicProjectile.setVelocity(location.getDirection(), 1.5);
}

@ParametersAreNonnullByDefault
public void eggHit(CastInformation castInformation) {
final UUID caster = castInformation.getCaster();
final Location location = castInformation.getProjectileLocation();
for (int i = 0; i < castInformation.getStaveLevel() * 2; i++) {
final Location spawnLocation = location.clone().add(
ThreadLocalRandom.current().nextDouble(-1, 1),
0,
ThreadLocalRandom.current().nextDouble(-1, 1)
);
SpellUtils.summonTemporaryMob(
EntityType.SILVERFISH,
caster,
spawnLocation,
new LeechGoal(caster),
(60 * castInformation.getStaveLevel()),
this::onTick
);
}
}

public void onTick(MagicSummon magicSummon) {
Mob mob = magicSummon.getMob();
Player player = magicSummon.getPlayer();
Block block = player.getLocation().subtract(0, 0.5, 0).getBlock();
if (!player.getWorld().equals(mob.getWorld())
|| (mob.getLocation().distance(player.getLocation()) > 50 && block.getType().isSolid())
) {
mob.teleport(player.getLocation());
}
displayParticleEffect(magicSummon.getMob(), Particle.SPORE_BLOSSOM_AIR, 1, 1);
}

@Nonnull
@Override
public String getId() {
return "LEECH_BOMB";
}

@Nonnull
@Override
public String[] getLore() {
return new String[]{
"Throws an egg filled with viscous",
"leeches that will attack your enemies."
};
}

@Nonnull
@Override
public Material getMaterial() {
return Material.CARVED_PUMPKIN;
}

@NotNull
@Override
public SpellRecipe getRecipe() {
return new SpellRecipe(
1,
StoryType.MECHANICAL,
StoryType.HUMAN,
StoryType.ANIMAL
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.github.sefiraat.crystamaehistoria.slimefun.machines.liquefactionbasin.SpellRecipe;
import io.github.sefiraat.crystamaehistoria.stories.definition.StoryType;
import io.github.sefiraat.crystamaehistoria.utils.SpellUtils;
import io.github.sefiraat.crystamaehistoria.utils.mobgoals.BoringGoal;
import io.github.sefiraat.crystamaehistoria.utils.mobgoals.FiendGoal;
import org.bukkit.Location;
import org.bukkit.Material;
Expand All @@ -17,7 +16,6 @@
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.UUID;
import java.util.concurrent.Phaser;
import java.util.concurrent.ThreadLocalRandom;

public class SpawnFiends extends Spell {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package io.github.sefiraat.crystamaehistoria.magic.spells.tier1;

import io.github.sefiraat.crystamaehistoria.magic.CastInformation;
import io.github.sefiraat.crystamaehistoria.magic.spells.core.MagicSummon;
import io.github.sefiraat.crystamaehistoria.magic.spells.core.Spell;
import io.github.sefiraat.crystamaehistoria.magic.spells.core.SpellCoreBuilder;
import io.github.sefiraat.crystamaehistoria.slimefun.machines.liquefactionbasin.SpellRecipe;
import io.github.sefiraat.crystamaehistoria.stories.definition.StoryType;
import io.github.sefiraat.crystamaehistoria.utils.SpellUtils;
import io.github.sefiraat.crystamaehistoria.utils.mobgoals.GolemGoal;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Mob;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

public class SummonGolem extends Spell {

public SummonGolem() {
SpellCoreBuilder spellCoreBuilder = new SpellCoreBuilder(5, true, 0, false, 50, true)
.makeInstantSpell(this::cast);
setSpellCore(spellCoreBuilder.build());
}

@ParametersAreNonnullByDefault
public void cast(CastInformation castInformation) {
final UUID caster = castInformation.getCaster();
final Location location = castInformation.getCastLocation();
final Location spawnLocation = location.clone().add(
ThreadLocalRandom.current().nextDouble(-3, 3),
0,
ThreadLocalRandom.current().nextDouble(-3, 3)
);
SpellUtils.summonTemporaryMob(
EntityType.IRON_GOLEM,
caster,
spawnLocation,
new GolemGoal(caster),
200 + (100 * castInformation.getStaveLevel()),
this::onTick
);
}

public void onTick(MagicSummon magicSummon) {
Mob mob = magicSummon.getMob();
Player player = magicSummon.getPlayer();
Block block = player.getLocation().subtract(0, 0.5, 0).getBlock();
if (!player.getWorld().equals(mob.getWorld())
|| (mob.getLocation().distance(player.getLocation()) > 50 && block.getType().isSolid())
) {
mob.teleport(player.getLocation());
}
displayParticleEffect(magicSummon.getMob(), Particle.SLIME, 1, 3);
}

@Nonnull
@Override
public String getId() {
return "SUMMON_GOLEM";
}

@Nonnull
@Override
public String[] getLore() {
return new String[]{
"Summons a golem that will follow you",
"and protect you.",
"Golems will follow you nearly anywhere."
};
}

@Nonnull
@Override
public Material getMaterial() {
return Material.CARVED_PUMPKIN;
}

@NotNull
@Override
public SpellRecipe getRecipe() {
return new SpellRecipe(
1,
StoryType.MECHANICAL,
StoryType.HUMAN,
StoryType.ANIMAL
);
}

}
Loading

0 comments on commit 3650d0c

Please sign in to comment.