mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-28 06:45:39 +00:00
Huge Overhaul to Fullscreen Modes + Folder Support for:
- Animations - Abilities - Forms - Auras - Outlines - Effects - Linked Items
This commit is contained in:
1 parent
c11cd4a6bb
commit
0b1e4f9ed4
29 files changed
+4110
-279
No files matched your search
@@ -32,6 +32,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
@@ -47,6 +48,7 @@ public class AnimationController implements IAnimationHandler {
|
||||
|
||||
public static AnimationController Instance = new AnimationController();
|
||||
private int lastUsedID = 0;
|
||||
public CategoryManager categoryManager = new CategoryManager();
|
||||
|
||||
public LinkedHashMap<String, Register.Animations> registeredAnimations = new LinkedHashMap<>();
|
||||
|
||||
@@ -164,45 +166,62 @@ public class AnimationController implements IAnimationHandler {
|
||||
File dir = getDir();
|
||||
if (!dir.exists()) {
|
||||
dir.mkdir();
|
||||
} else {
|
||||
for (File file : dir.listFiles()) {
|
||||
if (!file.isFile() || !file.getName().endsWith(".json"))
|
||||
continue;
|
||||
try {
|
||||
Animation animation = new Animation();
|
||||
animation.readFromNBT(NBTJsonUtil.LoadFile(file));
|
||||
animation.name = file.getName().substring(0, file.getName().length() - 5);
|
||||
return;
|
||||
}
|
||||
|
||||
if (animation.id == -1) {
|
||||
animation.id = getUnusedId();
|
||||
}
|
||||
categoryManager.loadCategories(dir);
|
||||
|
||||
int originalID = animation.id;
|
||||
int setID = animation.id;
|
||||
while (bootOrder.containsKey(setID) || animations.containsKey(setID)) {
|
||||
if (bootOrder.containsKey(setID))
|
||||
if (bootOrder.get(setID).equals(animation.name))
|
||||
break;
|
||||
// Load uncategorized animations (root level .json files)
|
||||
loadAnimationsFromDir(dir, CategoryManager.UNCATEGORIZED_ID);
|
||||
|
||||
setID++;
|
||||
}
|
||||
|
||||
animation.id = setID;
|
||||
if (originalID != setID) {
|
||||
LogWriter.info("Found Animation ID Mismatch: " + animation.name + ", New ID: " + setID);
|
||||
animation.save();
|
||||
}
|
||||
|
||||
animations.put(animation.id, animation);
|
||||
} catch (Exception e) {
|
||||
LogWriter.error("Error loading: " + file.getAbsolutePath(), e);
|
||||
}
|
||||
}
|
||||
// Load categorized animations (subdirectories)
|
||||
for (Map.Entry<Integer, noppes.npcs.controllers.data.Category> entry : categoryManager.getCategories().entrySet()) {
|
||||
File catDir = categoryManager.getCategoryDir(entry.getKey());
|
||||
loadAnimationsFromDir(catDir, entry.getKey());
|
||||
}
|
||||
|
||||
saveAnimationMap();
|
||||
}
|
||||
|
||||
private void loadAnimationsFromDir(File dir, int catId) {
|
||||
File[] files = dir.listFiles();
|
||||
if (files == null) return;
|
||||
for (File file : files) {
|
||||
if (!file.isFile() || !file.getName().endsWith(".json"))
|
||||
continue;
|
||||
try {
|
||||
Animation animation = new Animation();
|
||||
animation.readFromNBT(NBTJsonUtil.LoadFile(file));
|
||||
animation.name = file.getName().substring(0, file.getName().length() - 5);
|
||||
|
||||
if (animation.id == -1) {
|
||||
animation.id = getUnusedId();
|
||||
}
|
||||
|
||||
int originalID = animation.id;
|
||||
int setID = animation.id;
|
||||
while (bootOrder.containsKey(setID) || animations.containsKey(setID)) {
|
||||
if (bootOrder.containsKey(setID))
|
||||
if (bootOrder.get(setID).equals(animation.name))
|
||||
break;
|
||||
|
||||
setID++;
|
||||
}
|
||||
|
||||
animation.id = setID;
|
||||
if (originalID != setID) {
|
||||
LogWriter.info("Found Animation ID Mismatch: " + animation.name + ", New ID: " + setID);
|
||||
animation.save();
|
||||
}
|
||||
|
||||
animations.put(animation.id, animation);
|
||||
categoryManager.registerItem(animation.id, catId);
|
||||
} catch (Exception e) {
|
||||
LogWriter.error("Error loading: " + file.getAbsolutePath(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addAnimationRegister(String namespace, Register.Animations register) {
|
||||
registeredAnimations.put(namespace, register);
|
||||
}
|
||||
@@ -265,7 +284,7 @@ public class AnimationController implements IAnimationHandler {
|
||||
saveAnimationMap();
|
||||
|
||||
// Save Animation File
|
||||
File dir = this.getDir();
|
||||
File dir = categoryManager.getItemDir(animation.getID());
|
||||
if (!dir.exists())
|
||||
dir.mkdirs();
|
||||
|
||||
@@ -295,46 +314,29 @@ public class AnimationController implements IAnimationHandler {
|
||||
public void delete(String name) {
|
||||
Animation delete = getAnimationFromName(name);
|
||||
if (delete != null) {
|
||||
// Reject deleting built-in animations
|
||||
if (delete instanceof BuiltInAnimation) {
|
||||
LogWriter.info("Cannot delete built-in animation: " + name);
|
||||
return;
|
||||
}
|
||||
|
||||
Animation foundAnimation = this.animations.remove(delete.getID());
|
||||
if (foundAnimation != null && foundAnimation.name != null) {
|
||||
File dir = this.getDir();
|
||||
for (File file : dir.listFiles()) {
|
||||
if (!file.isFile() || !file.getName().endsWith(".json"))
|
||||
continue;
|
||||
if (file.getName().equals(foundAnimation.name + ".json")) {
|
||||
file.delete();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
saveAnimationMap();
|
||||
}
|
||||
delete(delete.getID());
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(int id) {
|
||||
// Only user animations have valid IDs (>= 0)
|
||||
if (id < 0 || !this.animations.containsKey(id))
|
||||
return;
|
||||
|
||||
// Reject deleting built-in animations
|
||||
Animation anim = this.animations.get(id);
|
||||
if (anim instanceof BuiltInAnimation) {
|
||||
LogWriter.info("Cannot delete built-in animation: " + anim.name);
|
||||
return;
|
||||
}
|
||||
|
||||
Animation foundAnimation = this.animations.remove(id);
|
||||
if (foundAnimation != null && foundAnimation.name != null) {
|
||||
File dir = this.getDir();
|
||||
for (File file : dir.listFiles()) {
|
||||
if (!file.isFile() || !file.getName().endsWith(".json"))
|
||||
continue;
|
||||
if (file.getName().equals(foundAnimation.name + ".json")) {
|
||||
file.delete();
|
||||
break;
|
||||
}
|
||||
File dir = categoryManager.getItemDir(id);
|
||||
File file = new File(dir, foundAnimation.name + ".json");
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
|
||||
categoryManager.removeItem(id);
|
||||
saveAnimationMap();
|
||||
}
|
||||
}
|
||||
@@ -553,5 +555,29 @@ public class AnimationController implements IAnimationHandler {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// CATEGORY HELPERS
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
public Map<String, Integer> getCategoryScrollData() {
|
||||
return categoryManager.getCategoryScrollData();
|
||||
}
|
||||
|
||||
public void moveItemToCategory(int itemId, int catId) {
|
||||
Animation animation = animations.get(itemId);
|
||||
if (animation == null) return;
|
||||
categoryManager.moveItem(itemId, animation.name + ".json", catId);
|
||||
saveAnimationMap();
|
||||
}
|
||||
|
||||
public Map<String, Integer> getItemsByCategoryScrollData(int catId) {
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
List<Integer> itemIds = categoryManager.getItemsInCategory(catId, animations.keySet());
|
||||
for (int itemId : itemIds) {
|
||||
Animation animation = animations.get(itemId);
|
||||
if (animation != null) {
|
||||
map.put(animation.name, animation.id);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import noppes.npcs.controllers.data.Category;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Filesystem-based category manager for organizing items into named groups.
|
||||
* Categories are subdirectories within the controller's base directory.
|
||||
* Items without a category mapping are "Uncategorized" (root-level files).
|
||||
*
|
||||
* One instance per controller (Effect, Animation, LinkedItem, Form, Aura, Outline, etc.)
|
||||
*/
|
||||
public class CategoryManager {
|
||||
public static final int UNCATEGORIZED_ID = 0;
|
||||
public static final String UNCATEGORIZED_NAME = "Uncategorized";
|
||||
|
||||
private File baseDir;
|
||||
private final HashMap<Integer, Category> categories = new HashMap<>();
|
||||
private final HashMap<Integer, Integer> itemCategoryMap = new HashMap<>();
|
||||
private int lastUsedCatID = 0;
|
||||
|
||||
/**
|
||||
* Scan the base directory for subdirectories and create Category objects.
|
||||
* Call at the start of controller loading, before loading items.
|
||||
*/
|
||||
public void loadCategories(File baseDir) {
|
||||
loadCategories(baseDir, new String[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan the base directory for subdirectories and create Category objects,
|
||||
* excluding any subdirectories whose names match excludeDirs.
|
||||
*/
|
||||
public void loadCategories(File baseDir, String... excludeDirs) {
|
||||
this.baseDir = baseDir;
|
||||
categories.clear();
|
||||
itemCategoryMap.clear();
|
||||
lastUsedCatID = 0;
|
||||
|
||||
if (!baseDir.exists()) return;
|
||||
|
||||
Set<String> excludeSet = new HashSet<>(Arrays.asList(excludeDirs));
|
||||
File[] files = baseDir.listFiles();
|
||||
if (files == null) return;
|
||||
for (File sub : files) {
|
||||
if (!sub.isDirectory()) continue;
|
||||
if (excludeSet.contains(sub.getName())) continue;
|
||||
lastUsedCatID++;
|
||||
categories.put(lastUsedCatID, new Category(lastUsedCatID, sub.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an item as belonging to a category.
|
||||
* Call when loading items from a subdirectory.
|
||||
*/
|
||||
public void registerItem(int itemId, int catId) {
|
||||
if (catId > UNCATEGORIZED_ID) {
|
||||
itemCategoryMap.put(itemId, catId);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeItem(int itemId) {
|
||||
itemCategoryMap.remove(itemId);
|
||||
}
|
||||
|
||||
public File getItemDir(int itemId) {
|
||||
int catId = itemCategoryMap.getOrDefault(itemId, UNCATEGORIZED_ID);
|
||||
return getCategoryDir(catId);
|
||||
}
|
||||
|
||||
public File getCategoryDir(int catId) {
|
||||
if (catId == UNCATEGORIZED_ID) return baseDir;
|
||||
Category cat = categories.get(catId);
|
||||
if (cat != null) return new File(baseDir, cat.title);
|
||||
return baseDir;
|
||||
}
|
||||
|
||||
public HashMap<Integer, Category> getCategories() {
|
||||
return categories;
|
||||
}
|
||||
|
||||
// ========== Category CRUD ==========
|
||||
|
||||
public Category createCategory(String name) {
|
||||
while (hasCategoryName(name)) name += "_";
|
||||
lastUsedCatID++;
|
||||
Category cat = new Category(lastUsedCatID, name);
|
||||
categories.put(cat.id, cat);
|
||||
File dir = new File(baseDir, name);
|
||||
if (!dir.exists()) dir.mkdirs();
|
||||
return cat;
|
||||
}
|
||||
|
||||
public void saveCategory(Category cat) {
|
||||
if (cat.id <= 0) return;
|
||||
Category existing = categories.get(cat.id);
|
||||
if (existing != null && !existing.title.equals(cat.title)) {
|
||||
String newTitle = cat.title;
|
||||
while (hasCategoryName(newTitle)) newTitle += "_";
|
||||
File oldDir = new File(baseDir, existing.title);
|
||||
File newDir = new File(baseDir, newTitle);
|
||||
if (oldDir.exists() && !newDir.exists()) {
|
||||
oldDir.renameTo(newDir);
|
||||
}
|
||||
cat.title = newTitle;
|
||||
}
|
||||
categories.put(cat.id, cat);
|
||||
}
|
||||
|
||||
public boolean removeCategory(int catId) {
|
||||
return removeCategory(catId, null);
|
||||
}
|
||||
|
||||
public boolean removeCategory(int catId, Set<Integer> allItemIds) {
|
||||
if (catId <= UNCATEGORIZED_ID) return false;
|
||||
Category cat = categories.get(catId);
|
||||
if (cat == null) return false;
|
||||
|
||||
// Server-side guard: refuse to delete if category has items
|
||||
if (allItemIds != null) {
|
||||
if (!isCategoryEmpty(catId, allItemIds)) return false;
|
||||
} else {
|
||||
// Without item set, check if any items are mapped to this category
|
||||
if (itemCategoryMap.containsValue(catId)) return false;
|
||||
}
|
||||
|
||||
// Also check filesystem — directory must be empty or non-existent
|
||||
File dir = new File(baseDir, cat.title);
|
||||
if (dir.exists()) {
|
||||
String[] contents = dir.list();
|
||||
if (contents != null && contents.length > 0) {
|
||||
return false;
|
||||
}
|
||||
dir.delete();
|
||||
}
|
||||
|
||||
categories.remove(catId);
|
||||
Iterator<Map.Entry<Integer, Integer>> it = itemCategoryMap.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
if (it.next().getValue() == catId) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void moveItem(int itemId, String fileName, int destCatId) {
|
||||
int oldCatId = itemCategoryMap.getOrDefault(itemId, UNCATEGORIZED_ID);
|
||||
if (oldCatId == destCatId) return;
|
||||
|
||||
File oldDir = getCategoryDir(oldCatId);
|
||||
File newDir = getCategoryDir(destCatId);
|
||||
if (!newDir.exists()) newDir.mkdirs();
|
||||
|
||||
File oldFile = new File(oldDir, fileName);
|
||||
File newFile = new File(newDir, fileName);
|
||||
if (oldFile.exists()) {
|
||||
oldFile.renameTo(newFile);
|
||||
}
|
||||
|
||||
if (destCatId == UNCATEGORIZED_ID) {
|
||||
itemCategoryMap.remove(itemId);
|
||||
} else {
|
||||
itemCategoryMap.put(itemId, destCatId);
|
||||
}
|
||||
}
|
||||
|
||||
// ========== Query ==========
|
||||
|
||||
public boolean hasCategoryName(String name) {
|
||||
for (Category cat : categories.values()) {
|
||||
if (cat.title.equalsIgnoreCase(name)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isCategoryEmpty(int catId, Set<Integer> allItemIds) {
|
||||
if (catId == UNCATEGORIZED_ID) {
|
||||
for (int id : allItemIds) {
|
||||
if (!itemCategoryMap.containsKey(id)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
for (Map.Entry<Integer, Integer> entry : itemCategoryMap.entrySet()) {
|
||||
if (entry.getValue() == catId && allItemIds.contains(entry.getKey())) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Category getCategory(int catId) {
|
||||
return categories.get(catId);
|
||||
}
|
||||
|
||||
public int getItemCategory(int itemId) {
|
||||
return itemCategoryMap.getOrDefault(itemId, UNCATEGORIZED_ID);
|
||||
}
|
||||
|
||||
public List<Integer> getItemsInCategory(int catId, Set<Integer> allItemIds) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
for (int itemId : allItemIds) {
|
||||
int assignedCat = itemCategoryMap.getOrDefault(itemId, UNCATEGORIZED_ID);
|
||||
if (assignedCat == catId) {
|
||||
result.add(itemId);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// ========== Scroll Data ==========
|
||||
|
||||
public Map<String, Integer> getCategoryScrollData() {
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
map.put(UNCATEGORIZED_NAME, UNCATEGORIZED_ID);
|
||||
for (Category cat : categories.values()) {
|
||||
map.put(cat.title, cat.id);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search all directories (root + subdirectories) for a file and delete it.
|
||||
*/
|
||||
public void deleteFile(String fileName) {
|
||||
if (baseDir == null || !baseDir.exists()) return;
|
||||
|
||||
File file = new File(baseDir, fileName);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
return;
|
||||
}
|
||||
|
||||
File[] subs = baseDir.listFiles();
|
||||
if (subs != null) {
|
||||
for (File sub : subs) {
|
||||
if (!sub.isDirectory()) continue;
|
||||
File subFile = new File(sub, fileName);
|
||||
if (subFile.exists()) {
|
||||
subFile.delete();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -43,6 +44,7 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
|
||||
public HashMap<Integer, EffectScript> customEffectScriptHandlers = new HashMap<>();
|
||||
private HashMap<Integer, String> bootOrder;
|
||||
public CategoryManager categoryManager = new CategoryManager();
|
||||
|
||||
private int lastUsedID = 0;
|
||||
public ConcurrentHashMap<UUID, ConcurrentHashMap<EffectKey, PlayerEffect>> playerEffects = new ConcurrentHashMap<>();
|
||||
@@ -119,16 +121,13 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
CustomEffect foundEffect = getCustomEffects().remove(effect.getID());
|
||||
customEffectScriptHandlers.remove(effect.getID());
|
||||
if (foundEffect != null && foundEffect.name != null) {
|
||||
File dir = this.getDir();
|
||||
for (File file : dir.listFiles()) {
|
||||
if (!file.isFile() || !file.getName().endsWith(".json"))
|
||||
continue;
|
||||
if (file.getName().equalsIgnoreCase(foundEffect.name + ".json")) {
|
||||
file.delete();
|
||||
SyncController.syncRemove(EnumSyncType.CUSTOM_EFFECTS, foundEffect.getID());
|
||||
break;
|
||||
}
|
||||
File dir = categoryManager.getItemDir(id);
|
||||
File file = new File(dir, foundEffect.name + ".json");
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
categoryManager.removeItem(id);
|
||||
SyncController.syncRemove(EnumSyncType.CUSTOM_EFFECTS, foundEffect.getID());
|
||||
saveEffectLoadMap();
|
||||
}
|
||||
}
|
||||
@@ -328,40 +327,58 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
File dir = getDir();
|
||||
if (!dir.exists()) {
|
||||
dir.mkdir();
|
||||
} else {
|
||||
for (File file : dir.listFiles()) {
|
||||
if (!file.isFile() || !file.getName().endsWith(".json"))
|
||||
continue;
|
||||
try {
|
||||
CustomEffect effect = new CustomEffect();
|
||||
effect.readFromNBT(NBTJsonUtil.LoadFile(file));
|
||||
effect.name = file.getName().substring(0, file.getName().length() - 5);
|
||||
if (effect.id == -1) {
|
||||
effect.id = getUnusedId();
|
||||
}
|
||||
int originalID = effect.id;
|
||||
int setID = effect.id;
|
||||
while (bootOrder.containsKey(setID) || getCustomEffects().containsKey(setID)) {
|
||||
if (bootOrder.containsKey(setID))
|
||||
if (bootOrder.get(setID).equalsIgnoreCase(effect.name))
|
||||
break;
|
||||
setID++;
|
||||
}
|
||||
effect.id = setID;
|
||||
if (originalID != setID) {
|
||||
LogWriter.info("Found Custom Effect ID Mismatch: " + effect.name + ", New ID: " + setID);
|
||||
effect.save();
|
||||
}
|
||||
getCustomEffects().put(effect.id, effect);
|
||||
} catch (Exception e) {
|
||||
LogWriter.error("Error loading: " + file.getAbsolutePath(), e);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
categoryManager.loadCategories(dir);
|
||||
|
||||
// Load uncategorized effects (root level .json files)
|
||||
loadEffectsFromDir(dir, CategoryManager.UNCATEGORIZED_ID);
|
||||
|
||||
// Load categorized effects (subdirectories)
|
||||
for (Map.Entry<Integer, noppes.npcs.controllers.data.Category> entry : categoryManager.getCategories().entrySet()) {
|
||||
File catDir = categoryManager.getCategoryDir(entry.getKey());
|
||||
loadEffectsFromDir(catDir, entry.getKey());
|
||||
}
|
||||
|
||||
this.registerEffectMap(0, getCustomEffects());
|
||||
saveEffectLoadMap();
|
||||
}
|
||||
|
||||
private void loadEffectsFromDir(File dir, int catId) {
|
||||
File[] files = dir.listFiles();
|
||||
if (files == null) return;
|
||||
for (File file : files) {
|
||||
if (!file.isFile() || !file.getName().endsWith(".json"))
|
||||
continue;
|
||||
try {
|
||||
CustomEffect effect = new CustomEffect();
|
||||
effect.readFromNBT(NBTJsonUtil.LoadFile(file));
|
||||
effect.name = file.getName().substring(0, file.getName().length() - 5);
|
||||
if (effect.id == -1) {
|
||||
effect.id = getUnusedId();
|
||||
}
|
||||
int originalID = effect.id;
|
||||
int setID = effect.id;
|
||||
while (bootOrder.containsKey(setID) || getCustomEffects().containsKey(setID)) {
|
||||
if (bootOrder.containsKey(setID))
|
||||
if (bootOrder.get(setID).equalsIgnoreCase(effect.name))
|
||||
break;
|
||||
setID++;
|
||||
}
|
||||
effect.id = setID;
|
||||
if (originalID != setID) {
|
||||
LogWriter.info("Found Custom Effect ID Mismatch: " + effect.name + ", New ID: " + setID);
|
||||
effect.save();
|
||||
}
|
||||
getCustomEffects().put(effect.id, effect);
|
||||
categoryManager.registerItem(effect.id, catId);
|
||||
} catch (Exception e) {
|
||||
LogWriter.error("Error loading: " + file.getAbsolutePath(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HashMap<Integer, CustomEffect> getEffectMap(int index) {
|
||||
return indexMapper.get(index);
|
||||
}
|
||||
@@ -370,7 +387,7 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
return new File(CustomNpcs.getWorldSaveDirectory(), "customeffects");
|
||||
}
|
||||
|
||||
private void saveEffectLoadMap() {
|
||||
public void saveEffectLoadMap() {
|
||||
try {
|
||||
File saveDir = getMapDir();
|
||||
File file = new File(saveDir, "customeffects.dat_new");
|
||||
@@ -453,12 +470,7 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
}
|
||||
|
||||
public void deleteEffectFile(String prevName) {
|
||||
File dir = this.getDir();
|
||||
if (!dir.exists())
|
||||
dir.mkdirs();
|
||||
File file2 = new File(dir, prevName + ".json");
|
||||
if (file2.exists())
|
||||
file2.delete();
|
||||
categoryManager.deleteFile(prevName + ".json");
|
||||
}
|
||||
|
||||
// API Versions
|
||||
@@ -490,21 +502,7 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
public void deleteEffect(String name) {
|
||||
ICustomEffect effect = getEffect(name);
|
||||
if (effect != null) {
|
||||
CustomEffect foundEffect = getCustomEffects().remove(effect.getID());
|
||||
customEffectScriptHandlers.remove(effect.getID());
|
||||
if (foundEffect != null && foundEffect.name != null) {
|
||||
File dir = this.getDir();
|
||||
for (File file : dir.listFiles()) {
|
||||
if (!file.isFile() || !file.getName().endsWith(".json"))
|
||||
continue;
|
||||
if (file.getName().equalsIgnoreCase(foundEffect.name + ".json")) {
|
||||
file.delete();
|
||||
SyncController.syncRemove(EnumSyncType.CUSTOM_EFFECTS, foundEffect.getID());
|
||||
break;
|
||||
}
|
||||
}
|
||||
saveEffectLoadMap();
|
||||
}
|
||||
delete(effect.getID());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -632,6 +630,33 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
return get(id, index);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// CATEGORY HELPERS
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
public Map<String, Integer> getCategoryScrollData() {
|
||||
return categoryManager.getCategoryScrollData();
|
||||
}
|
||||
|
||||
public void moveItemToCategory(int itemId, int catId) {
|
||||
CustomEffect effect = getCustomEffects().get(itemId);
|
||||
if (effect == null) return;
|
||||
categoryManager.moveItem(itemId, effect.name + ".json", catId);
|
||||
saveEffectLoadMap();
|
||||
}
|
||||
|
||||
public Map<String, Integer> getItemsByCategoryScrollData(int catId) {
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
List<Integer> itemIds = categoryManager.getItemsInCategory(catId, getCustomEffects().keySet());
|
||||
for (int itemId : itemIds) {
|
||||
CustomEffect effect = getCustomEffects().get(itemId);
|
||||
if (effect != null) {
|
||||
map.put(effect.name, effect.id);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICustomEffect saveEffect(ICustomEffect customEffect) {
|
||||
if (customEffect.getID() < 0) {
|
||||
@@ -648,7 +673,7 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
|
||||
saveEffectLoadMap();
|
||||
|
||||
File dir = this.getDir();
|
||||
File dir = categoryManager.getItemDir(customEffect.getID());
|
||||
if (!dir.exists())
|
||||
dir.mkdirs();
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class LinkedItemController implements ILinkedItemHandler {
|
||||
@@ -30,6 +32,7 @@ public class LinkedItemController implements ILinkedItemHandler {
|
||||
public HashMap<Integer, LinkedItemScript> linkedItemsScripts = new HashMap<>();
|
||||
|
||||
private HashMap<Integer, String> bootOrder;
|
||||
public CategoryManager categoryManager = new CategoryManager();
|
||||
|
||||
private LinkedItemController() {
|
||||
}
|
||||
@@ -121,45 +124,62 @@ public class LinkedItemController implements ILinkedItemHandler {
|
||||
File dir = getDir();
|
||||
if (!dir.exists()) {
|
||||
dir.mkdir();
|
||||
} else {
|
||||
for (File file : dir.listFiles()) {
|
||||
if (!file.isFile() || !file.getName().endsWith(".json"))
|
||||
continue;
|
||||
try {
|
||||
LinkedItem linkedItem = new LinkedItem();
|
||||
linkedItem.readFromNBT(NBTJsonUtil.LoadFile(file));
|
||||
linkedItem.name = file.getName().substring(0, file.getName().length() - 5);
|
||||
return;
|
||||
}
|
||||
|
||||
if (linkedItem.id == -1) {
|
||||
linkedItem.id = getUnusedId();
|
||||
}
|
||||
categoryManager.loadCategories(dir);
|
||||
|
||||
int originalID = linkedItem.id;
|
||||
int setID = linkedItem.id;
|
||||
while (bootOrder.containsKey(setID) || linkedItems.containsKey(setID)) {
|
||||
if (bootOrder.containsKey(setID))
|
||||
if (bootOrder.get(setID).equals(linkedItem.name))
|
||||
break;
|
||||
// Load uncategorized items (root level .json files)
|
||||
loadItemsFromDir(dir, CategoryManager.UNCATEGORIZED_ID);
|
||||
|
||||
setID++;
|
||||
}
|
||||
|
||||
linkedItem.id = setID;
|
||||
if (originalID != setID) {
|
||||
LogWriter.info("Found Linked Item ID Mismatch: " + linkedItem.name + ", New ID: " + setID);
|
||||
linkedItem.save();
|
||||
}
|
||||
|
||||
linkedItems.put(linkedItem.id, linkedItem);
|
||||
} catch (Exception e) {
|
||||
LogWriter.error("Error loading: " + file.getAbsolutePath(), e);
|
||||
}
|
||||
}
|
||||
// Load categorized items (subdirectories)
|
||||
for (Map.Entry<Integer, noppes.npcs.controllers.data.Category> entry : categoryManager.getCategories().entrySet()) {
|
||||
File catDir = categoryManager.getCategoryDir(entry.getKey());
|
||||
loadItemsFromDir(catDir, entry.getKey());
|
||||
}
|
||||
|
||||
saveLinkedItemsMap();
|
||||
}
|
||||
|
||||
private void loadItemsFromDir(File dir, int catId) {
|
||||
File[] files = dir.listFiles();
|
||||
if (files == null) return;
|
||||
for (File file : files) {
|
||||
if (!file.isFile() || !file.getName().endsWith(".json"))
|
||||
continue;
|
||||
try {
|
||||
LinkedItem linkedItem = new LinkedItem();
|
||||
linkedItem.readFromNBT(NBTJsonUtil.LoadFile(file));
|
||||
linkedItem.name = file.getName().substring(0, file.getName().length() - 5);
|
||||
|
||||
if (linkedItem.id == -1) {
|
||||
linkedItem.id = getUnusedId();
|
||||
}
|
||||
|
||||
int originalID = linkedItem.id;
|
||||
int setID = linkedItem.id;
|
||||
while (bootOrder.containsKey(setID) || linkedItems.containsKey(setID)) {
|
||||
if (bootOrder.containsKey(setID))
|
||||
if (bootOrder.get(setID).equals(linkedItem.name))
|
||||
break;
|
||||
|
||||
setID++;
|
||||
}
|
||||
|
||||
linkedItem.id = setID;
|
||||
if (originalID != setID) {
|
||||
LogWriter.info("Found Linked Item ID Mismatch: " + linkedItem.name + ", New ID: " + setID);
|
||||
linkedItem.save();
|
||||
}
|
||||
|
||||
linkedItems.put(linkedItem.id, linkedItem);
|
||||
categoryManager.registerItem(linkedItem.id, catId);
|
||||
} catch (Exception e) {
|
||||
LogWriter.error("Error loading: " + file.getAbsolutePath(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private File getDir() {
|
||||
return new File(CustomNpcs.getWorldSaveDirectory(), "linkeditems");
|
||||
}
|
||||
@@ -200,7 +220,7 @@ public class LinkedItemController implements ILinkedItemHandler {
|
||||
saveLinkedItemsMap();
|
||||
|
||||
// Save Linked Item File
|
||||
File dir = this.getDir();
|
||||
File dir = categoryManager.getItemDir(linkedItem.getId());
|
||||
if (!dir.exists())
|
||||
dir.mkdirs();
|
||||
|
||||
@@ -231,27 +251,19 @@ public class LinkedItemController implements ILinkedItemHandler {
|
||||
if (linkedItem != null) {
|
||||
LinkedItem foundItem = remove(id);
|
||||
if (foundItem != null && foundItem.name != null) {
|
||||
File dir = this.getDir();
|
||||
for (File file : dir.listFiles()) {
|
||||
if (!file.isFile() || !file.getName().endsWith(".json"))
|
||||
continue;
|
||||
if (file.getName().equalsIgnoreCase(foundItem.name + ".json")) {
|
||||
file.delete();
|
||||
break;
|
||||
}
|
||||
File dir = categoryManager.getItemDir(id);
|
||||
File file = new File(dir, foundItem.name + ".json");
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
categoryManager.removeItem(id);
|
||||
saveLinkedItemsMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteLinkedItemFile(String prevName) {
|
||||
File dir = this.getDir();
|
||||
if (!dir.exists())
|
||||
dir.mkdirs();
|
||||
File file2 = new File(dir, prevName + ".json");
|
||||
if (file2.exists())
|
||||
file2.delete();
|
||||
categoryManager.deleteFile(prevName + ".json");
|
||||
}
|
||||
|
||||
|
||||
@@ -350,5 +362,29 @@ public class LinkedItemController implements ILinkedItemHandler {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// CATEGORY HELPERS
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
public Map<String, Integer> getCategoryScrollData() {
|
||||
return categoryManager.getCategoryScrollData();
|
||||
}
|
||||
|
||||
public void moveItemToCategory(int itemId, int catId) {
|
||||
LinkedItem item = linkedItems.get(itemId);
|
||||
if (item == null) return;
|
||||
categoryManager.moveItem(itemId, item.name + ".json", catId);
|
||||
saveLinkedItemsMap();
|
||||
}
|
||||
|
||||
public Map<String, Integer> getItemsByCategoryScrollData(int catId) {
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
List<Integer> itemIds = categoryManager.getItemsInCategory(catId, linkedItems.keySet());
|
||||
for (int itemId : itemIds) {
|
||||
LinkedItem item = linkedItems.get(itemId);
|
||||
if (item != null) {
|
||||
map.put(item.name, item.id);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* Simple category data class for the generic category system.
|
||||
* Used by CategoryManager to organize items into named groups.
|
||||
*/
|
||||
public class Category {
|
||||
public int id = -1;
|
||||
public String title = "";
|
||||
|
||||
public Category() {
|
||||
}
|
||||
|
||||
public Category(int id, String title) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public void readNBT(NBTTagCompound compound) {
|
||||
id = compound.getInteger("CatID");
|
||||
title = compound.getString("CatTitle");
|
||||
}
|
||||
|
||||
public NBTTagCompound writeNBT(NBTTagCompound compound) {
|
||||
compound.setInteger("CatID", id);
|
||||
compound.setString("CatTitle", title);
|
||||
return compound;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user