-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Continue implementing node dispatching
- Loading branch information
1 parent
99f0f0b
commit 8d018fd
Showing
19 changed files
with
293 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
plugins { | ||
`java-library` | ||
} | ||
|
||
dependencies{ | ||
api(project(":nodes")) | ||
} |
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 |
---|---|---|
|
@@ -4,5 +4,6 @@ plugins{ | |
|
||
dependencies{ | ||
api(project(":nodes")) | ||
api(project(":api")) | ||
api(libs.bundles.eldoria.utilities) | ||
} |
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
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
7 changes: 0 additions & 7 deletions
7
core/src/main/java/de/eldoria/bloodnight/mobs/TriggerDispatcher.java
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
core/src/main/java/de/eldoria/bloodnight/mobs/dispatcher/DefaultTriggerDispatcher.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,42 @@ | ||
package de.eldoria.bloodnight.mobs.dispatcher; | ||
|
||
import de.eldoria.bloodnight.mobs.MobCoordinator; | ||
import de.eldoria.bloodnight.nodes.dispatching.TriggerData; | ||
import de.eldoria.bloodnight.nodes.trigger.TriggerNode; | ||
import de.eldoria.bloodnight.nodes.trigger.impl.events.OnDeathNode; | ||
import de.eldoria.bloodnight.nodes.trigger.impl.events.OnExplosionPrimeNode; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.entity.EntityDamageByBlockEvent; | ||
import org.bukkit.event.entity.EntityDamageByEntityEvent; | ||
import org.bukkit.event.entity.EntityDamageEvent; | ||
import org.bukkit.event.entity.EntityDeathEvent; | ||
import org.bukkit.event.entity.ExplosionPrimeEvent; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
/** | ||
* This class listens to events, wraps their data into a {@link TriggerData} and trigger corresponding {@link TriggerNode}. | ||
* This class only covers predefined trigger nodes. | ||
* Custom nodes will need to create their own trigger dispatcher. | ||
*/ | ||
public class DefaultTriggerDispatcher extends TriggerDispatcher { | ||
|
||
public DefaultTriggerDispatcher(MobCoordinator coordinator) { | ||
super(coordinator); | ||
} | ||
|
||
@EventHandler | ||
public void onDeath(EntityDeathEvent event) { | ||
trigger(event.getEntity(), TriggerData.forNode(OnDeathNode.class, event)); | ||
} | ||
|
||
@EventHandler | ||
public void onExplosionPrime(ExplosionPrimeEvent event) { | ||
trigger(event.getEntity(), TriggerData.forNode(OnExplosionPrimeNode.class, event)); | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
core/src/main/java/de/eldoria/bloodnight/mobs/dispatcher/KillDispatcher.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,42 @@ | ||
package de.eldoria.bloodnight.mobs.dispatcher; | ||
|
||
import de.eldoria.bloodnight.mobs.MobCoordinator; | ||
import de.eldoria.bloodnight.nodes.dispatching.TriggerData; | ||
import de.eldoria.bloodnight.nodes.trigger.impl.events.OnDeathNode; | ||
import de.eldoria.bloodnight.nodes.trigger.impl.events.OnEntityKillNode; | ||
import de.eldoria.bloodnight.nodes.trigger.impl.events.OnPlayerKillNode; | ||
import org.bukkit.entity.LivingEntity; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.entity.EntityDamageByEntityEvent; | ||
import org.bukkit.event.entity.EntityDeathEvent; | ||
|
||
public class KillDispatcher extends TriggerDispatcher { | ||
public KillDispatcher(MobCoordinator coordinator) { | ||
super(coordinator); | ||
} | ||
|
||
/** | ||
* This handler is purely for observing dealt damage to entities to notice who killed it. | ||
* | ||
* @param event damage event | ||
*/ | ||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) | ||
public void onEntityDamageDelegate(EntityDamageByEntityEvent event) { | ||
if (!(event.getEntity() instanceof LivingEntity living)) return; | ||
// Check if entity will be killed. | ||
if (event.getFinalDamage() >= living.getHealth()) { | ||
if (event.getEntity() instanceof Player) { | ||
trigger(event.getDamager(), TriggerData.forNode(OnPlayerKillNode.class, event)); | ||
} else { | ||
trigger(event.getDamager(), TriggerData.forNode(OnEntityKillNode.class, event)); | ||
} | ||
} | ||
} | ||
|
||
@EventHandler | ||
public void onEntityDeath(EntityDeathEvent event) { | ||
trigger(event.getEntity(), TriggerData.forNode(OnDeathNode.class, event)); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
core/src/main/java/de/eldoria/bloodnight/mobs/dispatcher/TriggerDispatcher.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 de.eldoria.bloodnight.mobs.dispatcher; | ||
|
||
import de.eldoria.bloodnight.mobs.MobCoordinator; | ||
import de.eldoria.bloodnight.nodes.dispatching.TriggerData; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.event.Listener; | ||
|
||
/** | ||
* Basic Trigger dispatcher. | ||
* Holds a {@link MobCoordinator} and provides delegates to the core functionality. | ||
*/ | ||
public class TriggerDispatcher implements Listener { | ||
private final MobCoordinator coordinator; | ||
|
||
public TriggerDispatcher(MobCoordinator coordinator) { | ||
this.coordinator = coordinator; | ||
} | ||
|
||
public void trigger(Entity entity, TriggerData<?> trigger) { | ||
coordinator.trigger(entity, trigger); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
core/src/main/java/de/eldoria/bloodnight/mobs/exceptions/MobIdAlreadyTakenException.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,25 @@ | ||
package de.eldoria.bloodnight.mobs.exceptions; | ||
|
||
import de.eldoria.bloodnight.mob.CustomMob; | ||
|
||
/** | ||
* Exception thrown when trying to register a CustomMob with an id that is already taken by another CustomMob. | ||
*/ | ||
public class MobIdAlreadyTakenException extends RuntimeException { | ||
private final CustomMob newMob; | ||
private final CustomMob currentMob; | ||
|
||
public MobIdAlreadyTakenException(CustomMob newMob, CustomMob currentMob) { | ||
super("Could not register %s. The id %s is already taken by %s".formatted(newMob.getClass().getName(), newMob.id(), currentMob.getClass().getName())); | ||
this.newMob = newMob; | ||
this.currentMob = currentMob; | ||
} | ||
|
||
public CustomMob newMob() { | ||
return newMob; | ||
} | ||
|
||
public CustomMob currentMob() { | ||
return currentMob; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
core/src/main/java/de/eldoria/bloodnight/util/MobTags.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 |
---|---|---|
@@ -1,7 +1,26 @@ | ||
package de.eldoria.bloodnight.util; | ||
|
||
import de.eldoria.bloodnight.mob.CustomMob; | ||
import org.bukkit.NamespacedKey; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.persistence.PersistentDataType; | ||
|
||
public class MobTags { | ||
/** | ||
* Marks that an {@link Entity} is a {@link CustomMob}. | ||
* This tag is solely for existence checks and should use a {@link PersistentDataType#BYTE}. | ||
* The value of the byte doesn't matter. | ||
* If this tag is set on the mob with the BYTE type, it is always considered a custom mob. | ||
*/ | ||
public static final NamespacedKey CUSTOM_MOB = new NamespacedKey("bloodnight", "custom_mob"); | ||
/** | ||
* Marks that a mob is an extension of a custom mob. | ||
* This tag should use a {@link PersistentDataType#INTEGER} containing the {@link Entity#getEntityId()} of the entity that the mob has, that is extended. | ||
*/ | ||
public static final NamespacedKey EXTENDS = new NamespacedKey("bloodnight", "extends"); | ||
/** | ||
* Marks that a mob is extended and has another mob attached to it. | ||
* This tag should use a {@link PersistentDataType#INTEGER} containing the {@link Entity#getEntityId()} of the entity that extends this mob. | ||
*/ | ||
public static final NamespacedKey EXTENDED = new NamespacedKey("bloodnight", "extended"); | ||
} |
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
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.