mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-26 13:53:07 +00:00
Merge branch 'dev' into pr-254
# Conflicts: # src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerSelector.java
This commit is contained in:
commit
22a8ef5036
791 files changed
+117380
-18377
No files matched your search
@@ -0,0 +1,25 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class APIRegistry {
|
||||
public static final APIRegistry Instance = new APIRegistry();
|
||||
|
||||
private final LinkedHashMap<String, String> entries = new LinkedHashMap<>();
|
||||
|
||||
public void register(String name, String url) {
|
||||
entries.put(name, url);
|
||||
}
|
||||
|
||||
public void unregister(String name) {
|
||||
entries.remove(name);
|
||||
}
|
||||
|
||||
public LinkedHashMap<String, String> getEntries() {
|
||||
return entries;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return entries.size();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.util.Register;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
@@ -21,7 +22,6 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
@@ -31,7 +31,8 @@ import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
@@ -42,17 +43,19 @@ public class AnimationController implements IAnimationHandler {
|
||||
|
||||
// Built-in animations loaded from assets folder (read-only, keyed by name)
|
||||
public HashMap<String, BuiltInAnimation> builtInAnimations = new HashMap<>();
|
||||
private static final String BUILTIN_ANIMATIONS_PATH = "/assets/customnpcs/animations";
|
||||
private static final String BUILTIN_ANIMATIONS_RESOURCE = "assets/customnpcs/animations";
|
||||
private static final String BUILTIN_ANIMATIONS_PATH = "/assets/customnpcs/cnpc_animations";
|
||||
private static final String BUILTIN_ANIMATIONS_RESOURCE = "assets/customnpcs/cnpc_animations";
|
||||
|
||||
public static AnimationController Instance;
|
||||
public static AnimationController Instance = new AnimationController();
|
||||
private int lastUsedID = 0;
|
||||
public CategoryManager categoryManager = new CategoryManager();
|
||||
|
||||
public LinkedHashMap<String, Register.Animations> registeredAnimations = new LinkedHashMap<>();
|
||||
|
||||
public AnimationController() {
|
||||
Instance = this;
|
||||
bootOrder = new HashMap<>();
|
||||
animations = new HashMap<>();
|
||||
load();
|
||||
}
|
||||
|
||||
public static AnimationController getInstance() {
|
||||
@@ -65,13 +68,14 @@ public class AnimationController implements IAnimationHandler {
|
||||
builtInAnimations = new HashMap<>();
|
||||
LogWriter.info("Loading animations...");
|
||||
loadBuiltInAnimations();
|
||||
loadRegisteredBuiltIns();
|
||||
readAnimationMap();
|
||||
loadAnimations();
|
||||
LogWriter.info("Done loading animations.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Load built-in animations from assets/customnpcs/animations/ folder.
|
||||
* Load built-in animations from assets/customnpcs/cnpc_animations/ folder.
|
||||
* These animations are read-only and accessed by name only (no IDs).
|
||||
* Scans the folder directly instead of using a manifest.
|
||||
*/
|
||||
@@ -124,6 +128,7 @@ public class AnimationController implements IAnimationHandler {
|
||||
String resourcePath = path + "/" + animName + ".json";
|
||||
try (InputStream stream = modClass.getResourceAsStream(resourcePath)) {
|
||||
if (stream == null) {
|
||||
LogWriter.error("Animation not found: " + animName.toLowerCase());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -144,6 +149,7 @@ public class AnimationController implements IAnimationHandler {
|
||||
|
||||
// Store with lowercase key for case-insensitive lookup
|
||||
builtInAnimations.put(animName.toLowerCase(), animation);
|
||||
LogWriter.info("Registered animation: " + animName.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,45 +166,83 @@ 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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private void loadRegisteredBuiltIns() {
|
||||
for (Register.Animations register : registeredAnimations.values()) {
|
||||
register.register();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads built-in animations for client-side usage.
|
||||
* On dedicated servers, AnimationController.load() never runs on the client JVM,
|
||||
* so built-in animations would be missing for client-only systems like ability preview.
|
||||
* This method loads just the built-in animations (from assets and registered addons)
|
||||
* without touching user animations or world save data.
|
||||
*/
|
||||
public void loadClientBuiltIns() {
|
||||
loadBuiltInAnimations();
|
||||
loadRegisteredBuiltIns();
|
||||
}
|
||||
|
||||
private File getDir() {
|
||||
return new File(CustomNpcs.getWorldSaveDirectory(), "animations");
|
||||
}
|
||||
@@ -239,7 +283,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();
|
||||
|
||||
@@ -266,49 +310,54 @@ public class AnimationController implements IAnimationHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Animation cloneAnimation(int originalId) {
|
||||
Animation original = animations.get(originalId);
|
||||
if (original == null || original instanceof BuiltInAnimation) return null;
|
||||
|
||||
int originalCatId = categoryManager.getItemCategory(originalId);
|
||||
|
||||
Animation clone = new Animation();
|
||||
clone.readFromNBT(original.writeToNBT());
|
||||
clone.id = getUnusedId();
|
||||
|
||||
String name = clone.name;
|
||||
while (hasName(name)) name += "_";
|
||||
clone.name = name;
|
||||
|
||||
if (originalCatId > CategoryManager.UNCATEGORIZED_ID) {
|
||||
categoryManager.registerItem(clone.id, originalCatId);
|
||||
}
|
||||
|
||||
saveAnimation(clone);
|
||||
return clone;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -353,6 +402,7 @@ public class AnimationController implements IAnimationHandler {
|
||||
|
||||
/**
|
||||
* Get a built-in animation by name.
|
||||
*
|
||||
* @param name The animation name (case-insensitive)
|
||||
* @return The built-in animation, or null if not found
|
||||
*/
|
||||
@@ -384,6 +434,7 @@ public class AnimationController implements IAnimationHandler {
|
||||
|
||||
/**
|
||||
* Check if an animation name is a built-in animation.
|
||||
*
|
||||
* @param name The animation name to check
|
||||
* @return true if this is a built-in animation
|
||||
*/
|
||||
@@ -525,5 +576,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;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import noppes.npcs.config.ConfigMarket;
|
||||
/**
|
||||
* Server-side utility for syncing auction configuration to clients.
|
||||
* Handles Vault integration for currency name resolution.
|
||||
*
|
||||
* <p>
|
||||
* This class is SERVER-SIDE ONLY. Client reads via AuctionClientConfig.
|
||||
*/
|
||||
public class AuctionConfigSync {
|
||||
@@ -15,7 +15,7 @@ public class AuctionConfigSync {
|
||||
/**
|
||||
* Write auction config to NBT for sending to client.
|
||||
* Called on server side when building login packet.
|
||||
*
|
||||
* <p>
|
||||
* Currency name is resolved from Vault if enabled and available,
|
||||
* otherwise falls back to ConfigMarket.CurrencyName.
|
||||
*/
|
||||
@@ -40,7 +40,7 @@ public class AuctionConfigSync {
|
||||
public static String getEffectiveCurrencyName() {
|
||||
if (ConfigMarket.UseVault && VaultUtil.isEnabled()) {
|
||||
String vaultName = VaultUtil.getCurrencyNamePlural();
|
||||
if (vaultName != null && !vaultName.isEmpty() && !vaultName.equals("coins")) {
|
||||
if (vaultName != null && !vaultName.isEmpty()) {
|
||||
return vaultName;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,255 @@
|
||||
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 boolean isLoaded() {
|
||||
return baseDir != null;
|
||||
}
|
||||
|
||||
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) {
|
||||
if (baseDir == null) return null;
|
||||
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 || baseDir == null) 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 (baseDir == null) return false;
|
||||
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) {
|
||||
if (baseDir == null) return;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -25,7 +25,9 @@ import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -37,11 +39,13 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
|
||||
public static CustomEffectController Instance = new CustomEffectController();
|
||||
public HashMap<Integer, HashMap<Integer, CustomEffect>> indexMapper = new HashMap<>();
|
||||
private HashMap<Integer, String> indexLabels = new HashMap<>();
|
||||
|
||||
public HashMap<Integer, CustomEffect> customEffectsSync = new HashMap<>();
|
||||
|
||||
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<>();
|
||||
@@ -59,6 +63,14 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
indexMapper.put(index, (HashMap<Integer, CustomEffect>) effectHashMap);
|
||||
}
|
||||
|
||||
public void registerEffectMapLabel(int index, String label) {
|
||||
indexLabels.put(index, label);
|
||||
}
|
||||
|
||||
public HashMap<Integer, String> getIndexLabels() {
|
||||
return indexLabels;
|
||||
}
|
||||
|
||||
public HashMap<Integer, CustomEffect> getCustomEffects() {
|
||||
return indexMapper.get(0);
|
||||
}
|
||||
@@ -110,16 +122,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(SyncType.CUSTOM_EFFECTS, foundEffect.getID());
|
||||
saveEffectLoadMap();
|
||||
}
|
||||
}
|
||||
@@ -319,52 +328,66 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public HashMap<Integer, CustomEffect> getEffectMap(int index) {
|
||||
if (indexMapper.containsKey(index)) {
|
||||
return getEffectMap(index);
|
||||
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);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public HashMap<Integer, CustomEffect> getEffectMap(int index) {
|
||||
return indexMapper.get(index);
|
||||
}
|
||||
|
||||
private File getDir() {
|
||||
return new File(CustomNpcs.getWorldSaveDirectory(), "customeffects");
|
||||
}
|
||||
|
||||
private void saveEffectLoadMap() {
|
||||
public void saveEffectLoadMap() {
|
||||
try {
|
||||
File saveDir = getMapDir();
|
||||
File file = new File(saveDir, "customeffects.dat_new");
|
||||
@@ -447,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
|
||||
@@ -484,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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -626,6 +630,45 @@ 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;
|
||||
}
|
||||
|
||||
public HashMap<String, HashSet<UUID>> getItemTagMapForCategory(int catId) {
|
||||
HashMap<String, HashSet<UUID>> tagMap = new HashMap<>();
|
||||
List<Integer> itemIds = categoryManager.getItemsInCategory(catId, getCustomEffects().keySet());
|
||||
for (int itemId : itemIds) {
|
||||
CustomEffect effect = getCustomEffects().get(itemId);
|
||||
if (effect != null && !effect.tagUUIDs.isEmpty()) {
|
||||
tagMap.put(effect.name, effect.tagUUIDs);
|
||||
}
|
||||
}
|
||||
return tagMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICustomEffect saveEffect(ICustomEffect customEffect) {
|
||||
if (customEffect.getID() < 0) {
|
||||
@@ -637,12 +680,13 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
while (hasOther(customEffect.getName(), customEffect.getID()))
|
||||
customEffect.setName(customEffect.getName() + "_");
|
||||
|
||||
TagController.validateTagUUIDs(((CustomEffect) customEffect).tagUUIDs);
|
||||
getCustomEffects().remove(customEffect.getID());
|
||||
getCustomEffects().put(customEffect.getID(), (CustomEffect) customEffect);
|
||||
|
||||
saveEffectLoadMap();
|
||||
|
||||
File dir = this.getDir();
|
||||
File dir = categoryManager.getItemDir(customEffect.getID());
|
||||
if (!dir.exists())
|
||||
dir.mkdirs();
|
||||
|
||||
@@ -656,11 +700,36 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
file2.delete();
|
||||
file.renameTo(file2);
|
||||
nbtTagCompound.removeTag("ScriptData");
|
||||
SyncController.syncUpdate(EnumSyncType.CUSTOM_EFFECTS, -1, nbtTagCompound);
|
||||
SyncController.syncUpdate(SyncType.CUSTOM_EFFECTS, -1, nbtTagCompound);
|
||||
} catch (Exception e) {
|
||||
LogWriter.except(e);
|
||||
}
|
||||
return getCustomEffects().get(customEffect.getID());
|
||||
}
|
||||
|
||||
public CustomEffect cloneEffect(int originalId) {
|
||||
CustomEffect original = getCustomEffects().get(originalId);
|
||||
if (original == null) return null;
|
||||
|
||||
int originalCatId = categoryManager.getItemCategory(originalId);
|
||||
|
||||
NBTTagCompound nbt = original.writeToNBT(true);
|
||||
int newId = getUnusedId();
|
||||
nbt.setInteger("ID", newId);
|
||||
|
||||
CustomEffect clone = new CustomEffect();
|
||||
clone.readFromNBT(nbt);
|
||||
|
||||
String name = clone.getName();
|
||||
while (has(name)) name += "_";
|
||||
clone.name = name;
|
||||
|
||||
if (originalCatId > CategoryManager.UNCATEGORIZED_ID) {
|
||||
categoryManager.registerItem(newId, originalCatId);
|
||||
}
|
||||
|
||||
saveEffect(clone);
|
||||
return clone;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import kamkeel.npcs.controllers.sync.handlers.DialogCategorySyncHandler;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
@@ -75,6 +76,7 @@ public class DialogController implements IDialogHandler {
|
||||
if (!file.isDirectory())
|
||||
continue;
|
||||
DialogCategory category = loadCategoryDir(file);
|
||||
List<Dialog> reassigned = new ArrayList<Dialog>();
|
||||
Iterator<Integer> ite = category.dialogs.keySet().iterator();
|
||||
while (ite.hasNext()) {
|
||||
int id = ite.next();
|
||||
@@ -82,12 +84,48 @@ public class DialogController implements IDialogHandler {
|
||||
lastUsedDialogID = id;
|
||||
Dialog dialog = category.dialogs.get(id);
|
||||
if (dialogs.containsKey(id)) {
|
||||
LogWriter.error("Duplicate id " + dialog.id + " from category " + category.title);
|
||||
// Dialog IDs live in the filename, not inside the JSON body,
|
||||
// so a simple rename permanently resolves the conflict.
|
||||
File catDir = new File(getDir(), category.title);
|
||||
|
||||
// Find the next free ID. It has to clear three things: the ids already
|
||||
// registered globally, the ids this category still holds but has not
|
||||
// reached yet, and any file already on disk - renameTo overwrites
|
||||
// silently on POSIX, so landing on an existing file would destroy it.
|
||||
int newId = lastUsedDialogID;
|
||||
do {
|
||||
newId++;
|
||||
} while (dialogs.containsKey(newId)
|
||||
|| category.dialogs.containsKey(newId)
|
||||
|| new File(catDir, newId + ".json").exists());
|
||||
lastUsedDialogID = newId;
|
||||
|
||||
File oldFile = new File(catDir, id + ".json");
|
||||
File newFile = new File(catDir, newId + ".json");
|
||||
boolean renamed = oldFile.renameTo(newFile);
|
||||
|
||||
dialog.id = newId;
|
||||
ite.remove();
|
||||
reassigned.add(dialog);
|
||||
|
||||
if (renamed) {
|
||||
LogWriter.info("Dialog ID conflict: reassigned \"" + dialog.title
|
||||
+ "\" from id " + id + " to " + newId
|
||||
+ " in category \"" + category.title + "\"");
|
||||
} else {
|
||||
LogWriter.error("Dialog ID conflict: could not rename file for \""
|
||||
+ dialog.title + "\" (id " + id
|
||||
+ " in category \"" + category.title + "\") to " + newId);
|
||||
}
|
||||
} else {
|
||||
dialogs.put(id, dialog);
|
||||
}
|
||||
}
|
||||
// Re-register reassigned dialogs under their new IDs.
|
||||
for (Dialog dialog : reassigned) {
|
||||
dialogs.put(dialog.id, dialog);
|
||||
category.dialogs.put(dialog.id, dialog);
|
||||
}
|
||||
lastUsedCatID++;
|
||||
category.id = lastUsedCatID;
|
||||
categories.put(category.id, category);
|
||||
@@ -239,7 +277,7 @@ public class DialogController implements IDialogHandler {
|
||||
dir.mkdirs();
|
||||
}
|
||||
categories.put(category.id, category);
|
||||
SyncController.syncUpdate(EnumSyncType.DIALOG_CATEGORY, -1, SyncController.updateDialogCat(category));
|
||||
SyncController.syncUpdate(SyncType.DIALOG_CATEGORY, -1, DialogCategorySyncHandler.serializeCategory(category));
|
||||
}
|
||||
|
||||
public void removeCategory(int category) {
|
||||
@@ -252,7 +290,7 @@ public class DialogController implements IDialogHandler {
|
||||
for (int dia : cat.dialogs.keySet())
|
||||
dialogs.remove(dia);
|
||||
categories.remove(category);
|
||||
SyncController.syncRemove(EnumSyncType.DIALOG_CATEGORY, category);
|
||||
SyncController.syncRemove(SyncType.DIALOG_CATEGORY, category);
|
||||
}
|
||||
|
||||
private boolean containsCategoryName(String name) {
|
||||
@@ -302,7 +340,7 @@ public class DialogController implements IDialogHandler {
|
||||
if (file2.exists())
|
||||
file2.delete();
|
||||
file.renameTo(file2);
|
||||
SyncController.syncUpdate(EnumSyncType.DIALOG, category.id, dialog.writeToNBT(new NBTTagCompound()));
|
||||
SyncController.syncUpdate(SyncType.DIALOG, category.id, dialog.writeToNBT(new NBTTagCompound()));
|
||||
} catch (Exception e) {
|
||||
LogWriter.except(e);
|
||||
}
|
||||
@@ -316,7 +354,7 @@ public class DialogController implements IDialogHandler {
|
||||
return;
|
||||
category.dialogs.remove(dialog.id);
|
||||
dialogs.remove(dialog.id);
|
||||
SyncController.syncRemove(EnumSyncType.DIALOG, dialog.id);
|
||||
SyncController.syncRemove(SyncType.DIALOG, dialog.id);
|
||||
}
|
||||
|
||||
private File getDir() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
@@ -159,7 +159,7 @@ public class FactionController implements IFactionHandler {
|
||||
|
||||
NBTTagCompound facCompound = new NBTTagCompound();
|
||||
faction.writeNBT(facCompound);
|
||||
SyncController.syncUpdate(EnumSyncType.FACTION, -1, facCompound);
|
||||
SyncController.syncUpdate(SyncType.FACTION, -1, facCompound);
|
||||
saveFactions();
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ public class FactionController implements IFactionHandler {
|
||||
} else {
|
||||
this.saveFactions();
|
||||
faction.id = -1;
|
||||
SyncController.syncRemove(EnumSyncType.FACTION, id);
|
||||
SyncController.syncRemove(SyncType.FACTION, id);
|
||||
return faction;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -148,9 +148,9 @@ public class HookDefinition implements IHookDefinition {
|
||||
}
|
||||
|
||||
// Build required imports from event type
|
||||
String importName = getImportForClass(eventType);
|
||||
if (importName != null) {
|
||||
builder.requiredImports(importName);
|
||||
String[] importNames = getImportsForClass(eventType);
|
||||
if (importNames.length > 0) {
|
||||
builder.requiredImports(importNames);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,26 +185,31 @@ public class HookDefinition implements IHookDefinition {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the import statement needed for a class.
|
||||
* For nested classes, returns the enclosing class.
|
||||
* Get the import statements needed for a class.
|
||||
* For nested classes, includes both enclosing and nested names.
|
||||
*/
|
||||
private static String getImportForClass(Class<?> clazz) {
|
||||
private static String[] getImportsForClass(Class<?> clazz) {
|
||||
if (clazz == null || clazz.isPrimitive()) {
|
||||
return null;
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
String fullName = clazz.getName();
|
||||
if (fullName.startsWith("java.lang.")) {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
// For nested classes, get the top-level enclosing class
|
||||
Class<?> enclosing = clazz;
|
||||
while (enclosing.getEnclosingClass() != null) {
|
||||
enclosing = enclosing.getEnclosingClass();
|
||||
}
|
||||
|
||||
String name = enclosing.getName();
|
||||
if (name.startsWith("java.lang.")) {
|
||||
return null;
|
||||
String enclosingName = enclosing.getName();
|
||||
String nestedName = fullName.replace('$', '.');
|
||||
if (!nestedName.equals(enclosingName)) {
|
||||
return new String[]{enclosingName, nestedName};
|
||||
}
|
||||
|
||||
return name;
|
||||
return new String[]{enclosingName};
|
||||
}
|
||||
|
||||
// ==================== Builder ====================
|
||||
@@ -231,9 +236,9 @@ public class HookDefinition implements IHookDefinition {
|
||||
if (clazz != null) {
|
||||
this.eventClassName = clazz.getName();
|
||||
|
||||
String importName = getImportForClass(clazz);
|
||||
if (importName != null) {
|
||||
this.requiredImports = new String[]{importName};
|
||||
String[] importNames = getImportsForClass(clazz);
|
||||
if (importNames.length > 0) {
|
||||
this.requiredImports = importNames;
|
||||
}
|
||||
|
||||
if (clazz.isAnnotationPresent(Cancelable.class)) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.api.handler.ILinkedItemHandler;
|
||||
import noppes.npcs.api.handler.data.ILinkedItem;
|
||||
import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.controllers.data.IScriptHandler;
|
||||
@@ -19,9 +20,13 @@ import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class LinkedItemController {
|
||||
public class LinkedItemController implements ILinkedItemHandler {
|
||||
private static LinkedItemController Instance;
|
||||
private int lastUsedID = 0;
|
||||
|
||||
@@ -29,6 +34,7 @@ public class LinkedItemController {
|
||||
public HashMap<Integer, LinkedItemScript> linkedItemsScripts = new HashMap<>();
|
||||
|
||||
private HashMap<Integer, String> bootOrder;
|
||||
public CategoryManager categoryManager = new CategoryManager();
|
||||
|
||||
private LinkedItemController() {
|
||||
}
|
||||
@@ -40,25 +46,28 @@ public class LinkedItemController {
|
||||
return Instance;
|
||||
}
|
||||
|
||||
public LinkedItem createItem(String name) {
|
||||
@Override
|
||||
public ILinkedItem createItem(String name) {
|
||||
return new LinkedItem(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack createItemStack(int id) {
|
||||
LinkedItem linkedItem = this.get(id);
|
||||
LinkedItem linkedItem = (LinkedItem) this.get(id);
|
||||
if (linkedItem != null) {
|
||||
return linkedItem.createStack();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void add(LinkedItem linkedItem) {
|
||||
@Override
|
||||
public void add(ILinkedItem linkedItem) {
|
||||
if (linkedItem != null) {
|
||||
String name = linkedItem.getName();
|
||||
if (name != null && !name.isEmpty()) {
|
||||
int linkedItemId = linkedItem.getId();
|
||||
int id = this.linkedItems.containsKey(linkedItemId) ? linkedItemId : this.getUnusedId();
|
||||
this.linkedItems.put(id, linkedItem);
|
||||
this.linkedItems.put(id, (LinkedItem) linkedItem);
|
||||
linkedItem.setId(id);
|
||||
this.addScript(id);
|
||||
}
|
||||
@@ -69,6 +78,7 @@ public class LinkedItemController {
|
||||
this.linkedItemsScripts.put(id, new LinkedItemScript());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinkedItem remove(int id) {
|
||||
this.removeScript(id);
|
||||
return this.linkedItems.remove(id);
|
||||
@@ -78,16 +88,19 @@ public class LinkedItemController {
|
||||
this.linkedItemsScripts.remove(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinkedItem get(int id) {
|
||||
return this.linkedItems.get(id);
|
||||
return (LinkedItem) this.linkedItems.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(int id) {
|
||||
return this.linkedItems.containsKey(id);
|
||||
}
|
||||
|
||||
public boolean contains(LinkedItem linkedItem) {
|
||||
return this.linkedItems.containsValue(linkedItem);
|
||||
@Override
|
||||
public boolean contains(ILinkedItem linkedItem) {
|
||||
return this.linkedItems.containsValue((LinkedItem) linkedItem);
|
||||
}
|
||||
|
||||
public IScriptHandler getScriptHandler(int id) {
|
||||
@@ -113,45 +126,61 @@ public class LinkedItemController {
|
||||
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);
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
@@ -187,12 +216,13 @@ public class LinkedItemController {
|
||||
while (hasOther(linkedItem.getName(), linkedItem.getId()))
|
||||
linkedItem.setName(linkedItem.getName() + "_");
|
||||
|
||||
TagController.validateTagUUIDs(((LinkedItem) linkedItem).tagUUIDs);
|
||||
linkedItems.remove(linkedItem.getId());
|
||||
linkedItems.put(linkedItem.getId(), (LinkedItem) linkedItem);
|
||||
saveLinkedItemsMap();
|
||||
|
||||
// Save Linked Item File
|
||||
File dir = this.getDir();
|
||||
File dir = categoryManager.getItemDir(linkedItem.getId());
|
||||
if (!dir.exists())
|
||||
dir.mkdirs();
|
||||
|
||||
@@ -210,6 +240,31 @@ public class LinkedItemController {
|
||||
return linkedItems.get(linkedItem.getId());
|
||||
}
|
||||
|
||||
public LinkedItem cloneLinkedItem(int originalId) {
|
||||
LinkedItem original = linkedItems.get(originalId);
|
||||
if (original == null) return null;
|
||||
|
||||
int originalCatId = categoryManager.getItemCategory(originalId);
|
||||
|
||||
NBTTagCompound nbt = original.writeToNBT(true);
|
||||
int newId = getUnusedId();
|
||||
nbt.setInteger("Id", newId);
|
||||
|
||||
LinkedItem clone = new LinkedItem();
|
||||
clone.readFromNBT(nbt);
|
||||
|
||||
String name = clone.getName();
|
||||
while (hasName(name)) name += "_";
|
||||
clone.name = name;
|
||||
|
||||
if (originalCatId > CategoryManager.UNCATEGORIZED_ID) {
|
||||
categoryManager.registerItem(newId, originalCatId);
|
||||
}
|
||||
|
||||
saveLinkedItem(clone);
|
||||
return clone;
|
||||
}
|
||||
|
||||
private boolean hasOther(String name, int id) {
|
||||
for (LinkedItem linkedItem : linkedItems.values()) {
|
||||
if (linkedItem.getId() != id && linkedItem.getName().equalsIgnoreCase(name))
|
||||
@@ -219,31 +274,23 @@ public class LinkedItemController {
|
||||
}
|
||||
|
||||
public void delete(int id) {
|
||||
LinkedItem linkedItem = get(id);
|
||||
LinkedItem linkedItem = (LinkedItem) get(id);
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
@@ -342,5 +389,41 @@ public class LinkedItemController {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// 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;
|
||||
}
|
||||
|
||||
public HashMap<String, HashSet<UUID>> getItemTagMapForCategory(int catId) {
|
||||
HashMap<String, HashSet<UUID>> tagMap = new HashMap<>();
|
||||
List<Integer> itemIds = categoryManager.getItemsInCategory(catId, linkedItems.keySet());
|
||||
for (int itemId : itemIds) {
|
||||
LinkedItem item = linkedItems.get(itemId);
|
||||
if (item != null && !item.tagUUIDs.isEmpty()) {
|
||||
tagMap.put(item.name, item.tagUUIDs);
|
||||
}
|
||||
}
|
||||
return tagMap;
|
||||
}
|
||||
}
|
||||
@@ -136,6 +136,7 @@ public class LinkedNpcController {
|
||||
|
||||
npc.ais.readToNBT(compound);
|
||||
npc.transform.readToNBT(compound);
|
||||
npc.abilities.readFromNBT(compound);
|
||||
npc.ais.setMovingPath(points);
|
||||
npc.updateClient = true;
|
||||
}
|
||||
@@ -161,6 +162,7 @@ public class LinkedNpcController {
|
||||
npc.ais.writeToNBT(compound);
|
||||
npc.advanced.writeToNBT(compound);
|
||||
npc.transform.writeToNBT(compound);
|
||||
npc.abilities.writeToNBT(compound);
|
||||
compound.setTag("ModelData", ((EntityCustomNpc) npc).modelData.writeToNBT());
|
||||
return compound;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -275,7 +275,7 @@ public class MagicController implements IMagicHandler {
|
||||
|
||||
NBTTagCompound magicCompound = new NBTTagCompound();
|
||||
mag.writeNBT(magicCompound);
|
||||
SyncController.syncUpdate(EnumSyncType.MAGIC, -1, magicCompound);
|
||||
SyncController.syncUpdate(SyncType.MAGIC, -1, magicCompound);
|
||||
|
||||
saveMagicData();
|
||||
}
|
||||
@@ -283,7 +283,7 @@ public class MagicController implements IMagicHandler {
|
||||
public void removeMagic(int magicID) {
|
||||
if (magics.containsKey(magicID)) {
|
||||
magics.remove(magicID);
|
||||
SyncController.syncRemove(EnumSyncType.MAGIC, magicID);
|
||||
SyncController.syncRemove(SyncType.MAGIC, magicID);
|
||||
saveMagicData();
|
||||
}
|
||||
}
|
||||
@@ -345,7 +345,7 @@ public class MagicController implements IMagicHandler {
|
||||
|
||||
NBTTagCompound cycleCompound = new NBTTagCompound();
|
||||
cycle.writeNBT(cycleCompound);
|
||||
SyncController.syncUpdate(EnumSyncType.MAGIC_CYCLE, -1, cycleCompound);
|
||||
SyncController.syncUpdate(SyncType.MAGIC_CYCLE, -1, cycleCompound);
|
||||
|
||||
saveMagicData();
|
||||
}
|
||||
@@ -353,7 +353,7 @@ public class MagicController implements IMagicHandler {
|
||||
public void removeCycle(int categoryId) {
|
||||
if (cycles.containsKey(categoryId)) {
|
||||
cycles.remove(categoryId);
|
||||
SyncController.syncRemove(EnumSyncType.MAGIC_CYCLE, categoryId);
|
||||
SyncController.syncRemove(SyncType.MAGIC_CYCLE, categoryId);
|
||||
saveMagicData();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import noppes.npcs.client.ProfileClientConfig;
|
||||
import kamkeel.npcs.network.packets.data.AchievementPacket;
|
||||
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -91,7 +92,9 @@ public class PlayerQuestController {
|
||||
questData.finishedQuests.put(quest.id, completeTime);
|
||||
}
|
||||
|
||||
if (ConfigMain.ProfilesEnabled && quest.profileOptions.enableOptions && quest.profileOptions.completeControl == EnumProfileSync.Shared)
|
||||
if (ConfigMain.ProfilesEnabled && quest.profileOptions.enableOptions
|
||||
&& (quest.profileOptions.completeControl == EnumProfileSync.Shared
|
||||
|| quest.profileOptions.cooldownControl == EnumProfileSync.Shared))
|
||||
ProfileController.Instance.shareQuestCompletion(player, quest.id, completeTime);
|
||||
}
|
||||
|
||||
@@ -125,27 +128,27 @@ public class PlayerQuestController {
|
||||
if (data.activeQuests.containsKey(quest.id))
|
||||
return false;
|
||||
|
||||
if (!data.finishedQuests.containsKey(quest.id) || quest.repeat == EnumQuestRepeat.REPEATABLE)
|
||||
boolean finishedLocally = data.finishedQuests.containsKey(quest.id);
|
||||
boolean completedShared = false;
|
||||
boolean hasCooldownShared = false;
|
||||
if (ProfileClientConfig.isProfilesEnabled() && quest.profileOptions.enableOptions
|
||||
&& ProfileClientConfig.hasSharedQuest(player, quest.id)) {
|
||||
if (quest.profileOptions.completeControl == EnumProfileSync.Shared)
|
||||
completedShared = true;
|
||||
if (quest.profileOptions.cooldownControl == EnumProfileSync.Shared)
|
||||
hasCooldownShared = true;
|
||||
}
|
||||
|
||||
boolean isFinished = finishedLocally || completedShared;
|
||||
|
||||
if (!isFinished && !hasCooldownShared)
|
||||
return true;
|
||||
if (quest.repeat == EnumQuestRepeat.REPEATABLE)
|
||||
return true;
|
||||
if (quest.repeat == EnumQuestRepeat.NONE)
|
||||
return false;
|
||||
return !isFinished;
|
||||
|
||||
long questTime = data.finishedQuests.get(quest.id);
|
||||
|
||||
if (quest.repeat == EnumQuestRepeat.MCDAILY) {
|
||||
return player.worldObj.getTotalWorldTime() - questTime >= 24000;
|
||||
} else if (quest.repeat == EnumQuestRepeat.MCWEEKLY) {
|
||||
return player.worldObj.getTotalWorldTime() - questTime >= 168000;
|
||||
} else if (quest.repeat == EnumQuestRepeat.MCCUSTOM) {
|
||||
return player.worldObj.getTotalWorldTime() - questTime >= quest.customCooldown;
|
||||
} else if (quest.repeat == EnumQuestRepeat.RLDAILY) {
|
||||
return System.currentTimeMillis() - questTime >= 86400000;
|
||||
} else if (quest.repeat == EnumQuestRepeat.RLWEEKLY) {
|
||||
return System.currentTimeMillis() - questTime >= 604800000;
|
||||
} else if (quest.repeat == EnumQuestRepeat.RLCUSTOM) {
|
||||
return System.currentTimeMillis() - questTime >= quest.customCooldown;
|
||||
}
|
||||
return false;
|
||||
return quest.getTimeUntilRepeat(player) <= 0;
|
||||
}
|
||||
|
||||
public static Vector<Quest> getActiveQuests(EntityPlayer player) {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.data.profile.Profile;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ProfileConfigSync {
|
||||
public static NBTTagCompound writeToNBT(EntityPlayer player) {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
if (!ConfigMain.ProfilesEnabled || ProfileController.Instance == null) {
|
||||
return compound;
|
||||
}
|
||||
|
||||
Profile profile = ProfileController.Instance.getProfile(player);
|
||||
if (profile == null) {
|
||||
return compound;
|
||||
}
|
||||
|
||||
NBTTagList questList = new NBTTagList();
|
||||
for (Map.Entry<Integer, Long> entry : profile.sharedQuestTimestamps.entrySet()) {
|
||||
NBTTagCompound questEntry = new NBTTagCompound();
|
||||
questEntry.setInteger("Quest", entry.getKey());
|
||||
questEntry.setLong("Date", entry.getValue());
|
||||
questList.appendTag(questEntry);
|
||||
}
|
||||
compound.setTag("SharedQuestTimestamps", questList);
|
||||
return compound;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import kamkeel.npcs.controllers.sync.handlers.QuestCategorySyncHandler;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
@@ -69,6 +70,7 @@ public class QuestController implements IQuestHandler {
|
||||
if (!file.isDirectory())
|
||||
continue;
|
||||
QuestCategory category = loadCategoryDir(file);
|
||||
List<Quest> reassigned = new ArrayList<Quest>();
|
||||
Iterator<Integer> ite = category.quests.keySet().iterator();
|
||||
while (ite.hasNext()) {
|
||||
int id = ite.next();
|
||||
@@ -76,15 +78,58 @@ public class QuestController implements IQuestHandler {
|
||||
lastUsedQuestID = id;
|
||||
Quest quest = category.quests.get(id);
|
||||
if (quests.containsKey(id)) {
|
||||
LogWriter.error("Duplicate id " + quest.id + " from category " + category.title);
|
||||
// Quest IDs live in the filename, not inside the JSON body,
|
||||
// so a simple rename permanently resolves the conflict.
|
||||
File catDir = new File(getDir(), category.title);
|
||||
|
||||
// Find the next free ID. It has to clear three things: the ids already
|
||||
// registered globally, the ids this category still holds but has not
|
||||
// reached yet, and any file already on disk - renameTo overwrites
|
||||
// silently on POSIX, so landing on an existing file would destroy it.
|
||||
int newId = lastUsedQuestID;
|
||||
do {
|
||||
newId++;
|
||||
} while (quests.containsKey(newId)
|
||||
|| category.quests.containsKey(newId)
|
||||
|| new File(catDir, newId + ".json").exists());
|
||||
lastUsedQuestID = newId;
|
||||
|
||||
File oldFile = new File(catDir, id + ".json");
|
||||
File newFile = new File(catDir, newId + ".json");
|
||||
boolean renamed = oldFile.renameTo(newFile);
|
||||
|
||||
quest.id = newId;
|
||||
ite.remove();
|
||||
reassigned.add(quest);
|
||||
|
||||
if (renamed) {
|
||||
LogWriter.info("Quest ID conflict: reassigned \"" + quest.title
|
||||
+ "\" from id " + id + " to " + newId
|
||||
+ " in category \"" + category.title + "\"");
|
||||
} else {
|
||||
LogWriter.error("Quest ID conflict: could not rename file for \""
|
||||
+ quest.title + "\" (id " + id
|
||||
+ " in category \"" + category.title + "\") to " + newId);
|
||||
}
|
||||
} else {
|
||||
quests.put(id, quest);
|
||||
if (quest.profileOptions.enableOptions && quest.profileOptions.completeControl == EnumProfileSync.Shared) {
|
||||
if (quest.profileOptions.enableOptions
|
||||
&& (quest.profileOptions.completeControl == EnumProfileSync.Shared
|
||||
|| quest.profileOptions.cooldownControl == EnumProfileSync.Shared)) {
|
||||
sharedQuests.put(id, quest);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Re-register reassigned quests under their new IDs.
|
||||
for (Quest quest : reassigned) {
|
||||
quests.put(quest.id, quest);
|
||||
category.quests.put(quest.id, quest);
|
||||
if (quest.profileOptions.enableOptions
|
||||
&& (quest.profileOptions.completeControl == EnumProfileSync.Shared
|
||||
|| quest.profileOptions.cooldownControl == EnumProfileSync.Shared)) {
|
||||
sharedQuests.put(quest.id, quest);
|
||||
}
|
||||
}
|
||||
lastUsedCatID++;
|
||||
category.id = lastUsedCatID;
|
||||
categories.put(category.id, category);
|
||||
@@ -156,7 +201,7 @@ public class QuestController implements IQuestHandler {
|
||||
for (int dia : cat.quests.keySet())
|
||||
quests.remove(dia);
|
||||
categories.remove(category);
|
||||
SyncController.syncRemove(EnumSyncType.QUEST_CATEGORY, category);
|
||||
SyncController.syncRemove(SyncType.QUEST_CATEGORY, category);
|
||||
}
|
||||
|
||||
public void saveCategory(QuestCategory category) {
|
||||
@@ -186,7 +231,7 @@ public class QuestController implements IQuestHandler {
|
||||
dir.mkdirs();
|
||||
}
|
||||
categories.put(category.id, category);
|
||||
SyncController.syncUpdate(EnumSyncType.QUEST_CATEGORY, -1, SyncController.updateQuestCat(category));
|
||||
SyncController.syncUpdate(SyncType.QUEST_CATEGORY, -1, QuestCategorySyncHandler.serializeCategory(category));
|
||||
}
|
||||
|
||||
private boolean containsCategoryName(String name) {
|
||||
@@ -225,7 +270,9 @@ public class QuestController implements IQuestHandler {
|
||||
category.quests.put(quest.id, quest);
|
||||
|
||||
sharedQuests.remove(quest.id);
|
||||
if (quest.profileOptions.enableOptions && quest.profileOptions.completeControl == EnumProfileSync.Shared) {
|
||||
if (quest.profileOptions.enableOptions
|
||||
&& (quest.profileOptions.completeControl == EnumProfileSync.Shared
|
||||
|| quest.profileOptions.cooldownControl == EnumProfileSync.Shared)) {
|
||||
sharedQuests.put(quest.id, quest);
|
||||
}
|
||||
|
||||
@@ -241,7 +288,7 @@ public class QuestController implements IQuestHandler {
|
||||
if (file2.exists())
|
||||
file2.delete();
|
||||
file.renameTo(file2);
|
||||
SyncController.syncUpdate(EnumSyncType.QUEST, category.id, quest.writeToNBT(new NBTTagCompound()));
|
||||
SyncController.syncUpdate(SyncType.QUEST, category.id, quest.writeToNBT(new NBTTagCompound()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
@@ -282,12 +283,12 @@ public class RecipeController implements IRecipeHandler {
|
||||
return null;
|
||||
RecipeCarpentry globalRecipe = globalRecipes.remove(recipe.id);
|
||||
if (globalRecipe != null)
|
||||
SyncController.syncAllWorkbenchRecipes();
|
||||
SyncController.syncAll(SyncType.WORKBENCH_RECIPES);
|
||||
|
||||
RecipeCarpentry carpentry = carpentryRecipes.remove(recipe.id);
|
||||
if (carpentry != null) {
|
||||
carpentryScripts.remove(recipe.id);
|
||||
SyncController.syncAllCarpentryRecipes();
|
||||
SyncController.syncAll(SyncType.CARPENTRY_RECIPES);
|
||||
}
|
||||
|
||||
saveCategories();
|
||||
@@ -302,7 +303,7 @@ public class RecipeController implements IRecipeHandler {
|
||||
|
||||
RecipeAnvil anvilRecipe = anvilRecipes.remove(recipe.id);
|
||||
if (anvilRecipe != null)
|
||||
SyncController.syncAllAnvilRecipes();
|
||||
SyncController.syncAll(SyncType.ANVIL_RECIPES);
|
||||
|
||||
saveCategories();
|
||||
return recipe;
|
||||
|
||||
@@ -5,7 +5,7 @@ import noppes.npcs.config.ConfigScript;
|
||||
|
||||
/**
|
||||
* Server-side utility for syncing script configuration to clients.
|
||||
*
|
||||
* <p>
|
||||
* This class is SERVER-SIDE ONLY. Client reads via ScriptClientConfig.
|
||||
*/
|
||||
public class ScriptConfigSync {
|
||||
|
||||
@@ -11,6 +11,7 @@ import noppes.npcs.controllers.data.IScriptHandler;
|
||||
import noppes.npcs.controllers.data.IScriptUnit;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
|
||||
import javax.script.Bindings;
|
||||
import javax.script.Compilable;
|
||||
import javax.script.CompiledScript;
|
||||
import javax.script.ScriptContext;
|
||||
@@ -45,11 +46,48 @@ public class ScriptContainer implements IScriptUnit {
|
||||
private static Method luaCall;
|
||||
private CompiledScript compScript = null;
|
||||
private final HashMap<String, ScriptObjectMirror> cachedFunctions = new HashMap<>();
|
||||
private long lastGlobalsVersion = -1;
|
||||
|
||||
/**
|
||||
* Persisted per-container language. Null means inherit from handler default.
|
||||
* Separate from currentScriptLanguage which is the engine cache.
|
||||
*/
|
||||
private String language = null;
|
||||
|
||||
/**
|
||||
* Per-instance bindings for variable isolation. When non-null, this container
|
||||
* is an instance scope sharing a template's engine. All eval/lookup uses these
|
||||
* bindings instead of the engine's default ENGINE_SCOPE.
|
||||
*/
|
||||
private Bindings instanceBindings = null;
|
||||
|
||||
public ScriptContainer(IScriptHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a lightweight instance scope that shares this container's engine
|
||||
* but has its own isolated Bindings for variable state.
|
||||
* The template's engine is initialized if needed.
|
||||
*
|
||||
* @param instanceHandler the script handler for the instance
|
||||
*/
|
||||
@Override
|
||||
public IScriptUnit createInstanceScope(IScriptHandler instanceHandler) {
|
||||
if (this.engine == null) {
|
||||
this.setEngine(this.getLanguage());
|
||||
}
|
||||
ScriptContainer instance = new ScriptContainer(instanceHandler);
|
||||
instance.script = this.script;
|
||||
instance.scripts = new ArrayList<>(this.scripts);
|
||||
instance.console = this.console;
|
||||
instance.language = this.language;
|
||||
instance.engine = this.engine;
|
||||
instance.currentScriptLanguage = this.currentScriptLanguage;
|
||||
instance.instanceBindings = this.engine.createBindings();
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
String prevScript = this.script;
|
||||
this.script = compound.getString("Script");
|
||||
@@ -68,6 +106,12 @@ public class ScriptContainer implements IScriptUnit {
|
||||
this.console = NBTTags.GetLongStringMap(compound.getTagList("Console", 10));
|
||||
this.scripts = NBTTags.getStringList(compound.getTagList("ScriptList", 10));
|
||||
this.lastCreated = 0L;
|
||||
|
||||
// Read per-container language (empty string or missing = inherit from handler)
|
||||
if (compound.hasKey("ContainerLanguage")) {
|
||||
String lang = compound.getString("ContainerLanguage");
|
||||
this.language = lang.isEmpty() ? null : lang;
|
||||
}
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
@@ -98,6 +142,11 @@ public class ScriptContainer implements IScriptUnit {
|
||||
//compound.setString("Type", this.type);
|
||||
compound.setTag("Console", NBTTags.NBTLongStringMap(this.console));
|
||||
compound.setTag("ScriptList", NBTTags.nbtStringList(this.scripts));
|
||||
|
||||
// Persist per-container language if explicitly set
|
||||
if (this.language != null) {
|
||||
compound.setString("ContainerLanguage", this.language);
|
||||
}
|
||||
return compound;
|
||||
}
|
||||
|
||||
@@ -169,13 +218,14 @@ public class ScriptContainer implements IScriptUnit {
|
||||
if (!CustomNpcs.proxy.isScriptingEnabled() || errored || !hasCode() || unknownFunctions.contains(type))
|
||||
return;
|
||||
|
||||
this.setEngine(handler.getLanguage());
|
||||
this.setEngine(this.getLanguage());
|
||||
if (engine == null)
|
||||
return;
|
||||
|
||||
if (ScriptController.Instance.lastLoaded > this.lastCreated) {
|
||||
this.lastCreated = ScriptController.Instance.lastLoaded;
|
||||
evaluated = false;
|
||||
lastGlobalsVersion = -1;
|
||||
}
|
||||
|
||||
synchronized (lock) {
|
||||
@@ -188,20 +238,39 @@ public class ScriptContainer implements IScriptUnit {
|
||||
engine.getContext().setWriter(pw);
|
||||
engine.getContext().setErrorWriter(pw);
|
||||
|
||||
engine.put("API", NpcAPI.Instance());
|
||||
HashMap<String, Object> engineEntries = new HashMap<>(NpcAPI.engineObjects);
|
||||
for (Map.Entry<String, Object> objectEntry : engineEntries.entrySet()) {
|
||||
engine.put(objectEntry.getKey(), objectEntry.getValue());
|
||||
// Populate bindings with API objects (skip if globals unchanged)
|
||||
long currentGlobalsVersion = NpcAPI.engineObjectsVersion;
|
||||
boolean globalsChanged = lastGlobalsVersion != currentGlobalsVersion;
|
||||
if (instanceBindings != null) {
|
||||
if (globalsChanged) {
|
||||
instanceBindings.put("API", NpcAPI.Instance());
|
||||
for (Map.Entry<String, Object> objectEntry : NpcAPI.engineObjects.entrySet()) {
|
||||
instanceBindings.put(objectEntry.getKey(), objectEntry.getValue());
|
||||
}
|
||||
lastGlobalsVersion = currentGlobalsVersion;
|
||||
}
|
||||
} else {
|
||||
if (globalsChanged) {
|
||||
engine.put("API", NpcAPI.Instance());
|
||||
for (Map.Entry<String, Object> objectEntry : NpcAPI.engineObjects.entrySet()) {
|
||||
engine.put(objectEntry.getKey(), objectEntry.getValue());
|
||||
}
|
||||
lastGlobalsVersion = currentGlobalsVersion;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (!evaluated) {
|
||||
this.cachedFunctions.clear();
|
||||
engine.eval(getFullCode());
|
||||
if (instanceBindings != null) {
|
||||
engine.eval(getFullCode(), instanceBindings);
|
||||
} else {
|
||||
engine.eval(getFullCode());
|
||||
}
|
||||
evaluated = true;
|
||||
}
|
||||
if (engine.getFactory().getLanguageName().equals("lua")) {
|
||||
Object ob = engine.get(type);
|
||||
Object ob = instanceBindings != null ? instanceBindings.get(type) : engine.get(type);
|
||||
if (ob != null) {
|
||||
if (luaCoerce == null) {
|
||||
luaCoerce = Class.forName("org.luaj.vm2.lib.jse.CoerceJavaToLua").getMethod("coerce", Object.class);
|
||||
@@ -213,8 +282,14 @@ public class ScriptContainer implements IScriptUnit {
|
||||
}
|
||||
} else {
|
||||
if (!this.cachedFunctions.containsKey(type)) {
|
||||
ScriptObjectMirror global = (ScriptObjectMirror) engine.getBindings(ScriptContext.ENGINE_SCOPE);
|
||||
ScriptObjectMirror func = (ScriptObjectMirror) global.get(type);
|
||||
ScriptObjectMirror func;
|
||||
if (instanceBindings != null) {
|
||||
Object val = instanceBindings.get(type);
|
||||
func = val instanceof ScriptObjectMirror ? (ScriptObjectMirror) val : null;
|
||||
} else {
|
||||
ScriptObjectMirror global = (ScriptObjectMirror) engine.getBindings(ScriptContext.ENGINE_SCOPE);
|
||||
func = (ScriptObjectMirror) global.get(type);
|
||||
}
|
||||
this.cachedFunctions.put(type, func);
|
||||
}
|
||||
ScriptObjectMirror func = this.cachedFunctions.get(type);
|
||||
@@ -261,14 +336,22 @@ public class ScriptContainer implements IScriptUnit {
|
||||
return !this.getFullCode().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnknownFunction(String type) {
|
||||
return unknownFunctions.contains(type);
|
||||
}
|
||||
|
||||
public void setEngine(String scriptLanguage) {
|
||||
if (!Objects.equals(scriptLanguage, this.currentScriptLanguage)) {
|
||||
// Instance scopes share the template's engine — never create a new one
|
||||
if (instanceBindings != null) return;
|
||||
this.currentScriptLanguage = scriptLanguage;
|
||||
if (ConfigScript.ScriptingECMA6 && scriptLanguage.equals("ECMAScript")) {
|
||||
System.setProperty("nashorn.args", "--language=es6");
|
||||
}
|
||||
this.engine = ScriptController.Instance.getEngineByName(scriptLanguage.toLowerCase());
|
||||
this.evaluated = false;
|
||||
this.lastGlobalsVersion = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,18 +391,15 @@ public class ScriptContainer implements IScriptUnit {
|
||||
|
||||
@Override
|
||||
public String getLanguage() {
|
||||
// If a specific language is set for this container, use it
|
||||
// Otherwise fall back to the handler's language
|
||||
if (currentScriptLanguage != null) {
|
||||
return currentScriptLanguage;
|
||||
}
|
||||
return handler != null ? handler.getLanguage() : "ECMAScript";
|
||||
// Return persisted per-container language, defaulting to ECMAScript.
|
||||
// This is separate from currentScriptLanguage which is the engine cache.
|
||||
return this.language != null ? this.language : "ECMAScript";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLanguage(String language) {
|
||||
if (!Objects.equals(this.currentScriptLanguage, language)) {
|
||||
this.currentScriptLanguage = language;
|
||||
if (!Objects.equals(this.language, language)) {
|
||||
this.language = language;
|
||||
this.evaluated = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import noppes.npcs.api.event.IAbilityEvent;
|
||||
import noppes.npcs.api.event.IChainEvent;
|
||||
import noppes.npcs.api.event.IAnimationEvent;
|
||||
import noppes.npcs.api.event.IAuctionEvent;
|
||||
import noppes.npcs.api.event.IBlockEvent;
|
||||
import noppes.npcs.api.event.ICustomGuiEvent;
|
||||
import noppes.npcs.api.event.ICustomNPCsEvent;
|
||||
import noppes.npcs.api.event.IDialogEvent;
|
||||
import noppes.npcs.api.event.IEnergyBarrierEvent;
|
||||
import noppes.npcs.api.event.IEnergyProjectileEvent;
|
||||
import noppes.npcs.api.event.IFactionEvent;
|
||||
import noppes.npcs.api.event.IForgeEvent;
|
||||
import noppes.npcs.api.event.IItemEvent;
|
||||
@@ -37,6 +41,8 @@ import static noppes.npcs.constants.ScriptContext.ITEM;
|
||||
import static noppes.npcs.constants.ScriptContext.LINKED_ITEM;
|
||||
import static noppes.npcs.constants.ScriptContext.NPC;
|
||||
import static noppes.npcs.constants.ScriptContext.PLAYER;
|
||||
import static noppes.npcs.constants.ScriptContext.ABILITY;
|
||||
import static noppes.npcs.constants.ScriptContext.CHAINED_ABILITY;
|
||||
import static noppes.npcs.constants.ScriptContext.RECIPE;
|
||||
|
||||
/**
|
||||
@@ -77,6 +83,7 @@ public class ScriptHookController implements IScriptHookHandler {
|
||||
initializeLinkedItemHooks();
|
||||
initializeRecipeHooks();
|
||||
initializeEffectHooks();
|
||||
initializeAbilityHooks();
|
||||
initializeForgeHooks();
|
||||
}
|
||||
|
||||
@@ -106,13 +113,41 @@ public class ScriptHookController implements IScriptHookHandler {
|
||||
hook(NPC, PROJECTILE_TICK, IProjectileEvent.UpdateEvent.class);
|
||||
hook(NPC, PROJECTILE_IMPACT, IProjectileEvent.ImpactEvent.class);
|
||||
|
||||
// Energy Projectile
|
||||
hook(NPC, ENERGY_PROJECTILE_FIRED, IEnergyProjectileEvent.FiredEvent.class);
|
||||
hook(NPC, ENERGY_PROJECTILE_TICK, IEnergyProjectileEvent.UpdateEvent.class);
|
||||
hook(NPC, ENERGY_PROJECTILE_ENTITY_IMPACT, IEnergyProjectileEvent.EntityImpactEvent.class);
|
||||
hook(NPC, ENERGY_PROJECTILE_BLOCK_IMPACT, IEnergyProjectileEvent.BlockImpactEvent.class);
|
||||
hook(NPC, ENERGY_PROJECTILE_EXPIRED, IEnergyProjectileEvent.ExpiredEvent.class);
|
||||
|
||||
// Ability
|
||||
hook(NPC, ABILITY_START, IAbilityEvent.StartEvent.class);
|
||||
hook(NPC, ABILITY_EXECUTE, IAbilityEvent.ExecuteEvent.class);
|
||||
hook(NPC, ABILITY_HIT, IAbilityEvent.HitEvent.class);
|
||||
hook(NPC, ABILITY_DEFEND, IAbilityEvent.DefendEvent.class);
|
||||
hook(NPC, ABILITY_TICK, IAbilityEvent.TickEvent.class);
|
||||
hook(NPC, ABILITY_INTERRUPT, IAbilityEvent.InterruptEvent.class);
|
||||
hook(NPC, ABILITY_COMPLETE, IAbilityEvent.CompleteEvent.class);
|
||||
hook(NPC, ABILITY_TOGGLE, IAbilityEvent.ToggleEvent.class);
|
||||
hook(NPC, ABILITY_TOGGLE_TICK, IAbilityEvent.ToggleUpdateEvent.class);
|
||||
|
||||
// Chain
|
||||
hook(NPC, CHAIN_START, IChainEvent.StartEvent.class);
|
||||
hook(NPC, CHAIN_NEXT, IChainEvent.NextEvent.class);
|
||||
hook(NPC, CHAIN_COMPLETE, IChainEvent.CompleteEvent.class);
|
||||
hook(NPC, CHAIN_INTERRUPT, IChainEvent.InterruptEvent.class);
|
||||
|
||||
// Energy Barrier
|
||||
hook(NPC, ENERGY_BARRIER_SPAWNED, IEnergyBarrierEvent.SpawnedEvent.class);
|
||||
hook(NPC, ENERGY_BARRIER_TICK, IEnergyBarrierEvent.UpdateEvent.class);
|
||||
hook(NPC, ENERGY_BARRIER_HIT, IEnergyBarrierEvent.HitEvent.class);
|
||||
hook(NPC, ENERGY_BARRIER_DESTROYED, IEnergyBarrierEvent.DestroyedEvent.class);
|
||||
|
||||
// Animation
|
||||
hook(NPC, ANIMATION_START, IAnimationEvent.Started.class);
|
||||
hook(NPC, ANIMATION_END, IAnimationEvent.Ended.class);
|
||||
hook(NPC, ANIMATION_FRAME_ENTER, IAnimationEvent.IFrameEvent.Entered.class);
|
||||
hook(NPC, ANIMATION_FRAME_EXIT, IAnimationEvent.IFrameEvent.Exited.class);
|
||||
}
|
||||
|
||||
private void initializePlayerHooks() {
|
||||
@@ -208,6 +243,43 @@ public class ScriptHookController implements IScriptHookHandler {
|
||||
hook(PLAYER, ANIMATION_FRAME_ENTER, IAnimationEvent.IFrameEvent.Entered.class);
|
||||
hook(PLAYER, ANIMATION_FRAME_EXIT, IAnimationEvent.IFrameEvent.Exited.class);
|
||||
|
||||
// Energy Projectile
|
||||
hook(PLAYER, ENERGY_PROJECTILE_FIRED, IEnergyProjectileEvent.FiredEvent.class);
|
||||
hook(PLAYER, ENERGY_PROJECTILE_TICK, IEnergyProjectileEvent.UpdateEvent.class);
|
||||
hook(PLAYER, ENERGY_PROJECTILE_ENTITY_IMPACT, IEnergyProjectileEvent.EntityImpactEvent.class);
|
||||
hook(PLAYER, ENERGY_PROJECTILE_BLOCK_IMPACT, IEnergyProjectileEvent.BlockImpactEvent.class);
|
||||
hook(PLAYER, ENERGY_PROJECTILE_EXPIRED, IEnergyProjectileEvent.ExpiredEvent.class);
|
||||
|
||||
// Energy Barrier
|
||||
hook(PLAYER, ENERGY_BARRIER_SPAWNED, IEnergyBarrierEvent.SpawnedEvent.class);
|
||||
hook(PLAYER, ENERGY_BARRIER_TICK, IEnergyBarrierEvent.UpdateEvent.class);
|
||||
hook(PLAYER, ENERGY_BARRIER_HIT, IEnergyBarrierEvent.HitEvent.class);
|
||||
hook(PLAYER, ENERGY_BARRIER_DESTROYED, IEnergyBarrierEvent.DestroyedEvent.class);
|
||||
|
||||
// Ability
|
||||
hook(PLAYER, ABILITY_START, IAbilityEvent.StartEvent.class);
|
||||
hook(PLAYER, ABILITY_EXECUTE, IAbilityEvent.ExecuteEvent.class);
|
||||
hook(PLAYER, ABILITY_HIT, IAbilityEvent.HitEvent.class);
|
||||
hook(PLAYER, ABILITY_DEFEND, IAbilityEvent.DefendEvent.class);
|
||||
hook(PLAYER, ABILITY_TICK, IAbilityEvent.TickEvent.class);
|
||||
hook(PLAYER, ABILITY_INTERRUPT, IAbilityEvent.InterruptEvent.class);
|
||||
hook(PLAYER, ABILITY_COMPLETE, IAbilityEvent.CompleteEvent.class);
|
||||
hook(PLAYER, ABILITY_TOGGLE, IAbilityEvent.ToggleEvent.class);
|
||||
hook(PLAYER, ABILITY_TOGGLE_TICK, IAbilityEvent.ToggleUpdateEvent.class);
|
||||
|
||||
// Chain
|
||||
hook(PLAYER, CHAIN_START, IChainEvent.StartEvent.class);
|
||||
hook(PLAYER, CHAIN_NEXT, IChainEvent.NextEvent.class);
|
||||
hook(PLAYER, CHAIN_COMPLETE, IChainEvent.CompleteEvent.class);
|
||||
hook(PLAYER, CHAIN_INTERRUPT, IChainEvent.InterruptEvent.class);
|
||||
|
||||
// Auction
|
||||
hook(PLAYER, AUCTION_CREATE, IAuctionEvent.CreateEvent.class);
|
||||
hook(PLAYER, AUCTION_BID, IAuctionEvent.BidEvent.class);
|
||||
hook(PLAYER, AUCTION_BUYOUT, IAuctionEvent.BuyoutEvent.class);
|
||||
hook(PLAYER, AUCTION_CANCEL, IAuctionEvent.CancelEvent.class);
|
||||
hook(PLAYER, AUCTION_CLAIM, IAuctionEvent.ClaimEvent.class);
|
||||
|
||||
// Profile
|
||||
hook(PLAYER, PROFILE_CHANGE, IPlayerEvent.ProfileEvent.Changed.class);
|
||||
hook(PLAYER, PROFILE_REMOVE, IPlayerEvent.ProfileEvent.Removed.class);
|
||||
@@ -282,6 +354,25 @@ public class ScriptHookController implements IScriptHookHandler {
|
||||
hook(EFFECT, ON_EFFECT_REMOVE, IPlayerEvent.EffectEvent.Removed.class);
|
||||
}
|
||||
|
||||
private void initializeAbilityHooks() {
|
||||
// Ability context (internal per-ability scripts)
|
||||
hook(ABILITY, ABILITY_START, IAbilityEvent.StartEvent.class);
|
||||
hook(ABILITY, ABILITY_EXECUTE, IAbilityEvent.ExecuteEvent.class);
|
||||
hook(ABILITY, ABILITY_HIT, IAbilityEvent.HitEvent.class);
|
||||
hook(ABILITY, ABILITY_DEFEND, IAbilityEvent.DefendEvent.class);
|
||||
hook(ABILITY, ABILITY_TICK, IAbilityEvent.TickEvent.class);
|
||||
hook(ABILITY, ABILITY_INTERRUPT, IAbilityEvent.InterruptEvent.class);
|
||||
hook(ABILITY, ABILITY_COMPLETE, IAbilityEvent.CompleteEvent.class);
|
||||
hook(ABILITY, ABILITY_TOGGLE, IAbilityEvent.ToggleEvent.class);
|
||||
hook(ABILITY, ABILITY_TOGGLE_TICK, IAbilityEvent.ToggleUpdateEvent.class);
|
||||
|
||||
// Chained ability context (chain-level lifecycle hooks)
|
||||
hook(CHAINED_ABILITY, CHAIN_START, IChainEvent.StartEvent.class);
|
||||
hook(CHAINED_ABILITY, CHAIN_NEXT, IChainEvent.NextEvent.class);
|
||||
hook(CHAINED_ABILITY, CHAIN_COMPLETE, IChainEvent.CompleteEvent.class);
|
||||
hook(CHAINED_ABILITY, CHAIN_INTERRUPT, IChainEvent.InterruptEvent.class);
|
||||
}
|
||||
|
||||
private void initializeForgeHooks() {
|
||||
hook(FORGE, INIT, IForgeEvent.InitEvent.class);
|
||||
hook(FORGE, FORGE_WORLD, IForgeEvent.WorldEvent.class);
|
||||
|
||||
@@ -223,11 +223,14 @@ public class SpawnController implements INaturalSpawnsHandler {
|
||||
}
|
||||
|
||||
public INaturalSpawn[] getSpawns(String biome) {
|
||||
return getSpawnList(biome).toArray(new INaturalSpawn[]{});
|
||||
List<SpawnData> biomeSpawns = getSpawnList(biome);
|
||||
if (biomeSpawns == null)
|
||||
return new INaturalSpawn[]{};
|
||||
return biomeSpawns.toArray(new INaturalSpawn[]{});
|
||||
}
|
||||
|
||||
public void addSpawn(INaturalSpawn spawn) {
|
||||
((SpawnData) spawn).id = 0;
|
||||
((SpawnData) spawn).id = -1;
|
||||
this.saveSpawnData((SpawnData) spawn);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
@@ -9,6 +12,9 @@ import noppes.npcs.api.handler.ITagHandler;
|
||||
import noppes.npcs.api.handler.data.ITag;
|
||||
import noppes.npcs.controllers.data.Tag;
|
||||
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
@@ -18,6 +24,7 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@@ -234,4 +241,69 @@ public class TagController implements ITagHandler {
|
||||
public HashSet<Tag> getAllTags() {
|
||||
return new HashSet<Tag>(this.tags.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a set of tag UUIDs to an NBT compound under the given key.
|
||||
*/
|
||||
public static void writeTagUUIDs(NBTTagCompound compound, String key, HashSet<UUID> tagUUIDs) {
|
||||
if (tagUUIDs != null && !tagUUIDs.isEmpty()) {
|
||||
NBTTagList list = new NBTTagList();
|
||||
for (UUID uuid : tagUUIDs) {
|
||||
list.appendTag(new NBTTagString(uuid.toString()));
|
||||
}
|
||||
compound.setTag(key, list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a set of tag UUIDs from an NBT compound under the given key.
|
||||
*/
|
||||
public static HashSet<UUID> readTagUUIDs(NBTTagCompound compound, String key) {
|
||||
HashSet<UUID> uuids = new HashSet<>();
|
||||
if (compound.hasKey(key)) {
|
||||
NBTTagList list = compound.getTagList(key, 8);
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
try {
|
||||
uuids.add(UUID.fromString(list.getStringTagAt(i)));
|
||||
} catch (IllegalArgumentException ignored) {}
|
||||
}
|
||||
}
|
||||
return uuids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove invalid tag UUIDs (those not in the tag registry).
|
||||
*/
|
||||
public static void validateTagUUIDs(HashSet<UUID> tagUUIDs) {
|
||||
TagController tc = getInstance();
|
||||
if (tc == null) return;
|
||||
tagUUIDs.removeIf(uuid -> tc.getTagFromUUID(uuid) == null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build and send a CategoryTagMap GuiData packet for a set of items.
|
||||
* @param player the target player
|
||||
* @param itemTags map of item name -> tag UUIDs (only validated tags are sent)
|
||||
*/
|
||||
public static void sendCategoryTagMap(EntityPlayerMP player, HashMap<String, HashSet<UUID>> itemTags) {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
NBTTagList entries = new NBTTagList();
|
||||
TagController tc = getInstance();
|
||||
for (Map.Entry<String, HashSet<UUID>> entry : itemTags.entrySet()) {
|
||||
HashSet<UUID> valid = new HashSet<>();
|
||||
for (UUID uuid : entry.getValue()) {
|
||||
if (tc != null && tc.getTagFromUUID(uuid) != null) {
|
||||
valid.add(uuid);
|
||||
}
|
||||
}
|
||||
if (!valid.isEmpty()) {
|
||||
NBTTagCompound itemEntry = new NBTTagCompound();
|
||||
itemEntry.setString("Name", entry.getKey());
|
||||
writeTagUUIDs(itemEntry, "Tags", valid);
|
||||
entries.appendTag(itemEntry);
|
||||
}
|
||||
}
|
||||
compound.setTag("CategoryTagMap", entries);
|
||||
GuiDataPacket.sendGuiData(player, compound);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class AbilityHotbarData {
|
||||
public static final String CHAIN_PREFIX = "chain:";
|
||||
public static final int TOTAL_SLOTS = 12;
|
||||
|
||||
public int slot = -1;
|
||||
public String abilityKey = "";
|
||||
|
||||
public AbilityHotbarData() {
|
||||
}
|
||||
|
||||
public AbilityHotbarData(int slot) {
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
public boolean isChainKey() {
|
||||
return abilityKey != null && abilityKey.startsWith(CHAIN_PREFIX);
|
||||
}
|
||||
|
||||
public String getResolveKey() {
|
||||
if (isChainKey()) return abilityKey.substring(CHAIN_PREFIX.length());
|
||||
return abilityKey;
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setInteger("slot", slot);
|
||||
tag.setString("abilityKey", abilityKey != null ? abilityKey : "");
|
||||
compound.setTag("AbilityHotbar" + slot, tag);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
abilityKey = compound.getString("abilityKey");
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
abilityKey = "";
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return abilityKey == null || abilityKey.isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import kamkeel.npcs.network.packets.request.script.AbilityScriptPacket;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.constants.ScriptContext;
|
||||
import noppes.npcs.janino.EventJaninoScript;
|
||||
|
||||
/**
|
||||
* Script handler for ability scripts.
|
||||
* Manages a single script container for ability hooks (abilityStart, abilityTick, abilityComplete, etc.).
|
||||
*/
|
||||
public class AbilityScript extends SingleScriptHandler implements IScriptHandlerPacket {
|
||||
|
||||
/**
|
||||
* The ability ID (UUID) for packet communication. Empty if not bound.
|
||||
*/
|
||||
private String abilityId = "";
|
||||
|
||||
/**
|
||||
* Create an unbound AbilityScript (for server-side use).
|
||||
*/
|
||||
public AbilityScript() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an AbilityScript bound to a specific ability (for GUI use).
|
||||
*
|
||||
* @param abilityId The UUID of the ability
|
||||
*/
|
||||
public AbilityScript(String abilityId) {
|
||||
this.abilityId = abilityId != null ? abilityId : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScriptContext getContext() {
|
||||
return ScriptContext.ABILITY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScriptUnit createJaninoScriptUnit() {
|
||||
return new EventJaninoScript(ScriptContext.ABILITY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String noticeString() {
|
||||
return !abilityId.isEmpty() ? "Ability[" + abilityId + "]" : "Ability";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestData() {
|
||||
if (!abilityId.isEmpty())
|
||||
AbilityScriptPacket.Get(abilityId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendSavePacket(int index, int totalCount, NBTTagCompound nbt) {
|
||||
if (!abilityId.isEmpty())
|
||||
AbilityScriptPacket.Save(abilityId, index, totalCount, nbt);
|
||||
}
|
||||
}
|
||||
@@ -10,15 +10,16 @@ import noppes.npcs.config.ConfigMarket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class AuctionBlacklist {
|
||||
private static Set<String> blacklistedItems = new HashSet<>();
|
||||
private static Set<Pattern> wildcardPatterns = new HashSet<>();
|
||||
private static Set<String> blacklistedMods = new HashSet<>();
|
||||
private static Set<String> blacklistedNBTTags = new HashSet<>();
|
||||
private static volatile Set<String> blacklistedItems = new HashSet<>();
|
||||
private static volatile Set<Pattern> wildcardPatterns = new HashSet<>();
|
||||
private static volatile Set<String> blacklistedMods = new HashSet<>();
|
||||
private static volatile Set<String> blacklistedNBTTags = new HashSet<>();
|
||||
|
||||
// Built-in bound item requirement keys (always blocked)
|
||||
private static final String SOULBIND_KEY = "cnpc_soulbind";
|
||||
@@ -28,10 +29,10 @@ public class AuctionBlacklist {
|
||||
private static final String BYPASS_PERMISSION = "customnpcs.auction.blacklist.bypass";
|
||||
|
||||
public static void reload() {
|
||||
blacklistedItems.clear();
|
||||
wildcardPatterns.clear();
|
||||
blacklistedMods.clear();
|
||||
blacklistedNBTTags.clear();
|
||||
Set<String> newItems = new HashSet<>();
|
||||
Set<Pattern> newWildcards = new HashSet<>();
|
||||
Set<String> newMods = new HashSet<>();
|
||||
Set<String> newNBTTags = new HashSet<>();
|
||||
|
||||
// Load blacklisted items
|
||||
for (String item : ConfigMarket.BlacklistedItems) {
|
||||
@@ -40,23 +41,29 @@ public class AuctionBlacklist {
|
||||
|
||||
if (item.contains("*")) {
|
||||
String regex = "^" + item.replace(".", "\\.").replace("*", ".*") + "$";
|
||||
wildcardPatterns.add(Pattern.compile(regex));
|
||||
newWildcards.add(Pattern.compile(regex));
|
||||
} else {
|
||||
blacklistedItems.add(item);
|
||||
newItems.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
// Load blacklisted mods
|
||||
for (String mod : ConfigMarket.BlacklistedMods) {
|
||||
if (mod == null || mod.isEmpty()) continue;
|
||||
blacklistedMods.add(mod.toLowerCase().trim());
|
||||
newMods.add(mod.toLowerCase().trim());
|
||||
}
|
||||
|
||||
// Load blacklisted NBT tags
|
||||
for (String tag : ConfigMarket.BlacklistedNBTTags) {
|
||||
if (tag == null || tag.isEmpty()) continue;
|
||||
blacklistedNBTTags.add(tag.trim());
|
||||
newNBTTags.add(tag.trim());
|
||||
}
|
||||
|
||||
// Atomic swap
|
||||
blacklistedItems = newItems;
|
||||
wildcardPatterns = newWildcards;
|
||||
blacklistedMods = newMods;
|
||||
blacklistedNBTTags = newNBTTags;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,7 +85,6 @@ public class AuctionBlacklist {
|
||||
* Check if item is blacklisted (without bypass check)
|
||||
*/
|
||||
public static boolean isBlacklisted(ItemStack item) {
|
||||
if (!ConfigMarket.BlacklistEnabled) return false;
|
||||
if (item == null || item.getItem() == null) return true;
|
||||
|
||||
// Check bound items (always blocked, even if blacklist is "disabled")
|
||||
@@ -86,6 +92,8 @@ public class AuctionBlacklist {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!ConfigMarket.BlacklistEnabled) return false;
|
||||
|
||||
// Get registry name
|
||||
GameRegistry.UniqueIdentifier uid = GameRegistry.findUniqueIdentifierFor(item.getItem());
|
||||
if (uid == null) return true;
|
||||
@@ -172,9 +180,13 @@ public class AuctionBlacklist {
|
||||
|
||||
if (registryName.contains("*")) {
|
||||
String regex = "^" + registryName.replace(".", "\\.").replace("*", ".*") + "$";
|
||||
wildcardPatterns.add(Pattern.compile(regex));
|
||||
Set<Pattern> newWildcards = new HashSet<>(wildcardPatterns);
|
||||
newWildcards.add(Pattern.compile(regex));
|
||||
wildcardPatterns = newWildcards;
|
||||
} else {
|
||||
blacklistedItems.add(registryName);
|
||||
Set<String> newItems = new HashSet<>(blacklistedItems);
|
||||
newItems.add(registryName);
|
||||
blacklistedItems = newItems;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -185,30 +197,55 @@ public class AuctionBlacklist {
|
||||
|
||||
if (registryName.contains("*")) {
|
||||
String regex = "^" + registryName.replace(".", "\\.").replace("*", ".*") + "$";
|
||||
return wildcardPatterns.removeIf(p -> p.pattern().equals(regex));
|
||||
Set<Pattern> newWildcards = new HashSet<>(wildcardPatterns);
|
||||
boolean removed = false;
|
||||
Iterator<Pattern> it = newWildcards.iterator();
|
||||
while (it.hasNext()) {
|
||||
if (it.next().pattern().equals(regex)) {
|
||||
it.remove();
|
||||
removed = true;
|
||||
}
|
||||
}
|
||||
wildcardPatterns = newWildcards;
|
||||
return removed;
|
||||
} else {
|
||||
return blacklistedItems.remove(registryName);
|
||||
Set<String> newItems = new HashSet<>(blacklistedItems);
|
||||
boolean removed = newItems.remove(registryName);
|
||||
blacklistedItems = newItems;
|
||||
return removed;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean addMod(String modId) {
|
||||
if (modId == null || modId.isEmpty()) return false;
|
||||
return blacklistedMods.add(modId.toLowerCase().trim());
|
||||
Set<String> newMods = new HashSet<>(blacklistedMods);
|
||||
boolean added = newMods.add(modId.toLowerCase().trim());
|
||||
blacklistedMods = newMods;
|
||||
return added;
|
||||
}
|
||||
|
||||
public static boolean removeMod(String modId) {
|
||||
if (modId == null || modId.isEmpty()) return false;
|
||||
return blacklistedMods.remove(modId.toLowerCase().trim());
|
||||
Set<String> newMods = new HashSet<>(blacklistedMods);
|
||||
boolean removed = newMods.remove(modId.toLowerCase().trim());
|
||||
blacklistedMods = newMods;
|
||||
return removed;
|
||||
}
|
||||
|
||||
public static boolean addNBTTag(String tag) {
|
||||
if (tag == null || tag.isEmpty()) return false;
|
||||
return blacklistedNBTTags.add(tag.trim());
|
||||
Set<String> newTags = new HashSet<>(blacklistedNBTTags);
|
||||
boolean added = newTags.add(tag.trim());
|
||||
blacklistedNBTTags = newTags;
|
||||
return added;
|
||||
}
|
||||
|
||||
public static boolean removeNBTTag(String tag) {
|
||||
if (tag == null || tag.isEmpty()) return false;
|
||||
return blacklistedNBTTags.remove(tag.trim());
|
||||
Set<String> newTags = new HashSet<>(blacklistedNBTTags);
|
||||
boolean removed = newTags.remove(tag.trim());
|
||||
blacklistedNBTTags = newTags;
|
||||
return removed;
|
||||
}
|
||||
|
||||
// =========================================
|
||||
|
||||
@@ -2,6 +2,7 @@ package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.api.handler.data.IAuctionClaim;
|
||||
import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.config.ConfigMarket;
|
||||
@@ -33,7 +34,9 @@ public class AuctionClaim implements IAuctionClaim {
|
||||
this.otherPlayerName = "";
|
||||
}
|
||||
|
||||
/** Create claim for winning an item (buyer won auction or buyout) */
|
||||
/**
|
||||
* Create claim for winning an item (buyer won auction or buyout)
|
||||
*/
|
||||
public static AuctionClaim createItemWonClaim(UUID playerUUID, String playerName, String listingId, ItemStack item) {
|
||||
AuctionClaim claim = new AuctionClaim();
|
||||
claim.playerUUID = playerUUID;
|
||||
@@ -46,7 +49,9 @@ public class AuctionClaim implements IAuctionClaim {
|
||||
return claim;
|
||||
}
|
||||
|
||||
/** Create claim for returned item (seller's expired/cancelled listing) */
|
||||
/**
|
||||
* Create claim for returned item (seller's expired/cancelled listing)
|
||||
*/
|
||||
public static AuctionClaim createItemReturnedClaim(UUID playerUUID, String playerName, String listingId, ItemStack item) {
|
||||
AuctionClaim claim = new AuctionClaim();
|
||||
claim.playerUUID = playerUUID;
|
||||
@@ -59,7 +64,9 @@ public class AuctionClaim implements IAuctionClaim {
|
||||
return claim;
|
||||
}
|
||||
|
||||
/** Create claim for seller's proceeds (stores item name for tooltip, not full item) */
|
||||
/**
|
||||
* Create claim for seller's proceeds (stores item name for tooltip, not full item)
|
||||
*/
|
||||
public static AuctionClaim createCurrencyClaim(UUID playerUUID, String playerName, String listingId, long currency, String itemName, String buyerName) {
|
||||
AuctionClaim claim = new AuctionClaim();
|
||||
claim.playerUUID = playerUUID;
|
||||
@@ -74,7 +81,9 @@ public class AuctionClaim implements IAuctionClaim {
|
||||
return claim;
|
||||
}
|
||||
|
||||
/** Create claim for outbid refund (stores item for display and rebid option) */
|
||||
/**
|
||||
* Create claim for outbid refund (stores item for display and rebid option)
|
||||
*/
|
||||
public static AuctionClaim createRefundClaim(UUID playerUUID, String playerName, String listingId, long currency, String itemName, String outbidderName, ItemStack item) {
|
||||
AuctionClaim claim = new AuctionClaim();
|
||||
claim.playerUUID = playerUUID;
|
||||
@@ -140,7 +149,7 @@ public class AuctionClaim implements IAuctionClaim {
|
||||
|
||||
@Override
|
||||
public boolean isCurrencyClaim() {
|
||||
return type == EnumClaimType.CURRENCY;
|
||||
return type.isCurrency();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -201,9 +210,7 @@ public class AuctionClaim implements IAuctionClaim {
|
||||
compound.setInteger("Type", type.ordinal());
|
||||
|
||||
if (item != null) {
|
||||
NBTTagCompound itemTag = new NBTTagCompound();
|
||||
item.writeToNBT(itemTag);
|
||||
compound.setTag("Item", itemTag);
|
||||
compound.setTag("Item", NoppesUtilServer.writeItem(item, new NBTTagCompound()));
|
||||
}
|
||||
|
||||
compound.setString("ItemName", itemName != null ? itemName : "");
|
||||
@@ -227,7 +234,7 @@ public class AuctionClaim implements IAuctionClaim {
|
||||
type = EnumClaimType.fromOrdinal(compound.getInteger("Type"));
|
||||
|
||||
if (compound.hasKey("Item")) {
|
||||
item = ItemStack.loadItemStackFromNBT(compound.getCompoundTag("Item"));
|
||||
item = NoppesUtilServer.readItem(compound.getCompoundTag("Item"));
|
||||
} else {
|
||||
item = null;
|
||||
}
|
||||
|
||||
@@ -4,16 +4,12 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import noppes.npcs.constants.EnumAuctionSort;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Filter for auction listings.
|
||||
* Supports search by item name or seller name and sorting options.
|
||||
*/
|
||||
public class AuctionFilter {
|
||||
private static final Pattern COLOR_CODE_PATTERN = Pattern.compile("§[0-9a-fk-or]", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
public String searchText;
|
||||
private String searchText;
|
||||
public EnumAuctionSort sortBy;
|
||||
|
||||
// Cached normalized search for efficiency
|
||||
@@ -29,15 +25,18 @@ public class AuctionFilter {
|
||||
return searchText != null && !searchText.trim().isEmpty();
|
||||
}
|
||||
|
||||
/** Normalize string for search (strip colors, lowercase, trim) */
|
||||
/**
|
||||
* Normalize string for search (strip colors, lowercase, trim)
|
||||
*/
|
||||
public static String normalizeForSearch(String input) {
|
||||
if (input == null || input.isEmpty()) return "";
|
||||
String stripped = COLOR_CODE_PATTERN.matcher(input).replaceAll("");
|
||||
stripped = EnumChatFormatting.getTextWithoutFormattingCodes(stripped);
|
||||
return stripped.toLowerCase().trim();
|
||||
String stripped = EnumChatFormatting.getTextWithoutFormattingCodes(input);
|
||||
return stripped != null ? stripped.toLowerCase().trim() : input.toLowerCase().trim();
|
||||
}
|
||||
|
||||
/** Check if item name or seller name matches search text */
|
||||
/**
|
||||
* Check if item name or seller name matches search text
|
||||
*/
|
||||
public boolean matchesSearch(String itemName, String sellerName) {
|
||||
if (!hasSearchText()) return true;
|
||||
String normalizedItem = normalizeForSearch(itemName);
|
||||
@@ -46,12 +45,16 @@ public class AuctionFilter {
|
||||
return normalizedItem.contains(normalizedSearch) || normalizedSeller.contains(normalizedSearch);
|
||||
}
|
||||
|
||||
/** Legacy method - only checks item name */
|
||||
/**
|
||||
* Legacy method - only checks item name
|
||||
*/
|
||||
public boolean matchesSearch(String itemName) {
|
||||
return matchesSearch(itemName, "");
|
||||
}
|
||||
|
||||
/** Advanced search - all words must be present in item name OR seller name */
|
||||
/**
|
||||
* Advanced search - all words must be present in item name OR seller name
|
||||
*/
|
||||
public boolean matchesSearchAdvanced(String itemName, String sellerName) {
|
||||
if (!hasSearchText()) return true;
|
||||
String normalizedItem = normalizeForSearch(itemName);
|
||||
@@ -68,7 +71,9 @@ public class AuctionFilter {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Legacy method - only checks item name */
|
||||
/**
|
||||
* Legacy method - only checks item name
|
||||
*/
|
||||
public boolean matchesSearchAdvanced(String itemName) {
|
||||
return matchesSearchAdvanced(itemName, "");
|
||||
}
|
||||
@@ -106,13 +111,20 @@ public class AuctionFilter {
|
||||
}
|
||||
|
||||
// Getters and setters
|
||||
public String getSearchText() { return searchText; }
|
||||
public String getSearchText() {
|
||||
return searchText;
|
||||
}
|
||||
|
||||
public void setSearchText(String searchText) {
|
||||
this.searchText = searchText;
|
||||
this.normalizedSearch = normalizeForSearch(searchText);
|
||||
}
|
||||
|
||||
public EnumAuctionSort getSortBy() { return sortBy; }
|
||||
public void setSortBy(EnumAuctionSort sortBy) { this.sortBy = sortBy; }
|
||||
public EnumAuctionSort getSortBy() {
|
||||
return sortBy;
|
||||
}
|
||||
|
||||
public void setSortBy(EnumAuctionSort sortBy) {
|
||||
this.sortBy = sortBy;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.api.handler.data.IAuctionListing;
|
||||
import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.config.ConfigMarket;
|
||||
@@ -24,6 +25,7 @@ public class AuctionListing implements IAuctionListing {
|
||||
public long createdTime;
|
||||
public long endTime;
|
||||
public EnumAuctionStatus status;
|
||||
public boolean isGlobalListing;
|
||||
|
||||
public AuctionListing() {
|
||||
this.id = UUID.randomUUID().toString();
|
||||
@@ -31,6 +33,7 @@ public class AuctionListing implements IAuctionListing {
|
||||
this.bidCount = 0;
|
||||
this.currentBid = 0;
|
||||
this.createdTime = System.currentTimeMillis();
|
||||
this.isGlobalListing = false;
|
||||
}
|
||||
|
||||
public AuctionListing(UUID sellerUUID, String sellerName, ItemStack item, long startingPrice, long buyoutPrice, long durationMs) {
|
||||
@@ -212,9 +215,7 @@ public class AuctionListing implements IAuctionListing {
|
||||
compound.setString("SellerName", sellerName != null ? sellerName : "");
|
||||
|
||||
if (item != null) {
|
||||
NBTTagCompound itemTag = new NBTTagCompound();
|
||||
item.writeToNBT(itemTag);
|
||||
compound.setTag("Item", itemTag);
|
||||
compound.setTag("Item", NoppesUtilServer.writeItem(item, new NBTTagCompound()));
|
||||
}
|
||||
|
||||
compound.setLong("StartingPrice", startingPrice);
|
||||
@@ -228,6 +229,7 @@ public class AuctionListing implements IAuctionListing {
|
||||
compound.setLong("CreatedTime", createdTime);
|
||||
compound.setLong("EndTime", endTime);
|
||||
compound.setInteger("Status", status.ordinal());
|
||||
compound.setBoolean("IsGlobalListing", isGlobalListing);
|
||||
|
||||
return compound;
|
||||
}
|
||||
@@ -240,7 +242,7 @@ public class AuctionListing implements IAuctionListing {
|
||||
sellerName = compound.getString("SellerName");
|
||||
|
||||
if (compound.hasKey("Item")) {
|
||||
item = ItemStack.loadItemStackFromNBT(compound.getCompoundTag("Item"));
|
||||
item = NoppesUtilServer.readItem(compound.getCompoundTag("Item"));
|
||||
}
|
||||
|
||||
startingPrice = compound.getLong("StartingPrice");
|
||||
@@ -255,6 +257,7 @@ public class AuctionListing implements IAuctionListing {
|
||||
createdTime = compound.getLong("CreatedTime");
|
||||
endTime = compound.getLong("EndTime");
|
||||
status = EnumAuctionStatus.fromOrdinal(compound.getInteger("Status"));
|
||||
isGlobalListing = compound.getBoolean("IsGlobalListing");
|
||||
}
|
||||
|
||||
public static AuctionListing fromNBT(NBTTagCompound compound) {
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.constants.EnumNotificationType;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class AuctionNotification {
|
||||
public String id;
|
||||
public UUID playerUUID;
|
||||
public EnumNotificationType type;
|
||||
public String listingId;
|
||||
public String message;
|
||||
public long timestamp;
|
||||
public boolean sent;
|
||||
|
||||
public AuctionNotification() {
|
||||
this.id = UUID.randomUUID().toString();
|
||||
this.timestamp = System.currentTimeMillis();
|
||||
this.sent = false;
|
||||
}
|
||||
|
||||
public AuctionNotification(UUID playerUUID, EnumNotificationType type, String listingId, String message) {
|
||||
this();
|
||||
this.playerUUID = playerUUID;
|
||||
this.type = type;
|
||||
this.listingId = listingId;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public boolean isForPlayer(UUID uuid) {
|
||||
return playerUUID != null && playerUUID.equals(uuid);
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
compound.setString("ID", id);
|
||||
compound.setString("PlayerUUID", playerUUID != null ? playerUUID.toString() : "");
|
||||
compound.setInteger("Type", type.ordinal());
|
||||
compound.setString("ListingID", listingId != null ? listingId : "");
|
||||
compound.setString("Message", message != null ? message : "");
|
||||
compound.setLong("Timestamp", timestamp);
|
||||
compound.setBoolean("Sent", sent);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
id = compound.getString("ID");
|
||||
|
||||
String playerUUIDStr = compound.getString("PlayerUUID");
|
||||
playerUUID = playerUUIDStr.isEmpty() ? null : UUID.fromString(playerUUIDStr);
|
||||
|
||||
type = EnumNotificationType.fromOrdinal(compound.getInteger("Type"));
|
||||
listingId = compound.getString("ListingID");
|
||||
message = compound.getString("Message");
|
||||
timestamp = compound.getLong("Timestamp");
|
||||
sent = compound.getBoolean("Sent");
|
||||
}
|
||||
|
||||
public static AuctionNotification fromNBT(NBTTagCompound compound) {
|
||||
AuctionNotification notification = new AuctionNotification();
|
||||
notification.readFromNBT(compound);
|
||||
return notification;
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ public class BuiltInAnimation extends Animation {
|
||||
|
||||
/**
|
||||
* Built-in animations cannot be saved.
|
||||
*
|
||||
* @return this animation unchanged
|
||||
*/
|
||||
@Override
|
||||
@@ -33,6 +34,7 @@ public class BuiltInAnimation extends Animation {
|
||||
|
||||
/**
|
||||
* Built-in animations have no valid ID.
|
||||
*
|
||||
* @return always -1
|
||||
*/
|
||||
@Override
|
||||
@@ -50,6 +52,7 @@ public class BuiltInAnimation extends Animation {
|
||||
|
||||
/**
|
||||
* Check if this is a built-in animation.
|
||||
*
|
||||
* @return always true for BuiltInAnimation
|
||||
*/
|
||||
public boolean isBuiltIn() {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import kamkeel.npcs.network.packets.request.script.ChainedAbilityScriptPacket;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.constants.ScriptContext;
|
||||
import noppes.npcs.janino.EventJaninoScript;
|
||||
|
||||
/**
|
||||
* Script handler for chained ability scripts.
|
||||
* Manages a single script container for chained ability hooks.
|
||||
*/
|
||||
public class ChainedAbilityScript extends SingleScriptHandler implements IScriptHandlerPacket {
|
||||
|
||||
/**
|
||||
* The chained ability ID (UUID) for packet communication. Empty if not bound.
|
||||
*/
|
||||
private String chainId = "";
|
||||
|
||||
/**
|
||||
* Create an unbound ChainedAbilityScript (for server-side use).
|
||||
*/
|
||||
public ChainedAbilityScript() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a ChainedAbilityScript bound to a specific chained ability (for GUI use).
|
||||
*
|
||||
* @param chainId The UUID of the chained ability
|
||||
*/
|
||||
public ChainedAbilityScript(String chainId) {
|
||||
this.chainId = chainId != null ? chainId : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScriptUnit createJaninoScriptUnit() {
|
||||
return new EventJaninoScript(ScriptContext.CHAINED_ABILITY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScriptContext getContext() {
|
||||
return ScriptContext.CHAINED_ABILITY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String noticeString() {
|
||||
return !chainId.isEmpty() ? "ChainedAbility[" + chainId + "]" : "ChainedAbility";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestData() {
|
||||
if (!chainId.isEmpty())
|
||||
ChainedAbilityScriptPacket.Get(chainId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendSavePacket(int index, int totalCount, NBTTagCompound nbt) {
|
||||
if (!chainId.isEmpty())
|
||||
ChainedAbilityScriptPacket.Save(chainId, index, totalCount, nbt);
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,11 @@ import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.handler.data.ICustomEffect;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.controllers.CustomEffectController;
|
||||
import noppes.npcs.controllers.TagController;
|
||||
import noppes.npcs.scripted.event.player.PlayerEvent;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class CustomEffect implements ICustomEffect {
|
||||
@@ -26,17 +29,18 @@ public class CustomEffect implements ICustomEffect {
|
||||
public String icon = "";
|
||||
public int iconX = 0, iconY = 0;
|
||||
|
||||
/**
|
||||
* Experimental script stuff.
|
||||
*/
|
||||
public Consumer<PlayerEvent.EffectEvent.Added> onAddedConsumer;
|
||||
public Consumer<PlayerEvent.EffectEvent.Ticked> onTickConsumer;
|
||||
public Consumer<PlayerEvent.EffectEvent.Removed> onRemovedConsumer;
|
||||
public String menuName = "§aNEW EFFECT";
|
||||
public int width = 16, height = 16;
|
||||
|
||||
// Animation
|
||||
public boolean animated = false;
|
||||
public int frameCount = 1;
|
||||
public int frametime = 2;
|
||||
|
||||
public int index = 0;
|
||||
|
||||
public HashSet<UUID> tagUUIDs = new HashSet<>();
|
||||
|
||||
public CustomEffect() {
|
||||
}
|
||||
|
||||
@@ -143,6 +147,36 @@ public class CustomEffect implements ICustomEffect {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnimated() {
|
||||
return animated;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAnimated(boolean animated) {
|
||||
this.animated = animated;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFrameCount() {
|
||||
return frameCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFrameCount(int frameCount) {
|
||||
this.frameCount = Math.max(1, frameCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFrameTime() {
|
||||
return frametime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFrameTime(int frametime) {
|
||||
this.frametime = Math.max(1, frametime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLossOnDeath() {
|
||||
return lossOnDeath;
|
||||
@@ -169,26 +203,10 @@ public class CustomEffect implements ICustomEffect {
|
||||
}
|
||||
|
||||
|
||||
public void onAdded(Consumer<PlayerEvent.EffectEvent.Added> function) {
|
||||
onAddedConsumer = function;
|
||||
}
|
||||
|
||||
public void onTick(Consumer<PlayerEvent.EffectEvent.Ticked> function) {
|
||||
onTickConsumer = function;
|
||||
}
|
||||
|
||||
public void onRemoved(Consumer<PlayerEvent.EffectEvent.Removed> function) {
|
||||
onRemovedConsumer = function;
|
||||
}
|
||||
|
||||
public void onAdded(EntityPlayer player, PlayerEffect playerEffect) {
|
||||
IPlayer iPlayer = NoppesUtilServer.getIPlayer(player);
|
||||
if (playerEffect.index == 0) {
|
||||
PlayerEvent.EffectEvent.Added event = new PlayerEvent.EffectEvent.Added(iPlayer, playerEffect);
|
||||
|
||||
if (onAddedConsumer != null)
|
||||
onAddedConsumer.accept(event);
|
||||
|
||||
EffectScript script = getScriptHandler();
|
||||
if (script == null) {
|
||||
return;
|
||||
@@ -204,11 +222,6 @@ public class CustomEffect implements ICustomEffect {
|
||||
IPlayer iPlayer = NoppesUtilServer.getIPlayer(player);
|
||||
if (playerEffect.index == 0) {
|
||||
PlayerEvent.EffectEvent.Ticked event = new PlayerEvent.EffectEvent.Ticked(iPlayer, playerEffect);
|
||||
|
||||
if (onTickConsumer != null) {
|
||||
onTickConsumer.accept(event);
|
||||
}
|
||||
|
||||
EffectScript script = getScriptHandler();
|
||||
if (script == null) {
|
||||
return;
|
||||
@@ -225,11 +238,6 @@ public class CustomEffect implements ICustomEffect {
|
||||
|
||||
if (playerEffect.index == 0) {
|
||||
PlayerEvent.EffectEvent.Removed event = new PlayerEvent.EffectEvent.Removed(iPlayer, playerEffect, type);
|
||||
|
||||
if (onRemovedConsumer != null) {
|
||||
onRemovedConsumer.accept(event);
|
||||
}
|
||||
|
||||
EffectScript script = getScriptHandler();
|
||||
if (script == null) {
|
||||
return;
|
||||
@@ -254,6 +262,11 @@ public class CustomEffect implements ICustomEffect {
|
||||
compound.setInteger("iconHeight", height);
|
||||
compound.setString("icon", icon);
|
||||
compound.setBoolean("lossOnDeath", lossOnDeath);
|
||||
compound.setBoolean("iconAnimated", animated);
|
||||
compound.setInteger("iconFrameCount", frameCount);
|
||||
compound.setInteger("iconFrameTime", frametime);
|
||||
|
||||
TagController.writeTagUUIDs(compound, "TagUUIDs", tagUUIDs);
|
||||
|
||||
if (saveScripts) {
|
||||
NBTTagCompound scriptData = new NBTTagCompound();
|
||||
@@ -296,6 +309,15 @@ public class CustomEffect implements ICustomEffect {
|
||||
icon = compound.getString("icon");
|
||||
lossOnDeath = compound.getBoolean("lossOnDeath");
|
||||
|
||||
if (compound.hasKey("iconAnimated"))
|
||||
animated = compound.getBoolean("iconAnimated");
|
||||
if (compound.hasKey("iconFrameCount"))
|
||||
frameCount = Math.max(1, compound.getInteger("iconFrameCount"));
|
||||
if (compound.hasKey("iconFrameTime"))
|
||||
frametime = Math.max(1, compound.getInteger("iconFrameTime"));
|
||||
|
||||
tagUUIDs = TagController.readTagUUIDs(compound, "TagUUIDs");
|
||||
|
||||
if (compound.hasKey("ScriptData", Constants.NBT.TAG_COMPOUND)) {
|
||||
EffectScript handler = new EffectScript();
|
||||
handler.readFromNBT(compound.getCompoundTag("ScriptData"));
|
||||
|
||||
@@ -20,6 +20,7 @@ import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.constants.ScriptContext;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.ScriptHookController;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.janino.EventJaninoScript;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
@@ -28,15 +29,10 @@ import noppes.npcs.scripted.constants.EntityType;
|
||||
import noppes.npcs.scripted.constants.JobType;
|
||||
import noppes.npcs.scripted.constants.RoleType;
|
||||
import noppes.npcs.scripted.entity.ScriptNpc;
|
||||
import noppes.npcs.api.handler.IHookDefinition;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.*;
|
||||
|
||||
public class DataScript implements IScriptHandlerPacket {
|
||||
public List<IScriptUnit> eventScripts = new ArrayList<>();
|
||||
@@ -49,6 +45,7 @@ public class DataScript implements IScriptHandlerPacket {
|
||||
public String scriptLanguage = "ECMAScript";
|
||||
private EntityNPCInterface npc;
|
||||
public boolean enabled = false;
|
||||
private final Map<ScriptEngine, Long> engineGlobalsVersion = new IdentityHashMap<>();
|
||||
|
||||
public ICustomNpc dummyNpc;
|
||||
public IWorld dummyWorld;
|
||||
@@ -56,6 +53,17 @@ public class DataScript implements IScriptHandlerPacket {
|
||||
public boolean aiNeedsUpdate = false;
|
||||
public boolean hasInited = false;
|
||||
|
||||
// Editor/runtime globals descriptor used for a single source of truth.
|
||||
private static final class GlobalDefinition {
|
||||
private final String typeName;
|
||||
private final Object value;
|
||||
|
||||
private GlobalDefinition(String typeName, Object value) {
|
||||
this.typeName = typeName;
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public DataScript(EntityNPCInterface npc) {
|
||||
for (int i = 0; i < 15; i++) {
|
||||
this.setNPCScript(i, new ScriptContainer(this));
|
||||
@@ -180,21 +188,12 @@ public class DataScript implements IScriptHandlerPacket {
|
||||
LogWriter.postScriptLog(npc.field_110179_h, type, String.format("[%s] NPC %s (%s, %s, %s) | Objects: %s", ((String) type.function).toUpperCase(), npc.display.name, (int) npc.posX, (int) npc.posY, (int) npc.posZ, Arrays.toString(obs)));
|
||||
}
|
||||
}
|
||||
return callScript(script, event);
|
||||
return callScript(script, type.function, event);
|
||||
}
|
||||
|
||||
private boolean callScript(ScriptContainer script, Event event) {
|
||||
private boolean callScript(ScriptContainer script, String hookName, Event event) {
|
||||
ScriptEngine engine = script.engine;
|
||||
engine.put("npc", dummyNpc);
|
||||
engine.put("world", dummyWorld);
|
||||
engine.put("event", event);
|
||||
engine.put("API", NpcAPI.Instance());
|
||||
engine.put("EntityType", entities);
|
||||
engine.put("RoleType", roles);
|
||||
engine.put("JobType", jobs);
|
||||
for (Map.Entry<String, Object> engineObjects : NpcAPI.engineObjects.entrySet()) {
|
||||
engine.put(engineObjects.getKey(), engineObjects.getValue());
|
||||
}
|
||||
applyGlobalsToEngine(engine, hookName, event);
|
||||
script.run(engine);
|
||||
|
||||
if (clientNeedsUpdate) {
|
||||
@@ -254,6 +253,66 @@ public class DataScript implements IScriptHandlerPacket {
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, String> getEditorGlobals(String hookName) {
|
||||
Map<String, GlobalDefinition> definitions = getGlobalDefinitions(hookName, null);
|
||||
Map<String, String> globals = new LinkedHashMap<>();
|
||||
for (Map.Entry<String, GlobalDefinition> entry : definitions.entrySet()) {
|
||||
String typeName = entry.getValue().typeName;
|
||||
if (typeName != null && !typeName.isEmpty()) {
|
||||
globals.put(entry.getKey(), typeName);
|
||||
}
|
||||
}
|
||||
return globals;
|
||||
}
|
||||
|
||||
// Apply runtime globals plus engine-only bindings.
|
||||
private void applyGlobalsToEngine(ScriptEngine engine, String hookName, Event event) {
|
||||
Map<String, GlobalDefinition> definitions = getGlobalDefinitions(hookName, event);
|
||||
for (Map.Entry<String, GlobalDefinition> entry : definitions.entrySet()) {
|
||||
engine.put(entry.getKey(), entry.getValue().value);
|
||||
}
|
||||
|
||||
long currentGlobalsVersion = NpcAPI.engineObjectsVersion;
|
||||
Long lastVersion = engineGlobalsVersion.get(engine);
|
||||
if (lastVersion == null || lastVersion != currentGlobalsVersion) {
|
||||
engine.put("API", NpcAPI.Instance());
|
||||
for (Map.Entry<String, Object> engineObjects : NpcAPI.engineObjects.entrySet()) {
|
||||
engine.put(engineObjects.getKey(), engineObjects.getValue());
|
||||
}
|
||||
engineGlobalsVersion.put(engine, currentGlobalsVersion);
|
||||
}
|
||||
}
|
||||
|
||||
// Build shared globals (editor types + runtime values).
|
||||
private Map<String, GlobalDefinition> getGlobalDefinitions(String hookName, Event event) {
|
||||
Map<String, GlobalDefinition> globals = new LinkedHashMap<>();
|
||||
globals.put("npc", new GlobalDefinition("ICustomNpc", dummyNpc));
|
||||
globals.put("world", new GlobalDefinition("IWorld", dummyWorld));
|
||||
globals.put("event", new GlobalDefinition(resolveEditorEventTypeName(hookName), event));
|
||||
globals.put("EntityType", new GlobalDefinition("noppes.npcs.scripted.constants.EntityType", entities));
|
||||
globals.put("RoleType", new GlobalDefinition("noppes.npcs.scripted.constants.RoleType", roles));
|
||||
globals.put("JobType", new GlobalDefinition("noppes.npcs.scripted.constants.JobType", jobs));
|
||||
|
||||
return globals;
|
||||
}
|
||||
|
||||
// Resolve editor-only event type from hook name with a single fallback.
|
||||
private String resolveEditorEventTypeName(String hookName) {
|
||||
final String fallback = "INpcEvent";
|
||||
if (hookName == null || hookName.isEmpty())
|
||||
return fallback;
|
||||
|
||||
IHookDefinition definition = ScriptHookController.Instance.getHookDefinition(getContext().hookContext, hookName);
|
||||
if (definition == null)
|
||||
return fallback;
|
||||
|
||||
String typeName = definition.getUsableTypeName();
|
||||
if (typeName == null || typeName.isEmpty())
|
||||
return fallback;
|
||||
|
||||
return typeName;
|
||||
}
|
||||
|
||||
public boolean isClient() {
|
||||
return this.npc.isRemote();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package noppes.npcs.controllers.data;
|
||||
import kamkeel.npcs.network.packets.request.script.EffectScriptPacket;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.constants.ScriptContext;
|
||||
import noppes.npcs.janino.EventJaninoScript;
|
||||
|
||||
/**
|
||||
* Script handler for CustomEffect scripts.
|
||||
@@ -35,6 +36,11 @@ public class EffectScript extends SingleScriptHandler implements IScriptHandlerP
|
||||
return ScriptContext.EFFECT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScriptUnit createJaninoScriptUnit() {
|
||||
return new EventJaninoScript(ScriptContext.EFFECT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String noticeString() {
|
||||
return effectId >= 0 ? "CustomEffect[" + effectId + "]" : "CustomEffect";
|
||||
|
||||
@@ -18,12 +18,14 @@ import noppes.npcs.constants.ScriptContext;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.ScriptHookController;
|
||||
import noppes.npcs.janino.EventJaninoScript;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class ForgeDataScript extends MultiScriptHandler {
|
||||
@@ -31,6 +33,7 @@ public class ForgeDataScript extends MultiScriptHandler {
|
||||
private static List<String> cachedHooks;
|
||||
|
||||
private long lastForgeUpdate = -1L;
|
||||
private final HashSet<String> globalUnknownEvents = new HashSet<>();
|
||||
|
||||
public ForgeDataScript() {
|
||||
}
|
||||
@@ -58,6 +61,7 @@ public class ForgeDataScript extends MultiScriptHandler {
|
||||
protected void reInitScripts() {
|
||||
lastInited = ScriptController.Instance.lastLoaded;
|
||||
lastForgeUpdate = ScriptController.Instance.lastForgeUpdate;
|
||||
globalUnknownEvents.clear();
|
||||
|
||||
for (IScriptUnit script : this.scripts) {
|
||||
if (script instanceof ScriptContainer)
|
||||
@@ -78,10 +82,25 @@ public class ForgeDataScript extends MultiScriptHandler {
|
||||
}
|
||||
}
|
||||
|
||||
// Skip events that no script tab handles
|
||||
if (globalUnknownEvents.contains(type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean anyHandled = false;
|
||||
for (IScriptUnit script : this.scripts) {
|
||||
if (script == null || script.hasErrored() || !script.hasCode())
|
||||
continue;
|
||||
boolean wasUnknown = script.isUnknownFunction(type);
|
||||
script.run(type, event);
|
||||
if (!wasUnknown || !script.isUnknownFunction(type)) {
|
||||
anyHandled = true;
|
||||
}
|
||||
}
|
||||
|
||||
// If no script tab handled this event type, cache it globally
|
||||
if (!anyHandled) {
|
||||
globalUnknownEvents.add(type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,6 +180,11 @@ public class ForgeDataScript extends MultiScriptHandler {
|
||||
ForgeScriptPacket.Save(index, totalCount, nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScriptUnit createJaninoScriptUnit() {
|
||||
return new EventJaninoScript(ScriptContext.FORGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClient() {
|
||||
return false;
|
||||
|
||||
@@ -8,6 +8,7 @@ import noppes.npcs.api.entity.ICustomNpc;
|
||||
import noppes.npcs.constants.ScriptContext;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.janino.EventJaninoScript;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.util.ScriptToStringHelper;
|
||||
|
||||
@@ -47,6 +48,11 @@ public class GlobalNPCDataScript extends MultiScriptHandler {
|
||||
lastNpcUpdate = ScriptController.Instance.lastGlobalNpcUpdate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScriptUnit createJaninoScriptUnit() {
|
||||
return new EventJaninoScript(ScriptContext.NPC);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestData() {
|
||||
GlobalNPCScriptPacket.Get();
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.api.entity.data.IHitboxData;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
|
||||
public class HitboxData {
|
||||
public class HitboxData implements IHitboxData {
|
||||
|
||||
private float widthScale = 1f;
|
||||
private float heightScale = 1f;
|
||||
|
||||
@@ -53,6 +53,12 @@ public interface IScriptHandlerPacket extends IScriptHandler {
|
||||
return new GuiDataResult(GuiDataKind.LOAD_COMPLETE, -1);
|
||||
}
|
||||
|
||||
// Ignore unrelated packets (e.g. ScriptInfoPacket config data)
|
||||
// that don't contain any expected keys for this handler
|
||||
if (!compound.hasKey("Tab") && !compound.hasKey("ScriptLanguage") && !compound.hasKey("ScriptEnabled")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!compound.hasKey("Tab")) {
|
||||
setLanguage(compound.getString("ScriptLanguage"));
|
||||
setEnabled(compound.getBoolean("ScriptEnabled"));
|
||||
|
||||
@@ -157,6 +157,24 @@ public interface IScriptUnit {
|
||||
*/
|
||||
void setErrored(boolean errored);
|
||||
|
||||
// ==================== INSTANCE SCOPE ====================
|
||||
|
||||
/**
|
||||
* Create an instance-scoped copy of this script unit for isolated execution.
|
||||
* The instance shares compiled code with the template but has isolated state.
|
||||
*
|
||||
* @param instanceHandler the script handler for the new instance
|
||||
* @return a new IScriptUnit with isolated variable state
|
||||
*/
|
||||
IScriptUnit createInstanceScope(IScriptHandler instanceHandler);
|
||||
|
||||
/**
|
||||
* Check if the given function name is known to be absent from this script unit.
|
||||
*/
|
||||
default boolean isUnknownFunction(String type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// ==================== EXECUTION ====================
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,11 @@ public class ItemDisplayData {
|
||||
public Boolean durabilityShow = false;
|
||||
public Integer durabilityColor = -1;
|
||||
|
||||
// Animation
|
||||
public Boolean animated = false;
|
||||
public Integer frameCount = 1;
|
||||
public Integer frametime = 2;
|
||||
|
||||
public NBTTagCompound writeToNBT() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
this.writeToNBT(compound);
|
||||
@@ -42,6 +47,10 @@ public class ItemDisplayData {
|
||||
this.setFloat(compound, "TranslateY", this.translateY);
|
||||
this.setFloat(compound, "TranslateZ", this.translateZ);
|
||||
|
||||
this.setBoolean(compound, "Animated", this.animated);
|
||||
this.setInteger(compound, "FrameCount", this.frameCount);
|
||||
this.setInteger(compound, "FrameTime", this.frametime);
|
||||
|
||||
return compound;
|
||||
}
|
||||
|
||||
@@ -97,6 +106,16 @@ public class ItemDisplayData {
|
||||
if (compound.hasKey("TranslateZ")) {
|
||||
this.translateZ = compound.getFloat("TranslateZ");
|
||||
}
|
||||
|
||||
if (compound.hasKey("Animated")) {
|
||||
this.animated = compound.getBoolean("Animated");
|
||||
}
|
||||
if (compound.hasKey("FrameCount")) {
|
||||
this.frameCount = Math.max(1, compound.getInteger("FrameCount"));
|
||||
}
|
||||
if (compound.hasKey("FrameTime")) {
|
||||
this.frametime = Math.max(1, compound.getInteger("FrameTime"));
|
||||
}
|
||||
}
|
||||
|
||||
private void setBoolean(NBTTagCompound compound, String key, Boolean value) {
|
||||
|
||||
@@ -56,11 +56,17 @@ public class JaninoScriptHandler<S extends JaninoScript<?>> extends ScriptHandle
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
// JaninoScriptable's helper generics assume JaninoScript<T>, but most of our scripts are JaninoScript<?>.
|
||||
// Keep it simple and safe: treat it as raw.
|
||||
script = (S) JaninoScript.readFromNBT(compound, (JaninoScript) script, (Supplier) factory);
|
||||
NBTTagCompound tag = compound.getCompoundTag("Script");
|
||||
enabled = tag.getBoolean("enabled");
|
||||
script = (S) JaninoScript.readFromNBT(tag, (JaninoScript) script, (Supplier) factory);
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound compound) {
|
||||
JaninoScript.writeToNBT(compound, (JaninoScript) script);
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setBoolean("enabled", enabled);
|
||||
JaninoScript.writeToNBT(tag, (JaninoScript) script);
|
||||
compound.setTag("Script", tag);
|
||||
|
||||
}
|
||||
|
||||
// -------------------- IScriptHandler --------------------
|
||||
|
||||
@@ -8,9 +8,13 @@ import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.api.handler.data.ILinkedItem;
|
||||
import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.controllers.LinkedItemController;
|
||||
import noppes.npcs.controllers.TagController;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.item.ScriptLinkedItem;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
public class LinkedItem implements ILinkedItem {
|
||||
public static final String LINKED_VERSION_VERSION_TAG = "LinkedVersion";
|
||||
public static final String LINKED_DATA_NBT_TAG = "LinkedData";
|
||||
@@ -33,6 +37,8 @@ public class LinkedItem implements ILinkedItem {
|
||||
public int armorType = -2; //-2: Fits in no armor slot, -1: Fits in all slots, 0 - 3: Fits in Head -> Boots slot respectively
|
||||
public int enchantability;
|
||||
|
||||
public HashSet<UUID> tagUUIDs = new HashSet<>();
|
||||
|
||||
public LinkedItem() {
|
||||
this("New");
|
||||
}
|
||||
@@ -67,6 +73,8 @@ public class LinkedItem implements ILinkedItem {
|
||||
compound.setInteger("MaxItemUseDuration", this.maxItemUseDuration);
|
||||
compound.setInteger("ItemUseAction", this.itemUseAction);
|
||||
|
||||
TagController.writeTagUUIDs(compound, "TagUUIDs", tagUUIDs);
|
||||
|
||||
if (saveScripts) {
|
||||
NBTTagCompound scriptData = new NBTTagCompound();
|
||||
LinkedItemScript handler = getScriptHandler();
|
||||
@@ -97,6 +105,8 @@ public class LinkedItem implements ILinkedItem {
|
||||
this.maxItemUseDuration = compound.getInteger("MaxItemUseDuration");
|
||||
this.itemUseAction = compound.getInteger("ItemUseAction");
|
||||
|
||||
tagUUIDs = TagController.readTagUUIDs(compound, "TagUUIDs");
|
||||
|
||||
if (compound.hasKey("ScriptData", Constants.NBT.TAG_COMPOUND)) {
|
||||
LinkedItemScript handler = new LinkedItemScript();
|
||||
handler.readFromNBT(compound.getCompoundTag("ScriptData"));
|
||||
|
||||
@@ -3,6 +3,7 @@ package noppes.npcs.controllers.data;
|
||||
import kamkeel.npcs.network.packets.request.script.item.LinkedItemScriptPacket;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.constants.ScriptContext;
|
||||
import noppes.npcs.janino.EventJaninoScript;
|
||||
|
||||
/**
|
||||
* Script handler for LinkedItem scripts.
|
||||
@@ -35,6 +36,11 @@ public class LinkedItemScript extends SingleScriptHandler implements IScriptHand
|
||||
return ScriptContext.LINKED_ITEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScriptUnit createJaninoScriptUnit() {
|
||||
return new EventJaninoScript(ScriptContext.LINKED_ITEM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String noticeString() {
|
||||
return "LinkedItem";
|
||||
|
||||
@@ -76,4 +76,15 @@ public class MagicData implements IMagicData {
|
||||
MagicEntry entry = magics.get(id);
|
||||
return entry == null ? 0 : entry.split;
|
||||
}
|
||||
|
||||
public MagicData copy() {
|
||||
MagicData copy = new MagicData();
|
||||
for (java.util.Map.Entry<Integer, MagicEntry> e : magics.entrySet()) {
|
||||
MagicEntry entryCopy = new MagicEntry();
|
||||
entryCopy.damage = e.getValue().damage;
|
||||
entryCopy.split = e.getValue().split;
|
||||
copy.magics.put(e.getKey(), entryCopy);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,90 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.network.packets.data.ability.AbilityHotbarSyncPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class PlayerAbilityHotbarData {
|
||||
public AbilityHotbarData[] slots = new AbilityHotbarData[AbilityHotbarData.TOTAL_SLOTS];
|
||||
|
||||
public PlayerAbilityHotbarData() {
|
||||
for (int i = 0; i < slots.length; i++) {
|
||||
slots[i] = new AbilityHotbarData(i);
|
||||
}
|
||||
}
|
||||
|
||||
public AbilityHotbarData getSlot(int index) {
|
||||
if (index < 0 || index >= slots.length) return null;
|
||||
return slots[index];
|
||||
}
|
||||
|
||||
public void setSlot(int index, String abilityKey) {
|
||||
if (index < 0 || index >= slots.length) return;
|
||||
slots[index].abilityKey = abilityKey != null ? abilityKey : "";
|
||||
}
|
||||
|
||||
public void clearSlot(int index) {
|
||||
if (index < 0 || index >= slots.length) return;
|
||||
slots[index].reset();
|
||||
}
|
||||
|
||||
public boolean hasAnyAbilities() {
|
||||
for (AbilityHotbarData slot : slots) {
|
||||
if (!slot.isEmpty()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound compound) {
|
||||
for (int i = 0; i < slots.length; i++) {
|
||||
slots[i].writeToNBT(compound);
|
||||
}
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
for (int i = 0; i < slots.length; i++) {
|
||||
NBTTagCompound slotTag = compound.getCompoundTag("AbilityHotbar" + i);
|
||||
slots[i].readFromNBT(slotTag);
|
||||
}
|
||||
validateSlots();
|
||||
}
|
||||
|
||||
public void validateSlots() {
|
||||
if (AbilityController.Instance == null) return;
|
||||
// Only validate on the server - the client trusts server-sent data.
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) return;
|
||||
for (AbilityHotbarData slot : slots) {
|
||||
if (slot.isEmpty()) continue;
|
||||
boolean valid;
|
||||
if (slot.isChainKey()) {
|
||||
valid = AbilityController.Instance.canResolveChainedAbility(slot.getResolveKey());
|
||||
} else {
|
||||
valid = AbilityController.Instance.canResolveAbility(slot.abilityKey);
|
||||
// Also check that resolved ability allows player usage
|
||||
if (valid) {
|
||||
Ability ability = AbilityController.Instance.resolveAbility(slot.abilityKey);
|
||||
if (ability != null && !ability.getAllowedBy().allowsPlayer()) {
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!valid) {
|
||||
slot.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync hotbar data only to the client.
|
||||
* Used after server confirms a client hotbar edit.
|
||||
*/
|
||||
public void syncToClient(EntityPlayer player) {
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
AbilityHotbarSyncPacket.sendToPlayer((EntityPlayerMP) player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,13 +18,13 @@ import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.api.ability.IPlayerAbilityData;
|
||||
import noppes.npcs.api.entity.ICustomNpc;
|
||||
import noppes.npcs.api.handler.IPlayerBankData;
|
||||
import noppes.npcs.api.handler.IPlayerTradeData;
|
||||
import noppes.npcs.api.handler.IPlayerData;
|
||||
import noppes.npcs.api.handler.IPlayerDialogData;
|
||||
import noppes.npcs.api.handler.IPlayerFactionData;
|
||||
import noppes.npcs.api.handler.IPlayerItemGiverData;
|
||||
import noppes.npcs.api.handler.IPlayerMailData;
|
||||
import noppes.npcs.api.handler.IPlayerQuestData;
|
||||
import noppes.npcs.api.handler.IPlayerTradeData;
|
||||
import noppes.npcs.api.handler.IPlayerTransportData;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.constants.EnumRoleType;
|
||||
@@ -47,8 +47,6 @@ import java.io.FileOutputStream;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import static noppes.npcs.util.CustomNPCsThreader.customNPCThread;
|
||||
|
||||
public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
public PlayerDialogData dialogData = new PlayerDialogData(this);
|
||||
public PlayerBankData bankData = new PlayerBankData(this);
|
||||
@@ -67,6 +65,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
public PlayerTradeData tradeData = new PlayerTradeData(this);
|
||||
|
||||
public PlayerAbilityData abilityData = new PlayerAbilityData(this);
|
||||
public PlayerAbilityHotbarData hotbarData = new PlayerAbilityHotbarData();
|
||||
public ActionManager actionManager = new ActionManager();
|
||||
public PlayerDataScript scriptData;
|
||||
|
||||
@@ -95,13 +94,25 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
private boolean specialKeyDown = false;
|
||||
|
||||
public void onLogin() {
|
||||
// Continue playing animation for self when re-logging
|
||||
// Clear any stale transient ability state that leaked via the PlayerData cache.
|
||||
// Must happen before the animation check since it may clear ability animation state.
|
||||
abilityData.resetOnLogin();
|
||||
|
||||
// Handle animation state from previous session
|
||||
AnimationData animationData = this.animationData;
|
||||
if (animationData != null && animationData.isClientAnimating()) {
|
||||
Animation currentAnimation = animationData.currentClientAnimation;
|
||||
NBTTagCompound compound = currentAnimation.writeToNBT();
|
||||
animationData.viewAnimation(currentAnimation, animationData, compound,
|
||||
animationData.isClientAnimating(), currentAnimation.currentFrame, currentAnimation.currentFrameTime);
|
||||
if (abilityData.isPlayingAbilityAnimation()) {
|
||||
// Ability animation was playing when player disconnected.
|
||||
// Ability state is transient (lost on disconnect), so this animation
|
||||
// is orphaned - clear it instead of replaying a stuck animation.
|
||||
abilityData.clearOrphanedAbilityAnimation();
|
||||
} else {
|
||||
// Non-ability animation (e.g. script-driven) - continue playing
|
||||
Animation currentAnimation = animationData.currentClientAnimation;
|
||||
NBTTagCompound compound = currentAnimation.writeToNBT();
|
||||
animationData.viewAnimation(currentAnimation, animationData, compound,
|
||||
animationData.isClientAnimating(), currentAnimation.currentFrame, currentAnimation.currentFrameTime);
|
||||
}
|
||||
}
|
||||
|
||||
CustomEffectController controller = CustomEffectController.getInstance();
|
||||
@@ -110,12 +121,12 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
if (!controller.playerEffects.containsKey(playerID)) {
|
||||
controller.playerEffects.put(playerID, effectData.getEffects());
|
||||
}
|
||||
|
||||
// Sync player ability data to client
|
||||
abilityData.syncToClient();
|
||||
}
|
||||
|
||||
public void onLogout() {
|
||||
// Interrupt executing ability (fires events, rolls cooldown), then clear
|
||||
// all transient state so nothing leaks via the PlayerData cache.
|
||||
abilityData.resetOnDisconnect();
|
||||
this.partyInvites.clear();
|
||||
this.actionManager.clear();
|
||||
}
|
||||
@@ -143,6 +154,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
magicData.readToNBT(data);
|
||||
tradeData.readFromNBT(data);
|
||||
abilityData.readFromNBT(data);
|
||||
hotbarData.readFromNBT(data);
|
||||
|
||||
if (player != null) {
|
||||
playername = player.getCommandSenderName();
|
||||
@@ -187,6 +199,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
magicData.writeToNBT(compound);
|
||||
tradeData.writeToNBT(compound);
|
||||
abilityData.writeToNBT(compound);
|
||||
hotbarData.writeToNBT(compound);
|
||||
|
||||
compound.setString("PlayerName", playername);
|
||||
compound.setString("UUID", uuid);
|
||||
@@ -240,6 +253,8 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
factionData.saveNBTData(compound);
|
||||
mailData.saveNBTData(compound);
|
||||
tradeData.writeToNBT(compound);
|
||||
abilityData.writeToNBT(compound);
|
||||
hotbarData.writeToNBT(compound);
|
||||
compound.setString("PlayerName", playername);
|
||||
compound.setString("UUID", uuid);
|
||||
DBCAddon.instance.writeToNBT(this, compound);
|
||||
@@ -254,6 +269,8 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
factionData.loadNBTData(data);
|
||||
mailData.loadNBTData(data);
|
||||
tradeData.readFromNBT(data);
|
||||
abilityData.readFromNBT(data);
|
||||
hotbarData.readFromNBT(data);
|
||||
if (player != null) {
|
||||
playername = player.getCommandSenderName();
|
||||
uuid = player.getPersistentID().toString();
|
||||
|
||||
@@ -167,6 +167,12 @@ public class PlayerDataScript extends MultiScriptHandler {
|
||||
return ScriptController.Instance.playerScripts.scriptLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLanguage(String lang) {
|
||||
ScriptController.Instance.playerScripts.scriptLanguage = lang;
|
||||
this.scriptLanguage = lang;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String noticeString() {
|
||||
if (this.player == null) {
|
||||
|
||||
@@ -8,7 +8,6 @@ import noppes.npcs.api.handler.data.IAuctionClaim;
|
||||
import noppes.npcs.config.ConfigMarket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
@@ -129,12 +128,13 @@ public class PlayerTradeData implements IPlayerTradeData {
|
||||
|
||||
// Built-in currency
|
||||
long newBalance = this.balance + amount;
|
||||
if (newBalance > ConfigMarket.MaxBalance) {
|
||||
return false;
|
||||
}
|
||||
// Overflow protection
|
||||
if (newBalance < this.balance) {
|
||||
// Overflow protection
|
||||
return false;
|
||||
newBalance = ConfigMarket.MaxBalance;
|
||||
}
|
||||
// Cap at MaxBalance instead of rejecting
|
||||
if (newBalance > ConfigMarket.MaxBalance) {
|
||||
newBalance = ConfigMarket.MaxBalance;
|
||||
}
|
||||
this.balance = newBalance;
|
||||
this.lifetimeEarned += amount;
|
||||
@@ -245,8 +245,14 @@ public class PlayerTradeData implements IPlayerTradeData {
|
||||
* Add a claim to this player's pending claims.
|
||||
* Thread-safe - can be called from any thread.
|
||||
*/
|
||||
public void addClaim(AuctionClaim claim) {
|
||||
public synchronized void addClaim(AuctionClaim claim) {
|
||||
if (claim != null && !claim.claimed) {
|
||||
// Prevent duplicate claim IDs
|
||||
for (AuctionClaim existing : claims) {
|
||||
if (existing.id.equals(claim.id)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
claims.add(claim);
|
||||
}
|
||||
}
|
||||
@@ -276,8 +282,9 @@ public class PlayerTradeData implements IPlayerTradeData {
|
||||
|
||||
/**
|
||||
* Get a specific claim by ID (internal use).
|
||||
* Synchronized to pair with claimAndRemove for thread safety.
|
||||
*/
|
||||
public AuctionClaim getClaimInternal(String claimId) {
|
||||
public synchronized AuctionClaim getClaimInternal(String claimId) {
|
||||
for (AuctionClaim claim : claims) {
|
||||
if (claim.id.equals(claimId) && !claim.claimed) {
|
||||
return claim;
|
||||
@@ -296,8 +303,9 @@ public class PlayerTradeData implements IPlayerTradeData {
|
||||
|
||||
/**
|
||||
* Mark a claim as claimed and remove it.
|
||||
* Synchronized to prevent double-claim from concurrent threads.
|
||||
*/
|
||||
public boolean claimAndRemove(String claimId) {
|
||||
public synchronized boolean claimAndRemove(String claimId) {
|
||||
for (AuctionClaim claim : claims) {
|
||||
if (claim.id.equals(claimId) && !claim.claimed) {
|
||||
claim.claimed = true;
|
||||
@@ -341,18 +349,16 @@ public class PlayerTradeData implements IPlayerTradeData {
|
||||
*/
|
||||
public int processExpiredClaims() {
|
||||
int expirationDays = ConfigMarket.ClaimExpirationDays;
|
||||
int removed = 0;
|
||||
|
||||
Iterator<AuctionClaim> iterator = claims.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
AuctionClaim claim = iterator.next();
|
||||
List<AuctionClaim> expired = new ArrayList<>();
|
||||
for (AuctionClaim claim : claims) {
|
||||
if (!claim.claimed && claim.isExpired(expirationDays)) {
|
||||
claims.remove(claim);
|
||||
removed++;
|
||||
expired.add(claim);
|
||||
}
|
||||
}
|
||||
|
||||
return removed;
|
||||
if (!expired.isEmpty()) {
|
||||
claims.removeAll(expired);
|
||||
}
|
||||
return expired.size();
|
||||
}
|
||||
|
||||
// =========================================
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.data.profile.Profile;
|
||||
import noppes.npcs.client.ProfileClientConfig;
|
||||
import kamkeel.npcs.network.packets.data.QuestCompletionPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
@@ -22,7 +21,6 @@ import noppes.npcs.api.handler.data.IQuestCategory;
|
||||
import noppes.npcs.api.handler.data.IQuestInterface;
|
||||
import noppes.npcs.api.handler.data.IQuestObjective;
|
||||
import noppes.npcs.api.handler.data.ISlot;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.constants.EnumProfileSync;
|
||||
import noppes.npcs.constants.EnumQuestCompletion;
|
||||
import noppes.npcs.constants.EnumQuestRepeat;
|
||||
@@ -176,21 +174,52 @@ public class Quest implements ICompatibilty, IQuest {
|
||||
}
|
||||
|
||||
public long getTimeUntilRepeat(EntityPlayer player) {
|
||||
if (ConfigMain.ProfilesEnabled && profileOptions.enableOptions && profileOptions.cooldownControl == EnumProfileSync.Shared) {
|
||||
Profile profile = ProfileController.Instance.getProfile(player);
|
||||
IPlayer iPlayer = NoppesUtilServer.getIPlayer(player);
|
||||
long timeRemaining = 0L;
|
||||
for (ISlot slot : profile.getSlots().values()) {
|
||||
IPlayerData playerData = ProfileController.Instance.getSlotPlayerData(iPlayer, slot.getId());
|
||||
IPlayerQuestData iPlayerQuestData = playerData.getQuestData();
|
||||
timeRemaining = Math.max(timeRemaining, getTimeUntilRepeatQuestData(player, iPlayerQuestData));
|
||||
if (ProfileClientConfig.isProfilesEnabled() && profileOptions.enableOptions
|
||||
&& profileOptions.cooldownControl == EnumProfileSync.Shared) {
|
||||
Long questTime = ProfileClientConfig.getSharedQuestTimestamp(player, this.id);
|
||||
if (questTime != null) {
|
||||
return calculateRemainingCooldown(player, questTime);
|
||||
}
|
||||
return timeRemaining;
|
||||
return 0L;
|
||||
}
|
||||
IPlayerQuestData questData = PlayerData.get(player).getQuestData();
|
||||
return getTimeUntilRepeatQuestData(player, questData);
|
||||
}
|
||||
|
||||
public long calculateRemainingCooldown(EntityPlayer player, long questTime) {
|
||||
switch (repeat) {
|
||||
case MCDAILY: {
|
||||
long now = player.worldObj.getTotalWorldTime();
|
||||
long remainingTicks = questTime + 24000 - now;
|
||||
return Math.max(0, remainingTicks * 50);
|
||||
}
|
||||
case MCWEEKLY: {
|
||||
long now = player.worldObj.getTotalWorldTime();
|
||||
long remainingTicks = questTime + 168000 - now;
|
||||
return Math.max(0, remainingTicks * 50);
|
||||
}
|
||||
case MCCUSTOM: {
|
||||
long now = player.worldObj.getTotalWorldTime();
|
||||
long remainingTicks = questTime + this.customCooldown - now;
|
||||
return Math.max(0, remainingTicks * 50);
|
||||
}
|
||||
case RLDAILY: {
|
||||
long remainingMillis = questTime + 86400000 - System.currentTimeMillis();
|
||||
return Math.max(0, remainingMillis);
|
||||
}
|
||||
case RLWEEKLY: {
|
||||
long remainingMillis = questTime + 604800000 - System.currentTimeMillis();
|
||||
return Math.max(0, remainingMillis);
|
||||
}
|
||||
case RLCUSTOM: {
|
||||
long remainingMillis = questTime + this.customCooldown - System.currentTimeMillis();
|
||||
return Math.max(0, remainingMillis);
|
||||
}
|
||||
default:
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
public long getTimeUntilRepeatQuestData(EntityPlayer player, IPlayerQuestData questData) {
|
||||
long questTime = questData.getLastCompletedTime(this.id);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import noppes.npcs.api.handler.data.IQuest;
|
||||
import noppes.npcs.api.handler.data.IQuestCategory;
|
||||
|
||||
@@ -21,8 +22,8 @@ public class QuestCategory implements IQuestCategory {
|
||||
public void readNBT(NBTTagCompound nbttagcompound) {
|
||||
id = nbttagcompound.getInteger("Slot");
|
||||
title = nbttagcompound.getString("Title");
|
||||
NBTTagList questList = nbttagcompound.getTagList("Quests", 10);
|
||||
if (questList != null) {
|
||||
NBTTagList questList = getFirstValidList(nbttagcompound, Constants.NBT.TAG_COMPOUND, "Quests", "Dialogs");
|
||||
if (questList.tagCount() > 0) {
|
||||
for (int ii = 0; ii < questList.tagCount(); ii++) {
|
||||
NBTTagCompound nbttagcompound2 = questList.getCompoundTagAt(ii);
|
||||
Quest quest = new Quest();
|
||||
@@ -33,6 +34,18 @@ public class QuestCategory implements IQuestCategory {
|
||||
}
|
||||
}
|
||||
|
||||
private NBTTagList getFirstValidList(NBTTagCompound nbt, int type, String... keys) {
|
||||
for (String key : keys) {
|
||||
if (nbt.hasKey(key, Constants.NBT.TAG_LIST)) {
|
||||
NBTTagList list = nbt.getTagList(key, type);
|
||||
if (list.tagCount() > 0) {
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
return new NBTTagList();
|
||||
}
|
||||
|
||||
public NBTTagCompound writeNBT(NBTTagCompound nbttagcompound) {
|
||||
nbttagcompound.setInteger("Slot", id);
|
||||
nbttagcompound.setString("Title", title);
|
||||
|
||||
@@ -3,6 +3,7 @@ package noppes.npcs.controllers.data;
|
||||
import kamkeel.npcs.network.packets.request.script.RecipeScriptPacket;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.constants.ScriptContext;
|
||||
import noppes.npcs.janino.EventJaninoScript;
|
||||
|
||||
/**
|
||||
* Script handler for Recipe scripts (both carpentry and anvil).
|
||||
@@ -42,6 +43,11 @@ public class RecipeScript extends SingleScriptHandler implements IScriptHandlerP
|
||||
return ScriptContext.RECIPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScriptUnit createJaninoScriptUnit() {
|
||||
return new EventJaninoScript(ScriptContext.RECIPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String noticeString() {
|
||||
return "RecipeScript";
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
public abstract class ScriptHandler implements IScriptHandler {
|
||||
public List<IScriptUnit> scripts = new ArrayList<>();
|
||||
protected String scriptLanguage = "ECMAScript";
|
||||
protected boolean enabled = false;
|
||||
protected boolean enabled = true;
|
||||
protected long lastInited = -1;
|
||||
|
||||
protected boolean canRunScripts() {
|
||||
|
||||
@@ -10,8 +10,10 @@ public class SkinOverlay implements ISkinOverlay {
|
||||
|
||||
public boolean glow = true;
|
||||
public boolean blend = true;
|
||||
|
||||
public float alpha = 1.0F;
|
||||
public float size = 1.0F;
|
||||
public int color = 0xFFFFFF;
|
||||
|
||||
public float speedX = 0.0F;
|
||||
public float speedY = 0.0F;
|
||||
@@ -78,6 +80,15 @@ public class SkinOverlay implements ISkinOverlay {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setColor(int color) {
|
||||
this.color = Math.max(0, color);
|
||||
this.updateClient();
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setTextureScale(float scaleX, float scaleY) {
|
||||
this.scaleX = scaleX;
|
||||
this.scaleY = scaleY;
|
||||
@@ -131,6 +142,11 @@ public class SkinOverlay implements ISkinOverlay {
|
||||
this.blend = compound.getBoolean("SkinOverlayBlend");
|
||||
this.alpha = compound.getFloat("SkinOverlayAlpha");
|
||||
this.size = compound.getFloat("SkinOverlaySize");
|
||||
if(compound.hasKey("SkinOverlayColor")){
|
||||
this.color = compound.getInteger("SkinOverlayColor");
|
||||
} else {
|
||||
this.color = 0xFFFFFF;
|
||||
}
|
||||
this.speedX = compound.getFloat("SkinOverlaySpeedX");
|
||||
this.speedY = compound.getFloat("SkinOverlaySpeedY");
|
||||
this.scaleX = compound.getFloat("SkinOverlayScaleX");
|
||||
@@ -146,6 +162,7 @@ public class SkinOverlay implements ISkinOverlay {
|
||||
compound.setBoolean("SkinOverlayBlend", this.getBlend());
|
||||
compound.setFloat("SkinOverlayAlpha", this.getAlpha());
|
||||
compound.setFloat("SkinOverlaySize", this.getSize());
|
||||
compound.setInteger("SkinOverlayColor", this.getColor());
|
||||
compound.setFloat("SkinOverlaySpeedX", this.getSpeedX());
|
||||
compound.setFloat("SkinOverlaySpeedY", this.getSpeedY());
|
||||
compound.setFloat("SkinOverlayScaleX", this.getTextureScaleX());
|
||||
@@ -166,6 +183,7 @@ public class SkinOverlay implements ISkinOverlay {
|
||||
private void updateClient() {
|
||||
if (this.parent != null) {
|
||||
this.parent.updateClient();
|
||||
this.parent.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,10 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class SpawnData extends WeightedRandom.Item implements INaturalSpawn {
|
||||
public static final int DESPAWN_FORCE_NATURAL = INaturalSpawn.DESPAWN_FORCE_NATURAL;
|
||||
public static final int DESPAWN_PRESERVE_TEMPLATE = INaturalSpawn.DESPAWN_PRESERVE_TEMPLATE;
|
||||
public static final int DESPAWN_FORCE_PERSISTENT = INaturalSpawn.DESPAWN_FORCE_PERSISTENT;
|
||||
|
||||
public List<String> biomes = new ArrayList<>();
|
||||
public HashSet<Integer> dimensions = new HashSet<>();
|
||||
public int id = -1;
|
||||
@@ -35,6 +39,11 @@ public class SpawnData extends WeightedRandom.Item implements INaturalSpawn {
|
||||
|
||||
public int spawnHeightMin;
|
||||
public int spawnHeightMax = 100;
|
||||
public int maxAlive = 0;
|
||||
public int cooldownTicks = 0;
|
||||
public int attemptsPerCycle = 1;
|
||||
public int playerMinDistance = 24;
|
||||
public int despawnMode = DESPAWN_FORCE_NATURAL;
|
||||
|
||||
public SpawnData() {
|
||||
super(10);
|
||||
@@ -74,6 +83,19 @@ public class SpawnData extends WeightedRandom.Item implements INaturalSpawn {
|
||||
} else {
|
||||
spawnHeightMax = compound.getInteger("HeightMax");
|
||||
}
|
||||
|
||||
maxAlive = compound.hasKey("MaxAlive") ? Math.max(0, compound.getInteger("MaxAlive")) : 0;
|
||||
cooldownTicks = compound.hasKey("CooldownTicks") ? Math.max(0, compound.getInteger("CooldownTicks")) : 0;
|
||||
attemptsPerCycle = compound.hasKey("AttemptsPerCycle") ? Math.max(1, compound.getInteger("AttemptsPerCycle")) : 1;
|
||||
playerMinDistance = compound.hasKey("PlayerMinDistance") ? Math.max(0, compound.getInteger("PlayerMinDistance")) : 24;
|
||||
if (compound.hasKey("DespawnMode")) {
|
||||
despawnMode = compound.getInteger("DespawnMode");
|
||||
} else {
|
||||
despawnMode = DESPAWN_FORCE_NATURAL;
|
||||
}
|
||||
if (despawnMode < DESPAWN_FORCE_NATURAL || despawnMode > DESPAWN_FORCE_PERSISTENT) {
|
||||
despawnMode = DESPAWN_FORCE_NATURAL;
|
||||
}
|
||||
}
|
||||
|
||||
public NBTTagCompound writeNBT(NBTTagCompound compound) {
|
||||
@@ -98,6 +120,11 @@ public class SpawnData extends WeightedRandom.Item implements INaturalSpawn {
|
||||
|
||||
compound.setInteger("HeightMin", spawnHeightMin);
|
||||
compound.setInteger("HeightMax", spawnHeightMax);
|
||||
compound.setInteger("MaxAlive", maxAlive);
|
||||
compound.setInteger("CooldownTicks", cooldownTicks);
|
||||
compound.setInteger("AttemptsPerCycle", attemptsPerCycle);
|
||||
compound.setInteger("PlayerMinDistance", playerMinDistance);
|
||||
compound.setInteger("DespawnMode", despawnMode);
|
||||
return compound;
|
||||
}
|
||||
|
||||
@@ -204,4 +231,46 @@ public class SpawnData extends WeightedRandom.Item implements INaturalSpawn {
|
||||
public void setBiomes(String[] biomes) {
|
||||
this.biomes = new ArrayList<>(Arrays.asList(biomes));
|
||||
}
|
||||
|
||||
public void setMaxAlive(int maxAlive) {
|
||||
this.maxAlive = Math.max(0, maxAlive);
|
||||
}
|
||||
|
||||
public int getMaxAlive() {
|
||||
return this.maxAlive;
|
||||
}
|
||||
|
||||
public void setCooldownTicks(int ticks) {
|
||||
this.cooldownTicks = Math.max(0, ticks);
|
||||
}
|
||||
|
||||
public int getCooldownTicks() {
|
||||
return this.cooldownTicks;
|
||||
}
|
||||
|
||||
public void setAttemptsPerCycle(int attempts) {
|
||||
this.attemptsPerCycle = Math.max(1, attempts);
|
||||
}
|
||||
|
||||
public int getAttemptsPerCycle() {
|
||||
return this.attemptsPerCycle;
|
||||
}
|
||||
|
||||
public void setPlayerMinDistance(int distance) {
|
||||
this.playerMinDistance = Math.max(0, distance);
|
||||
}
|
||||
|
||||
public int getPlayerMinDistance() {
|
||||
return this.playerMinDistance;
|
||||
}
|
||||
|
||||
public void setDespawnMode(int mode) {
|
||||
if (mode < DESPAWN_FORCE_NATURAL || mode > DESPAWN_FORCE_PERSISTENT)
|
||||
mode = DESPAWN_FORCE_NATURAL;
|
||||
this.despawnMode = mode;
|
||||
}
|
||||
|
||||
public int getDespawnMode() {
|
||||
return this.despawnMode;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.api.entity.data.ITintData;
|
||||
|
||||
public class TintData {
|
||||
public class TintData implements ITintData {
|
||||
private boolean tintEnabled = false;
|
||||
private boolean hurtTintEnabled = true;
|
||||
private boolean generalTintEnabled = false;
|
||||
|
||||
@@ -6,6 +6,7 @@ import noppes.npcs.api.handler.data.IActionQueue;
|
||||
import noppes.npcs.api.handler.data.actions.IConditionalAction;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.scripted.CustomNPCsException;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -344,6 +345,10 @@ public class Action implements IAction {
|
||||
try {
|
||||
onStart.accept(this);
|
||||
} catch (Throwable t) {
|
||||
String err = "IAction" + getName() + " onStart threw an exception:";
|
||||
if (reportTo != null)
|
||||
reportTo.appendConsole(err + "\n" + ExceptionUtils.getStackTrace(t));
|
||||
|
||||
manager.LOGGER.error("onStart Task of " + this + " threw an exception:", t);
|
||||
}
|
||||
|
||||
@@ -359,6 +364,11 @@ public class Action implements IAction {
|
||||
task.accept(this);
|
||||
count++;
|
||||
} catch (Throwable t) {
|
||||
String err = "IAction '" + name + "' threw an exception:";
|
||||
|
||||
if (reportTo != null)
|
||||
reportTo.appendConsole(err + "\n" + ExceptionUtils.getStackTrace(t));
|
||||
|
||||
manager.LOGGER.error("Task of " + this + " threw an exception:", t);
|
||||
markDone();
|
||||
}
|
||||
@@ -374,6 +384,10 @@ public class Action implements IAction {
|
||||
try {
|
||||
onDone.accept(this);
|
||||
} catch (Throwable t) {
|
||||
String err = "IAction" + getName() + " onDone threw an exception:";
|
||||
if (reportTo != null)
|
||||
reportTo.appendConsole(err + "\n" + ExceptionUtils.getStackTrace(t));
|
||||
|
||||
manager.LOGGER.error("onDone Task of " + this + " threw an exception:", t);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import noppes.npcs.api.handler.data.IAction;
|
||||
import noppes.npcs.api.handler.data.actions.IConditionalAction;
|
||||
import noppes.npcs.controllers.data.action.Action;
|
||||
import noppes.npcs.controllers.data.action.ActionManager;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
@@ -130,6 +131,10 @@ public class ConditionalAction extends Action implements IConditionalAction {
|
||||
count++;
|
||||
taskExecuted = true;
|
||||
} catch (Throwable t) {
|
||||
String err = "IConditionalAction '" + getName() + "' threw an exception:";
|
||||
if (reportTo != null)
|
||||
reportTo.appendConsole(err + "\n" + ExceptionUtils.getStackTrace(t));
|
||||
|
||||
manager.LOGGER.error("Task of " + this + " threw an exception:", t);
|
||||
markDone();
|
||||
}
|
||||
@@ -146,6 +151,10 @@ public class ConditionalAction extends Action implements IConditionalAction {
|
||||
try {
|
||||
onTermination.accept(this);
|
||||
} catch (Throwable t) {
|
||||
String err = "IConditionalAction" + getName() + " onTermination threw an exception:";
|
||||
if (reportTo != null)
|
||||
reportTo.appendConsole(err + "\n" + ExceptionUtils.getStackTrace(t));
|
||||
|
||||
manager.LOGGER.error("Termination Task of " + this + " threw an exception:", t);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user