Merge Dev into PR 110

This commit is contained in:
Kam committed 2024-01-18 14:45:08 -05:00
commit 3e43855128
39 files changed
+1149 -355

No files matched your search

@@ -3,15 +3,12 @@ package noppes.npcs.controllers;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.api.handler.IAnimationHandler;
import noppes.npcs.api.handler.data.IAnimation;
import noppes.npcs.api.handler.data.IFaction;
import noppes.npcs.controllers.data.Animation;
import noppes.npcs.controllers.data.Faction;
import noppes.npcs.controllers.data.TagMap;
import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.util.NBTJsonUtil;
import java.io.*;
@@ -120,6 +117,10 @@ public class AnimationController implements IAnimationHandler {
animations.remove(animation.getID());
animations.put(animation.getID(), (Animation) animation);
for (PlayerData playerData : PlayerDataController.Instance.getAllPlayerData()) {
playerData.animationData.uncacheAnimation(animation.getID());
}
saveAnimationMap();
// Save Animation File
@@ -0,0 +1,47 @@
package noppes.npcs.controllers;
import net.minecraft.entity.player.EntityPlayer;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.controllers.data.Party;
import noppes.npcs.controllers.data.PlayerData;
import java.util.HashMap;
import java.util.UUID;
public class PartyController {
private static PartyController Instance;
private HashMap<UUID, Party> parties = new HashMap<>();
private PartyController() {
}
public static PartyController Instance() {
if (Instance == null) {
Instance = new PartyController();
}
return Instance;
}
public Party createParty() {
Party party = new Party();
this.parties.put(party.getPartyUUID(), party);
return party;
}
public Party getParty(UUID partyUUID) {
return this.parties.get(partyUUID);
}
public void disbandParty(UUID partyUUID) {
Party party = this.parties.get(partyUUID);
if (party != null) {
for (UUID uuid: party.getPlayerUUIDs()) {
EntityPlayer player = NoppesUtilServer.getPlayer(uuid);
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
playerData.partyUUID = null;
}
this.parties.remove(partyUUID);
}
}
}
@@ -281,6 +281,17 @@ public class PlayerDataController {
return data;
}
public ArrayList<PlayerData> getAllPlayerData() {
ArrayList<PlayerData> playerDataList = new ArrayList<>();
List<?> list = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
for (Object o : list) {
if (o instanceof EntityPlayer) {
playerDataList.add(this.getPlayerData((EntityPlayer)o));
}
}
return playerDataList;
}
public PlayerData getPlayerData(EntityPlayer player){
PlayerData data = getPlayerDataCache(player.getUniqueID().toString());
if(data != null){
@@ -2,6 +2,7 @@ package noppes.npcs.controllers.data;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.api.handler.data.IAnimation;
@@ -13,7 +14,7 @@ import java.util.ArrayList;
public class Animation implements IAnimation {
public AnimationData parent; //Client-sided only
public int id = -1; // Only for internal usage
public ArrayList<Frame> frames = new ArrayList<>();
@@ -229,6 +230,10 @@ public class Animation implements IAnimation {
if (paused)
return;
if (this.parent != null && this.currentFrame < this.frames.size()) {
this.parent.finishedFrame = this.currentFrame;
}
this.currentFrameTime++;
if (this.currentFrameTime == this.currentFrame().getDuration()) {
Frame prevFrame = (Frame) this.currentFrame();
@@ -247,6 +252,8 @@ public class Animation implements IAnimation {
nextFrame.frameParts.get(part).prevPivots = prevFrame.frameParts.get(part).prevPivots;
}
}
} else if (this.parent != null && this.currentFrame > this.loop) {
this.parent.finishedTime = this.parent.animationEntity.getAge();
}
}
}
@@ -1,17 +1,23 @@
package noppes.npcs.controllers.data;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import noppes.npcs.DataDisplay;
import noppes.npcs.Server;
import noppes.npcs.api.handler.data.IAnimationData;
import noppes.npcs.api.handler.data.IAnimation;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.controllers.data.Animation;
import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.entity.EntityNPCInterface;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
public class AnimationData implements IAnimationData {
//Server-side: DataDisplay, PlayerData
//Client-side: DataDisplay, EntityPlayer
@@ -20,19 +26,45 @@ public class AnimationData implements IAnimationData {
public Animation animation;
public boolean allowAnimation = false;
private final HashSet<Integer> cachedAnimationIDs = new HashSet<>();
//Client-side values
public EntityLivingBase animationEntity;
public int finishedTime = -1;
public int finishedFrame = -1;
public AnimationData(Object parent){
this.parent = parent;
if (parent instanceof DataDisplay) {
this.animationEntity = ((DataDisplay) parent).npc;
} else if (parent instanceof EntityPlayer) {
this.animationEntity = (EntityLivingBase) parent;
}
}
public void updateClient() {
NBTTagCompound compound = new NBTTagCompound();
compound = this.writeToNBT(compound);
compound.setTag("Animation",this.animation == null ? new NBTTagCompound() : this.animation.writeToNBT());
if (parent instanceof PlayerData) {
Server.sendToAll(EnumPacketClient.UPDATE_ANIMATIONS, compound, ((PlayerData) parent).player.getCommandSenderName());
} else if (parent instanceof DataDisplay) {
compound.setInteger("EntityId",((DataDisplay) parent).npc.getEntityId());
Server.sendAssociatedData(((DataDisplay) parent).npc, EnumPacketClient.UPDATE_ANIMATIONS, compound);
this.updateClient(new EntityPlayer[0]);
}
public void updateClient(EntityPlayer... excludedPlayers) {
EntityLivingBase sendingEntity = parent instanceof PlayerData ? ((PlayerData) parent).player : parent instanceof DataDisplay ? ((DataDisplay) parent).npc : null;
float range = parent instanceof PlayerData ? 160 : 60;
if (sendingEntity != null) {
List<EntityPlayer> entities = sendingEntity.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(
sendingEntity.posX - range, sendingEntity.posY - range, sendingEntity.posZ - range,
sendingEntity.posX + range, sendingEntity.posY + range, sendingEntity.posZ + range));
entities.removeIf(player -> Arrays.stream(excludedPlayers).anyMatch(exp -> player == exp));
NBTTagCompound animationNBT = null;
for (EntityPlayer player : entities) {
AnimationData animationData = PlayerDataController.Instance.getPlayerData(player).animationData;
if (animationNBT == null && this.animation != null && !animationData.isCached(this.animation.getID())) {
animationNBT = this.animation.writeToNBT();
}
animationData.viewAnimation(this.animation, sendingEntity, this, animationNBT);
}
}
}
@@ -62,17 +94,49 @@ public class AnimationData implements IAnimationData {
}
}
public boolean isCached(int id) {
return this.cachedAnimationIDs.contains(id);
}
public void cacheAnimation(int id) {
this.cachedAnimationIDs.add(id);
}
public void uncacheAnimation(int id) {
this.cachedAnimationIDs.remove(id);
}
public void viewAnimation(Animation animation, EntityLivingBase entity, AnimationData animationData, NBTTagCompound animationNBT) {
NBTTagCompound data = animationData.writeToNBT(new NBTTagCompound());
if (animation != null) {
if (this.cachedAnimationIDs.contains(animation.getID())) {
data.setInteger("AnimationID", animation.getID());
} else {
data.setTag("Animation", animationNBT);
}
}
if (!(entity instanceof EntityPlayer)) {
data.setInteger("EntityId", entity.getEntityId());
}
Server.sendData((EntityPlayerMP) ((PlayerData) parent).player, EnumPacketClient.UPDATE_ANIMATIONS, data, entity.getCommandSenderName());
}
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
compound.setBoolean("AllowAnimation", allowAnimation);
return compound;
}
public void readFromNBT(NBTTagCompound compound) {
this.allowAnimation = compound.getBoolean("AllowAnimation");
this.setEnabled(compound.getBoolean("AllowAnimation"));
}
public void setEnabled(boolean enabled) {
this.allowAnimation = enabled;
if (this.allowAnimation != enabled) {
this.allowAnimation = enabled;
if (this.parent instanceof EntityPlayer) {
this.finishedTime = enabled ? -1 : ((EntityPlayer) this.parent).getAge();
}
}
}
public boolean enabled() {
@@ -2,9 +2,11 @@ package noppes.npcs.controllers.data;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import noppes.npcs.api.entity.IEntityLivingBase;
import noppes.npcs.api.handler.data.ILine;
public class Line {
public class Line implements ILine {
public Line(){
@@ -17,21 +19,55 @@ public class Line {
public String sound = "";
public boolean hideText = false;
public Line copy() {
public ILine copy() {
Line line = new Line(text);
line.sound = sound;
line.hideText = hideText;
return line;
}
public Line formatTarget(EntityLivingBase entity) {
public ILine formatTarget(EntityLivingBase entity) {
if(entity == null)
return this;
Line line = copy();
Line line = (Line) copy();
if(entity instanceof EntityPlayer)
line.text = line.text.replace("@target", ((EntityPlayer) entity).getDisplayName());
else
line.text = line.text.replace("@target", entity.getCommandSenderName());
return line;
}
public ILine formatTarget(IEntityLivingBase entityLivingBase) {
return this.formatTarget(entityLivingBase.getMCEntity());
}
@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;
}
}
@@ -2,13 +2,15 @@ package noppes.npcs.controllers.data;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.api.handler.data.ILine;
import noppes.npcs.api.handler.data.ILines;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
public class Lines {
public class Lines implements ILines {
private static final Random random = new Random();
private int lastLine = -1;
@@ -49,7 +51,11 @@ public class Lines {
lines = map;
}
public Line getLine(boolean isRandom) {
public ILine createLine(String text) {
return new Line(text);
}
public ILine getLine(boolean isRandom) {
if(lines.isEmpty())
return null;
if(isRandom){
@@ -66,7 +72,27 @@ public class Lines {
}
}
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]);
}
}
@@ -2,7 +2,13 @@ package noppes.npcs.controllers.data;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.api.handler.IPlayerQuestData;
import noppes.npcs.api.handler.data.IQuest;
import noppes.npcs.controllers.PlayerDataController;
@@ -14,8 +20,7 @@ import java.net.URL;
import java.util.*;
public class Party {
private final UUID partyUUID = UUID.randomUUID();
private final UUID partyUUID;
private UUID partyLeader;
private final HashMap<UUID, String> partyMembers = new HashMap<>();
@@ -23,12 +28,21 @@ public class Party {
private int currentQuestID = -1;
public UUID getPartyLeader() {
return partyLeader;
private boolean friendlyFire;
//Client-sided
private String partyLeaderName;
public Party() {
this.partyUUID = UUID.randomUUID();
}
public void setPartyLeader(UUID partyLeader) {
this.partyLeader = partyLeader;
public Party(UUID uuid) {
this.partyUUID = uuid;
}
public UUID getPartyUUID() {
return this.partyUUID;
}
public int getCurrentQuestID() {
@@ -44,6 +58,9 @@ public class Party {
return false;
}
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
playerData.partyUUID = this.partyUUID;
partyMembers.put(player.getUniqueID(), player.getCommandSenderName());
partyOrder.add(player.getUniqueID());
return true;
@@ -71,12 +88,13 @@ public class Party {
return false;
}
public boolean removePlayer(UUID player) {
if(partyMembers.containsKey(player)){
partyMembers.remove(player);
partyOrder.remove(player);
public boolean removePlayer(EntityPlayer player) {
UUID uuid = player.getUniqueID();
if(partyMembers.containsKey(uuid)){
partyMembers.remove(uuid);
partyOrder.remove(uuid);
if(player.equals(partyLeader)){
if(uuid.equals(partyLeader)){
if(partyMembers.size() > 0){
partyLeader = partyOrder.get(0);
}
@@ -88,8 +106,8 @@ public class Party {
return false;
}
public boolean hasPlayer(UUID player) {
return partyMembers.containsKey(player);
public boolean hasPlayer(EntityPlayer player) {
return partyMembers.containsKey(player.getUniqueID());
}
public boolean hasPlayer(String playerName) {
@@ -100,8 +118,18 @@ public class Party {
return partyMembers.containsKey(uuid);
}
public boolean setLeader(UUID uuid){
if(partyLeader.equals(uuid)){
public EntityPlayer getPartyLeader() {
return NoppesUtilServer.getPlayer(this.partyLeader);
}
@SideOnly(Side.CLIENT)
public String getPartyLeaderName() {
return this.partyLeaderName;
}
public boolean setLeader(EntityPlayer player){
UUID uuid = player.getUniqueID();
if(partyLeader != null && partyLeader.equals(uuid)){
return false;
}
@@ -120,6 +148,14 @@ public class Party {
return true;
}
public Collection<String> getPlayerNames() {
return this.partyMembers.values();
}
public Collection<UUID> getPlayerUUIDs() {
return this.partyMembers.keySet();
}
// To Be Called DURING Invite, Leave, Quest Switch, Leader Switch, etc.
public static boolean validateQuest(int questID, Collection<EntityPlayer> players){
IQuest quest = QuestController.Instance.get(questID);
@@ -154,6 +190,14 @@ public class Party {
}
}
public void toggleFriendlyFire() {
this.friendlyFire = !this.friendlyFire;
}
public boolean friendlyFire() {
return this.friendlyFire;
}
public static UUID getUUID(String name) {
UUID uuid = null;
try {
@@ -168,4 +212,35 @@ public class Party {
return uuid;
}
public void readFromNBT(NBTTagCompound compound) {
this.partyLeaderName = compound.getString("PartyLeader");
this.currentQuestID = compound.getInteger("PartyQuestID");
NBTTagList list = compound.getTagList("PartyMembers", 10);
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound tagCompound = list.getCompoundTagAt(i);
UUID uuid = UUID.fromString(tagCompound.getString("UUID"));
String playerName = tagCompound.getString("PlayerName");
this.partyOrder.add(uuid);
this.partyMembers.put(uuid, playerName);
}
}
public NBTTagCompound writeToNBT() {
NBTTagCompound compound = new NBTTagCompound();
compound.setString("PartyUUID", this.partyUUID.toString());
compound.setInteger("PartyQuestID", this.currentQuestID);
compound.setString("PartyLeader", getPartyLeader().getCommandSenderName());
NBTTagList list = new NBTTagList();
for (UUID uuid : this.partyOrder) {
NBTTagCompound uuidCompound = new NBTTagCompound();
uuidCompound.setString("UUID", uuid.toString());
uuidCompound.setString("PlayerName", this.partyMembers.get(uuid));
list.appendTag(uuidCompound);
}
compound.setTag("PartyMembers", list);
return compound;
}
}