Fixed setting multiple locations per villager
This commit is contained in:
parent
fb577b7b72
commit
73af8a8243
|
|
@ -1,6 +1,7 @@
|
|||
package com.alttd.fishingevent.config;
|
||||
|
||||
import com.alttd.fishingevent.FishingEvent;
|
||||
import com.alttd.fishingevent.objects.VillagerLocation;
|
||||
import com.alttd.fishingevent.util.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
|
@ -27,7 +28,7 @@ public class NPCLocationConfig extends AbstractConfig{
|
|||
public static class NPC_LOCATION {
|
||||
private static final String prefix = "npc.";
|
||||
|
||||
public static Map<String, List<Location>> ALL = new HashMap<>();
|
||||
public static Map<String, List<VillagerLocation>> ALL = new HashMap<>();
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
|
|
@ -42,7 +43,7 @@ public class NPCLocationConfig extends AbstractConfig{
|
|||
continue;
|
||||
}
|
||||
String villagerId = config.getString(prefix + key + ".", "villager-id", "villager1");
|
||||
ALL.computeIfAbsent(villagerId, list -> new ArrayList<>()).add(location.get());
|
||||
ALL.computeIfAbsent(villagerId, list -> new ArrayList<>()).add(new VillagerLocation(key, location.get()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,11 +30,11 @@ public abstract class LibNPC {
|
|||
return Optional.of(globalNPC);
|
||||
}
|
||||
|
||||
public void defaultSpawnNPC(FishingEvent fishingEvent, Location location, NPCCreateData npcCreateData, Logger logger, NPC npc) {
|
||||
public void defaultSpawnNPC(FishingEvent fishingEvent, Location location, String id, NPCCreateData npcCreateData, Logger logger, NPC npc) {
|
||||
dev.sergiferry.playernpc.api.NPC.NameTag nameTag = new dev.sergiferry.playernpc.api.NPC.NameTag("&6[Quest NPC] ", "&2" + npcCreateData.name(), "");
|
||||
logger.info(nameTag.getName());
|
||||
Optional<dev.sergiferry.playernpc.api.NPC.Global> tmp = spawn(
|
||||
fishingEvent, npcCreateData.simpleId(), location, npcCreateData.skin(), nameTag,
|
||||
fishingEvent, id, location, npcCreateData.skin(), nameTag,
|
||||
(a, player) -> npc.rightClick(player), (a, player) -> npc.leftClick(player),
|
||||
dev.sergiferry.playernpc.api.NPC.Global.Visibility.EVERYONE);
|
||||
if (tmp.isEmpty()) {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import org.bukkit.entity.Player;
|
|||
|
||||
public interface NPC {
|
||||
|
||||
void spawnNPC(FishingEvent fishingEvent, Location location);
|
||||
void spawnNPC(FishingEvent fishingEvent, Location location, String id);
|
||||
|
||||
void leftClick(Player player);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,21 +6,22 @@ import com.alttd.fishingevent.config.NPCLocationConfig;
|
|||
import com.alttd.fishingevent.util.Logger;
|
||||
import dev.sergiferry.playernpc.api.NPCLib;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class NPCManager {
|
||||
|
||||
private static Set<NPC> loaded = new HashSet<>();
|
||||
|
||||
public static void spawnNPCs(FishingEvent fishingEvent, Logger logger) {
|
||||
NPCLocationConfig.NPC_LOCATION.ALL.forEach((name, locations) -> {
|
||||
NPC npc = Config.NPC_DATA.NPC_MAP.getOrDefault(name, null);
|
||||
NPCLocationConfig.NPC_LOCATION.ALL.forEach((id, villagerLocation) -> {
|
||||
NPC npc = Config.NPC_DATA.NPC_MAP.getOrDefault(id, null);
|
||||
if (npc == null) {
|
||||
logger.warning("Found npc location entry without matching npc for [%]", name);
|
||||
logger.warning("Found npc location entry without matching npc for [%]", id);
|
||||
return;
|
||||
}
|
||||
logger.info("Spawning daily NPC " + name);
|
||||
locations.forEach(location -> npc.spawnNPC(fishingEvent, location));
|
||||
logger.info("Spawning daily NPC " + id);
|
||||
villagerLocation.forEach(entry -> npc.spawnNPC(fishingEvent, entry.location(), entry.villagerSpawnId()));
|
||||
loaded.add(npc);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ public class PrizeNPC extends LibNPC implements NPC {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void spawnNPC(FishingEvent fishingEvent, Location location) {
|
||||
defaultSpawnNPC(fishingEvent, location, npcCreateData, logger, this);
|
||||
public void spawnNPC(FishingEvent fishingEvent, Location location, String id) {
|
||||
defaultSpawnNPC(fishingEvent, location, id, npcCreateData, logger, this);
|
||||
isSpawned = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ public class SellNPC extends LibNPC implements NPC {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void spawnNPC(FishingEvent fishingEvent, Location location) {
|
||||
defaultSpawnNPC(fishingEvent, location, npcCreateData, logger, this);
|
||||
public void spawnNPC(FishingEvent fishingEvent, Location location, String id) {
|
||||
defaultSpawnNPC(fishingEvent, location, id, npcCreateData, logger, this);
|
||||
isSpawned = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ public class TutorialNPC extends LibNPC implements NPC {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void spawnNPC(FishingEvent fishingEvent, Location location) {
|
||||
defaultSpawnNPC(fishingEvent, location, npcCreateData, logger, this);
|
||||
public void spawnNPC(FishingEvent fishingEvent, Location location, String id) {
|
||||
defaultSpawnNPC(fishingEvent, location, id, npcCreateData, logger, this);
|
||||
isSpawned = true;
|
||||
getGlobalNPC().addOpenBookClickAction(dev.sergiferry.playernpc.api.NPC.Interact.ClickType.RIGHT_CLICK, book);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import com.alttd.fishingevent.util.NPCCreateData;
|
|||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -36,8 +35,8 @@ public class UpgradeNPC extends LibNPC implements NPC {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void spawnNPC(FishingEvent fishingEvent, Location location) {
|
||||
defaultSpawnNPC(fishingEvent, location, npcCreateData, logger, this);
|
||||
public void spawnNPC(FishingEvent fishingEvent, Location location, String id) {
|
||||
defaultSpawnNPC(fishingEvent, location, id, npcCreateData, logger, this);
|
||||
isSpawned = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
package com.alttd.fishingevent.objects;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public record VillagerLocation (String villagerSpawnId, Location location) {
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user