summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/network/packet/RenameS2CPacket.java
blob: 058f0e582ff30f9f6d6743ec0311cac7f8fdcb50 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package cuchaz.enigma.network.packet;

import cuchaz.enigma.analysis.EntryReference;
import cuchaz.enigma.gui.GuiController;
import cuchaz.enigma.translation.representation.entry.Entry;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class RenameS2CPacket implements Packet<GuiController> {
	private int syncId;
	private Entry<?> entry;
	private String newName;
	private boolean refreshClassTree;

	RenameS2CPacket() {
	}

	public RenameS2CPacket(int syncId, Entry<?> entry, String newName, boolean refreshClassTree) {
		this.syncId = syncId;
		this.entry = entry;
		this.newName = newName;
		this.refreshClassTree = refreshClassTree;
	}

	@Override
	public void read(DataInput input) throws IOException {
		this.syncId = input.readUnsignedShort();
		this.entry = PacketHelper.readEntry(input);
		this.newName = PacketHelper.readString(input);
		this.refreshClassTree = input.readBoolean();
	}

	@Override
	public void write(DataOutput output) throws IOException {
		output.writeShort(syncId);
		PacketHelper.writeEntry(output, entry);
		PacketHelper.writeString(output, newName);
		output.writeBoolean(refreshClassTree);
	}

	@Override
	public void handle(GuiController controller) {
		controller.rename(new EntryReference<>(entry, entry.getName()), newName, refreshClassTree, false);
		controller.sendPacket(new ConfirmChangeC2SPacket(syncId));
	}
}