Skip to content

Commit 95bde27

Browse files
committed
2.13.2
- Fixed Drain not activating and messily leaving water blocks behind
1 parent 696189f commit 95bde27

File tree

5 files changed

+58
-41
lines changed

5 files changed

+58
-41
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ Join our [Discord](https://discord.gg/gh9MfDmwZm) to discuss the plugin, suggest
55

66
## Changelog
77

8+
### 2.13.2
9+
- Fixed Drain not activating and messily leaving water blocks behind
10+
811
### 2.13.1
912
- Fixed board command overriding PK's when our board is disabled
1013

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.jedk1</groupId>
66
<artifactId>jedcore</artifactId>
7-
<version>2.13.1-PK1.11.1</version>
7+
<version>2.13.2-PK1.11.1</version>
88
<packaging>jar</packaging>
99
<name>JedCore</name>
1010

src/com/jedk1/jedcore/ability/waterbending/Drain.java

+34-23
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.jedk1.jedcore.JCMethods;
44
import com.jedk1.jedcore.JedCore;
55
import com.jedk1.jedcore.configuration.JedCoreConfig;
6-
import com.jedk1.jedcore.util.RegenTempBlock;
76
import com.projectkorra.projectkorra.GeneralMethods;
87
import com.projectkorra.projectkorra.ability.AddonAbility;
98
import com.projectkorra.projectkorra.ability.ElementalAbility;
@@ -15,6 +14,7 @@
1514

1615
import org.bukkit.Location;
1716
import org.bukkit.Material;
17+
import org.bukkit.World;
1818
import org.bukkit.block.Block;
1919
import org.bukkit.block.BlockFace;
2020
import org.bukkit.block.data.Levelled;
@@ -27,12 +27,15 @@
2727
import java.util.ArrayList;
2828
import java.util.Arrays;
2929
import java.util.HashMap;
30+
import java.util.HashSet;
3031
import java.util.List;
3132
import java.util.Random;
33+
import java.util.Set;
3234

3335
public class Drain extends WaterAbility implements AddonAbility {
3436

3537
private final List<Location> locations = new ArrayList<>();
38+
static final Set<TempBlock> WATER_TEMPS = new HashSet<>();
3639

3740
//Savannas are 1.0 temp with 0 humidity. Deserts are 2.0 temp with 0 humidity.
3841
private static float MAX_TEMP = 1.0F;
@@ -107,10 +110,10 @@ public void setFields() {
107110
blastSpeed = config.getDouble("Abilities.Water.Drain.BlastSpeed");
108111
useRain = config.getBoolean("Abilities.Water.Drain.AllowRainSource");
109112
drainTemps = config.getBoolean("Abilities.Water.Drain.DrainTempBlocks");
110-
113+
111114
applyModifiers();
112115
}
113-
116+
114117
private void applyModifiers() {
115118
if (isNight(player.getWorld())) {
116119
cooldown -= ((long) getNightFactor(cooldown) - cooldown);
@@ -197,9 +200,11 @@ private void fireBlast() {
197200

198201
private void displayWaterSource() {
199202
Location location = player.getEyeLocation().add(player.getLocation().getDirection().multiply(holdRange));
200-
if (!GeneralMethods.isSolid(location.getBlock()) || isTransparent(location.getBlock())) {
201-
Block block = location.getBlock();
202-
new RegenTempBlock(block, Material.WATER, Material.WATER.createBlockData(bd -> ((Levelled)bd).setLevel(charge)), 100L);
203+
Block block = location.getBlock();
204+
if (!GeneralMethods.isSolid(block) || isTransparent(block)) {
205+
TempBlock tb = new TempBlock(block, Material.WATER.createBlockData(bd -> ((Levelled) bd).setLevel(charge)), 100L);
206+
WATER_TEMPS.add(tb);
207+
tb.setRevertTask(() -> WATER_TEMPS.remove(tb));
203208
}
204209
}
205210

@@ -250,25 +255,29 @@ private void checkForValidSource() {
250255
List<Location> locs = GeneralMethods.getCircle(player.getLocation(), radius, radius, false, true, 0);
251256
for (int i = 0; i < locs.size(); i++) {
252257
Block block = locs.get(rand.nextInt(locs.size()-1)).getBlock();
253-
if (block.getY() > block.getWorld().getMinHeight() && block.getY() < block.getWorld().getMaxHeight()) {
254-
if (rand.nextInt(chance) == 0) {
255-
double temp = player.getLocation().getWorld().getTemperature(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ());
256-
double humidity = player.getLocation().getWorld().getHumidity(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ());
257-
if (useRain && player.getWorld().hasStorm() && !(temp >= MAX_TEMP || humidity <= MIN_HUMIDITY)) {
258-
if (player.getLocation().getY() >= player.getWorld().getHighestBlockAt(player.getLocation()).getLocation().getY()) {
259-
if (block.getLocation().getY() >= player.getWorld().getHighestBlockAt(player.getLocation()).getLocation().getY()) {
260-
locations.add(block.getLocation().clone().add(.5, .5, .5));
258+
if (rand.nextInt(chance) == 0) {
259+
Location pLoc = player.getLocation();
260+
World world = pLoc.getWorld();
261+
double temp = world.getTemperature(pLoc.getBlockX(), pLoc.getBlockY(), pLoc.getBlockZ());
262+
double humidity = world.getHumidity(pLoc.getBlockX(), pLoc.getBlockY(), pLoc.getBlockZ());
263+
if (block.getY() > world.getMinHeight() && block.getY() < world.getMaxHeight()) {
264+
Location bLoc = block.getLocation();
265+
if (useRain && world.hasStorm() && !(temp >= MAX_TEMP || humidity <= MIN_HUMIDITY)) {
266+
if (pLoc.getY() >= world.getHighestBlockAt(pLoc).getLocation().getY()) {
267+
if (bLoc.getY() >= world.getHighestBlockAt(pLoc).getLocation().getY()) {
268+
locations.add(bLoc.clone().add(.5, .5, .5));
261269
return;
262270
}
263271
}
264272
}
265-
if (usePlants && JCMethods.isSmallPlant(block) && !isObstructed(block.getLocation(), player.getEyeLocation())) {
273+
if (usePlants && JCMethods.isSmallPlant(block) && !isObstructed(bLoc, player.getEyeLocation())) {
266274
drainPlant(block);
267-
} else if(usePlants && ElementalAbility.isPlant(block) && !isObstructed(block.getLocation(), player.getEyeLocation())) {
268-
locations.add(block.getLocation().clone().add(.5, .5, .5));
269-
new RegenTempBlock(block, Material.AIR, Material.AIR.createBlockData(), regenDelay);
275+
} else if (usePlants && ElementalAbility.isPlant(block) && !isObstructed(bLoc, player.getEyeLocation())) {
276+
locations.add(bLoc.clone().add(.5, .5, .5));
277+
new TempBlock(block, Material.AIR.createBlockData(), regenDelay);
270278
} else if (isWater(block)) {
271-
if (drainTemps || !TempBlock.isTempBlock(block)) {
279+
TempBlock tb = TempBlock.get(block);
280+
if ((tb == null || (drainTemps && !WATER_TEMPS.contains(tb)))) {
272281
drainWater(block);
273282
}
274283
}
@@ -303,23 +312,25 @@ private void drainPlant(Block block) {
303312
if (JCMethods.isDoublePlant(block.getType())) {
304313
block = block.getRelative(BlockFace.DOWN);
305314
locations.add(block.getLocation().clone().add(.5, .5, .5));
306-
new RegenTempBlock(block, Material.DEAD_BUSH, Material.DEAD_BUSH.createBlockData(), regenDelay);
315+
new TempBlock(block, Material.DEAD_BUSH.createBlockData(), regenDelay);
307316
return;
308317
}
309318
block = block.getRelative(BlockFace.DOWN);
310319
}
311320
locations.add(block.getLocation().clone().add(.5, .5, .5));
312-
new RegenTempBlock(block, Material.DEAD_BUSH, Material.DEAD_BUSH.createBlockData(), regenDelay);
321+
new TempBlock(block, Material.DEAD_BUSH.createBlockData(), regenDelay);
313322
}
314323
}
315324

316325
private void drainWater(Block block) {
317326
if (isTransparent(block.getRelative(BlockFace.UP)) && !isWater(block.getRelative(BlockFace.UP))) {
318327
locations.add(block.getLocation().clone().add(.5, .5, .5));
319328
if (block.getBlockData() instanceof Waterlogged) {
320-
new RegenTempBlock(block, block.getBlockData().getMaterial(), block.getBlockData().getMaterial().createBlockData(bd -> ((Waterlogged) bd).setWaterlogged(false)), regenDelay);
329+
new TempBlock(block, block.getType().createBlockData(bd -> ((Waterlogged) bd).setWaterlogged(false)), regenDelay);
321330
} else {
322-
new RegenTempBlock(block, Material.WATER, Material.WATER.createBlockData(bd -> ((Levelled) bd).setLevel(1)), regenDelay);
331+
TempBlock tb = new TempBlock(block, Material.WATER.createBlockData(bd -> ((Levelled) bd).setLevel(1)), regenDelay);
332+
WATER_TEMPS.add(tb);
333+
tb.setRevertTask(() -> WATER_TEMPS.remove(tb));
323334
}
324335
}
325336
}

src/com/jedk1/jedcore/ability/waterbending/DrainBlast.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import com.jedk1.jedcore.JedCore;
44
import com.jedk1.jedcore.configuration.JedCoreConfig;
5-
import com.jedk1.jedcore.util.RegenTempBlock;
65
import com.projectkorra.projectkorra.GeneralMethods;
76
import com.projectkorra.projectkorra.ability.AddonAbility;
87
import com.projectkorra.projectkorra.ability.WaterAbility;
98
import com.projectkorra.projectkorra.attribute.Attribute;
109
import com.projectkorra.projectkorra.util.DamageHandler;
10+
import com.projectkorra.projectkorra.util.TempBlock;
1111

1212
import org.bukkit.Location;
1313
import org.bukkit.Material;
@@ -69,7 +69,9 @@ private void advanceAttack() {
6969
}
7070

7171
playWaterbendingSound(location);
72-
new RegenTempBlock(location.getBlock(), Material.WATER, Material.WATER.createBlockData(bd -> ((Levelled) bd).setLevel(0)), 100L);
72+
TempBlock tb = new TempBlock(location.getBlock(), Material.WATER.createBlockData(bd -> ((Levelled) bd).setLevel(0)), 100L);
73+
Drain.WATER_TEMPS.add(tb);
74+
tb.setRevertTask(() -> Drain.WATER_TEMPS.remove(tb));
7375

7476
for (Entity entity : GeneralMethods.getEntitiesAroundPoint(location, 2.5)) {
7577
if (entity instanceof LivingEntity && entity.getEntityId() != player.getEntityId() && !(entity instanceof ArmorStand)) {
@@ -79,7 +81,7 @@ private void advanceAttack() {
7981
}
8082
}
8183
}
82-
84+
8385
@Override
8486
public long getCooldown() {
8587
return 0;
@@ -158,7 +160,7 @@ public void load() {}
158160

159161
@Override
160162
public void stop() {}
161-
163+
162164
@Override
163165
public boolean isEnabled() {
164166
ConfigurationSection config = JedCoreConfig.getConfig(this.player);

src/com/jedk1/jedcore/listener/AbilityListener.java

+14-13
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,14 @@ public void onPlayerSwing(PlayerInteractEvent event) {
173173
} else if (GeneralMethods.isInteractable(player.getTargetBlock((Set<Material>)null, 5))) {
174174
return;
175175
}
176-
176+
177177
if (bPlayer.isToggled()) {
178178
new WallRun(player);
179179
}
180180

181181
CoreAbility coreAbil = bPlayer.getBoundAbility();
182182
if (coreAbil == null) {
183-
if(MultiAbilityManager.hasMultiAbilityBound(player)){
183+
if (MultiAbilityManager.hasMultiAbilityBound(player)){
184184
String abil = MultiAbilityManager.getBoundMultiAbility(player);
185185
if (abil.equalsIgnoreCase("elementsphere")) {
186186
new ElementSphere(player);
@@ -189,6 +189,7 @@ public void onPlayerSwing(PlayerInteractEvent event) {
189189
return;
190190
}
191191

192+
String abilName = bPlayer.getBoundAbilityName();
192193
Class<? extends CoreAbility> abilClass = coreAbil.getClass();
193194

194195
if (bPlayer.canBendIgnoreCooldowns(coreAbil)) {
@@ -204,7 +205,7 @@ public void onPlayerSwing(PlayerInteractEvent event) {
204205
new AirPunch(player);
205206
}
206207
}
207-
208+
208209
if (coreAbil instanceof EarthAbility && bPlayer.isElementToggled(Element.EARTH)) {
209210
if (GeneralMethods.isWeapon(player.getInventory().getItemInMainHand().getType()) && !ProjectKorra.plugin.getConfig().getBoolean("Properties.Earth.CanBendWithWeapons")) {
210211
return;
@@ -270,7 +271,7 @@ public void onPlayerSwing(PlayerInteractEvent event) {
270271
FireShots.fireShot(player);
271272
}
272273
}
273-
274+
274275
if (coreAbil instanceof WaterAbility && bPlayer.isElementToggled(Element.WATER)) {
275276
if (GeneralMethods.isWeapon(player.getInventory().getItemInMainHand().getType()) && !ProjectKorra.plugin.getConfig().getBoolean("Properties.WATER.CanBendWithWeapons")) {
276277
return;
@@ -284,7 +285,7 @@ public void onPlayerSwing(PlayerInteractEvent event) {
284285
if (abilClass.equals(IceClaws.class)) {
285286
IceClaws.throwClaws(player);
286287
}
287-
if (abilClass.equals(Drain.class)) {
288+
if (abilName.equals("Drain")) {
288289
Drain.fireBlast(player);
289290
}
290291
if (coreAbil.getName().equalsIgnoreCase("watermanipulation")) {
@@ -302,15 +303,15 @@ public void onPlayerSwing(PlayerInteractEvent event) {
302303
new DaggerThrow(player);
303304
}
304305
}
305-
306+
306307
if (coreAbil instanceof AvatarAbility) {
307308
if (abilClass.equals(ElementSphere.class)) {
308309
new ElementSphere(player);
309310
}
310311
}
311312
}
312313
}
313-
314+
314315
public static ConcurrentHashMap<UUID, Long> recent = new ConcurrentHashMap<UUID, Long>();
315316

316317
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
@@ -377,7 +378,7 @@ public void onPlayerSneak(PlayerToggleSneakEvent event) {
377378
new SonicBlast(player);
378379
}
379380
}
380-
381+
381382
if (coreAbil instanceof EarthAbility && bPlayer.isElementToggled(Element.EARTH)) {
382383
if (GeneralMethods.isWeapon(player.getInventory().getItemInMainHand().getType()) && !ProjectKorra.plugin.getConfig().getBoolean("Properties.Earth.CanBendWithWeapons")) {
383384
return;
@@ -419,7 +420,7 @@ public void onPlayerSneak(PlayerToggleSneakEvent event) {
419420
Crevice.closeCrevice(player);
420421
}
421422
}
422-
423+
423424
if (coreAbil instanceof FireAbility && bPlayer.isElementToggled(Element.FIRE)) {
424425
if (GeneralMethods.isWeapon(player.getInventory().getItemInMainHand().getType()) && !ProjectKorra.plugin.getConfig().getBoolean("Properties.Fire.CanBendWithWeapons")) {
425426
return;
@@ -451,7 +452,7 @@ public void onPlayerSneak(PlayerToggleSneakEvent event) {
451452
new LightningBurst(player);
452453
}
453454
}
454-
455+
455456
if (coreAbil instanceof WaterAbility && bPlayer.isElementToggled(Element.WATER)) {
456457
if (GeneralMethods.isWeapon(player.getInventory().getItemInMainHand().getType()) && !ProjectKorra.plugin.getConfig().getBoolean("Properties.Water.CanBendWithWeapons")) {
457458
return;
@@ -471,14 +472,14 @@ public void onPlayerSneak(PlayerToggleSneakEvent event) {
471472
if (abilClass.equals(IceWall.class)) {
472473
new IceWall(player);
473474
}
474-
if (abilClass.equals(Drain.class)) {
475+
if (abilName.equals("Drain")) {
475476
new Drain(player);
476477
}
477478
if (abilClass.equals(WakeFishing.class)) {
478479
new WakeFishing(player);
479480
}
480481
}
481-
482+
482483
if (coreAbil instanceof AvatarAbility) {
483484
if (abilClass.equals(SpiritBeam.class)) {
484485
new SpiritBeam(player);
@@ -497,7 +498,7 @@ public void onArrowHit(EntityDamageByEntityEvent event) {
497498
}
498499
}
499500
}
500-
501+
501502
@EventHandler(priority = EventPriority.NORMAL)
502503
public void onPlayerInteraction(PlayerInteractEvent event) {
503504
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {

0 commit comments

Comments
 (0)