mirror of
https://github.com/BG-Software-LLC/WildLoaders.git
synced 2024-12-23 16:58:35 +01:00
Fixed npcs have similar names causing weird behaviors with other plugins (#39)
This commit is contained in:
parent
fdfe5655e1
commit
6fdd0b578d
@ -16,11 +16,14 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public final class NPCHandler implements NPCManager {
|
public final class NPCHandler implements NPCManager {
|
||||||
|
|
||||||
|
private static int NPCS_COUNTER = 0;
|
||||||
|
|
||||||
private final WildLoadersPlugin plugin;
|
private final WildLoadersPlugin plugin;
|
||||||
private final Map<NPCIdentifier, ChunkLoaderNPC> npcs = Maps.newConcurrentMap();
|
private final Map<NPCIdentifier, ChunkLoaderNPC> npcs = Maps.newConcurrentMap();
|
||||||
private final Map<NPCIdentifier, UUID> npcUUIDs = Maps.newConcurrentMap();
|
private final Map<NPCIdentifier, UUID> npcUUIDs = Maps.newConcurrentMap();
|
||||||
|
|
||||||
public NPCHandler(WildLoadersPlugin plugin){
|
|
||||||
|
public NPCHandler(WildLoadersPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +59,7 @@ public final class NPCHandler implements NPCManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void killAllNPCs() {
|
public void killAllNPCs() {
|
||||||
for(ChunkLoaderNPC npc : npcs.values()){
|
for (ChunkLoaderNPC npc : npcs.values()) {
|
||||||
npc.die();
|
npc.die();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,19 +70,19 @@ public final class NPCHandler implements NPCManager {
|
|||||||
return Collections.unmodifiableMap(npcs);
|
return Collections.unmodifiableMap(npcs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerUUID(Location location, UUID uuid){
|
public void registerUUID(Location location, UUID uuid) {
|
||||||
npcUUIDs.put(new NPCIdentifier(location), uuid);
|
npcUUIDs.put(new NPCIdentifier(location), uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private UUID getUUID(NPCIdentifier identifier){
|
private UUID getUUID(NPCIdentifier identifier) {
|
||||||
if(npcUUIDs.containsKey(identifier))
|
if (npcUUIDs.containsKey(identifier))
|
||||||
return npcUUIDs.get(identifier);
|
return npcUUIDs.get(identifier);
|
||||||
|
|
||||||
UUID uuid;
|
UUID uuid;
|
||||||
|
|
||||||
do{
|
do {
|
||||||
uuid = UUID.randomUUID();
|
uuid = UUID.randomUUID();
|
||||||
}while(npcUUIDs.containsValue(uuid));
|
} while (npcUUIDs.containsValue(uuid));
|
||||||
|
|
||||||
npcUUIDs.put(identifier, uuid);
|
npcUUIDs.put(identifier, uuid);
|
||||||
|
|
||||||
@ -92,8 +95,7 @@ public final class NPCHandler implements NPCManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getName(String worldName) {
|
public static String getName(String worldName) {
|
||||||
String name = "Loader-" + worldName;
|
return "Loader-" + (worldName.length() > 7 ? worldName.substring(0, 7) : worldName) + "-" + (NPCS_COUNTER++);
|
||||||
return name.length() > 16 ? name.substring(0, 16) : name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user