/
DestroySpell.java
75 lines (57 loc) · 2.22 KB
/
DestroySpell.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
public class DestroySpell extends Spell {
// spell costs
private int REDSTONE_COST;
private int OTHER_COST;
private String OTHER_COST_NAME;
private int OTHER_COST_AMT;
// options
private int BLAST_RADIUS;
// strings
private String STR_CAST;
private String STR_CAST_OTHERS;
// reagents
private int [][] reagents;
public DestroySpell(MagicSpellsListener listener, PropertiesFile properties) {
super(listener,properties);
// register spell
listener.registerSpellName(properties.getString("destroy-spellname","destroy"),this,properties.getString("destroy-desc","Destroys target blocks"));
// get properties
REDSTONE_COST = properties.getInt("destroy-redstone-cost",10);
OTHER_COST = properties.getInt("destroy-other-cost-type",289);
OTHER_COST_NAME = properties.getString("destroy-other-cost-name","gunpowder");
OTHER_COST_AMT = properties.getInt("destroy-other-cost-amt",1);
BLAST_RADIUS = properties.getInt("destroy-blast-radius",2);
STR_CAST = properties.getString("destroy-cast-str","Boom!");
STR_CAST_OTHERS = properties.getString("destroy-cast-others-str","Boom!");
// setup reagents
reagents = new int [][] {{REDSTONE_DUST,REDSTONE_COST},{OTHER_COST,OTHER_COST_AMT}};
}
public boolean cast(Player player, String [] command) {
if (removeReagents(player,reagents)) {
// reagents removed - cast spell
// get targeted block
HitBlox hit = new HitBlox(player);
Block target = hit.getTargetBlock();
// remove blocks around target block
Server s = etc.getServer();
for (int x = target.getX()-BLAST_RADIUS; x <= target.getX()+BLAST_RADIUS; x++) {
for (int y = target.getY()-BLAST_RADIUS; y <= target.getY()+BLAST_RADIUS; y++) {
for (int z = target.getZ()-BLAST_RADIUS; z <= target.getZ()+BLAST_RADIUS; z++) {
s.setBlockAt(0,x,y,z);
}
}
}
// send alerts
player.sendMessage(TEXT_COLOR + STR_CAST);
sendMessageToPlayersInRange(player,STR_CAST_OTHERS);
return true;
} else {
// reagents missing
player.sendMessage(TEXT_COLOR + STR_NO_REAGENTS);
return false;
}
}
public String getCostDesc(String s) {
return REDSTONE_COST + " " + REDSTONE_NAME + (OTHER_COST_AMT>0?", "+OTHER_COST_AMT+" "+OTHER_COST_NAME:"");
}
}