The New API for adding Events

1. Open your IDE, for this tutorial i use Eclipse

2. Make a new Project and add my Plugin to the Build Path

3. Create a New Class in the DRFAULT Package, just leave the package Declaration empty

4. let the Class implement Module (IMPORTANT: Do not implement JavaPlugin!)

5. Click at add Unimplemented Methods, this will Create the Methods getName(), getVersion(), getAuthor() and load(LuckyBlocks lb, API api);

Thats how your class could look now:

public class test implements Module {

	@Override
	public String getName() {
		// The modules name
		return "LuckyBlock Addon";
	}

	@Override
	public String getVersion() {
		// The modules Version
		return "v1.0";
	}

	@Override
	public String getAuthor() {
		// The author of the module
		return "Lin_XX";
	}

	@Override
	public void load(LuckyBlocks lb, API api) {
		// Do when module is loaded
		
	}

}

 

6. Export your Project to a .jar file

7. Open your .jar file with 7z WinRar usw.

8. Find your Class(In this Tutorial test.class) and Extract it

9. Move your Class to /plugins/LuckyBlocks/modules/ or Upload it for others to Download

10. Start your Server

 

That is a working module for LuckyBlocks, but it is doing nothing, until you add Stuff to the load() method.

Now i show you, how to make a LuckyEvent:

 

 

	@SuppressWarnings("rawtypes")
	public void addCustomEvents() {
		
		//commandArg array for the Action, this needs to look like this, else, it throws an Error:
		Class[] commandArg = new Class[1];
		commandArg[0] = BlockBreakEvent.class;
		

		try {
			//create a new LuckyEvent(name, action(the method gets executed, if the custom LuckyEvent is used), instance of the class in which your Method is)
			LuckyEvent event;
			event = new LuckyEvent("CustomEventName", this.getClass().getMethod("customEvent", commandArg), this, EventType.LUCKY);
			//add the LuckyEvent to the LuckyBlocks
			api.addLuckyEvent(event);
		} catch (NoSuchMethodException | SecurityException e) {e.printStackTrace();}
		
	}
	//this is the custom event, the method name can be changed, but the Method must have the argument BlockBreakEvent, else it throws an Error
	public void customEvent(BlockBreakEvent e) {
		//get the Player, who opened the LuckyBlock
		e.getPlayer().sendMessage("This is a custom event!");
		//get the LuckyBlocks position
		Location loc = e.getBlock().getLocation();
	}

 

 

 

 


Comments

Posts Quoted:
Reply
Clear All Quotes