Dimensions API
  • Setting up
  • Creating an addon
  • Example Addon
  • Reference
    • API Reference
      • CustomPortal
      • CompletePortal
      • PortalGeometry
      • Events
Powered by GitBook
On this page
  • Creating the project
  • Creating the main class
  • Registering listener
  • CustomPortalIgniteEvent
  • Finishing up
  • Done

Example Addon

PreviousCreating an addonNextAPI Reference

Last updated 2 years ago

The source code for the example addon can be found

Creating the project

Create a new project and add to your build path

Creating the main class

package me.xxastaspastaxx.dimensions.addons.exampleaddon;

import org.bukkit.event.Listener;

import me.xxastaspastaxx.dimensions.addons.DimensionsAddon;
import me.xxastaspastaxx.dimensions.addons.DimensionsAddonPriority;

public class DimensionsExampleAddonMain extends DimensionsAddon implements Listener {

	public DimensionsExampleAddonMain() {
		super(addonName, addonVersion, addonDescription, addonPriority); //Replace with whatever you want
	}
	
}

Registering listener

@Override
public void onEnable(Dimensions pl) {
	Bukkit.getPluginManager().registerEvents(this, pl);
}

CustomPortalIgniteEvent

	
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void postPortalIgnite(CustomPortalIgniteEvent e) {
		//We check if the entity is a player, if its not we skip
		//If the player does not have permission, we also skip
		if (!(e.getEntity() instanceof Player) || !e.getEntity().hasPermission("dimensions.exampleaddon.explosion")) return;
		
		//Everything looks fine so we summon the explosion
		CompletePortal complete = e.getCompletePortal(); //We get the complete portal
		Location location = complete.getCenter(); //We get the center of the portal
		
		//We summon the particles
		location.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, location, 5);
}
	

Finishing up

Now that we are done with coding, we have to let Dimensions know about our addon otherwise its not going to load it.

You need to create a few folders and files inside our src folder.

src
└───main
    └───java
        └───META-INF
            └───services

Inside the services folder we need to create a new file named:

me.xxastaspastaxx.dimensions.addons.DimensionsAddon

Finally, inside the file, enter the path to your main class as you would with plugin.yml

for example in this case it would be

me.xxastaspastaxx.dimensions.addons.exampleaddon.DimensionsExampleAddonMain

Done

Now you can put the addon you made inside ./plugins/Dimensions/Addons/ and restart your server.

Now we want to register our addon as a listener when the addon is being enabled so we add

And finally we want to listen to the so we can summon the explosion particles. We use the EventHandler like we would in any other case.

This last part is required by in order to load the addons properly

here
Dimensions.jar
onEnable
CustomPortalIgniteEvent
ServiceLoader