feat: added PortalEvent to EventBuilder

This commit is contained in:
Yannik Bretschneider 2021-06-24 15:37:30 +02:00
parent 81e53edb2a
commit 371424e6c3
3 changed files with 58 additions and 0 deletions

View File

@ -12,6 +12,8 @@ public enum EntityType {
Rocks,
/** Represents an InfinityStone entity */
InfinityStones,
/** Represents a Portal */
Portals,
/** Represents nothing */
None
}

View File

@ -46,6 +46,10 @@ public class EventBuilder {
private Integer[] stoneCooldowns;
private Boolean winCondition;
// Keys used in TeleportedEvents (plus origin/targetFields)
public EntityID teleportedEntity;
public EntityID originPortal, targetPortal;
// Keys used in CustomEvents
private String teamIdentifier;
private HashMap<String, Object> customContent;
@ -167,6 +171,21 @@ public class EventBuilder {
return this;
}
public EventBuilder withTeleportedEntity(EntityID teleportedEntity) {
this.teleportedEntity = teleportedEntity;
return this;
}
public EventBuilder withOriginPortal(EntityID originPortal) {
this.originPortal = originPortal;
return this;
}
public EventBuilder withTargetPortal(EntityID targetPortal) {
this.targetPortal = targetPortal;
return this;
}
public EventBuilder withTeamIdentifier(String teamIdentifier) {
this.teamIdentifier = teamIdentifier;
return this;
@ -293,6 +312,21 @@ public class EventBuilder {
return customEvent;
}
/**
* Builds a {@link TeleportedEvent}, used for describing teleporting Players into Portals.
* @return the built {@link TeleportedEvent}
*/
public TeleportedEvent buildTeleportedEvent() {
var teleportedEvent = new TeleportedEvent();
teleportedEvent.type = this.type;
teleportedEvent.originField = this.originField;
teleportedEvent.targetField = this.targetField;
teleportedEvent.teleportedEntity = this.teleportedEntity;
teleportedEvent.originPortal = this.originPortal;
teleportedEvent.targetPortal = this.targetPortal;
return teleportedEvent;
}
@Override
public String toString() {
StringJoiner joiner = new StringJoiner("\n");

View File

@ -394,4 +394,26 @@ class EventBuilderTest {
}
@Test
void buildPortalEvents() {
var built = new EventBuilder(EventType.TeleportedEvent)
.withTeleportedEntity(new EntityID(EntityType.P1, 3))
.withOriginField(new IntVector2(6, 2))
.withTargetField(new IntVector2(11, 14))
.withOriginPortal(new EntityID(EntityType.Portals, 0))
.withTargetPortal(new EntityID(EntityType.Portals, 2))
.buildTeleportedEvent();
var actual = new TeleportedEvent();
actual.type = EventType.TeleportedEvent;
actual.originField = new IntVector2(6, 2);
actual.targetField = new IntVector2(11, 14);
actual.teleportedEntity = new EntityID(EntityType.P1, 3);
actual.originPortal = new EntityID(EntityType.Portals, 0);
actual.targetPortal = new EntityID(EntityType.Portals, 2);
assertThat(built).isEqualTo(actual);
}
}