Skip to content

Commit 3dc4381

Browse files
committed
Fixed block regen
Closes #473
1 parent 8ca81ae commit 3dc4381

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

src/main/java/me/zombie_striker/qg/guns/utils/GunUtil.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import me.zombie_striker.qg.handlers.*;
1919
import me.zombie_striker.qg.hooks.CoreProtectHook;
2020
import me.zombie_striker.qg.hooks.protection.ProtectionHandler;
21+
import me.zombie_striker.qg.utils.BlockRegenData;
2122
import org.bukkit.*;
2223
import org.bukkit.attribute.Attribute;
2324
import org.bukkit.attribute.AttributeModifier;
@@ -380,13 +381,13 @@ public static void shootInstantVector(Gun g, Player p, double sway, double damag
380381
ParticleHandlers.spawnGunParticles(g, start);
381382
}
382383

383-
final Map<Block,Material> regenBlocks = new HashMap<>();
384+
final Map<Block, BlockRegenData> regenBlocks = new HashMap<>();
384385
for (Block l : blocksThatWillBreak) {
385386
QAMain.DEBUG("Breaking " + l.getX() + " " + l.getY() + " " + l.getZ() + ": " + l.getType());
386387
QAWeaponDamageBlockEvent event = new QAWeaponDamageBlockEvent(p,g,l);
387388
Bukkit.getPluginManager().callEvent(event);
388389
if (!event.isCancelled()) {
389-
if (!l.getType().isAir()) regenBlocks.put(l,l.getType());
390+
if (!l.getType().equals(Material.AIR)) regenBlocks.put(l,new BlockRegenData(l));
390391
if (QAMain.regenDestructableBlocksAfter > 0) {
391392
l.setType(Material.AIR);
392393
} else {
@@ -404,7 +405,7 @@ public void run() {
404405
QAMain.DEBUG("Replacing " + regenBlocks.size() + " blocks");
405406

406407
for (Block l : regenBlocks.keySet()) {
407-
l.setType(regenBlocks.get(l));
408+
regenBlocks.get(l).place(l.getLocation());
408409
CoreProtectHook.logPlace(l,p);
409410
}
410411
}
@@ -659,6 +660,7 @@ public void run() {
659660
}
660661

661662
public static void updateXPBar(Player player, Gun g, int amount) {
663+
if (g == null || player == null) return;
662664
player.setLevel(amount);
663665

664666
if (amount > 0) {

src/main/java/me/zombie_striker/qg/handlers/IronsightsHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class IronsightsHandler {
2121
public static void aim(Player player){
2222
if(!QualityArmory.isIronSights(player.getItemInHand())){
2323
//offHandStorage.put(player, player.getInventory().getItemInOffHand());
24-
if(player.getInventory().getItemInOffHand() != null && !player.getInventory().getItemInOffHand().getType().isAir()){
24+
if(player.getInventory().getItemInOffHand() != null && !player.getInventory().getItemInOffHand().getType().equals(Material.AIR)){
2525
if(player.getInventory().firstEmpty()==-1){
2626
player.getWorld().dropItem(player.getLocation(),player.getInventory().getItemInOffHand());
2727
}else {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package me.zombie_striker.qg.utils;
2+
3+
import org.bukkit.Location;
4+
import org.bukkit.Material;
5+
import org.bukkit.block.Block;
6+
import org.bukkit.block.data.BlockData;
7+
8+
public class BlockRegenData {
9+
private final Material material;
10+
private Object data;
11+
12+
public BlockRegenData(Block block) {
13+
this.material = block.getType();
14+
try {
15+
this.data = block.getBlockData();
16+
} catch (Exception | Error e) {
17+
this.data = null;
18+
}
19+
}
20+
21+
public void place(Location location) {
22+
location.getBlock().setType(material);
23+
24+
try {
25+
location.getBlock().setBlockData((BlockData) data);
26+
} catch (Exception | Error ignored) {}
27+
}
28+
}

src/main/resources/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Added headshot blacklist
88
- Fixed ammo in exp bar
99
- Fixed medkit
10+
- Fixed block regen
1011

1112
2.0.18
1213
- Fixed resourcepack for 1.21.4

0 commit comments

Comments
 (0)