Skip to content

Commit

Permalink
Add new 1.14 Events related to Raids, Merchants and Villagers.
Browse files Browse the repository at this point in the history
  • Loading branch information
i509VCB committed Dec 19, 2019
1 parent 14f6f25 commit 0270d0d
Show file tree
Hide file tree
Showing 7 changed files with 273 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/main/java/org/spongepowered/api/data/Keys.java
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,11 @@ public final class Keys {
*/
public static final Supplier<Key<Value<Profession>>> PROFESSION = Sponge.getRegistry().getCatalogRegistry().provideSupplier(Key.class, "PROFESSION");

/**
* Represents the {@link Key} for the {@link Villager}'s {@link Profession} level.
*/
public static final Supplier<Key<Value<Integer>>> PROFESSION_LEVEL = Sponge.getRegistry().getCatalogRegistry().provideSupplier(Key.class, "PROFESSION_LEVEL");

/**
* Represents the {@link Key} for the type of a {@link Rabbit}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,12 @@ default Value.Mutable<VillagerType> type() {
default Value.Mutable<Profession> profession() {
return getValue(Keys.PROFESSION.get()).get().asMutable();
}

/**
* {@link Keys#PROFESSION_LEVEL}
* @return The profession level of this villager
*/
default Value.Mutable<Integer> professionLevel() {
return getValue(Keys.PROFESSION_LEVEL).get().asMutable();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.spongepowered.api.event.block.entity;

import org.spongepowered.api.block.entity.Bell;
import org.spongepowered.api.effect.potion.PotionEffectTypes;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.event.Cancellable;
import org.spongepowered.api.event.Event;

import java.util.List;

/**
* An event when a {@link Bell} is rung.
*/
public interface RingBellEvent extends Event, Cancellable {

/**
* The {@link Bell} which was rung.
*
* @return The bell which was rung.
*/
Bell getBell();

/**
* The {@link Entity}s which will get a {@link PotionEffectTypes#GLOWING} effect because the {@link Bell} was rung.
*
* @return A list of Entities that will get the glowing effect.
*/
List<Entity> entitiesToGlow();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package org.spongepowered.api.event.entity.living.trader;

import org.spongepowered.api.data.type.Profession;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.living.Hostile;
import org.spongepowered.api.entity.living.golem.IronGolem;
import org.spongepowered.api.entity.living.monster.raider.Raider;
import org.spongepowered.api.entity.living.monster.zombie.ZombieEntity;
import org.spongepowered.api.entity.living.trader.Villager;
import org.spongepowered.api.event.Cancellable;
import org.spongepowered.api.event.Event;
import org.spongepowered.api.raid.Raid;
import org.spongepowered.api.util.annotation.eventgen.GenerateFactoryMethod;

/**
* An event which involves a {@link Villager}.
*/
public interface VillagerEvent extends Event {

/**
* Gets the {@link Villager} involved with this event.\
*
* @return The villager.
*/
Villager getVillager();

/**
* Fired when a {@link Villager}'s profession changes.
*
* <p>This can include both gaining an losing a {@link Profession}.</p>
*/
@GenerateFactoryMethod
interface ChangeProfession extends VillagerEvent, Cancellable {

/**
* Gets the villager's original {@link Profession}.
*
* @return The {@link Villager}'s next {@link Profession}.
*/
Profession getOriginalProfession();

/**
* Gets the {@link Profession} the villager will change to.
*
* @return The {@link Villager}'s next {@link Profession}.
*/
Profession getNextProfession();

/**
* Sets the {@link Villager}'s next {@link Profession}.
*/
void setNextProfession(Profession profession);
}

/**
* Fired when a {@link Villager} levels up it's {@link Profession}.
*/
@GenerateFactoryMethod
interface LevelUpProfession extends VillagerEvent, Cancellable {

/**
* Gets the {@link Villager}'s original {@link Profession} level.
*
* @return The {@link Profession} level.
*/
int getOriginalProfessionLevel();

/**
* Gets the {@link Villager}'s next {@link Profession} level.
*
* @return The {@link Profession} level.
*/
int getNextProfessionLevel();

/**
* Sets the profession level of this {@link Villager} will reach.
*
* @param level The level to set the {@link Villager}'s {@link Profession} to.
*
* <p>Please note that any level above 5 usually does not define TradeOfferGenerators and is therefore ignored.</p>
*/
void setNextProfessionLevel(int level);
}

/**
* Fired when a {@link Villager} starts panicking.
*
* <p>This can occur because of a {@link Raid} or a {@link ZombieEntity}/{@link Raider}
* or both a {@link Raid} and {@link Entity}.</p>
*
* <p>The {@link Villager}'s Panic task will always prioritize the last {@link Entity} which attacked before considering any nearby {@link Hostile} agents.</>
*
*/
@GenerateFactoryMethod
interface Panic extends VillagerEvent, Cancellable {

/**
* Checks if an {@link IronGolem} will be summoned.
*
* @return True if an {@link IronGolem} will be summoned.
*/
boolean willSpawnGolem();

/**
* Sets if the {@link Villager} should summon an {@link IronGolem}.
*
* @param spawnGolem If the {@link Villager} should summon an {@link IronGolem}.
*/
void setShouldSpawnGolem(boolean spawnGolem);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.spongepowered.api.event.item.merchant;

import org.spongepowered.api.entity.living.Humanoid;
import org.spongepowered.api.event.Cancellable;
import org.spongepowered.api.event.Event;
import org.spongepowered.api.item.merchant.Merchant;
import org.spongepowered.api.item.merchant.TradeOffer;

/**
* An event when a {@link Humanoid} trades with a {@link Merchant}.
*/
public interface TradeWithMerchantEvent extends Event, Cancellable {

/**
* Gets the {@link Merchant} which is trading.
*
* @return The trading merchant.
*/
Merchant getMerchant();

/**
* Gets the selected {@link TradeOffer} a {@link Humanoid} could buy.
*
* @return The trade offer.
*/
TradeOffer getSelectedOffer();

/**
* Sets the selected {@link TradeOffer}.
*
* @param offer The offer.
*/
void setTradeOffer(TradeOffer offer);

/**
* Gets the {@link Humanoid} who is the customer of this transaction.
*
* @return The customer.
*/
Humanoid getCustomer();

}
54 changes: 54 additions & 0 deletions src/main/java/org/spongepowered/api/event/raid/RaidEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.spongepowered.api.event.raid;

import org.spongepowered.api.data.type.RaidStatuses;
import org.spongepowered.api.event.Cancellable;
import org.spongepowered.api.event.Event;
import org.spongepowered.api.raid.Raid;
import org.spongepowered.api.raid.Wave;
import org.spongepowered.api.util.annotation.eventgen.GenerateFactoryMethod;

/**
* An event when a raid changes it's current state. Always involves
* a {@link Raid}.
*/
public interface RaidEvent extends Event {

/**
* Gets the {@link Raid} involved with this event.
*
* @return The raid.
*/
Raid getRaid();

/**
* An event where the {@link Raid} is started.
*
* <p>This is fired before any {@link Wave}s have started.</p>
*/
@GenerateFactoryMethod
interface Start extends RaidEvent, Cancellable {}

/**
* An event where a {@link Wave} in a {@link Raid} has started.
*/
@GenerateFactoryMethod
interface StartWave extends RaidEvent, Cancellable {

/**
* The {@link Wave} which is starting.
*
* @return The current wave.
*/
Wave getWave();

}

/**
* An event for when a {@link Raid} has ended.
*
* <p>The raid's state could be either a {@link RaidStatuses#VICTORY}
* or {@link RaidStatuses#LOSS}</p>
*/
@GenerateFactoryMethod
interface End extends RaidEvent {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@

import org.spongepowered.api.Server;
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
import org.spongepowered.api.raid.Raid;
import org.spongepowered.api.util.Identifiable;
import org.spongepowered.api.world.ChunkRegenerateFlag;
import org.spongepowered.api.world.ChunkRegenerateFlags;
import org.spongepowered.api.world.SerializationBehavior;
import org.spongepowered.api.world.SerializationBehaviors;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.chunk.Chunk;
import org.spongepowered.api.world.dimension.DimensionType;
import org.spongepowered.api.world.dimension.DimensionTypes;
import org.spongepowered.api.world.explosion.Explosion;
import org.spongepowered.api.world.storage.WorldProperties;
import org.spongepowered.api.world.storage.WorldStorage;
Expand Down Expand Up @@ -112,7 +115,7 @@ default Optional<Chunk> regenerateChunk(Vector3i chunkPosition, ChunkRegenerateF
/**
* Instructs the world to save all data.
*
* @return True if save was successfull, or false if
* @return True if save was successful, or false if
* {@link SerializationBehavior} is {@link SerializationBehaviors#NONE}
* @throws IOException If the save failed
*/
Expand Down Expand Up @@ -147,4 +150,23 @@ default UUID getUniqueId() {

@Override
Collection<ServerPlayer> getPlayers();

/**
* Gets all {@link Raid}s occuring in this {@link ServerWorld}
*
* <p>Please note by default, some {@link DimensionType}s such as {@link DimensionTypes#THE_NETHER}
* will not contain any Raids because the game prevents Raids from starting in the nether.</p>
*
* @return All the raids in this world.
*/
Collection<Raid> getRaids();

/**
* Gets the {@link Raid} occurring at a position in the world.
*
* @param blockPosition The location of the Raid.
* @return The raid at that location, if present
*/
Optional<Raid> getRaidAt(Vector3i blockPosition);

}

0 comments on commit 0270d0d

Please sign in to comment.