Skip to content

Commit

Permalink
Fix listeners registering twice
Browse files Browse the repository at this point in the history
  • Loading branch information
WiIIiam278 committed Sep 10, 2023
1 parent 52f9999 commit e579b2b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void onEnable() {
});

// Register event listener
initialize("events", (plugin) -> this.eventListener = registerListener());
initialize("events", (plugin) -> this.eventListener = getListener().register(this));

// Register commands
initialize("commands", (plugin) -> this.commands = BukkitCommand.Type.getCommands(this));
Expand All @@ -194,7 +194,7 @@ public void onEnable() {

// Register the event listener
@NotNull
protected EventListener registerListener() {
protected BukkitEventListener getListener() {
return new BukkitEventListener(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ public class BukkitEventListener extends EventListener implements Listener {

public BukkitEventListener(@NotNull BukkitHuskHomes plugin) {
super(plugin);
}

@NotNull
public BukkitEventListener register(@NotNull BukkitHuskHomes plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
return this;
}

@EventHandler(priority = EventPriority.NORMAL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@

package net.william278.huskhomes;

import net.william278.huskhomes.listener.EventListener;
import net.william278.huskhomes.listener.PaperEventListener;
import org.jetbrains.annotations.NotNull;

public class PaperHuskHomes extends BukkitHuskHomes {

@Override
@NotNull
protected EventListener registerListener() {
protected PaperEventListener getListener() {
return new PaperEventListener(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package net.william278.huskhomes.listener;

import com.destroystokyo.paper.event.player.PlayerSetSpawnEvent;
import net.william278.huskhomes.BukkitHuskHomes;
import net.william278.huskhomes.PaperHuskHomes;
import net.william278.huskhomes.position.Position;
import net.william278.huskhomes.user.BukkitUser;
Expand All @@ -35,7 +36,13 @@ public class PaperEventListener extends BukkitEventListener implements Listener
public PaperEventListener(@NotNull PaperHuskHomes plugin) {
super(plugin);
this.checkForBed = false;
}

@Override
@NotNull
public PaperEventListener register(@NotNull BukkitHuskHomes plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
return this;
}

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
Expand Down

0 comments on commit e579b2b

Please sign in to comment.