Skip to content

Commit

Permalink
Implements VechicleCreateEvent and delegate its implementation to Glo…
Browse files Browse the repository at this point in the history
…wVehicle (GlowstoneMC#922)
  • Loading branch information
VaiTon committed Dec 17, 2018
1 parent 761e468 commit 12b9c7c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
23 changes: 23 additions & 0 deletions src/main/java/net/glowstone/entity/GlowVehicle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.glowstone.entity;

import net.glowstone.EventFactory;
import org.bukkit.Location;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.vehicle.VehicleCreateEvent;

public abstract class GlowVehicle extends GlowEntity implements Vehicle {
/**
* Creates a vehicle and adds it to the specified world.
*
* @param location The location of the entity.
*/
public GlowVehicle(Location location) {
super(location);
VehicleCreateEvent event = EventFactory.getInstance()
.callEvent(new VehicleCreateEvent(this));
if (event.isCancelled()) {
this.remove();
return;
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/net/glowstone/entity/objects/GlowBoat.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import java.util.List;
import lombok.Getter;
import net.glowstone.EventFactory;
import net.glowstone.entity.GlowEntity;
import net.glowstone.entity.GlowPlayer;
import net.glowstone.entity.GlowVehicle;
import net.glowstone.entity.meta.MetadataIndex;
import net.glowstone.net.message.play.entity.EntityMetadataMessage;
import net.glowstone.net.message.play.entity.SpawnObjectMessage;
Expand All @@ -25,7 +25,7 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;

public class GlowBoat extends GlowEntity implements Boat {
public class GlowBoat extends GlowVehicle implements Boat {
private static final double VERTICAL_GRAVITY_ACCEL = -0.04;

@Getter
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/glowstone/entity/objects/GlowMinecart.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import net.glowstone.entity.GlowEntity;
import net.glowstone.entity.GlowPlayer;
import net.glowstone.entity.GlowVehicle;
import net.glowstone.inventory.GlowInventory;
import net.glowstone.net.message.play.entity.SpawnObjectMessage;
import net.glowstone.net.message.play.player.InteractEntityMessage;
Expand All @@ -31,7 +31,7 @@
import org.bukkit.util.Vector;

// TODO: Implement movement and collision detection.
public abstract class GlowMinecart extends GlowEntity implements Minecart {
public abstract class GlowMinecart extends GlowVehicle implements Minecart {
private static final double VERTICAL_GRAVITY_ACCEL = -0.04;

@Getter
Expand Down

0 comments on commit 12b9c7c

Please sign in to comment.