RuneHive-Game
Loading...
Searching...
No Matches
PvPTimerTask.java
Go to the documentation of this file.
1package com.runehive.game.task.impl;
2
3import com.runehive.game.task.Task;
4import com.runehive.game.world.entity.mob.player.Player;
5import com.runehive.game.world.entity.mob.player.PlayerOption;
6import com.runehive.game.world.position.Area;
7import com.runehive.net.packet.out.SendPlayerOption;
8import com.runehive.net.packet.out.SendString;
9
10import java.util.concurrent.TimeUnit;
11
12public class PvPTimerTask extends Task {
13 private static final int[] TIMES = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1 };
14
15 private final Player player;
16
18 super(false, 1);
19 this.player = player;
20 }
21
22 @Override
23 protected void onSchedule() {
24 player.pvpTimer.reset();
25 player.hasPvPTimer = true;
26 }
27
28 @Override
29 protected void execute() {
30 int time = TIMES[(int) player.pvpTimer.elapsedTime(TimeUnit.SECONDS)];
31
32 if (!player.pvpInstance || Area.inPvP(player) || player.pvpTimer.elapsedTime(TimeUnit.SECONDS) > 10 || time == -1) {
33 cancel();
34 return;
35 }
36
37 player.send(new SendString("<col=FF0011>" + time, 23327));
38 }
39
40 @Override
41 protected void onCancel(boolean logout) {
42 player.getCombat().reset();
43 player.send(new SendString("<col=36CF4D>Safe", 23327));
44 player.send(new SendPlayerOption(PlayerOption.ATTACK, false, true));
45 player.send(new SendPlayerOption(PlayerOption.DUEL_REQUEST, false, true));
46 player.hasPvPTimer = false;
47 }
48}
synchronized final void cancel()
Cancels all subsequent executions.
Definition Task.java:113
Task(boolean instant, int delay)
Creates a new Task.
Definition Task.java:41
void execute()
A function representing the unit of work that will be carried out.
void onSchedule()
A function executed on registration.
void onCancel(boolean logout)
A function executed on cancellation.
This class represents a character controlled by a player.
Definition Player.java:125
Handles checking if mobs are in a certain area.
Definition Area.java:13
static boolean inPvP(Interactable entity)
Definition Area.java:355
Shows a player options such as right clicking a player.
The OutgoingPacket that sends a string to a Players itemcontainer in the client.
Represents the options for right-clicking players.
DUEL_REQUEST
The option for challenging another player to a duel.
ATTACK
The option for attacking another player.