mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-28 11:16:02 +00:00
Profile + Effect Loading
This commit is contained in:
1 parent
e8f657f7e6
commit
5a38f9057f
9 files changed
+354
-139
No files matched your search
@@ -232,7 +232,7 @@ public class CommandProfileAdmin extends CommandProfileBase {
|
||||
return;
|
||||
}
|
||||
String targetPlayer = args[0];
|
||||
String backupFileName = args[1];
|
||||
String backupFileName = args[1] += ".dat";
|
||||
File backupDir = new File(ProfileController.getBackupDir(), ProfileController.getProfile(targetPlayer).player.getUniqueID().toString());
|
||||
File backupFile = new File(backupDir, backupFileName);
|
||||
if(!backupFile.exists()){
|
||||
|
||||
@@ -576,6 +576,40 @@ public class ProfileController {
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> getProfileInfo(EntityPlayer player, int slotId) {
|
||||
List<String> infoList = new ArrayList<>();
|
||||
Profile profile = getProfile(player);
|
||||
if (profile == null)
|
||||
return infoList;
|
||||
|
||||
List<IProfileData> dataList = new ArrayList<>(profileTypes.values());
|
||||
dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority));
|
||||
|
||||
if (slotId == profile.currentID) {
|
||||
// Use current data (not stored slot data) for active slot.
|
||||
for (IProfileData pd : dataList) {
|
||||
NBTTagCompound currentNBT = pd.getCurrentNBT(player);
|
||||
List<String> subInfo = pd.getInfo(player, currentNBT);
|
||||
infoList.addAll(subInfo);
|
||||
}
|
||||
} else {
|
||||
// Use stored data from the specified slot.
|
||||
if (!profile.slots.containsKey(slotId))
|
||||
return infoList;
|
||||
NBTTagCompound slotCompound = profile.slots.get(slotId).getCompound();
|
||||
for (IProfileData pd : dataList) {
|
||||
if (slotCompound.hasKey(pd.getTagName())) {
|
||||
NBTTagCompound sub = slotCompound.getCompoundTag(pd.getTagName());
|
||||
List<String> subInfo = pd.getInfo(player, sub);
|
||||
infoList.addAll(subInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
return infoList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static EntityPlayerMP getPlayer(String username){
|
||||
return MinecraftServer.getServer().getConfigurationManager().func_152612_a(username);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CNPCData implements IProfileData {
|
||||
|
||||
@@ -33,7 +35,8 @@ public class CNPCData implements IProfileData {
|
||||
PlayerData newData = new PlayerData();
|
||||
newData.player = player;
|
||||
customNPCData.setNBT((NBTTagCompound) newData.getNBT().copy());
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
customNPCData.setNBT(replace);
|
||||
}
|
||||
customNPCData.updateClient = true;
|
||||
@@ -48,4 +51,19 @@ public class CNPCData implements IProfileData {
|
||||
public boolean verifySwitch(EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getInfo(EntityPlayer player, NBTTagCompound compound) {
|
||||
PlayerData playerData = new PlayerData();
|
||||
playerData.player = player;
|
||||
playerData.setNBT(compound);
|
||||
|
||||
List<String> info = new ArrayList<>();
|
||||
|
||||
info.add("QuestsFinished" + "###" + playerData.questData.finishedQuests.size());
|
||||
info.add("QuestsActive" + "###" + playerData.questData.activeQuests.size());
|
||||
info.add("DialogsRead" + "###" + playerData.dialogData.dialogsRead.size());
|
||||
|
||||
return info;
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,12 @@ package kamkeel.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import java.util.List;
|
||||
|
||||
public interface IProfileData {
|
||||
|
||||
/**
|
||||
* Do not use the tags: Name, lastLoaded, ID.
|
||||
*
|
||||
* @return The save tag utilized in the Profile.
|
||||
*/
|
||||
public String getTagName();
|
||||
@@ -39,4 +39,13 @@ public interface IProfileData {
|
||||
* @return true if allowed, false if not.
|
||||
*/
|
||||
public boolean verifySwitch(EntityPlayer player);
|
||||
|
||||
/**
|
||||
* NEW: Builds and returns a list of informational strings about this profile data,
|
||||
* based on the provided NBTTagCompound from the slot.
|
||||
* @param player The player in question.
|
||||
* @param compound The NBT data from the slot under this profile data's tag.
|
||||
* @return A list of strings with information (could be empty).
|
||||
*/
|
||||
public List<String> getInfo(EntityPlayer player, NBTTagCompound compound);
|
||||
}
|
||||
@@ -56,6 +56,7 @@ import kamkeel.npcs.network.packets.request.pather.MovingPathSavePacket;
|
||||
import kamkeel.npcs.network.packets.request.playerdata.PlayerDataGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.playerdata.PlayerDataMapRegenPacket;
|
||||
import kamkeel.npcs.network.packets.request.playerdata.PlayerDataRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.profile.ProfileGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.quest.*;
|
||||
import kamkeel.npcs.network.packets.request.recipe.RecipeGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.recipe.RecipeRemovePacket;
|
||||
@@ -323,6 +324,9 @@ public class PacketHandler {
|
||||
REQUEST_PACKET.registerPacket(new EffectSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new EffectRemovePacket());
|
||||
|
||||
// Profile Packets
|
||||
REQUEST_PACKET.registerPacket(new ProfileGetPacket());
|
||||
|
||||
// Other Packets
|
||||
REQUEST_PACKET.registerPacket(new IsGuiOpenInform());
|
||||
REQUEST_PACKET.registerPacket(new GuiRequestPacket());
|
||||
|
||||
@@ -185,5 +185,5 @@ public enum EnumRequestPacket {
|
||||
EffectSave,
|
||||
|
||||
ColorSet,
|
||||
ColorBrush
|
||||
ProfileGet, ProfileGetAll, ColorBrush
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package kamkeel.npcs.network.packets.request.profile;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.data.Profile;
|
||||
import kamkeel.npcs.network.*;
|
||||
import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.controllers.LinkedItemController;
|
||||
import noppes.npcs.controllers.LinkedNpcController;
|
||||
import noppes.npcs.controllers.data.LinkedItem;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class ProfileGetPacket extends AbstractPacket {
|
||||
public static String packetName = "Request|ProfileGet";
|
||||
|
||||
public ProfileGetPacket() {}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.ProfileGet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
|
||||
Profile profile = ProfileController.getProfile(player);
|
||||
NBTTagCompound compound = profile.writeToNBT();
|
||||
compound.setBoolean("PROFILE", true);
|
||||
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user