mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 22:27:32 +00:00
merged separate gui packet calls in the ProfileChangePacket
This commit is contained in:
1 parent
e973605be6
commit
43bf4d3427
4 files changed
+43
-19
No files matched your search
@@ -10,8 +10,10 @@ import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumPlayerPacket;
|
||||
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
|
||||
@@ -60,8 +62,13 @@ public final class ProfileChangePacket extends AbstractPacket {
|
||||
|
||||
int slot = in.readInt();
|
||||
ProfileOperation operation = ProfileController.Instance.changeSlot(player, slot);
|
||||
ProfileGetPacket.sendProfileNBT(player);
|
||||
ProfileGetInfoPacket.sendProfileInfo(player);
|
||||
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setBoolean("CHANGE_PACKET", true);
|
||||
compound.setTag("PROFILE", ProfileGetPacket.profileNBTPayload(player));
|
||||
compound.setTag("PROFILE_INFO", ProfileGetInfoPacket.profileInfoPayload(player));
|
||||
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
|
||||
|
||||
ChatAlertPacket.sendChatAlert((EntityPlayerMP) player, operation.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,10 @@ public final class ProfileGetInfoPacket extends AbstractPacket {
|
||||
}
|
||||
|
||||
public static void sendProfileInfo(EntityPlayer player) {
|
||||
GuiDataPacket.sendGuiData((EntityPlayerMP) player, profileInfoPayload(player));
|
||||
}
|
||||
|
||||
public static NBTTagCompound profileInfoPayload(EntityPlayer player) {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setBoolean("PROFILE_INFO", true);
|
||||
NBTTagList slotList = new NBTTagList();
|
||||
@@ -75,7 +79,7 @@ public final class ProfileGetInfoPacket extends AbstractPacket {
|
||||
}
|
||||
compound.setTag("SLOTS", slotList);
|
||||
}
|
||||
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public static HashMap<Integer, List<ProfileInfoEntry>> readProfileInfo(NBTTagCompound compound) {
|
||||
|
||||
@@ -50,9 +50,13 @@ public final class ProfileGetPacket extends AbstractPacket {
|
||||
}
|
||||
|
||||
public static void sendProfileNBT(EntityPlayer player) {
|
||||
GuiDataPacket.sendGuiData((EntityPlayerMP) player, profileNBTPayload(player));
|
||||
}
|
||||
|
||||
public static NBTTagCompound profileNBTPayload(EntityPlayer player) {
|
||||
Profile profile = ProfileController.Instance.getProfile(player);
|
||||
NBTTagCompound compound = profile.writeToNBT();
|
||||
compound.setBoolean("PROFILE", true);
|
||||
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
|
||||
return compound;
|
||||
}
|
||||
}
|
||||
@@ -335,22 +335,15 @@ public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, IC
|
||||
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
this.slot = null;
|
||||
if (compound.hasKey("PROFILE")) {
|
||||
// Load Profile
|
||||
this.profile = new Profile(mc.thePlayer, compound);
|
||||
this.data = new HashMap<>();
|
||||
String currentSlot = "\u00A7e";
|
||||
String otherSlot = "\u00A7f";
|
||||
for (ISlot slot1 : profile.getSlots().values()) {
|
||||
String name = slot1.getId() + " - " + slot1.getName();
|
||||
if (profile.currentSlotId == slot1.getId())
|
||||
name = currentSlot + name;
|
||||
else
|
||||
name = otherSlot + name;
|
||||
this.data.put(name, slot1.getId());
|
||||
}
|
||||
if (compound.hasKey("CHANGE_PACKET")) {
|
||||
this.readProfileCompound(
|
||||
compound.getCompoundTag("PROFILE"));
|
||||
this.slotInfoMap = ProfileGetInfoPacket.readProfileInfo(
|
||||
compound.getCompoundTag("PROFILE_INFO"));
|
||||
} else if (compound.hasKey("PROFILE")) {
|
||||
this.readProfileCompound(compound);
|
||||
} else if (compound.hasKey("PROFILE_INFO")) {
|
||||
slotInfoMap = ProfileGetInfoPacket.readProfileInfo(compound);
|
||||
this.slotInfoMap = ProfileGetInfoPacket.readProfileInfo(compound);
|
||||
}
|
||||
if (scroll != null) {
|
||||
scroll.setSelected("");
|
||||
@@ -358,6 +351,22 @@ public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, IC
|
||||
initGui();
|
||||
}
|
||||
|
||||
private void readProfileCompound(NBTTagCompound compound) {
|
||||
// Load Profile
|
||||
this.profile = new Profile(mc.thePlayer, compound);
|
||||
this.data = new HashMap<>();
|
||||
String currentSlot = "\u00A7e";
|
||||
String otherSlot = "\u00A7f";
|
||||
for (ISlot slot1 : profile.getSlots().values()) {
|
||||
String name = slot1.getId() + " - " + slot1.getName();
|
||||
if (profile.currentSlotId == slot1.getId())
|
||||
name = currentSlot + name;
|
||||
else
|
||||
name = otherSlot + name;
|
||||
this.data.put(name, slot1.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles mouse clicks for the scrollbar.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user