More Core Class Conversion

This commit is contained in:
Kam committed 2026-03-13 16:22:48 -04:00
1 parent 43a52ad407
commit 89f81f96bc
51 files changed
+744 -189

No files matched your search

@@ -0,0 +1,38 @@
package noppes.npcs.constants;
public enum EnumAuctionSort {
NEWEST("auction.sort.newest"),
ENDING_SOON("auction.sort.endingSoon"),
PRICE_LOW("auction.sort.priceLow"),
PRICE_HIGH("auction.sort.priceHigh"),
MOST_BIDS("auction.sort.mostBids");
private final String langKey;
EnumAuctionSort(String langKey) {
this.langKey = langKey;
}
public String getLangKey() {
return langKey;
}
public String getDisplayName() {
return langKey;
}
public static String[] getDisplayNames() {
String[] names = new String[values().length];
for (int i = 0; i < values().length; i++) {
names[i] = values()[i].getDisplayName();
}
return names;
}
public static EnumAuctionSort fromOrdinal(int ordinal) {
if (ordinal >= 0 && ordinal < values().length) {
return values()[ordinal];
}
return NEWEST;
}
}
@@ -0,0 +1,127 @@
package noppes.npcs.controllers.data;
import noppes.npcs.platform.nbt.INBTCompound;
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 FORMATTING_PATTERN = Pattern.compile("\u00a7.");
private String searchText;
public EnumAuctionSort sortBy;
// Cached normalized search for efficiency
private String normalizedSearch;
public AuctionFilter() {
this.searchText = "";
this.sortBy = EnumAuctionSort.NEWEST;
this.normalizedSearch = "";
}
public boolean hasSearchText() {
return searchText != null && !searchText.trim().isEmpty();
}
/**
* Normalize string for search (strip colors, lowercase, trim)
*/
public static String normalizeForSearch(String input) {
if (input == null || input.isEmpty()) return "";
String stripped = FORMATTING_PATTERN.matcher(input).replaceAll("");
return stripped.toLowerCase().trim();
}
/**
* 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);
String normalizedSeller = normalizeForSearch(sellerName);
// Match if search text is found in either item name or seller name
return normalizedItem.contains(normalizedSearch) || normalizedSeller.contains(normalizedSearch);
}
/**
* 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
*/
public boolean matchesSearchAdvanced(String itemName, String sellerName) {
if (!hasSearchText()) return true;
String normalizedItem = normalizeForSearch(itemName);
String normalizedSeller = normalizeForSearch(sellerName);
String[] words = normalizedSearch.split("\\s+");
for (String word : words) {
if (!word.isEmpty()) {
// Word must be in item name OR seller name
if (!normalizedItem.contains(word) && !normalizedSeller.contains(word)) {
return false;
}
}
}
return true;
}
/**
* Legacy method - only checks item name
*/
public boolean matchesSearchAdvanced(String itemName) {
return matchesSearchAdvanced(itemName, "");
}
public void reset() {
searchText = "";
sortBy = EnumAuctionSort.NEWEST;
normalizedSearch = "";
}
public INBTCompound writeToNBT(INBTCompound compound) {
compound.setString("SearchText", searchText != null ? searchText : "");
compound.setInteger("SortBy", sortBy.ordinal());
return compound;
}
public void readFromNBT(INBTCompound compound) {
searchText = compound.getString("SearchText");
normalizedSearch = normalizeForSearch(searchText);
sortBy = EnumAuctionSort.fromOrdinal(compound.getInteger("SortBy"));
}
public AuctionFilter copy() {
AuctionFilter copy = new AuctionFilter();
copy.searchText = this.searchText;
copy.normalizedSearch = this.normalizedSearch;
copy.sortBy = this.sortBy;
return copy;
}
// Getters and setters
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;
}
}
@@ -0,0 +1,63 @@
package noppes.npcs.controllers.data;
import noppes.npcs.api.entity.data.IHitboxData;
import noppes.npcs.platform.nbt.INBTCompound;
import noppes.npcs.core.CoreConfig;
public class HitboxData implements IHitboxData {
private float widthScale = 1f;
private float heightScale = 1f;
private boolean hitboxEnabled = false;
public INBTCompound writeToNBT(INBTCompound nbttagcompound) {
nbttagcompound.setBoolean("HitboxEnabled", hitboxEnabled);
if (hitboxEnabled) {
if (widthScale > CoreConfig.HitBoxScaleMax)
widthScale = CoreConfig.HitBoxScaleMax;
nbttagcompound.setFloat("HitboxWidthScale", widthScale);
if (heightScale > CoreConfig.HitBoxScaleMax)
heightScale = CoreConfig.HitBoxScaleMax;
nbttagcompound.setFloat("HitboxHeightScale", heightScale);
}
return nbttagcompound;
}
public void readFromNBT(INBTCompound nbttagcompound) {
hitboxEnabled = nbttagcompound.getBoolean("HitboxEnabled");
if (hitboxEnabled) {
widthScale = nbttagcompound.getFloat("HitboxWidthScale");
if (widthScale > CoreConfig.HitBoxScaleMax)
widthScale = CoreConfig.HitBoxScaleMax;
heightScale = nbttagcompound.getFloat("HitboxHeightScale");
if (heightScale > CoreConfig.HitBoxScaleMax)
heightScale = CoreConfig.HitBoxScaleMax;
}
}
public float getWidthScale() {
return widthScale;
}
public void setWidthScale(float widthScale) {
this.widthScale = widthScale;
}
public float getHeightScale() {
return heightScale;
}
public void setHeightScale(float heightScale) {
this.heightScale = heightScale;
}
public boolean isHitboxEnabled() {
return hitboxEnabled;
}
public void setHitboxEnabled(boolean hitboxEnabled) {
this.hitboxEnabled = hitboxEnabled;
}
}
@@ -0,0 +1,56 @@
package noppes.npcs.controllers.data;
import noppes.npcs.api.handler.data.ILine;
public class Line implements ILine {
public Line() {
}
public Line(String text) {
this.text = text;
}
public String text = "";
public String sound = "";
public boolean hideText = false;
public ILine copy() {
Line line = new Line(text);
line.sound = sound;
line.hideText = hideText;
return line;
}
@Override
public String getText() {
return this.text;
}
@Override
public void setText(String text) {
this.text = text;
}
@Override
public String getSound() {
return this.sound;
}
@Override
public void setSound(String sound) {
this.sound = sound;
}
@Override
public void hideText(boolean hide) {
this.hideText = hide;
}
@Override
public boolean hideText() {
return this.hideText;
}
}
@@ -0,0 +1,97 @@
package noppes.npcs.controllers.data;
import noppes.npcs.api.handler.data.ILine;
import noppes.npcs.api.handler.data.ILines;
import noppes.npcs.platform.nbt.INBTCompound;
import noppes.npcs.platform.nbt.INBTList;
import noppes.npcs.core.NBT;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
public class Lines implements ILines {
private static final Random random = new Random();
private int lastLine = -1;
public HashMap<Integer, Line> lines = new HashMap<Integer, Line>();
public INBTCompound writeToNBT() {
INBTCompound compound = NBT.compound();
INBTList nbttaglist = NBT.list();
for (int slot : lines.keySet()) {
Line line = lines.get(slot);
INBTCompound nbttagcompound = NBT.compound();
nbttagcompound.setInteger("Slot", slot);
nbttagcompound.setString("Line", line.text);
nbttagcompound.setString("Song", line.sound);
nbttaglist.addCompound(nbttagcompound);
}
compound.setList("Lines", nbttaglist);
return compound;
}
public void readNBT(INBTCompound compound) {
INBTList nbttaglist = compound.getList("Lines", 10);
HashMap<Integer, Line> map = new HashMap<Integer, Line>();
for (int i = 0; i < nbttaglist.size(); i++) {
INBTCompound nbttagcompound = nbttaglist.getCompound(i);
Line line = new Line();
line.text = nbttagcompound.getString("Line");
line.sound = nbttagcompound.getString("Song");
map.put(nbttagcompound.getInteger("Slot"), line);
}
lines = map;
}
public ILine createLine(String text) {
return new Line(text);
}
public ILine getLine(boolean isRandom) {
if (lines.isEmpty())
return null;
if (isRandom) {
List<Line> lines = new ArrayList<Line>(this.lines.values());
return lines.get(random.nextInt(lines.size()));
}
lastLine++;
while (true) {
lastLine %= 8;
Line line = lines.get(lastLine);
if (line != null)
return line.copy();
lastLine++;
}
}
public ILine getLine(int lineIndex) {
return lines.get(lineIndex);
}
public void setLine(int lineIndex, ILine line) {
lines.put(lineIndex, (Line) line);
}
public void removeLine(int lineIndex) {
lines.remove(lineIndex);
}
public void clear() {
lines.clear();
}
public boolean isEmpty() {
return lines.isEmpty();
}
public Integer[] getKeys() {
return lines.keySet().toArray(new Integer[0]);
}
}
@@ -0,0 +1,246 @@
package noppes.npcs.controllers.data;
import noppes.npcs.api.handler.data.IPartyOptions;
import noppes.npcs.platform.nbt.INBTCompound;
import noppes.npcs.core.NBT;
import noppes.npcs.core.CoreConfig;
import noppes.npcs.constants.EnumPartyExchange;
import noppes.npcs.constants.EnumPartyObjectives;
import noppes.npcs.constants.EnumPartyRequirements;
import java.util.Vector;
public class PartyOptions implements IPartyOptions {
public boolean allowParty = false;
public boolean onlyParty = false;
public EnumPartyRequirements partyRequirements = EnumPartyRequirements.Leader;
public EnumPartyExchange rewardControl = EnumPartyExchange.Leader;
public EnumPartyExchange completeFor = EnumPartyExchange.Leader;
public EnumPartyExchange executeCommand = EnumPartyExchange.Leader;
public EnumPartyObjectives objectiveRequirement = EnumPartyObjectives.Shared;
public int minPartySize = CoreConfig.DefaultMinPartySize;
public int maxPartySize = CoreConfig.DefaultMaxPartySize;
public void readFromNBT(INBTCompound compound) {
// Party Management
allowParty = compound.getBoolean("AllowParty");
if (allowParty) {
onlyParty = compound.getBoolean("OnlyParty");
partyRequirements = EnumPartyRequirements.values()[compound.getInteger("PartyRequirements")];
rewardControl = EnumPartyExchange.values()[compound.getInteger("RewardControl")];
completeFor = EnumPartyExchange.values()[compound.getInteger("CompleteFor")];
executeCommand = EnumPartyExchange.values()[compound.getInteger("ExecuteCommand")];
minPartySize = compound.getInteger("MinPartySize");
maxPartySize = compound.getInteger("MaxPartySize");
objectiveRequirement = EnumPartyObjectives.values()[compound.getInteger("ObjectiveRequirement")];
} else {
if (compound.hasKey("OnlyParty")) {
compound.removeTag("OnlyParty");
}
if (compound.hasKey("PartyRequirements")) {
compound.removeTag("PartyRequirements");
}
if (compound.hasKey("RewardControl")) {
compound.removeTag("RewardControl");
}
if (compound.hasKey("CompleteFor")) {
compound.removeTag("CompleteFor");
}
if (compound.hasKey("ExecuteCommand")) {
compound.removeTag("ExecuteCommand");
}
if (compound.hasKey("MinPartySize")) {
compound.removeTag("MinPartySize");
}
if (compound.hasKey("MaxPartySize")) {
compound.removeTag("MaxPartySize");
}
if (compound.hasKey("ObjectiveRequirement")) {
compound.removeTag("ObjectiveRequirement");
}
onlyParty = false;
partyRequirements = EnumPartyRequirements.Leader;
rewardControl = EnumPartyExchange.Leader;
completeFor = EnumPartyExchange.Leader;
executeCommand = EnumPartyExchange.Leader;
minPartySize = CoreConfig.DefaultMinPartySize;
maxPartySize = CoreConfig.DefaultMaxPartySize;
objectiveRequirement = EnumPartyObjectives.Shared;
}
}
public INBTCompound writeToNBT() {
INBTCompound compound = NBT.compound();
compound.setBoolean("AllowParty", allowParty);
if (allowParty) {
compound.setBoolean("OnlyParty", onlyParty);
compound.setInteger("PartyRequirements", partyRequirements.ordinal());
compound.setInteger("RewardControl", rewardControl.ordinal());
compound.setInteger("CompleteFor", completeFor.ordinal());
compound.setInteger("ExecuteCommand", executeCommand.ordinal());
compound.setInteger("MinPartySize", minPartySize);
compound.setInteger("MaxPartySize", maxPartySize);
compound.setInteger("ObjectiveRequirement", objectiveRequirement.ordinal());
} else {
if (compound.hasKey("OnlyParty")) {
compound.removeTag("OnlyParty");
}
if (compound.hasKey("PartyRequirements")) {
compound.removeTag("PartyRequirements");
}
if (compound.hasKey("RewardControl")) {
compound.removeTag("RewardControl");
}
if (compound.hasKey("CompleteFor")) {
compound.removeTag("CompleteFor");
}
if (compound.hasKey("ExecuteCommand")) {
compound.removeTag("ExecuteCommand");
}
if (compound.hasKey("MinPartySize")) {
compound.removeTag("MinPartySize");
}
if (compound.hasKey("MaxPartySize")) {
compound.removeTag("MaxPartySize");
}
if (compound.hasKey("ObjectiveRequirement")) {
compound.removeTag("ObjectiveRequirement");
}
}
return compound;
}
@Override
public boolean isAllowParty() {
return allowParty;
}
@Override
public void setAllowParty(boolean allowParty) {
this.allowParty = allowParty;
}
@Override
public boolean isOnlyParty() {
return onlyParty;
}
@Override
public void setOnlyParty(boolean onlyParty) {
this.onlyParty = onlyParty;
}
@Override
public int getPartyRequirements() {
return partyRequirements.ordinal();
}
@Override
public void setPartyRequirements(int partyReq) {
if (partyReq < 0 || partyReq >= EnumPartyRequirements.values().length) {
return;
}
this.partyRequirements = EnumPartyRequirements.values()[partyReq];
}
@Override
public int getRewardControl() {
return rewardControl.ordinal();
}
@Override
public void setRewardControl(int rewardCon) {
if (rewardCon < 0 || rewardCon >= EnumPartyExchange.values().length) {
return;
}
this.rewardControl = EnumPartyExchange.values()[rewardCon];
}
@Override
public int getCompleteFor() {
return completeFor.ordinal();
}
@Override
public void setCompleteFor(int compFor) {
if (compFor < 0 || compFor >= EnumPartyExchange.values().length) {
return;
}
this.completeFor = EnumPartyExchange.values()[compFor];
}
@Override
public int getExecuteCommandFor() {
return executeCommand.ordinal();
}
@Override
public void setExecuteCommandFor(int commandFor) {
if (commandFor < 0 || commandFor >= EnumPartyExchange.values().length) {
return;
}
this.executeCommand = EnumPartyExchange.values()[commandFor];
}
@Override
public int getObjectiveRequirement() {
return objectiveRequirement.ordinal();
}
@Override
public void setObjectiveRequirement(int requirement) {
if (requirement < 0 || requirement >= EnumPartyObjectives.values().length) {
return;
}
this.objectiveRequirement = EnumPartyObjectives.values()[requirement];
}
@Override
public int getMinPartySize() {
return minPartySize;
}
@Override
public void setMinPartySize(int newSize) {
if (newSize < 1)
newSize = 1;
if (newSize > maxPartySize)
newSize = maxPartySize;
minPartySize = newSize;
}
@Override
public int getMaxPartySize() {
return maxPartySize;
}
@Override
public void setMaxPartySize(int newSize) {
if (newSize < minPartySize)
newSize = minPartySize;
maxPartySize = newSize;
}
public Vector<String> getPartyOptionsList() {
Vector<String> vec = new Vector<String>();
if (onlyParty) {
vec.add("party.only" + ":" + "gui.yes");
}
vec.add("party.partyRequirements" + ":" + partyRequirements.name);
vec.add("quest.objectives" + ":" + objectiveRequirement.name);
vec.add("party.completeFor" + ":" + completeFor.name);
vec.add("quest.reward" + ":" + rewardControl.name);
vec.add("party.minPartySize" + ":" + minPartySize);
vec.add("party.maxPartySize" + ":" + maxPartySize);
return vec;
}
}
@@ -0,0 +1,185 @@
package noppes.npcs.controllers.data;
import noppes.npcs.api.ISkinOverlay;
import noppes.npcs.platform.nbt.INBTCompound;
public class SkinOverlay implements ISkinOverlay {
private Runnable onChanged;
public String texture;
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;
public float scaleX = 1.0F;
public float scaleY = 1.0F;
public float offsetX = 0.0F;
public float offsetY = 0.0F;
public float offsetZ = 0.0F;
//Client-sided
public long ticks = 0;
public SkinOverlay() {
}
public SkinOverlay(String texture) {
this.texture = texture;
}
public void setOnChanged(Runnable onChanged) {
this.onChanged = onChanged;
}
public void setTexture(String texture) {
this.texture = texture;
this.notifyChanged();
}
public String getTexture() {
return this.texture;
}
public void setGlow(boolean glow) {
this.glow = glow;
this.notifyChanged();
}
public boolean getGlow() {
return glow;
}
public void setBlend(boolean blend) {
this.blend = blend;
this.notifyChanged();
}
public boolean getBlend() {
return blend;
}
public void setAlpha(float alpha) {
this.alpha = alpha;
this.notifyChanged();
}
public float getAlpha() {
return alpha;
}
public void setSize(float size) {
this.size = size;
this.notifyChanged();
}
public float getSize() {
return size;
}
public void setColor(int color) {
this.color = Math.max(0, color);
this.notifyChanged();
}
public int getColor() {
return color;
}
public void setTextureScale(float scaleX, float scaleY) {
this.scaleX = scaleX;
this.scaleY = scaleY;
this.notifyChanged();
}
public float getTextureScaleX() {
return scaleX;
}
public float getTextureScaleY() {
return scaleY;
}
public void setSpeed(float speedX, float speedY) {
this.speedX = speedX;
this.speedY = speedY;
this.notifyChanged();
}
public float getSpeedX() {
return speedX;
}
public float getSpeedY() {
return speedY;
}
public void setOffset(float offsetX, float offsetY, float offsetZ) {
this.offsetX = offsetX;
this.offsetY = offsetY;
this.offsetZ = offsetZ;
this.notifyChanged();
}
public float getOffsetX() {
return offsetX;
}
public float getOffsetY() {
return offsetY;
}
public float getOffsetZ() {
return offsetZ;
}
public void readFromNBT(INBTCompound compound) {
this.texture = compound.getString("SkinOverlayTexture");
this.glow = compound.getBoolean("SkinOverlayGlow");
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");
this.scaleY = compound.getFloat("SkinOverlayScaleY");
this.offsetX = compound.getFloat("SkinOverlayOffsetX");
this.offsetY = compound.getFloat("SkinOverlayOffsetY");
this.offsetZ = compound.getFloat("SkinOverlayOffsetZ");
}
public INBTCompound writeToNBT(INBTCompound compound) {
compound.setString("SkinOverlayTexture", this.getTexture());
compound.setBoolean("SkinOverlayGlow", this.getGlow());
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());
compound.setFloat("SkinOverlayScaleY", this.getTextureScaleY());
compound.setFloat("SkinOverlayOffsetX", this.getOffsetX());
compound.setFloat("SkinOverlayOffsetY", this.getOffsetY());
compound.setFloat("SkinOverlayOffsetZ", this.getOffsetZ());
return compound;
}
private void notifyChanged() {
if (this.onChanged != null) {
this.onChanged.run();
}
}
}
@@ -0,0 +1,99 @@
package noppes.npcs.controllers.data;
import noppes.npcs.api.handler.data.ITag;
import noppes.npcs.platform.nbt.INBTCompound;
import java.util.UUID;
import static java.util.UUID.randomUUID;
public class Tag implements ITag {
public String name = "";
public int color = Integer.parseInt("FF00", 16);
public int id = -1;
public UUID uuid = randomUUID();
public boolean hideTag = false;
private Runnable saveHandler;
public Tag() {
}
public Tag(int id, String name, int color) {
this.name = name;
this.color = color;
this.id = id;
}
public void setSaveHandler(Runnable saveHandler) {
this.saveHandler = saveHandler;
}
public static String formatName(String name) {
name = name.toLowerCase().trim();
return name.substring(0, 1).toUpperCase() + name.substring(1);
}
public void readNBT(INBTCompound compound) {
name = compound.getString("Name");
color = compound.getInteger("Color");
id = compound.getInteger("Slot");
hideTag = compound.getBoolean("HideTag");
uuid = UUID.fromString(compound.getString("Uuid"));
}
public void writeNBT(INBTCompound compound) {
compound.setInteger("Slot", id);
compound.setString("Name", name);
compound.setInteger("Color", color);
compound.setString("Uuid", uuid.toString());
compound.setBoolean("HideTag", hideTag);
}
public void readShortNBT(INBTCompound compound) {
name = compound.getString("Name");
uuid = UUID.fromString(compound.getString("Uuid"));
}
public void writeShortNBT(INBTCompound compound) {
compound.setString("Name", name);
compound.setString("Uuid", uuid.toString());
}
public int getId() {
return this.id;
}
public String getUuid() {
return this.uuid.toString();
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public void setColor(int color) {
this.color = color;
}
public int getColor() {
return this.color;
}
public boolean getIsHidden() {
return this.hideTag;
}
public void setIsHidden(boolean bo) {
this.hideTag = bo;
}
public void save() {
if (saveHandler != null)
saveHandler.run();
}
}
@@ -0,0 +1,87 @@
package noppes.npcs.controllers.data;
import noppes.npcs.api.handler.data.ITransportCategory;
import noppes.npcs.api.handler.data.ITransportLocation;
import noppes.npcs.platform.nbt.INBTCompound;
import noppes.npcs.platform.nbt.INBTList;
import noppes.npcs.core.NBT;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
public class TransportCategory implements ITransportCategory {
public int id = -1;
public String title = "";
public HashMap<Integer, TransportLocation> locations;
public TransportCategory() {
locations = new HashMap<Integer, TransportLocation>();
}
public Vector<TransportLocation> getDefaultLocations() {
Vector<TransportLocation> list = new Vector<TransportLocation>();
for (TransportLocation loc : locations.values())
if (loc.isDefault())
list.add(loc);
return list;
}
public void readNBT(INBTCompound compound) {
id = compound.getInteger("CategoryId");
title = compound.getString("CategoryTitle");
INBTList locs = compound.getList("CategoryLocations", 10);
if (locs == null || locs.size() == 0)
return;
for (int ii = 0; ii < locs.size(); ii++) {
TransportLocation location = new TransportLocation();
location.readNBT(locs.getCompound(ii));
location.category = this;
locations.put(location.id, location);
}
}
public void writeNBT(INBTCompound compound) {
compound.setInteger("CategoryId", id);
compound.setString("CategoryTitle", title);
INBTList locs = NBT.list();
for (TransportLocation location : locations.values()) {
locs.addCompound(location.writeNBT());
}
compound.setList("CategoryLocations", locs);
}
public int getId() {
return id;
}
public void setTitle(String title) {
this.title = title;
}
public String getTitle() {
return title;
}
public void addLocation(String name) {
// Overridden in version-specific code
}
public ITransportLocation getLocation(String name) {
TransportLocation location = null;
for (TransportLocation l : locations.values()) {
if (l.getName().equals(name)) {
location = l;
break;
}
}
return location;
}
public void removeLocation(String name) {
// Overridden in version-specific code
}
}
@@ -0,0 +1,114 @@
package noppes.npcs.controllers.data;
import noppes.npcs.api.IPos;
import noppes.npcs.api.handler.data.ITransportLocation;
import noppes.npcs.platform.nbt.INBTCompound;
import noppes.npcs.core.NBT;
public class TransportLocation implements ITransportLocation {
public int id = -1;
public String name = "default name";
public double posX;
public double posY;
public double posZ;
public int type = 0;
public int dimension = 0;
public TransportCategory category;
private Runnable saveHandler;
public void setSaveHandler(Runnable saveHandler) {
this.saveHandler = saveHandler;
}
public void readNBT(INBTCompound compound) {
if (compound == null)
return;
id = compound.getInteger("Id");
posX = compound.getDouble("PosX");
posY = compound.getDouble("PosY");
posZ = compound.getDouble("PosZ");
type = compound.getInteger("Type");
dimension = compound.getInteger("Dimension");
name = compound.getString("Name");
}
public INBTCompound writeNBT() {
INBTCompound compound = NBT.compound();
compound.setInteger("Id", id);
compound.setDouble("PosX", posX);
compound.setDouble("PosY", posY);
compound.setDouble("PosZ", posZ);
compound.setInteger("Type", type);
compound.setInteger("Dimension", dimension);
compound.setString("Name", name);
return compound;
}
public boolean isDefault() {
return type == 1;
}
public int getId() {
return id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setDimension(int dimension) {
this.dimension = dimension;
}
public int getDimension() {
return dimension;
}
public void setType(int type) {
this.type = type;
}
public int getType() {
return type;
}
public void setPosition(int x, int y, int z) {
this.posX = x;
this.posY = y;
this.posZ = z;
}
public void setPosition(IPos pos) {
this.posX = pos.getX();
this.posY = pos.getY();
this.posZ = pos.getZ();
}
public IPos getPos() {
return null; // Overridden in version-specific code
}
public double getX() {
return posX;
}
public double getY() {
return posY;
}
public double getZ() {
return posZ;
}
public void save() {
if (saveHandler != null)
saveHandler.run();
}
}
@@ -0,0 +1,20 @@
package noppes.npcs.core;
/**
* Static config values accessible to core module code.
* Values are populated by the platform-specific config system at startup.
* Defaults match the original ConfigMain defaults.
*/
public final class CoreConfig {
// NPC Hitbox
public static int HitBoxScaleMax = 15;
// Party defaults
public static int DefaultMinPartySize = 1;
public static int DefaultMaxPartySize = 4;
// Dialog
public static int DialogImageLimit = 10;
private CoreConfig() {}
}
@@ -0,0 +1,78 @@
package noppes.npcs.util;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class CacheHashMap<K, V extends CacheHashMap.CachedObject<?>> extends HashMap<K, V> {
private final long maxCacheTime;
private long saveInterval;
public CacheHashMap(long maxCacheTime) {
this.maxCacheTime = maxCacheTime;
}
public CacheHashMap(long maxCacheTime, long saveInterval) {
this.maxCacheTime = maxCacheTime;
this.saveInterval = saveInterval;
}
@Override
public V get(Object key) {
V object = super.get(key);
object.updateTimeAccessed();
Iterator<Map.Entry<K, V>> iterator = this.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<K, V> entry = iterator.next();
long lifeTimeDiff = entry.getValue().timeSinceAccessed();
if (lifeTimeDiff > this.maxCacheTime) {
entry.getValue().save();
iterator.remove();
} else if (this.saveInterval > 0) {
long saveTimeDiff = entry.getValue().timeSinceSaved();
if (saveTimeDiff > this.saveInterval) {
entry.getValue().save();
entry.getValue().updateSaveTime();
}
}
}
return object;
}
public static class CachedObject<T> {
private long timeSaved;
private long lastTimeAccessed;
private final T object;
public CachedObject(T object) {
this.object = object;
this.lastTimeAccessed = System.currentTimeMillis();
this.timeSaved = System.currentTimeMillis();
}
public long timeSinceAccessed() {
return System.currentTimeMillis() - this.lastTimeAccessed;
}
public long timeSinceSaved() {
return System.currentTimeMillis() - this.timeSaved;
}
public void updateTimeAccessed() {
this.lastTimeAccessed = System.currentTimeMillis();
}
public void updateSaveTime() {
this.timeSaved = System.currentTimeMillis();
}
public void save() {
}
public T getObject() {
return this.object;
}
}
}
@@ -0,0 +1,13 @@
package noppes.npcs.util;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
public class CustomNPCsThreader {
/**
* Executor used for all asynchronous profile and player data saves.
* It is single-threaded so submitted tasks run sequentially and the
* save order for a given player is preserved.
*/
public static final Executor customNPCThread = Executors.newSingleThreadExecutor();
}
@@ -0,0 +1,17 @@
package noppes.npcs.util;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
public class LRUHashMap<K, V> extends LinkedHashMap<K, V> {
private final int maxSize;
public LRUHashMap(int size) {
super(size, 0.75F, true);
this.maxSize = size;
}
protected boolean removeEldestEntry(Entry<K, V> eldest) {
return this.size() > this.maxSize;
}
}
@@ -0,0 +1,74 @@
package noppes.npcs.util;
public class MillisTimer {
float ticksPerSecond;
private double lastHRTime;
public int elapsedTicks;
public float renderPartialTicks;
public float timerSpeed = 1.0F;
public float elapsedPartialTicks;
private long lastSyncSysClock;
private long lastSyncHRClock;
private long field_74285_i;
private double timeSyncAdjustment = 1.0D;
public MillisTimer(float p_i1018_1_) {
this.ticksPerSecond = p_i1018_1_;
this.lastSyncSysClock = this.getLastSyncSysClock();
this.lastSyncHRClock = System.nanoTime() / 1000000L;
}
/**
* Updates all fields of the Timer using the current time
*/
public void updateTimer() {
long i = this.getLastSyncSysClock();
long j = i - this.lastSyncSysClock;
long k = System.nanoTime() / 1000000L;
double d0 = (double) k / 1000.0D;
if (j <= 1000L && j >= 0L) {
this.field_74285_i += j;
if (this.field_74285_i > 1000L) {
long l = k - this.lastSyncHRClock;
double d1 = (double) this.field_74285_i / (double) l;
this.timeSyncAdjustment += (d1 - this.timeSyncAdjustment) * 0.20000000298023224D;
this.lastSyncHRClock = k;
this.field_74285_i = 0L;
}
if (this.field_74285_i < 0L) {
this.lastSyncHRClock = k;
}
} else {
this.lastHRTime = d0;
}
this.lastSyncSysClock = i;
double d2 = (d0 - this.lastHRTime) * this.timeSyncAdjustment;
this.lastHRTime = d0;
if (d2 < 0.0D) {
d2 = 0.0D;
}
if (d2 > 1.0D) {
d2 = 1.0D;
}
this.elapsedPartialTicks = (float) ((double) this.elapsedPartialTicks + d2 * (double) this.timerSpeed * (double) this.ticksPerSecond);
this.elapsedTicks = (int) this.elapsedPartialTicks;
this.elapsedPartialTicks -= (float) this.elapsedTicks;
if (this.elapsedTicks > 10) {
this.elapsedTicks = 10;
}
this.renderPartialTicks = this.elapsedPartialTicks;
}
private long getLastSyncSysClock() {
return System.nanoTime() / 1_000_000L;
}
}
@@ -0,0 +1,34 @@
package noppes.npcs.util;
import java.lang.reflect.Field;
public class SizeOfObjectUtil {
public static long sizeOfObject(Object obj) {
long size = 0;
for (Field field : obj.getClass().getDeclaredFields()) {
try {
field.setAccessible(true);
Class<?> type = field.getType();
if (type == int.class || type == Integer.class) {
size += Integer.BYTES;
} else if (type == long.class || type == Long.class) {
size += Long.BYTES;
} else if (type == byte.class || type == Byte.class) {
size += Byte.BYTES;
} else if (type == boolean.class || type == Boolean.class) {
size += 1; // Assuming 1 byte for boolean
} // Add more cases for other primitive types if needed
else {
// If it's a reference type, recursively calculate its size
Object value = field.get(obj);
if (value != null) {
size += sizeOfObject(value);
}
}
} catch (IllegalAccessException e) {
// Handle exception
}
}
return size;
}
}
@@ -0,0 +1,72 @@
package noppes.npcs.util;
public class ValueUtil {
public static float lerp(float start, float end, float delta) {
return start + delta * (end - start);
}
public static double lerp(double start, double end, double delta) {
return start + delta * (end - start);
}
public static float clamp(float given, float min, float max) {
if (given < min)
return min;
return Math.min(given, max);
}
public static int clamp(int given, int min, int max) {
if (given < min)
return min;
return Math.min(given, max);
}
public static byte clamp(byte given, byte min, byte max) {
if (given < min)
return min;
if (given > max)
return max;
return given;
}
public static double clamp(double given, double min, double max) {
if (given < min)
return min;
return Math.min(given, max);
}
public static long clamp(long given, long min, long max) {
if (given < min)
return min;
return Math.min(given, max);
}
public static float correctFloat(float given, float min, float max) {
if (given < min)
return min;
if (given > max)
return max;
return given;
}
public static int CorrectInt(int given, int min, int max) {
if (given < min)
return min;
if (given > max)
return max;
return given;
}
public static String format(double value) {
return (value % 1 == 0) ? String.format("%.0f", value) : String.format("%.2f", value);
}
public static String format(String precision, float value) {
return (value % 1 == 0) ? String.format("%.0f", value) : String.format(precision, value);
}
public static String format(String precision, double value) {
return (value % 1 == 0) ? String.format("%.0f", value) : String.format(precision, value);
}
}