-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathProcessingTask.java
More file actions
57 lines (55 loc) · 2.57 KB
/
ProcessingTask.java
File metadata and controls
57 lines (55 loc) · 2.57 KB
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
49
50
51
52
53
54
55
56
57
package io.github.cccm5.async;
import com.degitise.minevid.dtlTraders.guis.items.TradableGUIItem;
import io.github.cccm5.CargoMain;
import io.github.cccm5.config.Config;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
/**
* Write a description of class ProcessingTask here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class ProcessingTask extends BukkitRunnable implements Listener
{
private static final int DELAY_BETWEEN_DISPLAY = 1;
private int remainingTime;
private final int remainingChests;
private final Player player;
private final Objective objective;
public ProcessingTask(Player player, TradableGUIItem item, int remainingChests){//, int remainingChests){
if (item == null)
throw new IllegalArgumentException("item must not be null");
if (player == null)
throw new IllegalArgumentException("player must not be null");
this.player = player;
this.remainingTime = Config.delay/20;
this.remainingChests = remainingChests;
Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
String itemDisplayName = item.getMainItem().getItemMeta().getDisplayName() != null && item.getMainItem().getItemMeta().getDisplayName().length() > 0 ? item.getMainItem().getItemMeta().getDisplayName() : item.getMainItem().getType().name().toLowerCase();
objective = itemDisplayName.length() <=14 ? board.registerNewObjective(ChatColor.DARK_AQUA + itemDisplayName, "dummy") : board.registerNewObjective(ChatColor.DARK_AQUA + "Cargo", "dummy","Cargo");
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
player.setScoreboard(board);
}
@Override
public void run() {
if(remainingTime > DELAY_BETWEEN_DISPLAY)
remainingTime-=DELAY_BETWEEN_DISPLAY;
else{
this.cancel();
player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
return;
}
//Score score = objective.getScore(ChatColor.GREEN + "Time:"); //Get a fake offline player
objective.getScore(ChatColor.GREEN + "Remaining Chests:").setScore(remainingChests);
objective.getScore(ChatColor.GREEN + "Time:").setScore(remainingTime);
//Bukkit.broadcastMessage(ChatColor.GREEN + "Time:" + remainingTime);
//player.setScoreboard(board);
}
}