mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-22 18:45:27 +01:00
Avoid double registration of NPC event listener
This commit is contained in:
parent
335360b640
commit
df564644cf
@ -16,6 +16,8 @@ import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.RegisteredListener;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import com.alessiodp.parties.api.Parties;
|
||||
@ -29,6 +31,7 @@ import com.herocraftonline.heroes.Heroes;
|
||||
import com.herocraftonline.heroes.characters.Hero;
|
||||
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import me.blackvein.quests.listeners.NpcListener;
|
||||
import me.blackvein.quests.reflect.denizen.DenizenAPI;
|
||||
import me.blackvein.quests.reflect.worldguard.WorldGuardAPI;
|
||||
import me.blackvein.quests.util.Lang;
|
||||
@ -125,29 +128,37 @@ public class Dependencies {
|
||||
|
||||
public CitizensPlugin getCitizens() {
|
||||
if (citizens == null) {
|
||||
enableCitizens();
|
||||
linkCitizens();
|
||||
}
|
||||
return citizens;
|
||||
}
|
||||
|
||||
public void enableCitizens() {
|
||||
public void linkCitizens() {
|
||||
if (isPluginAvailable("Citizens")) {
|
||||
try {
|
||||
citizens = (CitizensPlugin) plugin.getServer().getPluginManager().getPlugin("Citizens");
|
||||
plugin.getServer().getPluginManager().registerEvents(plugin.getNpcListener(), plugin);
|
||||
if (plugin.getSettings().canNpcEffects()) {
|
||||
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, plugin.getNpcEffectThread(),
|
||||
20, 20);
|
||||
boolean found = false;
|
||||
for (final RegisteredListener listener : HandlerList.getRegisteredListeners(plugin)) {
|
||||
if (listener.getListener() instanceof NpcListener) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
plugin.getServer().getPluginManager().registerEvents(plugin.getNpcListener(), plugin);
|
||||
if (plugin.getSettings().canNpcEffects()) {
|
||||
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, plugin.getNpcEffectThread(),
|
||||
20, 20);
|
||||
}
|
||||
plugin.getLogger().info("Successfully linked Quests with Citizens "
|
||||
+ citizens.getDescription().getVersion());
|
||||
}
|
||||
plugin.getLogger().info("Successfully linked Quests with Citizens "
|
||||
+ citizens.getDescription().getVersion());
|
||||
} catch (final Exception e) {
|
||||
plugin.getLogger().warning("Legacy version of Citizens found. Citizens in Quests not enabled.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void disableCitizens() {
|
||||
public void unlinkCitizens() {
|
||||
citizens = null;
|
||||
}
|
||||
|
||||
|
@ -217,7 +217,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
// 10 - Register listeners
|
||||
getServer().getPluginManager().registerEvents(blockListener, this);
|
||||
getServer().getPluginManager().registerEvents(itemListener, this);
|
||||
depends.enableCitizens();
|
||||
depends.linkCitizens();
|
||||
getServer().getPluginManager().registerEvents(playerListener, this);
|
||||
if (settings.getStrictPlayerMovement() > 0) {
|
||||
final long ticks = settings.getStrictPlayerMovement() * 20;
|
||||
@ -650,7 +650,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
if (depends.getCitizens().getNPCRegistry() == null) {
|
||||
getLogger().log(Level.SEVERE,
|
||||
"Citizens was enabled but NPCRegistry was null. Disabling linkage.");
|
||||
depends.disableCitizens();
|
||||
depends.unlinkCitizens();
|
||||
}
|
||||
}
|
||||
loadModules();
|
||||
|
Loading…
Reference in New Issue
Block a user