RuneHive-Game
Loading...
Searching...
No Matches
PlayerManagement.java
Go to the documentation of this file.
1package com.runehive.content.staff;
2
3import com.runehive.Config;
4import com.runehive.content.dialogue.DialogueFactory;
5import com.runehive.game.world.InterfaceConstants;
6import com.runehive.game.world.World;
7import com.runehive.game.world.entity.mob.Mob;
8import com.runehive.game.world.entity.mob.UpdateFlag;
9import com.runehive.game.world.entity.mob.npc.definition.NpcDefinition;
10import com.runehive.game.world.entity.mob.player.Player;
11import com.runehive.game.world.entity.mob.player.PlayerRight;
12import com.runehive.game.world.entity.mob.player.persist.PlayerSerializer;
13import com.runehive.game.world.entity.mob.player.profile.ProfileRepository;
14import com.runehive.game.world.entity.skill.Skill;
15import com.runehive.game.world.items.containers.pricechecker.PriceType;
16import com.runehive.net.packet.out.SendInputAmount;
17import com.runehive.net.packet.out.SendInputMessage;
18import com.runehive.net.packet.out.SendItemOnInterface;
19import com.runehive.net.packet.out.SendString;
20import com.runehive.util.Utility;
21
22import java.util.List;
23import java.util.concurrent.TimeUnit;
24
25import static com.runehive.game.world.entity.mob.player.PlayerRight.*;
26
27/**
28 * Handles the player management.
29 *
30 * @author Daniel
31 */
32public enum PlayerManagement implements ActionEffect {
33 TELEPORT_TO(PlayerRight.getColor(MODERATOR) + "Teleport To") {
34 @Override
35 public void handle(Player player) {
36 if (PlayerRight.isModerator(player) && player.managing.isPresent()) {
37 Player other = player.managing.get();
38
39 player.move(other.getPosition());
40 player.instance = other.instance;
41 player.pvpInstance = other.pvpInstance;
42 }
43 }
44 },
45 TELEPORT_TO_ME(PlayerRight.getColor(MODERATOR) + "Teleport To Me") {
46 @Override
47 public void handle(Player player) {
48 if (PlayerRight.isModerator(player) && player.managing.isPresent()) {
49 Player other = player.managing.get();
50
51 other.move(player.getPosition());
52 other.instance = player.instance;
53 other.pvpInstance = player.pvpInstance;
54 other.message("<col=FF0D5D>You have been force teleported to " + player.getName() + ".");
55 }
56 }
57 },
58 MOVE_HOME(PlayerRight.getColor(MODERATOR) + "Move Home") {
59 @Override
60 public void handle(Player player) {
61 if (PlayerRight.isModerator(player) && player.managing.isPresent()) {
62 Player other = player.managing.get();
63
65 other.instance = Mob.DEFAULT_INSTANCE;
66 other.pvpInstance = false;
67 other.message("<col=FF0D5D>You have been force teleported home by " + player.getName() + ".");
68 }
69 }
70 },
71 KICK(PlayerRight.getColor(MODERATOR) + "Kick") {
72 @Override
73 public void handle(Player player) {
74 if (PlayerRight.isModerator(player) && player.managing.isPresent()) {
75 Player other = player.managing.get();
76
77 confirm(player, () -> {
78 World.kickPlayer(other);
79 player.message("<col=FF0D5D>You have force kicked: " + other.getName() + ".");
80 });
81 }
82 }
83 },
84 JAIL(PlayerRight.getColor(MODERATOR) + "Jail") {
85 @Override
86 public void handle(Player player) {
87 if (PlayerRight.isModerator(player) && player.managing.isPresent()) {
88 Player other = player.managing.get();
89
90 confirm(player, () -> {
91 DialogueFactory factory = player.dialogueFactory;
92 factory.sendOption("Jail by day", () -> {
93 factory.onAction(() -> player.send(new SendInputAmount("How long do you want this jail to last for?", 2, input -> {
94 other.punishment.jail(Integer.parseInt(input), TimeUnit.DAYS);
95 factory.clear();
96 })));
97 }, "Jail by hour", () -> {
98 factory.onAction(() -> player.send(new SendInputAmount("How long do you want this jail to last for?", 3, input -> {
99 other.punishment.jail(Integer.parseInt(input), TimeUnit.HOURS);
100 factory.clear();
101 })));
102 }, "Jail by minute", () -> {
103 factory.onAction(() -> player.send(new SendInputAmount("How long do you want this jail to last for?", 3, input -> {
104 other.punishment.jail(Integer.parseInt(input), TimeUnit.MINUTES);
105 factory.clear();
106 })));
107 }, "Jail forever", () -> {
108 factory.onAction(() -> {
109 other.punishment.jail(9999, TimeUnit.DAYS);
110 factory.clear();
111 });
112 });
113 });
114 }
115 }
116 },
117 UNJAIL(PlayerRight.getColor(MODERATOR) + "Un-Jail") {
118 @Override
119 public void handle(Player player) {
120 if (PlayerRight.isModerator(player) && player.managing.isPresent()) {
121 Player other = player.managing.get();
122
123 other.punishment.unJail();
124 other.dialogueFactory.sendStatement("You have been unjailed!").execute();
125 other.message("<col=FF0D5D>You have been unjailed by: " + player.getName());
126 player.message("<col=FF0D5D>You have unjailed: " + other.getName());
127 }
128 }
129 },
130 MUTE(PlayerRight.getColor(MODERATOR) + "Mute") {
131 @Override
132 public void handle(Player player) {
133 if (PlayerRight.isModerator(player) && player.managing.isPresent()) {
134 Player other = player.managing.get();
135
136 confirm(player, () -> {
137 DialogueFactory factory = player.dialogueFactory;
138 factory.sendOption("Mute by day", () -> {
139 factory.onAction(() -> player.send(new SendInputAmount("How long do you want this mute to last for?", 2, input -> {
140 other.punishment.mute(Integer.parseInt(input), TimeUnit.DAYS);
141 factory.clear();
142 })));
143 }, "Mute by hour", () -> {
144 factory.onAction(() -> player.send(new SendInputAmount("How long do you want this mute to last for?", 3, input -> {
145 other.punishment.mute(Integer.parseInt(input), TimeUnit.HOURS);
146 factory.clear();
147 })));
148 }, "Mute by minute", () -> {
149 factory.onAction(() -> player.send(new SendInputAmount("How long do you want this mute to last for?", 3, input -> {
150 other.punishment.mute(Integer.parseInt(input), TimeUnit.MINUTES);
151 factory.clear();
152 })));
153 }, "Mute forever", () -> {
154 factory.onAction(() -> {
155 other.punishment.mute(9999, TimeUnit.DAYS);
156 factory.clear();
157 });
158 });
159 });
160 }
161 }
162 },
163 UNMUTE(PlayerRight.getColor(MODERATOR) + "Un-Mute") {
164 @Override
165 public void handle(Player player) {
166 if (PlayerRight.isModerator(player) && player.managing.isPresent()) {
167 Player other = player.managing.get();
168
169 other.punishment.unmute();
170 other.dialogueFactory.sendStatement("You have been unmuted!").execute();
171 other.message("<col=FF0D5D>You have been unmuted by: " + player.getName());
172 player.message("<col=FF0D5D>You have unmuted: " + other.getName());
173 }
174 }
175 },
176 CHECK_BANK(PlayerRight.getColor(MODERATOR) + "Check Bank") {
177 @Override
178 public void handle(Player player) {
179 if (PlayerRight.isModerator(player) && player.managing.isPresent()) {
180 Player other = player.managing.get();
181 long totalValue = other.bank.containerValue(PriceType.VALUE);
182 long vaultCoins = other.bankVault.coinsContainer;
183 long vaultBM = other.bankVault.bloodMoneyContainer;
184
185 player.interfaceManager.openInventory(60000, 5063);
188 player.send(new SendString("", 60_079));
189 player.dialogueFactory.sendInformationBox(other.getName() + "'s Bank:", "Bank Value: " + (totalValue), "Bank Vault (Coins): " + (vaultCoins), "Bank Vault (BM): " + (vaultBM)).execute();
190 }
191 }
192 },
193 LINKED_ACCOUNTS(PlayerRight.getColor(MODERATOR) + "Linked Accounts") {
194 @Override
195 public void handle(Player player) {
196 if (PlayerRight.isModerator(player) && player.managing.isPresent()) {
197 Player other = player.managing.get();
198 List<String> list = ProfileRepository.getRegistry(other.lastHost);
199
200 if (!list.isEmpty()) {
201 for (int index = 0; index < 50; index++) {
202 String name = index >= list.size() ? "" : list.get(index);
203 player.send(new SendString(name, 37111 + index));
204 }
205
206 player.message("<col=FF0D5D>There are " + list.size() + " accounts linked to " + Utility.formatName(other.getName()) + ".");
207 player.send(new SendString("Profiles:\\n" + list.size(), 37107));
208 player.send(new SendString(other.getName(), 37103));
209 player.interfaceManager.open(37100);
210 }
211 }
212 }
213 },
214 PROMOTE(PlayerRight.getColor(ADMINISTRATOR) + "Promote") {
215 @Override
216 public void handle(Player player) {
217 if (PlayerRight.isAdministrator(player) && player.managing.isPresent()) {
218 Player other = player.managing.get();
219
220 player.dialogueFactory.sendOption("Helper", () -> {
221 other.right = PlayerRight.HELPER;
223 other.dialogueFactory.sendStatement("You were promoted to helper by " + player.getName()).execute();
224 player.message("You have promoted " + other.getName() + " to helper.");
225 }, "Moderator", () -> {
226 other.right = PlayerRight.MODERATOR;
228 other.dialogueFactory.sendStatement("You were promoted to moderator by " + player.getName()).execute();
229 player.message("You have promoted " + other.getName() + " to moderator.");
230 }, "Administrator", () -> {
231 other.right = PlayerRight.ADMINISTRATOR;
233 other.dialogueFactory.sendStatement("You were promoted to administrator by " + player.getName()).execute();
234 player.message("You have promoted " + other.getName() + " to administrator.");
235 }).execute();
236 }
237 }
238 },
239 DEMOTE(PlayerRight.getColor(ADMINISTRATOR) + "Demote") {
240 @Override
241 public void handle(Player player) {
242 if (PlayerRight.isAdministrator(player) && player.managing.isPresent()) {
243 Player other = player.managing.get();
244
245 other.right = PlayerRight.PLAYER;
247 other.dialogueFactory.sendStatement("You were demoted by " + player.getName()).execute();
248 player.message("You have demoted " + other.getName() + ".");
249 }
250 }
251 },
252 COPY(PlayerRight.getColor(ADMINISTRATOR) + "Copy") {
253 @Override
254 public void handle(Player player) {
255 if (PlayerRight.isAdministrator(player) && player.managing.isPresent()) {
256 Player other = player.managing.get();
257
258 player.playerAssistant.copy(other);
260 player.message("<col=FF0D5D>You have copied " + other.getName() + ".");
261 }
262 }
263 },
264 COPY_ME(PlayerRight.getColor(OWNER) + "Copy Me") {
265 @Override
266 public void handle(Player player) {
267 if (PlayerRight.isOwner(player) && player.managing.isPresent()) {
268 Player other = player.managing.get();
269
270 other.playerAssistant.copy(player);
272 player.message("<col=FF0D5D>You have X-copied " + other.getName() + ".");
273 }
274 }
275 },
276 CLEAR(PlayerRight.getColor(OWNER) + "Clear Account") {
277 @Override
278 public void handle(Player player) {
279 if (PlayerRight.isOwner(player) && player.managing.isPresent()) {
280 Player other = player.managing.get();
281
282 confirm(player, () -> {
283 other.bank.clear();
284 other.inventory.clear();
285
286 for (int index = 0; index < Skill.SKILL_COUNT; index++) {
287 other.skills.setLevel(index, index == 3 ? 10 : 1);
288 other.skills.setMaxLevel(index, index == 3 ? 10 : 1);
289 }
290
291 other.skills.setCombatLevel();
293 });
294 }
295 }
296 },
297 PNPCS(PlayerRight.getColor(OWNER) + "Transform") {
298 @Override
299 public void handle(Player player) {
300 if (PlayerRight.isOwner(player) && player.managing.isPresent()) {
301 Player other = player.managing.get();
302
303 player.send(new SendInputAmount("Enter NPC ID:", 4, input -> {
304 int id = Integer.parseInt(input);
305 if (id == 0)
306 id = -1;
307 other.playerAssistant.transform(id);
308 player.message("<col=FF0D5D>You have turned " + other.getName() + " into " + NpcDefinition.get(id).getName() + ".");
309 }));
310 }
311 }
312 },
313 CHANGE_USERNAME(PlayerRight.getColor(OWNER) + "Change Username") {
314 @Override
315 public void handle(Player player) {
316 if (PlayerRight.isOwner(player) && player.managing.isPresent()) {
317 Player other = player.managing.get();
318
319 player.send(new SendInputMessage("Enter their new username", 12, input -> {
320 if (ProfileRepository.exist(input)) {
321 player.dialogueFactory.sendStatement("The name " + input + " is already taken.").execute();
322 return;
323 }
324 other.setUsername(input);
326 PlayerSerializer.save(other);
327 player.dialogueFactory.sendStatement("You have successfully changed their username.").execute();
328 }));
329 }
330 }
331 },;
332
333
334 public final String string;
335
336 PlayerManagement(String string) {
337 this.string = string;
338 }
339
340 public static void confirm(Player player, Runnable runnable) {
341 DialogueFactory factory = player.dialogueFactory;
342 factory.sendStatement("Are you sure you want to execute this action?");
343 factory.sendOption("Confirm action", runnable, "Nevermind", factory::clear);
344 factory.execute();
345 }
346
347 public static PlayerManagement forOrdinal(int ordinal) {
348 for (PlayerManagement management : values()) {
349 if (management.ordinal() == ordinal) {
350 return management;
351 }
352 }
353 return null;
354 }
355}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final Position DEFAULT_POSITION
The default, i.e.
Definition Config.java:197
Represents a factory class that contains important functions for building dialogues.
final DialogueFactory execute()
Retrieves the next dialogue in the chain and executes it.
void clear()
Clears the current dialogue chain.
final DialogueFactory onAction(Runnable action)
Sets an action so this action can be executed after dialogues are done.
final DialogueFactory sendInformationBox(String title, String...lines)
final DialogueFactory sendStatement(String... lines)
Appends a StatementDialogue to the current dialogue chain.
final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2)
Appends the OptionDialogue onto the current dialogue chain.
The class that contains helpful information on interfaces.
Represents the game world.
Definition World.java:46
static void kickPlayer(Player other)
Definition World.java:217
Handles the mob class.
Definition Mob.java:66
final EnumSet< UpdateFlag > updateFlags
Definition Mob.java:94
void move(Position position)
Moves the mob to a set position.
Definition Mob.java:340
static NpcDefinition get(int id)
Gets a npc definition from the definition array.
void openInventory(int identification, int overlay)
Opens an inventory interface for the player.
void open(int identification)
Opens an interface for the player.
void copy(Player other)
Copy's the inventory and equipment of another player.
This class represents a character controlled by a player.
Definition Player.java:125
String getName()
Gets the name of this entity.
Definition Player.java:774
Handles the profile repository, used for gathering important information for all created profiles.
static List< String > getRegistry(String host)
Gets all the registered accounts to a specific host.
static boolean exist(String name)
Checks if a profile is registered to the parameter.
Represents a trainable and usable skill.
Definition Skill.java:18
static final int SKILL_COUNT
The amount of available skills.
Definition Skill.java:90
void setMaxLevel(int id, int level)
Sets the max level of a skill.
void setCombatLevel()
Sets the mob's combat level.
void setLevel(int id, int level)
Sets the level of a skill.
void clear()
Removes all of the items from this container.
long containerValue(PriceType type)
Gets the total worth of the container using the item's values.
final Item[] toArray()
Returns a shallow copy of the backing array.
void clear()
Removes all of the items from this container.
Definition Bank.java:467
Sends a chatbox input prompt that accepts full text with spaces.
The OutgoingPacket that sends a string to a Players itemcontainer in the client.
Handles miscellaneous methods.
Definition Utility.java:27
static String formatName(final String input)
Definition Utility.java:645
static PlayerManagement forOrdinal(int ordinal)
static void confirm(Player player, Runnable runnable)
static boolean isModerator(Player player)
Checks if the player is a management member.
static boolean isAdministrator(Player player)
Checks if the player is a privileged member.
The action execute of the staff panel.
void handle(final Player player)
Handles the execute of the staff panel action.