Makes sure music is stopped immediately if an NPC is removed
This commit is contained in:
parent
9d7a9117be
commit
9db2f871c6
@ -3,7 +3,7 @@ package net.knarcraft.minstrel;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.knarcraft.minstrel.command.MinstrelCommand;
|
||||
import net.knarcraft.minstrel.command.MinstrelTabCompleter;
|
||||
import net.knarcraft.minstrel.listener.PlayerListener;
|
||||
import net.knarcraft.minstrel.listener.MinstrelListener;
|
||||
import net.knarcraft.minstrel.trait.MinstrelTrait;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
@ -32,7 +32,7 @@ public final class MinstrelPlugin extends JavaPlugin {
|
||||
net.citizensnpcs.api.trait.TraitInfo.create(MinstrelTrait.class).withName("minstrel"));
|
||||
|
||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
pluginManager.registerEvents(new PlayerListener(), this);
|
||||
pluginManager.registerEvents(new MinstrelListener(), this);
|
||||
|
||||
PluginCommand minstrelCommand = this.getCommand("minstrel");
|
||||
if (minstrelCommand != null) {
|
||||
|
@ -0,0 +1,45 @@
|
||||
package net.knarcraft.minstrel.listener;
|
||||
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.event.NPCRemoveEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.knarcraft.minstrel.trait.MinstrelTrait;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
/**
|
||||
* A listener for minstrel-relate events
|
||||
*/
|
||||
public class MinstrelListener implements Listener {
|
||||
|
||||
/**
|
||||
* Listens for any players joining, and makes all minstrels play for them
|
||||
*
|
||||
* @param event <p>The triggered event</p>
|
||||
*/
|
||||
@EventHandler
|
||||
public void playerJoinListener(PlayerJoinEvent event) {
|
||||
for (NPC npc : CitizensAPI.getNPCRegistry()) {
|
||||
if (npc.hasTrait(MinstrelTrait.class)) {
|
||||
MinstrelTrait minstrelTrait = npc.getTraitNullable(MinstrelTrait.class);
|
||||
minstrelTrait.getPlaylist().play(minstrelTrait, event.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens for the deletion of any NPCs, and stops their music
|
||||
*
|
||||
* @param event <p>The triggered event</p>
|
||||
*/
|
||||
@EventHandler
|
||||
public void npcDeletionListener(NPCRemoveEvent event) {
|
||||
NPC npc = event.getNPC();
|
||||
if (npc.hasTrait(MinstrelTrait.class)) {
|
||||
MinstrelTrait minstrelTrait = npc.getTraitNullable(MinstrelTrait.class);
|
||||
minstrelTrait.getPlaylist().stop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package net.knarcraft.minstrel.listener;
|
||||
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.knarcraft.minstrel.trait.MinstrelTrait;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
/**
|
||||
* A listener for events where a player isn't hearing music when they should
|
||||
*/
|
||||
public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void playerJoinListener(PlayerJoinEvent event) {
|
||||
for (NPC npc : CitizensAPI.getNPCRegistry()) {
|
||||
if (npc.hasTrait(MinstrelTrait.class)) {
|
||||
MinstrelTrait minstrelTrait = npc.getTraitNullable(MinstrelTrait.class);
|
||||
minstrelTrait.getPlaylist().play(minstrelTrait, event.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user