-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathCargoTask.java
More file actions
66 lines (58 loc) · 2.46 KB
/
CargoTask.java
File metadata and controls
66 lines (58 loc) · 2.46 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
58
59
60
61
62
63
64
65
66
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 net.countercraft.movecraft.craft.PlayerCraft;
import net.countercraft.movecraft.craft.type.CraftType;
import net.countercraft.movecraft.util.hitboxes.HitBox;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import net.countercraft.movecraft.craft.CraftManager;
public abstract class CargoTask extends BukkitRunnable {
protected PlayerCraft craft;
protected final HitBox originalLocations;
protected final Player originalPilot;
protected TradableGUIItem item;
protected CargoTask(PlayerCraft craft, TradableGUIItem guiItem) {
if (craft == null) {
throw new IllegalArgumentException("craft must not be null");
}
this.craft = craft;
if (guiItem == null)
throw new IllegalArgumentException("item must not be null");
else
item = guiItem;
originalLocations = craft.getHitBox();
originalPilot = craft.getPilot();
}
@Override
public void run() {
if (CraftManager.getInstance().getCraftByPlayer(originalPilot) == null) {
if (Config.debug)
CargoMain.getInstance().getLogger().info("canceling CargoTask due to missing player/craft");
CargoMain.getQue().remove(originalPilot);
cancel();
return;
}
if (craft.getPilot() != originalPilot) {
originalPilot.sendMessage("Pilots changed!");
CargoMain.getQue().remove(originalPilot);
cancel();
return;
}
if (craft.getHitBox() != originalLocations) {
originalPilot.sendMessage("Blocks moved/changed!");
CargoMain.getQue().remove(originalPilot);
cancel();
return;
}
if (Config.debug)
CargoMain.getInstance().getLogger().info("Running execute method for CargoTask with address " + this + ". Pilot: "
+ originalPilot.getName() + " CraftSize: " + originalLocations.size() + " CraftType: "
+ craft.getType().getStringProperty(CraftType.NAME) + " StockItem: "
+ (item.getDisplayName().length() > 0 ? item.getDisplayName()
: item.getMainItem().getType().name().toLowerCase()));
execute();
}
protected abstract void execute();
}