Skip to content
Permalink
Browse files

Use the config to listen for the correct cause.

  • Loading branch information...
bmhm committed Apr 7, 2016
1 parent a6964a5 commit a870f274f83e78b2febd5a72fff83417cbb8be67
@@ -23,21 +23,24 @@
*/
public class ExamplePlugin extends JavaPlugin {

private ExamplePluginConfig config = null;

@Override
public void onDisable() {
}

@Override
public void onEnable() {
// 1.) init your config.
this.config = new ExamplePluginConfig(this);

// 2.) register events.
registerEvents();
}

private void registerEvents() {
Bukkit.getServer().getPluginManager().registerEvents(
new PlayerTeleportListener(), this);
new PlayerTeleportListener(config), this);
}

}
@@ -11,6 +11,7 @@

package de.bmarwell.bukkit.listener;

import de.bmarwell.bukkit.ExamplePluginConfig;
import de.bmarwell.bukkit.events.PlayerTeleportCancelledEvent;

import org.bukkit.Bukkit;
@@ -26,15 +27,28 @@
*/
public class PlayerTeleportListener implements Listener {

private ExamplePluginConfig config = null;

public PlayerTeleportListener(final ExamplePluginConfig config) {
this.config = config;
}

@EventHandler
public void onPlayerTeleport(PlayerTeleportEvent event) {
// if this event was cancelled, why bother?
if (event.isCancelled()) {
return;
}

// If this is not an ender teleport, don't bother.
if (!TeleportCause.ENDER_PEARL.equals(event.getCause())) {
if (!config.getTeleportCauseToCancel().isPresent()) {
// No event defined which could be cancelled.
return;
}

TeleportCause cancelCause = config.getTeleportCauseToCancel().get();

// If this is not a configured teleport cause, so don't bother.
if (!cancelCause.equals(event.getCause())) {
return;
}

0 comments on commit a870f27

Please sign in to comment.
You can’t perform that action at this time.