Convert Set to HashSet

This commit is contained in:
KAMKEEL committed 2023-03-22 13:35:49 -04:00
1 parent 418d345293
commit 33e5071b11
3 files changed
+46 -5

No files matched your search

@@ -1,7 +1,6 @@
package noppes.npcs.client.controllers;
import noppes.npcs.CustomNpcs;
import noppes.npcs.controllers.ServerCloneController;
import noppes.npcs.controllers.ServerTagMapController;
import java.io.File;
@@ -4,6 +4,7 @@ import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.controllers.data.Faction;
import noppes.npcs.controllers.data.TagMap;
@@ -61,4 +62,30 @@ public class ServerTagMapController {
this.tagMap.readNBT(nbtCompound);
}
public void saveTagMap(TagMap tagMap){
try {
File saveDir = getCloneTabDir(tagMap.cloneTab);
File file = new File(saveDir, "_____tag_map.dat_new");
File file1 = new File(saveDir, "_____tag_map.dat_old");
File file2 = new File(saveDir, "_____tag_map.dat");
CompressedStreamTools.writeCompressed(tagMap.writeNBT(), new FileOutputStream(file));
if(file1.exists())
{
file1.delete();
}
file2.renameTo(file1);
if(file2.exists())
{
file2.delete();
}
file.renameTo(file2);
if(file.exists())
{
file.delete();
}
} catch (Exception e) {
LogWriter.except(e);
}
}
}
@@ -6,11 +6,11 @@ import java.util.*;
public class TagMap {
public int cloneTab;
public HashMap<String, Set<UUID>> tagMap;
public HashMap<String, HashSet<UUID>> tagMap;
public TagMap(int tab){
this.cloneTab = tab;
this.tagMap = new HashMap<String, Set<UUID>>();
this.tagMap = new HashMap<String, HashSet<UUID>>();
}
public void readNBT(NBTTagCompound compound){
@@ -21,7 +21,7 @@ public class TagMap {
NBTTagCompound nbttagcompound = list.getCompoundTagAt(i);
String cloneName = nbttagcompound.getString("Clone");
NBTTagList allUUIDs = compound.getTagList("UUIDs", 10);
Set<UUID> uuids = new HashSet<UUID>();
HashSet<UUID> uuids = new HashSet<UUID>();
if(list != allUUIDs){
for(int j = 0; j < allUUIDs.tagCount(); j++)
{
@@ -42,7 +42,7 @@ public class TagMap {
NBTTagList cloneList = new NBTTagList();
for(String key: tagMap.keySet()){
Set<UUID> uuidSet = tagMap.get(key);
HashSet<UUID> uuidSet = tagMap.get(key);
if(uuidSet.size() > 0){
NBTTagCompound cloneCompound = new NBTTagCompound();
cloneCompound.setString("Clone", key);
@@ -65,4 +65,19 @@ public class TagMap {
return this.cloneTab;
}
public HashSet<UUID> getUUIDs(String cloneName) {
if(tagMap.containsKey(cloneName)){
return tagMap.get(cloneName);
}
return null;
}
public boolean hasTag(String cloneName, UUID tag) {
HashSet<UUID> uuids = getUUIDs(cloneName);
if(uuids == null){
return false;
}
return uuids.contains(tag);
}
}