From 53783f503291f606f79c031948b404ce570d45b2 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 23 Jul 2023 12:11:36 -0700 Subject: [PATCH] Do not generate multiple listeners https://github.com/BentoBoxWorld/AOneBlock/issues/326 --- .../world/bentobox/aoneblock/AOneBlock.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/world/bentobox/aoneblock/AOneBlock.java b/src/main/java/world/bentobox/aoneblock/AOneBlock.java index ca46ae7..e87660e 100644 --- a/src/main/java/world/bentobox/aoneblock/AOneBlock.java +++ b/src/main/java/world/bentobox/aoneblock/AOneBlock.java @@ -88,8 +88,13 @@ private boolean loadSettings() { @Override public void onEnable() { - loadData(); - + oneBlockManager = new OneBlocksManager(this); + if (loadData()) { + // Failed to load - don't register anything + return; + } + blockListener = new BlockListener(this); + registerListener(blockListener); registerListener(new NoBlockHandler(this)); registerListener(new BlockProtect(this)); registerListener(new JoinLeaveListener(this)); @@ -106,20 +111,18 @@ public void onEnable() { registerListener(holoListener); } - //Load some of Manager - public void loadData() { + // Load phase data + public boolean loadData() { try { - oneBlockManager = new OneBlocksManager(this); oneBlockManager.loadPhases(); - blockListener = new BlockListener(this); } catch (IOException e) { // Disable logError("AOneBlock settings could not load (oneblock.yml error)! Addon disabled."); logError(e.getMessage()); setState(State.DISABLED); - return; + return true; } - registerListener(blockListener); + return false; } private void registerPlaceholders() {