-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMagmaRush.java
More file actions
337 lines (285 loc) · 9.47 KB
/
MagmaRush.java
File metadata and controls
337 lines (285 loc) · 9.47 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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
import com.projectkorra.projectkorra.Element;
import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ability.AddonAbility;
import com.projectkorra.projectkorra.ability.CoreAbility;
import com.projectkorra.projectkorra.ability.LavaAbility;
import com.projectkorra.projectkorra.attribute.Attribute;
import com.projectkorra.projectkorra.command.Commands;
import com.projectkorra.projectkorra.region.RegionProtection;
import com.projectkorra.projectkorra.util.DamageHandler;
import com.projectkorra.projectkorra.util.ParticleEffect;
import com.projectkorra.projectkorra.util.TempBlock;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.*;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.Consumer;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
public class MagmaRush extends LavaAbility implements AddonAbility {
private final String path = "";
@Attribute(Attribute.COOLDOWN)
private long cooldown;
@Attribute(Attribute.SELECT_RANGE)
private double select_range;
@Attribute(Attribute.SPEED)
private double speed;
@Attribute(Attribute.DAMAGE)
private double damage;
@Attribute(Attribute.RANGE)
private double range;
@Attribute(Attribute.RADIUS)
private int radius;
@Attribute(Attribute.FIRE_TICK)
private int fire_ticks;
@Attribute("RevertTime")
private long lava_revert_time;
private boolean update;
private Block target;
private Location origin, location;
private Vector direction;
private List<Block> lavaBlocks;
private Set<Integer> indices;
private Set<FallingBlock> magmaBlocks;
public MagmaRush(Player player) {
super(player);
if (!bPlayer.canBend(this)) {
return;
} else if (!bPlayer.canLavabend()) {
return;
} else if (!RegionProtection.isRegionProtected(player, player.getLocation(), this)) {
return;
}
this.cooldown = ConfigManager.getConfig().getLong(path + "Cooldown");
this.select_range = ConfigManager.getConfig().getDouble(path + "SelectRange");
this.speed = ConfigManager.getConfig().getDouble(path + "Speed");
this.damage = ConfigManager.getConfig().getDouble(path + "Damage");
this.range = ConfigManager.getConfig().getDouble(path + "Range");
this.radius = ConfigManager.getConfig().getInt(path + "Radius");
this.fire_ticks = ConfigManager.getConfig().getInt(path + "FireTicks");
this.lava_revert_time = ConfigManager.getConfig().getLong(path + "LavaRevertTime");
this.target = rayTraceBlock(player, this.select_range);
if (this.target == null) return;
if (RegionProtection.isRegionProtected(player, this.target.getLocation(), this)) {
return;
}
this.origin = this.target.getLocation().clone();
this.location = this.origin.clone();
this.direction = player.getLocation().getDirection();
this.lavaBlocks =
GeneralMethods.getBlocksAroundPoint(this.origin.clone(), 1.75)
.stream()
.filter(b -> (isAir(b.getRelative(BlockFace.UP).getType()) || isPlant(b.getRelative(BlockFace.UP))) && isEarthbendable(b) && !isIndestructible(b) && !RegionProtection.isRegionProtected(player, b.getLocation(), this))
.collect(Collectors.toList());
this.indices = new HashSet<>();
this.magmaBlocks = new HashSet<>();
if (RegionProtection.isRegionProtected(player, this.target.getLocation(), this)) {
return;
} else if (RegionProtection.isRegionProtected(player, player.getLocation(), this)) {
return;
}
playEarthbendingSound(this.origin);
prepare();
start();
}
@Override
public void progress() {
if (!player.isSneaking()) {
if (!update) {
remove();
return;
}
} else {
this.direction = player.getLocation().getDirection();
}
if (update) {
rush();
}
prepareLavaPool();
}
private void rush() {
this.direction = player.getLocation().getDirection();
this.location.add(this.direction.multiply(this.speed));
if (ThreadLocalRandom.current().nextInt(100) < 30) {
playLavabendingSound(this.location);
}
if (this.location.distanceSquared(this.origin) > this.range * this.range) {
remove();
return;
}
this.direction.setY(0);
Block top = GeneralMethods.getTopBlock(this.location, 2);
if (!isTransparent(top.getRelative(BlockFace.UP))) {
remove();
return;
}
if (!isEarthbendable(top)) {
Block under = top.getRelative(BlockFace.DOWN);
if (isTransparent(top) && isEarthbendable(under)) {
top = under;
} else {
remove();
return;
}
}
this.location.setY(top.getY() + 1);
for (Location location : shape(this.location)) {
FallingBlock fallingBlock = GeneralMethods.spawnFallingBlock(location.clone(), Material.MAGMA_BLOCK);
fallingBlock.setVelocity(new Vector(0, 0.3, 0));
fallingBlock.setDropItem(false);
fallingBlock.setMetadata("pa:magmarush", new FixedMetadataValue(ProjectKorra.plugin, 0));
this.magmaBlocks.add(fallingBlock);
}
for (FallingBlock magma : this.magmaBlocks) {
for (Entity entity : GeneralMethods.getEntitiesAroundPoint(magma.getLocation(), 1)) {
if (entity instanceof ArmorStand || entity.getUniqueId() == player.getUniqueId()) continue;
if (entity instanceof LivingEntity) {
if (entity instanceof Player) {
if (Commands.invincible.contains(entity.getName())) continue;
}
DamageHandler.damageEntity(entity, this.damage, this);
entity.setFireTicks(this.fire_ticks);
}
}
}
}
private void prepare() {
for (Location location : shape(this.target.getLocation())) {
FallingBlock fallingBlock = GeneralMethods.spawnFallingBlock(location.clone(), Material.MAGMA_BLOCK);
fallingBlock.setVelocity(new Vector(0, 0.5, 0));
fallingBlock.setDropItem(false);
fallingBlock.setMetadata("pa:magmarush", new FixedMetadataValue(ProjectKorra.plugin, 0));
}
for (Block block : this.lavaBlocks) {
ParticleEffect.LAVA.display(block.getLocation(), 1, 0, 0, 0, 0);
}
}
private void prepareLavaPool() {
if (this.indices.size() < this.lavaBlocks.size()) {
int idx = ThreadLocalRandom.current().nextInt(this.lavaBlocks.size());
if (this.indices.contains(idx)) {
while (this.indices.contains(idx)) {
idx = ThreadLocalRandom.current().nextInt(this.lavaBlocks.size());
}
}
new TempBlock(this.lavaBlocks.get(idx), Material.LAVA.createBlockData(), this.lava_revert_time);
}
}
private List<Location> shape(Location location) {
return GeneralMethods.getBlocksAroundPoint(location, 1.75)
.stream()
.filter(b -> (isAir(b.getRelative(BlockFace.UP).getType()) || (isPlant(b.getRelative(BlockFace.UP)) && !isLeaves(b.getRelative(BlockFace.UP))) && !isWood(b.getRelative(BlockFace.UP)))
&& isEarthbendable(b) && !isIndestructible(b) && !RegionProtection.isRegionProtected(player, b.getLocation(), this))
.map(b -> (Location) b.getRelative(BlockFace.UP).getLocation().clone())
.collect(Collectors.toList());
}
public void update(boolean update) {
this.update = update;
}
public static void update(Player player, boolean update) {
getAbility(player, MagmaRush.class).update(update);
}
public static Block rayTraceBlock(Player player, double range) {
RayTraceResult result = player.getWorld().rayTraceBlocks(player.getEyeLocation().clone(), player.getEyeLocation().getDirection(), range);
if (result != null) {
return result.getHitBlock();
}
return null;
}
public static boolean isIndestructible(Material type) {
switch (type) {
case COMMAND_BLOCK:
case BEDROCK:
case BARRIER:
case END_PORTAL:
case END_PORTAL_FRAME:
case NETHER_PORTAL:
case STRUCTURE_BLOCK:
return true;
}
return false;
}
public static boolean isIndestructible(Block block) {
return isIndestructible(block.getType());
}
public static boolean isWood(Material type) {
if (type.name().contains("_WOOD") || type.name().contains("_LOG")) {
return true;
}
return false;
}
public static boolean isWood(Block block) {
return isWood(block.getType());
}
public static boolean isLeaves(Material type) {
return type.name().contains("LEAVES");
}
public static boolean isLeaves(Block block) {
return isLeaves(block.getType());
}
@Override
public boolean isSneakAbility() {
return true;
}
@Override
public boolean isHarmlessAbility() {
return false;
}
@Override
public long getCooldown() {
return cooldown;
}
@Override
public String getName() {
return "MagmaRush";
}
@Override
public Location getLocation() {
return null;
}
@Override
public List<Location> getLocations() {
return this.magmaBlocks.stream().map(magma -> (Location) magma.getLocation()).collect(Collectors.toList());
}
@Override
public double getCollisionRadius() {
return 1;
}
@Override
public void remove() {
bPlayer.addCooldown(this);
super.remove();
}
@Override
public void load() { }
@Override
public void stop() { }
@Override
public boolean isEnabled() {
return ConfigManager.getConfig().getBoolean("MagmaRush.Enabled", true);
}
@Override
public String getAuthor() {
return "Prride";
}
@Override
public String getVersion() {
return "1.0.0";
}
@Override
public String getDescription() {
return Element.EARTH.getColor() + "Launch a wave of destructive magma!";
}
@Override
public String getInstructions() {
return "Hold sneak on an earth block, and left click. You are able to control the ability while sneaking.";
}
}