RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
AppearanceChangePacketListener.java
1package com.osroyale.net.packet.in;
2
3import com.google.common.collect.ImmutableSet;
4import com.osroyale.game.world.entity.mob.player.Player;
5import com.osroyale.game.world.entity.mob.player.PlayerRight;
6import com.osroyale.game.world.entity.mob.player.appearance.Appearance;
7import com.osroyale.net.packet.GamePacket;
8import com.osroyale.net.packet.PacketListener;
9import com.osroyale.net.packet.PacketListenerMeta;
10import com.osroyale.net.packet.out.SendMessage;
11import org.jire.tarnishps.event.widget.AppearanceChangeEvent;
12
40
41public final class AppearanceChangePacketListener implements PacketListener {
42
43 private static final ImmutableSet<Integer> VALID_MALE_HEAD_MODELS = ImmutableSet.of(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 129, 130, 131, 132, 133, 134, 142, 144, 145, 146, 147, 148, 149, 150);
44 private static final ImmutableSet<Integer> VALID_MALE_JAW_MODELS = ImmutableSet.of(10, 11, 12, 13, 14, 15, 16, 17, 111, 112, 113, 114, 115, 116, 117);
45 private static final ImmutableSet<Integer> VALID_MALE_TORSO_MODELS = ImmutableSet.of(18, 19, 20, 21, 22, 23, 24, 25, 105, 106, 107, 108, 109, 110);
46 private static final ImmutableSet<Integer> VALID_MALE_ARM_MODELS = ImmutableSet.of(26, 27, 28, 29, 30, 31, 32, 84, 85, 86, 87, 88);
47 private static final ImmutableSet<Integer> VALID_MALE_LEG_MODLES = ImmutableSet.of(36, 37, 38, 39, 40, 41, 100, 101, 102, 103, 104);
48 private static final ImmutableSet<Integer> VALID_FEMALE_HEAD_MODELS = ImmutableSet.of(45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 141, 143);
49 private static final ImmutableSet<Integer> VALID_FEMALE_TORSO_MODELS = ImmutableSet.of(56, 57, 58, 59, 60, 89, 90, 91, 92, 93, 94);
50 private static final ImmutableSet<Integer> VALID_FEMALE_ARM_MODELS = ImmutableSet.of(61, 62, 63, 64, 65, 66, 95, 96, 97, 98, 99);
51 private static final ImmutableSet<Integer> VALID_FEMALE_LEG_MODELS = ImmutableSet.of(70, 71, 72, 73, 74, 75, 76, 77, 78, 135, 136, 137, 138, 139, 140);
52
53 @Override
54 public void handlePacket(Player player, GamePacket packet) {
55 final int gender = packet.readByte(false);
56 final int head = packet.readByte(false);
57 final int jaw = packet.readByte(false);
58 final int torso = packet.readByte(false);
59 final int arms = packet.readByte(false);
60 final int hands = packet.readByte(false);
61 final int legs = packet.readByte(false);
62 final int feet = packet.readByte(false);
63 final int hairColor = packet.readByte(false);
64 final int torsoColor = packet.readByte(false);
65 final int legsColor = packet.readByte(false);
66 final int feetColor = packet.readByte(false);
67 final int skinColor = packet.readByte(false);
68
69 player.getEvents().widget(player, new AppearanceChangeEvent(
70 gender, head, jaw, torso, arms, hands, legs, feet,
71 hairColor, torsoColor, legsColor, feetColor, skinColor
72 ));
73 }
74
75 public static boolean isValid(Player player, Appearance appearance) {
76 switch (appearance.getGender()) {
77
78 case MALE:
79
80 if (!VALID_MALE_HEAD_MODELS.contains(appearance.getHead())) {
81 player.send(new SendMessage(PlayerRight.isDeveloper(player) ? String.format("Cannot change appearance - Invalid head id %d", appearance.getHead()) : "You cannot change your appearance, because you have an invalid head id."));
82 return false;
83 }
84
85 if (!VALID_MALE_JAW_MODELS.contains(appearance.getBeard())) {
86 player.send(new SendMessage(PlayerRight.isDeveloper(player) ? String.format("Cannot change appearance - Invalid jaw id %d", appearance.getBeard()) : "You cannot change your appearance, because you have an invalid jaw id."));
87 return false;
88 }
89
90 if (!VALID_MALE_TORSO_MODELS.contains(appearance.getTorso())) {
91 player.send(new SendMessage(PlayerRight.isDeveloper(player) ? String.format("Cannot change appearance - Invalid torso id %d", appearance.getTorso()) : "You cannot change your appearance, because you have an invalid torso id."));
92 return false;
93 }
94
95 if (!VALID_MALE_ARM_MODELS.contains(appearance.getArms())) {
96 player.send(new SendMessage(PlayerRight.isDeveloper(player) ? String.format("Cannot change appearance - Invalid arm id %d", appearance.getHead()) : "You cannot change your appearance, because you have an invalid arm id."));
97 return false;
98 }
99
100 if (!(appearance.getHands() >= 33 && appearance.getHands() <= 34)) {
101 player.send(new SendMessage(PlayerRight.isDeveloper(player) ? String.format("Cannot change appearance - Invalid hand id %d", appearance.getHands()) : "You cannot change your appearance, because you have an invalid hand id."));
102 return false;
103 }
104
105 if (!VALID_MALE_LEG_MODLES.contains(appearance.getLegs())) {
106 player.send(new SendMessage(PlayerRight.isDeveloper(player) ? String.format("Cannot change appearance - Invalid leg id %d", appearance.getLegs()) : "You cannot change your appearance, because you have an invalid leg id."));
107 return false;
108 }
109
110 if (!(appearance.getFeet() >= 42 && appearance.getFeet() <= 43)) {
111 player.send(new SendMessage(PlayerRight.isDeveloper(player) ? String.format("Cannot change appearance - Invalid feet id %d", appearance.getFeet()) : "You cannot change your appearance, because you have an invalid feet id."));
112 return false;
113 }
114 break;
115
116 case FEMALE:
117 if (!VALID_FEMALE_HEAD_MODELS.contains(appearance.getHead())) {
118 player.send(new SendMessage(PlayerRight.isDeveloper(player) ? String.format("Cannot change appearance - Invalid head id %d", appearance.getHead()) : "You cannot change your appearance, because you have an invalid head id."));
119 return false;
120 }
121
122 if (appearance.getBeard() != -1) {
123 player.send(new SendMessage(PlayerRight.isDeveloper(player) ? String.format("Cannot change appearance - Invalid jaw id %d", appearance.getBeard()) : "You cannot change your appearance, because you have an invalid jaw id."));
124 return false;
125 }
126
127 if (!VALID_FEMALE_TORSO_MODELS.contains(appearance.getTorso())) {
128 player.send(new SendMessage(PlayerRight.isDeveloper(player) ? String.format("Cannot change appearance - Invalid torso id %d", appearance.getTorso()) : "You cannot change your appearance, because you have an invalid torso id."));
129 return false;
130 }
131
132 if (!VALID_FEMALE_ARM_MODELS.contains(appearance.getArms())) {
133 player.send(new SendMessage(PlayerRight.isDeveloper(player) ? String.format("Cannot change appearance - Invalid arm id %d", appearance.getHead()) : "You cannot change your appearance, because you have an invalid arm id."));
134 return false;
135 }
136
137 if (!(appearance.getHands() >= 67 && appearance.getHands() <= 68)) {
138 player.send(new SendMessage(PlayerRight.isDeveloper(player) ? String.format("Cannot change appearance - Invalid hand id %d", appearance.getHands()) : "You cannot change your appearance, because you have an invalid hand id."));
139 return false;
140 }
141
142 if (!VALID_FEMALE_LEG_MODELS.contains(appearance.getLegs())) {
143 player.send(new SendMessage(PlayerRight.isDeveloper(player) ? String.format("Cannot change appearance - Invalid leg id %d", appearance.getLegs()) : "You cannot change your appearance, because you have an invalid leg id."));
144 return false;
145 }
146
147 if (!(appearance.getFeet() >= 79 && appearance.getFeet() <= 80)) {
148 player.send(new SendMessage(PlayerRight.isDeveloper(player) ? String.format("Cannot change appearance - Invalid feet id %d", appearance.getFeet()) : "You cannot change your appearance, because you have an invalid feet id."));
149 return false;
150 }
151 break;
152 }
153
154 if (!(appearance.getHairColor() >= 0 && appearance.getHairColor() <= 11)) {
155 player.send(new SendMessage(PlayerRight.isDeveloper(player) ? String.format("Cannot change appearance - Invalid hair color %d", appearance.getHairColor()) : "Cannot change appearance, invalid hair color."));
156 return false;
157 }
158
159 if (!(appearance.getTorsoColor() >= 0 && appearance.getTorsoColor() <= 15)) {
160 player.send(new SendMessage(PlayerRight.isDeveloper(player) ? String.format("Cannot change appearance, invalid torso color %d", appearance.getTorsoColor()) : "Cannot change appearance, invalid torso color."));
161 return false;
162 }
163
164 if (!(appearance.getLegsColor() >= 0 && appearance.getLegsColor() <= 15)) {
165 player.send(new SendMessage(PlayerRight.isDeveloper(player) ? String.format("Cannot change appearance, invalid leg color %d", appearance.getLegsColor()) : "Cannot change appearance, invalid leg color."));
166 return false;
167 }
168
169 if (!(appearance.getFeetColor() >= 0 && appearance.getFeetColor() <= 5)) {
170 player.send(new SendMessage(PlayerRight.isDeveloper(player) ? String.format("Cannot change appearance, invalid feet color %d", appearance.getFeetColor()) : "Cannot change appearance, invalid feet color."));
171 return false;
172 }
173
174 if (!(appearance.getSkinColor() >= 0 && appearance.getSkinColor() <= 9)) {
175 player.send(new SendMessage(PlayerRight.isDeveloper(player) ? String.format("Cannot change appearance, invalid skin color %d", appearance.getSkinColor()) : "Cannot change appearance, invalid skin color."));
176 return false;
177 }
178
179 int[] DONATOR_SKINS = { 8, 9 };
180
181 for (int skin : DONATOR_SKINS) {
182 if (appearance.getSkinColor() == skin && !PlayerRight.isDonator(player)) {
183 player.message("You need to be a donator to use this skin!");
184 }
185 }
186 return true;
187 }
188
189}