api/events/documentation/DMGenerationChest

Dungeon Maze API - Events - Event Documentation - DMGenerationChest

The DMGenerationChest is called when a chest is generated in Dungeon Maze. This event could be used to set the contents of the chest, you can cancel the chest generation and you can even do other things too.

How to listen to the event

It's very easy to listen to Dungeon Maze events, the same system is used as bukkit does. Because of this, listening to an event should be extremely easy to do. If you want to listen to an event, you don't even have to hook into the Dungeon Maze api, wich makes it even easier to use. Read the paragraph bellow for an example about listening to the event.

Dungeon Maze Event Listener example - DMGenerationChest

We hightly recommend to create a new listener class for the Dungeon Maze API to keep your project organized, but it's up to you where you put the listener. You can add them in the same class file as your block listeners for example.

First make sure you've implemeted the DungeonMaze.jar file into your project.

Bellow you can see an example of a listener using this event:

import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;

import com.timvisee.DungeonMaze.event.generation.DMGenerationChestEvent;

public class DungeonMazeApiListener implements Listener  {
	
	@EventHandler
	public void onDMGenerationChest(DMGenerationChestEvent event) {
		// Clear the contents of the chest first
		event.getContents().clear();

		// Add a stack of 3 diamonds to the chest
		event.getContents().add(new ItemStack(Material.DIAMOND, 3));
	}
}

This listener puts 3 diamonds in every chest and removes its original contents.

Event Features

Bellow you can find a list of features this event contains.

FunctionDescription
.isCancelled();Check if the event is cancelled
.setCancelled(boolean cancelled);Set if the event will be cancelled
.getBlock();Get the block location the chest is created
.getDMLevel();Get the level the block is on
.getWorld();Get the world the chest is created in
.getContents();Get the list of contents witch will be added to the chest. These contents may be modified to change the contents
.setContents();Set the contents of a chest
.getRandom();Get the random object from the Dungeon Maze generator, to add seeds support
.getAddContentsInOrder();Check if the items will be placed in order, or randomly
.setAddContentsInOrder(boolean addInOrder);Set if items will be placed in order, or randomly
.getHandlers()Get the handlers list
.getHandlerList();Get the handlers list
.getServer();Get the server

Comments

Posts Quoted:
Reply
Clear All Quotes