Skip to content

Commit 41e8f0f

Browse files
Should fix doubledrop on break (Civcraft#27)
* Should fix doubledrop on break * Missing import * Correct block placements healing bastions, it has to always be start - end never end - start... * Correct block placements healing bastions, add your start, dont subtract it * minor health balance fix * Fixing conversion error * Numerous fixes to address raised issues. With listeners having proper boot config; includes instabreak if you hit the actual bastion block. * Trying to figure out why its not dropping correctly. * Fix Y level check logic to prevent blocking inversion * Sometimes Im an idiot too * Should fix square radius issue -- use squared not radius, pearl blocking where disabled, and should resolve ability to get back a bastion block placed but unreinforced * Forgot to add second half of pending bastion return, you know, the break listener. * Adding better pending handling across all breaking points. Fixed regressive logic reversion on pearl blocking * just some code quality fix and a config patch * Allow bastions to not block most things, but still prevent exiles, yet not be breakable unless physically removed * Should fix midair block failures, there was an extraneously malformed check. Removed some excess logging, and moved the non-block bastion alert to a different section.
1 parent a7ba8b7 commit 41e8f0f

10 files changed

+247
-85
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<groupId>isaac</groupId>
77
<artifactId>Bastion</artifactId>
88
<packaging>jar</packaging>
9-
<version>2.0.2</version>
9+
<version>2.0.3</version>
1010
<name>Bastion</name>
1111
<url>https://github.com/DevotedMC/Bastion</url>
1212

src/main/java/isaac/bastion/BastionBlock.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public BastionBlock(Location location, long placed, double balance, int ID, Bast
4848
} else{
4949
this.health = 0;
5050
destroy();
51+
Bastion.getPlugin().severe("Reinforcement removed during BastionBlock instantiation, removing");
5152
}
5253

5354
}
@@ -64,7 +65,7 @@ public double getErosionFromBlock() {
6465
if(type.getWarmupTime() == 0) {
6566
return scaleStart;
6667
} else if(time < type.getWarmupTime()) {
67-
return (((scaleEnd - scaleStart) / (float) type.getWarmupTime()) * time - scaleStart);
68+
return (((scaleEnd - scaleStart) / (float) type.getWarmupTime()) * time + scaleStart);
6869
} else {
6970
return scaleEnd;
7071
}
@@ -91,13 +92,14 @@ public double getErosionFromElytra() {
9192
* @return true if in field
9293
*/
9394
public boolean inField(Location loc) {
94-
return !(yLevelCheck(loc)) ||
95+
return !(yLevelCheck(loc) || // don't add parens if you don't know why it wasn't there.
9596
(type.isSquare() &&
9697
(Math.abs(loc.getBlockX() - location.getBlockX()) > type.getEffectRadius() ||
97-
Math.abs(loc.getBlockZ() - location.getBlockZ()) > type.getEffectRadius())) ||
98+
Math.abs(loc.getBlockZ() - location.getBlockZ()) > type.getEffectRadius() ) ) ||
9899
(!type.isSquare() &&
99-
((loc.getBlockX() - location.getX()) * (float)(loc.getBlockX() - location.getX()) +
100-
(loc.getBlockZ() - location.getZ()) * (float)(loc.getBlockZ() - location.getZ()) >= type.getEffectRadius()));
100+
((loc.getBlockX() - location.getX()) * (float)(loc.getBlockX() - location.getX()) +
101+
(loc.getBlockZ() - location.getZ()) * (float)(loc.getBlockZ() - location.getZ()) >= type.getRadiusSquared() ) )
102+
);
101103
}
102104

103105
public boolean yLevelCheck(Location loc) {
@@ -190,7 +192,7 @@ public boolean oneCanPlace(Set<UUID> players){
190192
* @return true if the Bastion's strength is at zero and it should be removed
191193
*/
192194
public boolean shouldCull() {
193-
return health - balance <= 0;
195+
return (health - balance) <= 0;
194196
}
195197

196198
/**
@@ -205,6 +207,7 @@ public void regen() {
205207
reinf.setDurability(Math.min(health + 1, maxHealth));
206208
} else {
207209
destroy();
210+
Bastion.getPlugin().severe("Reinforcement removed without removing bastion, fixed");
208211
}
209212
}
210213
}
@@ -229,11 +232,14 @@ public void erode(double amount) {
229232

230233
health -= wholeToRemove;
231234
balance = fractionToRemove;
235+
236+
if (health <= 0) health = 0;
232237

233238
reinforcement.setDurability(health);
234239

235240
if (shouldCull()) {
236241
destroy();
242+
Bastion.getPlugin().severe("Reinforcement destroyed, removing bastion");
237243
} else {
238244
Bastion.getBastionStorage().updated(this);
239245
}

src/main/java/isaac/bastion/BastionType.java

+40-9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class BastionType {
3333
private int erosionTime;
3434
private long placementCooldown;
3535
private boolean destroyOnRemove;
36+
private boolean onlyDirectDestruction;
3637
private boolean blockPearls;
3738
private boolean blockMidair;
3839
private int pearlScale;
@@ -54,7 +55,8 @@ public BastionType(String name, MaterialData material, String itemName, List<Str
5455
int erosionTime, long placementCooldown, boolean destroyOnRemove, boolean blockPearls,
5556
boolean blockMidair, int pearlScale, boolean pearlRequireMature, boolean consumeOnBlock, int blocksToErode,
5657
boolean blockElytra, boolean destroyOnBlockElytra, boolean damageElytra, int elytraScale, boolean elytraRequireMature,
57-
boolean explodeOnBlock, double explodeOnBlockStrength, boolean damageFirstBastion, int regenTime) {
58+
boolean explodeOnBlock, double explodeOnBlockStrength, boolean damageFirstBastion, int regenTime,
59+
boolean onlyDirectDestruction) {
5860
this.name = name;
5961
this.material = material;
6062
this.itemName = itemName;
@@ -69,6 +71,7 @@ public BastionType(String name, MaterialData material, String itemName, List<Str
6971
this.erosionTime = erosionTime;
7072
this.placementCooldown = placementCooldown;
7173
this.destroyOnRemove = destroyOnRemove;
74+
this.onlyDirectDestruction = onlyDirectDestruction;
7275
this.blockPearls = blockPearls;
7376
this.blockMidair = blockMidair;
7477
this.pearlScale = pearlScale;
@@ -176,6 +179,14 @@ public int getErosionTime() {
176179
public boolean isDestroyOnRemove() {
177180
return destroyOnRemove;
178181
}
182+
183+
/**
184+
*
185+
* @return true if a bastion can only be removed by destroying the block itself.
186+
*/
187+
public boolean isOnlyDirectDestruction() {
188+
return onlyDirectDestruction;
189+
}
179190

180191
/**
181192
*
@@ -344,7 +355,7 @@ public ItemStack getItemRepresentation() {
344355
im.setDisplayName(itemName);
345356
}
346357
is.setItemMeta(im);
347-
Bastion.getPlugin().getLogger().log(Level.INFO, "Bastion {0} represented as {1}", new Object[] {name, is.toString()});
358+
//Bastion.getPlugin().getLogger().log(Level.INFO, "Bastion {0} represented as {1}", new Object[] {name, is.toString()});
348359
return is;
349360
}
350361

@@ -390,14 +401,14 @@ public static BastionType getBastionType(String name) {
390401
public static BastionType getBastionType(MaterialData mat, String itemName, List<String> lore) {
391402
if (lore != null && lore.size() == 0) lore = null;
392403
for (BastionType type : types.values()) {
393-
StringBuilder sb = new StringBuilder();
404+
//StringBuilder sb = new StringBuilder();
394405
boolean test = type.material.equals(mat);
395-
sb.append(type.getName()).append(" is").append(test ? " " : "n't ").append(mat);
406+
//sb.append(type.getName()).append(" is").append(test ? " " : "n't ").append(mat);
396407
test &= ((itemName == null && type.itemName == null) || (type.itemName != null && type.itemName.equals(itemName)));
397-
sb.append(" name is ").append(itemName).append(test ? " = " : " not ").append(type.itemName);
408+
//sb.append(" name is ").append(itemName).append(test ? " = " : " not ").append(type.itemName);
398409
test &= ((lore == null && (type.lore == null || type.lore.size() == 0)) || (type.lore != null && type.lore.equals(lore)));
399-
sb.append(" lore is ").append(lore).append(test ? " = " : " not ").append(type.lore);
400-
Bastion.getPlugin().getLogger().log(Level.INFO, "BastionType check {0}", sb);
410+
//sb.append(" lore is ").append(lore).append(test ? " = " : " not ").append(type.lore);
411+
//Bastion.getPlugin().getLogger().log(Level.INFO, "BastionType check {0}", sb);
401412
if (test) return type;
402413
}
403414
return null;
@@ -442,6 +453,7 @@ public static BastionType getBastionType(ConfigurationSection config) {
442453
}
443454
long placementCooldown = config.getLong("placementCooldown");
444455
boolean destroyOnRemove = config.getBoolean("destroyOnRemove");
456+
boolean onlyDirectDestroy = config.getBoolean("onlyDirectDestroy");
445457
boolean blockPearls = config.getBoolean("pearls.block");
446458
boolean blockMidair = config.getBoolean("pearls.blockMidair");
447459
int scaleFactor = config.getInt("pearls.scaleFactor");
@@ -465,15 +477,34 @@ public static BastionType getBastionType(ConfigurationSection config) {
465477
return new BastionType(name, material, itemName, lore, square, effectRadius, includeY, startScaleFactor, finalScaleFactor, warmupTime,
466478
erosionTime, placementCooldown, destroyOnRemove, blockPearls, blockMidair, scaleFactor, requireMaturity, consumeOnBlock,
467479
blocksToErode, blockElytra, destroyElytra, damageElytra, elytraScale, elytraRequireMature, explodeOnBlock,
468-
explodeOnBlockStrength, damageFirstBastion, regenTime);
480+
explodeOnBlockStrength, damageFirstBastion, regenTime, onlyDirectDestroy);
469481
}
470482

471483
@Override
472484
public String toString() {
473485
StringBuilder sb = new StringBuilder(this.name);
474486
sb.append(": ").append(material)
475487
.append(" name:").append(itemName)
476-
.append(" lore[").append(lore != null ? lore.size() : 0).append("]: ").append(lore);
488+
.append(" lore[").append(lore != null ? lore.size() : 0).append("]: ").append(lore)
489+
.append(" scale[").append(this.startScaleFactor).append("->").append(this.finalScaleFactor)
490+
.append(" ").append(this.effectRadius).append(this.square ? "cb": "r")
491+
.append(" wm").append(this.warmupTime).append(" cd").append(this.placementCooldown)
492+
.append(" ed").append(this.erosionTime).append(" rd").append(this.regenTime)
493+
.append(" iY").append(this.includeY).append(" bte").append(this.blocksToErode)
494+
.append(" doR").append(this.destroyOnRemove).append(" oDD").append(this.onlyDirectDestruction)
495+
.append(" pearls[").append(this.blockPearls);
496+
if (this.blockPearls) {
497+
sb.append(": mid").append(this.blockMidair).append(" rM").append(this.pearlRequireMature)
498+
.append(" sc").append(this.pearlScale).append(" cob").append(this.consumeOnBlock)
499+
.append(" dfB").append(this.damageFirstBastion);
500+
}
501+
sb.append("] elytra[").append(this.blockElytra);
502+
if (this.blockElytra) {
503+
sb.append(": rM").append(this.elytraRequireMature).append(" sc").append(this.elytraScale)
504+
.append(" dob").append(this.damageElytra).append(" Dob").append(this.destroyElytra)
505+
.append(" eob").append(this.explodeOnBlock).append(" eos").append(this.explodeOnBlockStrength);
506+
}
507+
sb.append("]");
477508
return sb.toString();
478509
}
479510
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package isaac.bastion.listeners;
22

3-
import java.util.ArrayList;
3+
import java.util.HashSet;
44
import java.util.Iterator;
5+
import java.util.logging.Level;
56

67
import org.bukkit.Location;
8+
import org.bukkit.Material;
79
import org.bukkit.block.Block;
810
import org.bukkit.block.PistonMoveReaction;
911
import org.bukkit.event.EventHandler;
@@ -20,6 +22,7 @@
2022
import org.bukkit.util.Vector;
2123

2224
import isaac.bastion.Bastion;
25+
import isaac.bastion.BastionBlock;
2326
import isaac.bastion.BastionType;
2427
import isaac.bastion.storage.BastionBlockStorage;
2528
import vg.civcraft.mc.citadel.Utility;
@@ -32,91 +35,132 @@ public BastionBreakListener(BastionBlockStorage storage) {
3235
this.storage = storage;
3336
}
3437

35-
private void dropBastionItem(Location loc) {
36-
BastionType type = storage.getTypeAtLocation(loc);
38+
private void dropBastionItem(Location loc, BastionType type) {
3739
ItemStack item = type.getItemRepresentation();
3840
new BukkitRunnable() {
3941
@Override
4042
public void run() {
4143
loc.getWorld().dropItem(loc.add(0.5, 0.5, 0.5), item).setVelocity(new Vector(0, 0.05, 0));;
4244
}
4345
}.runTaskLater(Bastion.getPlugin(), 1);
44-
storage.deleteDeadBastion(loc);
46+
storage.deleteDeadBastion(loc); // just in case.
4547
}
4648

47-
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
49+
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
4850
public void onBlockBreak(BlockBreakEvent event) {
51+
// we will only reach this is allowed by Citadel -- e.g. is not cancelled.
4952
Block block = Utility.getRealBlock(event.getBlock());
50-
if(storage.getTypeAtLocation(block.getLocation()) != null) {
51-
block.getDrops().clear();
52-
dropBastionItem(block.getLocation());
53+
BastionType type = storage.getTypeAtLocation(block.getLocation());
54+
if (type == null) {
55+
type = storage.getAndRemovePendingBastion(block.getLocation());
56+
}
57+
if(type != null) {
58+
Bastion.getPlugin().getLogger().log(Level.INFO, "BastionType broken {0}", type.toString());
59+
BastionBlock bastion = storage.getBastionBlock(block.getLocation());
60+
if (bastion != null) {
61+
bastion.destroy();
62+
}
63+
event.setCancelled(true);
64+
block.setType(Material.AIR);
65+
dropBastionItem(block.getLocation(), type);
5366
}
5467
}
5568

56-
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
69+
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
5770
public void onEntityExplode(EntityExplodeEvent event) {
5871
Iterator<Block> iterator = event.blockList().iterator();
59-
ArrayList<Block> blocks = new ArrayList<Block>();
72+
HashSet<Block> blocks = new HashSet<Block>();
6073
while(iterator.hasNext()) {
6174
Block block = Utility.getRealBlock(iterator.next());
62-
if(storage.getTypeAtLocation(block.getLocation()) != null) {
75+
BastionType type = storage.getTypeAtLocation(block.getLocation());
76+
if (type == null) {
77+
type = storage.getAndRemovePendingBastion(block.getLocation());
78+
}
79+
if( type != null) {
6380
if(blocks.contains(block)) {
64-
block.getDrops().clear();
6581
continue;
6682
}
6783
blocks.add(block);
68-
dropBastionItem(block.getLocation());
69-
block.getDrops().clear();
84+
block.setType(Material.AIR);
85+
dropBastionItem(block.getLocation(), type);
86+
iterator.remove(); // don't explode it, we've got it covered now.
7087
}
7188
}
7289
}
7390

74-
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
91+
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
7592
public void onEntityDoorBreak(EntityBreakDoorEvent event) {
93+
// we will only reach this if citadel allows
7694
Block block = Utility.getRealBlock(event.getBlock());
77-
if(storage.getTypeAtLocation(block.getLocation()) != null) {
78-
block.getDrops().clear();
79-
dropBastionItem(block.getLocation());
95+
BastionType type = storage.getTypeAtLocation(block.getLocation());
96+
if (type == null) {
97+
type = storage.getAndRemovePendingBastion(block.getLocation());
98+
}
99+
if(type != null) {
100+
BastionBlock bastion = storage.getBastionBlock(block.getLocation());
101+
if (bastion != null) {
102+
bastion.destroy();
103+
}
104+
event.setCancelled(true);
105+
block.setType(Material.AIR);
106+
event.getBlock().setType(Material.AIR);
107+
dropBastionItem(block.getLocation(), type);
80108
}
81109
}
82-
83-
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
110+
111+
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
84112
public void onPistonExtend(BlockPistonExtendEvent event) {
113+
// we will only reach this if citadel allows
85114
for(Block block : event.getBlocks()) {
86-
if(storage.getTypeAtLocation(block.getLocation()) != null) {
115+
BastionType type = storage.getTypeAtLocation(block.getLocation());
116+
if (type == null) {
117+
type = storage.getAndRemovePendingBastion(block.getLocation());
118+
}
119+
if(type != null) {
87120
if(block.getPistonMoveReaction() == PistonMoveReaction.BREAK) {
88-
dropBastionItem(block.getLocation());
89-
block.getDrops().clear();
121+
dropBastionItem(block.getLocation(), type);
122+
block.setType(Material.AIR);
90123
} else if(block.getPistonMoveReaction() == PistonMoveReaction.MOVE) {
91124
Block toBlock = block.getRelative(event.getDirection());
92125
storage.moveDeadBastion(block.getLocation(), toBlock.getLocation());
126+
// TODO might need special handling if was pending previously
93127
}
94128
}
95129
}
96130
}
97131

98-
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
132+
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
99133
public void onPistonRetract(BlockPistonRetractEvent event) {
100134
if(!event.isSticky()) return;
101135
for(Block block : event.getBlocks()) {
102-
if(storage.getTypeAtLocation(block.getLocation()) != null) {
136+
BastionType type = storage.getTypeAtLocation(block.getLocation());
137+
if (type == null) {
138+
type = storage.getAndRemovePendingBastion(block.getLocation());
139+
}
140+
if(type != null) {
103141
if(block.getPistonMoveReaction() == PistonMoveReaction.BREAK) {
104-
dropBastionItem(block.getLocation());
105-
block.getDrops().clear();
142+
dropBastionItem(block.getLocation(), type);
143+
block.setType(Material.AIR);
106144
} else if(block.getPistonMoveReaction() == PistonMoveReaction.MOVE) {
107145
Block toBlock = block.getRelative(event.getDirection());
108146
storage.moveDeadBastion(block.getLocation(), toBlock.getLocation());
147+
// TODO might need special handling if pending previously
109148
}
110149
}
111150
}
112151
}
113152

114-
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
153+
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
115154
public void onBlockBurn(BlockBurnEvent event) {
116155
Block block = Utility.getRealBlock(event.getBlock());
117-
if(storage.getTypeAtLocation(block.getLocation()) != null) {
118-
block.getDrops().clear();
119-
dropBastionItem(block.getLocation());
156+
BastionType type = storage.getTypeAtLocation(block.getLocation());
157+
if (type == null) {
158+
type = storage.getAndRemovePendingBastion(block.getLocation());
159+
}
160+
if(type != null) {
161+
block.setType(Material.AIR);
162+
dropBastionItem(block.getLocation(), type);
163+
event.setCancelled(true);
120164
}
121165
}
122166
}

0 commit comments

Comments
 (0)