-
-
Notifications
You must be signed in to change notification settings - Fork 349
/
ProtectionRegenTask.java
108 lines (83 loc) · 2.36 KB
/
ProtectionRegenTask.java
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package com.palmergames.bukkit.towny.tasks;
import com.palmergames.bukkit.towny.Towny;
import com.palmergames.bukkit.towny.regen.TownyRegenAPI;
import com.palmergames.bukkit.towny.regen.block.BlockLocation;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
import org.bukkit.block.data.BlockData;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
public class ProtectionRegenTask extends TownyTimerTask {
private BlockState state;
@SuppressWarnings("unused")
private BlockState altState;
private BlockLocation blockLocation;
private int TaskId;
private List<ItemStack> contents = new ArrayList<ItemStack>();
//Tekkit - InventoryView
public ProtectionRegenTask(Towny plugin, Block block) {
super(plugin);
this.state = block.getState();
this.altState = null;
this.setBlockLocation(new BlockLocation(block.getLocation()));
if (state instanceof InventoryHolder) {
Inventory inven;
if (state instanceof Chest) {
inven = ((Chest) state).getBlockInventory();
} else {
// Contents we are respawning.
inven = ((InventoryHolder) state).getInventory();
}
for (ItemStack item : inven.getContents()) {
contents.add((item != null) ? item.clone() : null);
}
inven.clear();
}
}
@Override
public void run() {
replaceProtections();
TownyRegenAPI.removeProtectionRegenTask(this);
}
public void replaceProtections() {
Block block = state.getBlock();
try {
BlockData blockData = state.getBlockData().clone();
block.setType(state.getType(), false);
block.setBlockData(blockData);
} catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* @return the blockLocation
*/
public BlockLocation getBlockLocation() {
return blockLocation;
}
/**
* @param blockLocation the blockLocation to set
*/
private void setBlockLocation(BlockLocation blockLocation) {
this.blockLocation = blockLocation;
}
public BlockState getState() {
return state;
}
/**
* @return the taskId
*/
public int getTaskId() {
return TaskId;
}
/**
* @param taskId the taskId to set
*/
public void setTaskId(int taskId) {
TaskId = taskId;
}
}