forked from nisovin/MagicSpells
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added PortalEnter/Leave events to the Portal spell. They are now cancellable, and their destination location is stored and can be modified. Added passive triggers: "portalenter" and "portalleave".
- Loading branch information
1 parent
2991961
commit 1d92baf
Showing
8 changed files
with
184 additions
and
97 deletions.
There are no files selected for viewing
13 changes: 0 additions & 13 deletions
13
core/src/main/java/com/nisovin/magicspells/events/MagicSpellsExplosionPrimeEvent.java
This file was deleted.
Oops, something went wrong.
46 changes: 5 additions & 41 deletions
46
core/src/main/java/com/nisovin/magicspells/events/PortalEnterEvent.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,53 +1,17 @@ | ||
package com.nisovin.magicspells.events; | ||
|
||
import org.bukkit.event.Event; | ||
import org.bukkit.event.HandlerList; | ||
import org.bukkit.Location; | ||
import org.bukkit.entity.LivingEntity; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import com.nisovin.magicspells.spells.instant.PortalSpell; | ||
|
||
/** | ||
* This event is fired whenever an entity enters a portal from PortalSpell. | ||
* This event is fired whenever an entity enters a portal from {@link PortalSpell}. | ||
*/ | ||
public class PortalEnterEvent extends Event { | ||
|
||
private static final HandlerList handlers = new HandlerList(); | ||
|
||
private final LivingEntity entity; | ||
|
||
private final PortalSpell portalSpell; | ||
|
||
public PortalEnterEvent(LivingEntity entity, PortalSpell portalSpell) { | ||
this.entity = entity; | ||
this.portalSpell = portalSpell; | ||
} | ||
|
||
/** | ||
* Gets the entity who entered the portal | ||
* @return the entity | ||
*/ | ||
public LivingEntity getEntity() { | ||
return entity; | ||
} | ||
|
||
/** | ||
* Gets the portal spell | ||
* @return the spell | ||
*/ | ||
public PortalSpell getPortalSpell() { | ||
return portalSpell; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public HandlerList getHandlers() { | ||
return handlers; | ||
} | ||
public class PortalEnterEvent extends PortalEvent { | ||
|
||
public static HandlerList getHandlerList() { | ||
return handlers; | ||
public PortalEnterEvent(LivingEntity entity, Location destination, PortalSpell portalSpell) { | ||
super(entity, destination, portalSpell); | ||
} | ||
|
||
} |
84 changes: 84 additions & 0 deletions
84
core/src/main/java/com/nisovin/magicspells/events/PortalEvent.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,84 @@ | ||
package com.nisovin.magicspells.events; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.event.Cancellable; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.HandlerList; | ||
import org.bukkit.entity.LivingEntity; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import com.nisovin.magicspells.spells.instant.PortalSpell; | ||
|
||
/** | ||
* {@link PortalSpell} | ||
*/ | ||
public class PortalEvent extends Event implements Cancellable { | ||
|
||
private static final HandlerList handlers = new HandlerList(); | ||
|
||
private Location destination; | ||
private final LivingEntity entity; | ||
private final PortalSpell portalSpell; | ||
|
||
private boolean cancelled = false; | ||
|
||
public PortalEvent(LivingEntity entity, Location destination, PortalSpell portalSpell) { | ||
this.entity = entity; | ||
this.destination = destination; | ||
this.portalSpell = portalSpell; | ||
} | ||
|
||
/** | ||
* Gets the entity who entered the portal | ||
* @return the entity | ||
*/ | ||
public LivingEntity getEntity() { | ||
return entity; | ||
} | ||
|
||
/** | ||
* Gets a clone of the portal destination | ||
* @return location | ||
*/ | ||
public Location getDestination() { | ||
return destination.clone(); | ||
} | ||
|
||
/** | ||
* Set the portal destination for this event | ||
* @param destination new destination | ||
*/ | ||
public void setDestination(Location destination) { | ||
this.destination = destination; | ||
} | ||
|
||
/** | ||
* Gets the portal spell | ||
* @return the spell | ||
*/ | ||
public PortalSpell getPortalSpell() { | ||
return portalSpell; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public HandlerList getHandlers() { | ||
return handlers; | ||
} | ||
|
||
public static HandlerList getHandlerList() { | ||
return handlers; | ||
} | ||
|
||
@Override | ||
public boolean isCancelled() { | ||
return cancelled; | ||
} | ||
|
||
@Override | ||
public void setCancelled(boolean cancel) { | ||
cancelled = cancel; | ||
} | ||
|
||
} |
46 changes: 5 additions & 41 deletions
46
core/src/main/java/com/nisovin/magicspells/events/PortalLeaveEvent.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,53 +1,17 @@ | ||
package com.nisovin.magicspells.events; | ||
|
||
import org.bukkit.event.Event; | ||
import org.bukkit.event.HandlerList; | ||
import org.bukkit.Location; | ||
import org.bukkit.entity.LivingEntity; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import com.nisovin.magicspells.spells.instant.PortalSpell; | ||
|
||
/** | ||
* This event is fired whenever an entity leaves a portal from PortalSpell. | ||
* This event is fired whenever an entity leaves a portal from {@link PortalSpell}. | ||
*/ | ||
public class PortalLeaveEvent extends Event { | ||
|
||
private static final HandlerList handlers = new HandlerList(); | ||
|
||
private final LivingEntity entity; | ||
|
||
private final PortalSpell portalSpell; | ||
|
||
public PortalLeaveEvent(LivingEntity entity, PortalSpell portalSpell) { | ||
this.entity = entity; | ||
this.portalSpell = portalSpell; | ||
} | ||
|
||
/** | ||
* Gets the entity who left the portal | ||
* @return the entity | ||
*/ | ||
public LivingEntity getEntity() { | ||
return entity; | ||
} | ||
|
||
/** | ||
* Gets the portal spell | ||
* @return the spell | ||
*/ | ||
public PortalSpell getPortalSpell() { | ||
return portalSpell; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public HandlerList getHandlers() { | ||
return handlers; | ||
} | ||
public class PortalLeaveEvent extends PortalEvent { | ||
|
||
public static HandlerList getHandlerList() { | ||
return handlers; | ||
public PortalLeaveEvent(LivingEntity entity, Location destination, PortalSpell portalSpell) { | ||
super(entity, destination, portalSpell); | ||
} | ||
|
||
} |
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
38 changes: 38 additions & 0 deletions
38
core/src/main/java/com/nisovin/magicspells/spells/passive/PortalEnterListener.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,38 @@ | ||
package com.nisovin.magicspells.spells.passive; | ||
|
||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.entity.LivingEntity; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import com.nisovin.magicspells.util.Name; | ||
|
||
import com.nisovin.magicspells.util.SpellFilter; | ||
import com.nisovin.magicspells.events.PortalEnterEvent; | ||
import com.nisovin.magicspells.spells.passive.util.PassiveListener; | ||
|
||
@Name("portalenter") | ||
public class PortalEnterListener extends PassiveListener { | ||
|
||
private SpellFilter filter; | ||
|
||
@Override | ||
public void initialize(@NotNull String var) { | ||
if (var.isEmpty()) return; | ||
filter = SpellFilter.fromString(var); | ||
} | ||
|
||
@EventHandler | ||
public void onEnter(PortalEnterEvent event) { | ||
if (!isCancelStateOk(event.isCancelled())) return; | ||
|
||
LivingEntity entity = event.getEntity(); | ||
if (!canTrigger(entity)) return; | ||
|
||
if (filter != null && !filter.check(event.getPortalSpell())) return; | ||
|
||
boolean casted = passiveSpell.activate(entity); | ||
if (cancelDefaultAction(casted)) event.setCancelled(true); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
core/src/main/java/com/nisovin/magicspells/spells/passive/PortalLeaveListener.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,38 @@ | ||
package com.nisovin.magicspells.spells.passive; | ||
|
||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.entity.LivingEntity; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import com.nisovin.magicspells.util.Name; | ||
|
||
import com.nisovin.magicspells.util.SpellFilter; | ||
import com.nisovin.magicspells.events.PortalLeaveEvent; | ||
import com.nisovin.magicspells.spells.passive.util.PassiveListener; | ||
|
||
@Name("portalleave") | ||
public class PortalLeaveListener extends PassiveListener { | ||
|
||
private SpellFilter filter; | ||
|
||
@Override | ||
public void initialize(@NotNull String var) { | ||
if (var.isEmpty()) return; | ||
filter = SpellFilter.fromString(var); | ||
} | ||
|
||
@EventHandler | ||
public void onLeave(PortalLeaveEvent event) { | ||
if (!isCancelStateOk(event.isCancelled())) return; | ||
|
||
LivingEntity entity = event.getEntity(); | ||
if (!canTrigger(entity)) return; | ||
|
||
if (filter != null && !filter.check(event.getPortalSpell())) return; | ||
|
||
boolean casted = passiveSpell.activate(entity); | ||
if (cancelDefaultAction(casted)) event.setCancelled(true); | ||
} | ||
|
||
} |
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