mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 21:17:32 +00:00
Register mail packets
This commit is contained in:
1 parent
a2a3d94de6
commit
94fc6e035c
6 files changed
+112
-110
No files matched your search
@@ -14,10 +14,7 @@ import kamkeel.npcs.network.packets.data.gui.IsGuiOpenPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.*;
|
||||
import kamkeel.npcs.network.packets.data.npc.*;
|
||||
import kamkeel.npcs.network.packets.data.script.*;
|
||||
import kamkeel.npcs.network.packets.player.BankActionPacket;
|
||||
import kamkeel.npcs.network.packets.player.FollowerPacket;
|
||||
import kamkeel.npcs.network.packets.player.InputDevicePacket;
|
||||
import kamkeel.npcs.network.packets.player.TransportPacket;
|
||||
import kamkeel.npcs.network.packets.player.*;
|
||||
import kamkeel.npcs.network.packets.request.*;
|
||||
import kamkeel.npcs.network.packets.request.animation.*;
|
||||
import kamkeel.npcs.network.packets.request.bank.BankGetPacket;
|
||||
@@ -351,6 +348,9 @@ public class PacketHandler {
|
||||
|
||||
PLAYER_PACKET.registerPacket(new BankActionPacket());
|
||||
|
||||
PLAYER_PACKET.registerPacket(new MailActionPacket());
|
||||
PLAYER_PACKET.registerPacket(new MailActionPacket.MailSendPacket());
|
||||
|
||||
PLAYER_PACKET.registerPacket(new InputDevicePacket());
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class MailActionPacket extends AbstractPacket {
|
||||
public static final String packetName = "Player|Mail";
|
||||
public static final String packetName = "Player|MailAction";
|
||||
|
||||
private Action action;
|
||||
private long time;
|
||||
|
||||
@@ -204,83 +204,83 @@ public class PacketHandlerPlayer{
|
||||
PlayerFactionData data = PlayerDataController.Instance.getPlayerData(player).factionData;
|
||||
GuiDataPacket.sendGuiData(player, data.getPlayerGuiData());
|
||||
}
|
||||
else if(type == EnumPlayerPacket.MailGet){
|
||||
PlayerMailData data = PlayerDataController.Instance.getPlayerData(player).mailData;
|
||||
GuiDataPacket.sendGuiData(player, data.saveNBTData(new NBTTagCompound()));
|
||||
}
|
||||
else if(type == EnumPlayerPacket.MailDelete){
|
||||
long time = buffer.readLong();
|
||||
String username = ByteBufUtils.readString(buffer);
|
||||
PlayerMailData data = PlayerDataController.Instance.getPlayerData(player).mailData;
|
||||
|
||||
Iterator<PlayerMail> it = data.playermail.iterator();
|
||||
while(it.hasNext()){
|
||||
PlayerMail mail = it.next();
|
||||
if(mail.time == time && mail.sender.equals(username)){
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
GuiDataPacket.sendGuiData(player, data.saveNBTData(new NBTTagCompound()));
|
||||
}
|
||||
else if(type == EnumPlayerPacket.MailSend){
|
||||
if(!(player.openContainer instanceof ContainerMail))
|
||||
return;
|
||||
String username = PlayerDataController.Instance.hasPlayer(ByteBufUtils.readString(buffer));
|
||||
if(username.isEmpty()){
|
||||
NoppesUtilServer.sendGuiError(player, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerMail mail = new PlayerMail();
|
||||
//String s = player.func_145748_c_().getFormattedText();
|
||||
String s = player.getDisplayName();
|
||||
if(!s.equals(player.getCommandSenderName()))
|
||||
s += "(" + player.getCommandSenderName() + ")";
|
||||
mail.readNBT(ByteBufUtils.readNBT(buffer));
|
||||
mail.sender = s;
|
||||
mail.items = ((ContainerMail)player.openContainer).mail.items;
|
||||
|
||||
if(mail.subject.isEmpty()){
|
||||
NoppesUtilServer.sendGuiError(player, 1);
|
||||
return;
|
||||
}
|
||||
PlayerDataController.Instance.addPlayerMessage(username, mail);
|
||||
|
||||
NBTTagCompound comp = new NBTTagCompound();
|
||||
comp.setString("username", username);
|
||||
NoppesUtilServer.sendGuiClose(player, 1,comp);
|
||||
}
|
||||
else if(type == EnumPlayerPacket.MailboxOpenMail){
|
||||
long time = buffer.readLong();
|
||||
String username = ByteBufUtils.readString(buffer);
|
||||
player.closeContainer();
|
||||
PlayerMailData data = PlayerDataController.Instance.getPlayerData(player).mailData;
|
||||
|
||||
Iterator<PlayerMail> it = data.playermail.iterator();
|
||||
while(it.hasNext()){
|
||||
PlayerMail mail = it.next();
|
||||
if(mail.time == time && mail.sender.equals(username)){
|
||||
ContainerMail.staticmail = mail;
|
||||
player.openGui(CustomNpcs.instance, EnumGuiType.PlayerMailman.ordinal(), player.worldObj, 0, 0, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(type == EnumPlayerPacket.MailRead){
|
||||
long time = buffer.readLong();
|
||||
String username = ByteBufUtils.readString(buffer);
|
||||
PlayerMailData data = PlayerDataController.Instance.getPlayerData(player).mailData;
|
||||
|
||||
Iterator<PlayerMail> it = data.playermail.iterator();
|
||||
while(it.hasNext()){
|
||||
PlayerMail mail = it.next();
|
||||
if(mail.time == time && mail.sender.equals(username)){
|
||||
mail.beenRead = true;
|
||||
if(mail.hasQuest())
|
||||
PlayerQuestController.addActiveQuest(new QuestData(mail.getQuest()), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
// else if(type == EnumPlayerPacket.MailGet){
|
||||
// PlayerMailData data = PlayerDataController.Instance.getPlayerData(player).mailData;
|
||||
// GuiDataPacket.sendGuiData(player, data.saveNBTData(new NBTTagCompound()));
|
||||
// }
|
||||
// else if(type == EnumPlayerPacket.MailDelete){
|
||||
// long time = buffer.readLong();
|
||||
// String username = ByteBufUtils.readString(buffer);
|
||||
// PlayerMailData data = PlayerDataController.Instance.getPlayerData(player).mailData;
|
||||
//
|
||||
// Iterator<PlayerMail> it = data.playermail.iterator();
|
||||
// while(it.hasNext()){
|
||||
// PlayerMail mail = it.next();
|
||||
// if(mail.time == time && mail.sender.equals(username)){
|
||||
// it.remove();
|
||||
// }
|
||||
// }
|
||||
// GuiDataPacket.sendGuiData(player, data.saveNBTData(new NBTTagCompound()));
|
||||
// }
|
||||
// else if(type == EnumPlayerPacket.MailSend){
|
||||
// if(!(player.openContainer instanceof ContainerMail))
|
||||
// return;
|
||||
// String username = PlayerDataController.Instance.hasPlayer(ByteBufUtils.readString(buffer));
|
||||
// if(username.isEmpty()){
|
||||
// NoppesUtilServer.sendGuiError(player, 0);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// PlayerMail mail = new PlayerMail();
|
||||
// //String s = player.func_145748_c_().getFormattedText();
|
||||
// String s = player.getDisplayName();
|
||||
// if(!s.equals(player.getCommandSenderName()))
|
||||
// s += "(" + player.getCommandSenderName() + ")";
|
||||
// mail.readNBT(ByteBufUtils.readNBT(buffer));
|
||||
// mail.sender = s;
|
||||
// mail.items = ((ContainerMail)player.openContainer).mail.items;
|
||||
//
|
||||
// if(mail.subject.isEmpty()){
|
||||
// NoppesUtilServer.sendGuiError(player, 1);
|
||||
// return;
|
||||
// }
|
||||
// PlayerDataController.Instance.addPlayerMessage(username, mail);
|
||||
//
|
||||
// NBTTagCompound comp = new NBTTagCompound();
|
||||
// comp.setString("username", username);
|
||||
// NoppesUtilServer.sendGuiClose(player, 1,comp);
|
||||
// }
|
||||
// else if(type == EnumPlayerPacket.MailboxOpenMail){
|
||||
// long time = buffer.readLong();
|
||||
// String username = ByteBufUtils.readString(buffer);
|
||||
// player.closeContainer();
|
||||
// PlayerMailData data = PlayerDataController.Instance.getPlayerData(player).mailData;
|
||||
//
|
||||
// Iterator<PlayerMail> it = data.playermail.iterator();
|
||||
// while(it.hasNext()){
|
||||
// PlayerMail mail = it.next();
|
||||
// if(mail.time == time && mail.sender.equals(username)){
|
||||
// ContainerMail.staticmail = mail;
|
||||
// player.openGui(CustomNpcs.instance, EnumGuiType.PlayerMailman.ordinal(), player.worldObj, 0, 0, 0);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else if(type == EnumPlayerPacket.MailRead){
|
||||
// long time = buffer.readLong();
|
||||
// String username = ByteBufUtils.readString(buffer);
|
||||
// PlayerMailData data = PlayerDataController.Instance.getPlayerData(player).mailData;
|
||||
//
|
||||
// Iterator<PlayerMail> it = data.playermail.iterator();
|
||||
// while(it.hasNext()){
|
||||
// PlayerMail mail = it.next();
|
||||
// if(mail.time == time && mail.sender.equals(username)){
|
||||
// mail.beenRead = true;
|
||||
// if(mail.hasQuest())
|
||||
// PlayerQuestController.addActiveQuest(new QuestData(mail.getQuest()), player);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
else if(type == EnumPlayerPacket.SignSave) {
|
||||
int x = buffer.readInt(), y = buffer.readInt(), z = buffer.readInt();
|
||||
if (player.worldObj.blockExists(x, y, z)) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package noppes.npcs.client.gui.player;
|
||||
|
||||
import kamkeel.npcs.network.packets.player.MailActionPacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiYesNo;
|
||||
import net.minecraft.client.gui.GuiYesNoCallback;
|
||||
@@ -18,16 +19,16 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiMailbox extends GuiNPCInterface implements IGuiData, ICustomScrollListener, GuiYesNoCallback{
|
||||
|
||||
|
||||
private GuiCustomScroll scroll;
|
||||
private PlayerMailData data;
|
||||
private PlayerMail selected;
|
||||
|
||||
|
||||
public GuiMailbox() {
|
||||
super();
|
||||
xSize = 256;
|
||||
setBackground("menubg.png");
|
||||
NoppesUtilPlayer.sendData(EnumPlayerPacket.MailGet);
|
||||
MailActionPacket.RequestMailData();
|
||||
}
|
||||
public void initGui()
|
||||
{
|
||||
@@ -39,7 +40,7 @@ public class GuiMailbox extends GuiNPCInterface implements IGuiData, ICustomScro
|
||||
scroll.guiLeft = guiLeft + 4;
|
||||
scroll.guiTop = guiTop + 4;
|
||||
addScroll(scroll);
|
||||
|
||||
|
||||
String title = StatCollector.translateToLocal("mailbox.name");
|
||||
int x = (xSize - this.fontRendererObj.getStringWidth(title)) / 2;
|
||||
|
||||
@@ -81,7 +82,7 @@ public class GuiMailbox extends GuiNPCInterface implements IGuiData, ICustomScro
|
||||
public void confirmClicked(boolean flag, int i)
|
||||
{
|
||||
if(flag && selected != null){
|
||||
NoppesUtilPlayer.sendData(EnumPlayerPacket.MailDelete, selected.time, selected.sender);
|
||||
MailActionPacket.DeleteMail(selected.time, selected.sender);
|
||||
selected = null;
|
||||
}
|
||||
NoppesUtil.openGUI(player, this);
|
||||
@@ -94,7 +95,7 @@ public class GuiMailbox extends GuiNPCInterface implements IGuiData, ICustomScro
|
||||
if(id == 0){
|
||||
GuiMailmanWrite.parent = this;
|
||||
GuiMailmanWrite.mail = selected;
|
||||
NoppesUtilPlayer.sendData(EnumPlayerPacket.MailboxOpenMail, selected.time, selected.sender);
|
||||
MailActionPacket.OpenMail(selected.time, selected.sender);
|
||||
selected = null;
|
||||
scroll.selected = -1;
|
||||
}
|
||||
@@ -103,7 +104,7 @@ public class GuiMailbox extends GuiNPCInterface implements IGuiData, ICustomScro
|
||||
displayGuiScreen(guiyesno);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int i, int j, int k)
|
||||
{
|
||||
@@ -121,13 +122,13 @@ public class GuiMailbox extends GuiNPCInterface implements IGuiData, ICustomScro
|
||||
@Override
|
||||
public void save() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
@Override
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
PlayerMailData data = new PlayerMailData();
|
||||
data.loadNBTData(compound);
|
||||
|
||||
|
||||
List<String> list = new ArrayList<String>();
|
||||
Collections.sort(data.playermail, new Comparator<PlayerMail>(){
|
||||
public int compare(PlayerMail o1, PlayerMail o2){
|
||||
@@ -150,10 +151,10 @@ public class GuiMailbox extends GuiNPCInterface implements IGuiData, ICustomScro
|
||||
GuiCustomScroll guiCustomScroll) {
|
||||
selected = data.playermail.get(guiCustomScroll.selected);
|
||||
initGui();
|
||||
|
||||
|
||||
if(selected != null && !selected.beenRead){
|
||||
selected.beenRead = true;
|
||||
NoppesUtilPlayer.sendData(EnumPlayerPacket.MailRead, selected.time, selected.sender);
|
||||
MailActionPacket.ReadMail(selected.time, selected.sender);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package noppes.npcs.client.gui.player;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.network.packets.player.MailActionPacket;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
@@ -38,15 +39,15 @@ public class GuiMailmanWrite extends GuiContainerNPCInterface implements ITextfi
|
||||
private NBTTagList bookPages;
|
||||
private GuiButtonNextPage buttonNextPage;
|
||||
private GuiButtonNextPage buttonPreviousPage;
|
||||
|
||||
|
||||
private boolean canEdit;
|
||||
private boolean canSend;
|
||||
|
||||
/** The GuiButton to sign this book. */
|
||||
|
||||
|
||||
public static GuiScreen parent;
|
||||
public static PlayerMail mail = new PlayerMail();
|
||||
|
||||
|
||||
private Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
private String username = "";
|
||||
@@ -105,7 +106,7 @@ public class GuiMailmanWrite extends GuiContainerNPCInterface implements ITextfi
|
||||
addLabel(new GuiNpcLabel(0, "mailbox.sender", guiLeft + 170, guiTop + 32, 0));
|
||||
else
|
||||
addLabel(new GuiNpcLabel(0, "mailbox.username", guiLeft + 170, guiTop + 32, 0));
|
||||
|
||||
|
||||
if(canEdit && !canSend)
|
||||
addTextField(new GuiNpcTextField(2, this, fontRendererObj, guiLeft + 170, guiTop + 42, 114, 20, mail.sender));
|
||||
else if(canEdit)
|
||||
@@ -124,7 +125,7 @@ public class GuiMailmanWrite extends GuiContainerNPCInterface implements ITextfi
|
||||
addButton(new GuiNpcButton(0, this.guiLeft + 200, guiTop + 171, 60, 20, "gui.done"));
|
||||
else if(canEdit)
|
||||
addButton(new GuiNpcButton(0, this.guiLeft + 200, guiTop + 171, 60, 20, "mailbox.send"));
|
||||
|
||||
|
||||
if(!canEdit && !canSend)
|
||||
addButton(new GuiNpcButton(4, this.guiLeft + 200, guiTop + 171, 60, 20, "selectWorld.deleteButton"));
|
||||
if(!canEdit || canSend)
|
||||
@@ -148,12 +149,12 @@ public class GuiMailmanWrite extends GuiContainerNPCInterface implements ITextfi
|
||||
this.buttonNextPage.setVisible(this.currPage < this.bookTotalPages - 1 || this.canEdit);
|
||||
this.buttonPreviousPage.setVisible(this.currPage > 0);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void confirmClicked(boolean flag, int i)
|
||||
{
|
||||
if(flag){
|
||||
NoppesUtilPlayer.sendData(EnumPlayerPacket.MailDelete, mail.time, mail.sender);
|
||||
MailActionPacket.DeleteMail(mail.time, mail.sender);
|
||||
close();
|
||||
}
|
||||
else
|
||||
@@ -172,7 +173,7 @@ public class GuiMailmanWrite extends GuiContainerNPCInterface implements ITextfi
|
||||
if(id == 0){
|
||||
mail.message.setTag("pages", bookPages);
|
||||
if(canSend)
|
||||
NoppesUtilPlayer.sendData(EnumPlayerPacket.MailSend, this.username, mail.writeNBT());
|
||||
MailActionPacket.SendMail(this.username, mail.writeNBT());
|
||||
else
|
||||
close();
|
||||
}
|
||||
@@ -327,7 +328,7 @@ public class GuiMailmanWrite extends GuiContainerNPCInterface implements ITextfi
|
||||
{
|
||||
s1 = this.bookPages.getStringTagAt(this.currPage);
|
||||
}
|
||||
|
||||
|
||||
if(canEdit){
|
||||
if (mc.fontRenderer.getBidiFlag())
|
||||
{
|
||||
@@ -349,14 +350,14 @@ public class GuiMailmanWrite extends GuiContainerNPCInterface implements ITextfi
|
||||
|
||||
this.drawGradientRect(guiLeft + 175, guiTop + 136, guiLeft + 269, guiTop + 154, -1072689136, -804253680);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
|
||||
|
||||
this.mc.getTextureManager().bindTexture(bookWidgets);
|
||||
for(int i = 0; i < 4; i++)
|
||||
this.drawTexturedModalRect(guiLeft + 175 + i * 24, guiTop + 134, 0, 22, 24, 24);
|
||||
|
||||
|
||||
super.drawScreen(par1, par2, par3);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void close(){
|
||||
@@ -390,6 +391,6 @@ public class GuiMailmanWrite extends GuiContainerNPCInterface implements ITextfi
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -13,11 +13,11 @@ public enum EnumPlayerPacket {
|
||||
CheckQuestCompletion,
|
||||
// BankSlotOpen,
|
||||
FactionsGet,
|
||||
MailGet,
|
||||
// MailGet,
|
||||
MailDelete,
|
||||
MailSend,
|
||||
MailRead,
|
||||
MailboxOpenMail,
|
||||
// MailSend,
|
||||
// MailRead,
|
||||
// MailboxOpenMail,
|
||||
SignSave,
|
||||
SaveBook,
|
||||
CompanionOpenInv,
|
||||
|
||||
Reference in new issue
Block a user