Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand Events #330

Closed
wants to merge 1 commit into from
Closed

Expand Events #330

wants to merge 1 commit into from

Conversation

gabizou
Copy link
Member

@gabizou gabizou commented Dec 27, 2014

Adds the following events:

  • TileEntityEvents
    • BrewingStandBrewEvent
    • BrewingStandEvent
    • FurnaceBurnEvent
    • FurnaceCookEvent
    • FurnaceEvent
    • SignChangeEvent
    • SignEvent
    • TileEntityEvent
  • EntityEvents
    • EntityBreedEvent
    • EntityEquipmentChangeEvent
    • EntityExpireEvent
    • EntityIgniteEvent
    • EntityItemConsumeEvent
    • EnttyLeashEvent
    • ProjectileLaunchEvent
  • LivingEvents
    • LivingChangeBlockEvent
    • LivingChangeHealthEvent
    • LivingDeathEvent
    • LivingDropItemEvent
    • LivingEquipmentChangeEvent
    • LivingEvent
    • LivingExpirePotionEffectEvent
    • LivingInteractBlockEvent
    • LivingInteractEntityEvent
    • LivingInteractEvent
    • LivingItemConsumeEvent
    • LivingMoveEvent
    • LivingPickUpItemEvent
    • LivingPlaceBlockEvent
    • LivingPotionEffectEvent
    • LivingRemovePotionEffectEvent
    • LivingUpdateEvent
  • HumanEvents
    • HumanBreakBlockEvent
    • HumanChangeBlockEvent
    • HumanChangeGameModeEvent
    • HumanChangeHealthEvent
    • HumanDeathEvent
    • HumanDropItemEvent
    • HumanEnterBedEvent
    • HumanEquipmentChangeEvent
    • HumanEvent
    • HumanExpChangeEvent
    • HumanInteractBlockEvent
    • HumanInteractEntityEvent
    • HumanInteractEvent
    • HumanItemConsumeEvent
    • HumanLeaveBedEvent
    • HumanLevelChangeEvent
    • HumanMoveEvent
    • HumanPickUpItemEvent
    • HumanPlaceBlockEvent
    • HumanSleepEvent
    • HumanUpdateEvent
  • PlayerEvents
    • PlayerChangeGameModeEvent
    • PlayerChangeHealthEvent
    • PlayerDeathEvent
    • PlayerEnterBedEvent
    • PlayerEquipmentChangeEvent
    • PlayerEvent
    • PlayerExpChangeEvent
    • PlayerItemConsumeEvent
    • PlayerLeaveBedEvent
    • PlayerLevelChangeEvent
    • PlayerPickUpItemEvent
  • MinecartEvents
    • MinecartEvent
  • ItemEvents
    • ItemEvent
    • ItemExpireEvent
    • ItemMergeEvent

Modifies the following events:

  • EntityDeathEvent
  • EntityInteractEvent
  • ProjectileLaunchEvent

More events are to follow as seen fit.

public interface PlayerBedEvent extends PlayerEvent {

/**
* Gets the location of the player in respect to the bed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be Gets the location of the player *before entering the bed* instead.

@gabizou gabizou added this to the 1.1-Release milestone Dec 27, 2014
@gabizou gabizou self-assigned this Dec 27, 2014
/**
* Called when an {@link Entity} is killed or removed due to unload.
*/
public interface EntityDeathEvent extends EntityEvent, CauseTracked, Cancellable {

/**
* Gets a copy of the {@link ItemStack}s this entity will drop on death.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a copy? Could this list be mutable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's addressed by setDrops

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, but seems unnecessary since List has methods to make it simpler

event.getDrops().add(event.getGame().getRegistry().getItemBuilder() ...);

Is neater than

List<ItemStack> drops = event.getDrops();
drops.add(event.getGame().getRegistry().getItemBuilder() ...);
event.setDrops(drops);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree with leaving lists mutable, I'd rather have copies handed around to prevent manipulating or holding references of live ItemStacks following death events.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there not a way to use a mutable list, without leaking references to itemstacks afterwards? Like using an editable snapshot which doesn't get used again?

@ST-DDT
Copy link
Member

ST-DDT commented Dec 29, 2014

What about EntityDamagedEvent, EntityDamagedByBlockEvent, EntityDamagedByEntityEvent or PlayerDamagedEvent?

@simon816
Copy link
Contributor

@ST-DDT I'm not sure how event causes are going to work but that sounds like something that would be described in the cause.

@gabizou
Copy link
Member Author

gabizou commented Dec 29, 2014

What about EntityDamagedEvent, EntityDamagedByBlockEvent, EntityDamagedByEntityEvent or PlayerDamagedEvent?

What about them? Are you copying the events we had from Bukkit?

@ST-DDT
Copy link
Member

ST-DDT commented Dec 29, 2014

@simon816 Maybe, i'm not sure about using Cause for that (or at least not as standalone solution). Because there are multiple mutable values involved in that: the damage itself, the damage modifiers ... Although i can thing of some advantages of additionally using the Cause/Reason stuff. Entity died -> get cause = entity damaged -> get cause = projectile hit -> get cause = projectile shot -> by whom = playerABC. (Some kind of gameplay stacktrace)

@gabizou What? I only suggested them or similar things to be added.
(Was my phrasing impolite or unclear? Maybe this in one of the things you cannot properly translate. It was intended to be a simple question pointing to something that has not been part of the discussion here yet.)
I just want to (help) recreate most part of the API, so that I can easily move my plugins if there is no similar method/class/interface in the API either does it in another way or it is not implemented yet.
Currently there is no way (i don't know any way) to get the functionality of the DamageEvents so I pointed at them / asked whether they have been forgotten until yet. simon816 gave me a good hint that they are already/will be handled using the Causes.

*
* @param drops The list of drops the entity will drop on death
*/
void setDrops(List<ItemStack> drops);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are set drops removed from the players inventory, or will removing an item from the drops not replace it in the players inventory?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the player will lose everything on death, and this is what it drops. (Correct me if I am wrong)

* Gets the clicked position of this interact event.
*
* <p>This may not always be available, in which case
* {@link Optional#absent()} is returned. Specifically, when a player
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clicked position is sent by the client for all entities. The only time it's not available is for blocks.

Is this event going to be subclassed to handle interacting with entities, or are those method going to be added to this class?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clicked position is sent by the client for all entities

No it is not. Again, refer to the protocol.

The only time it's not available is for blocks.

It's almost always available for blocks.

Is this event going to be subclassed to handle interacting with entities, or are those method going to be added to this class?

No. It isn't necessary since PlayerInteractEntity extends PlayerInteract.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it is not. Again, refer to the protocol.

I've looked at MCP - two packets get sent for all interactions, except for ArmorStand: only INTERACT_AT is sent. Even if it wasn't, there's no reason it couldn't be calculated server-side.

Additionally, I've seen thing while working on handling the Use Entity packet in Glowstone.

@thomas15v
Copy link
Contributor

Just wondering should PlayerExpChangeEvent not have a setCurrent. It would avoid the whole getPlayer().setExperience() thing. And it would allow multiple plugins to change/modify the experience gain.

@gabizou gabizou changed the title [WIP] Add more expansive Player related events [WIP] Expand Events Jan 15, 2015
int getTotalExperinece();

/**
* Sets the experience accumulated towards the next level.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a note about how much experience advances a player to the next level.

public interface HumanLeaveBedEvent extends HumanSleepEvent {

/**
* Gets whether the spawn location for the player was set.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a note explaining why this could be false.

@AlphaModder
Copy link
Contributor

Some events I thought of:

EntityAddStatusEffectEvent
EntityRemoveStatusEffectEvent
BlockHitEvent
BlockFallEvent
EntityStruckByLightningEvent
NoteblockPlayEvent
EntityIgniteEvent
EntityExplodeEvent (maybe)
EntityEnterPortalEvent
EntityLeashedEvent

* Gets the clicked position of this interact event.
*
* <p>This may not always be available, in which case
* {@link Optional#absent()} is returned. Specifically, when a player
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the location is sent for all entities (although it's only used for AmorStands)

@me4502
Copy link
Contributor

me4502 commented Jan 21, 2015

From what I can tell we are missing SignChangeEvent. Maybe make it extend BlockChangeEvent

@gabizou
Copy link
Member Author

gabizou commented Jan 22, 2015

Just wondering should PlayerExpChangeEvent not have a setCurrent. It would avoid the whole getPlayer().setExperience() thing. And it would allow multiple plugins to change/modify the experience gain.

The problem with doing this is that the event is a "state". Changing the experience via getPlayer() would be overwritten when the event is completed and processed.

From what I can tell we are missing SignChangeEvent. Maybe make it extend BlockChangeEvent

Will add.

EntityAddStatusEffectEvent
EntityRemoveStatusEffectEvent

Adding in a different way, but being added nonetheless.

BlockHitEvent

Could you elaborate on what this does?

BlockFallEvent

EntityStruckByLightningEvent

Already covered by LightingStrikeEvent#getStruckEntities()

NoteblockPlayEvent

Perhaps a more generic way to do this?

EntityIgniteEvent

Will add.

EntityEnterPortalEvent

Perhaps can be handled via EntityTeleportEvent since all portals do teleport entities.

EntityLeashedEvent

Will add.

@AlphaModder
Copy link
Contributor

@gabizou BlockHitEvent is essentially when a player starts breaking a block. Bukkit had a BlockDamageEvent that did the same thing and allowed you to get/setInstant(). You might say you could do the same with interact and then set the block to air, but if you want drops or other vanilla block breaking handling or something it's useful.

@gabizou gabizou force-pushed the feature/player-events branch 2 times, most recently from c6c539c to 97b3e76 Compare January 22, 2015 01:37
@gabizou gabizou changed the title [WIP] Expand Events Expand Events Jan 22, 2015
@AlphaModder
Copy link
Contributor

MerchantTradeEvent? perhaps with TradeOffer getOffer(), ItemStack getFirstStack() and ItemStack getSecondStack()?

import org.spongepowered.api.item.inventory.ItemStack;

/**
* An event when a {@link Furnace}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docs?

@gabizou gabizou closed this in 57d70e3 Jan 23, 2015
@gabizou gabizou deleted the feature/player-events branch January 23, 2015 04:10
gabizou added a commit that referenced this pull request Jan 23, 2015
- Living
- Human
- Player
- TileEntity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet