Skip to content

Commit 380503f

Browse files
committed
Fixed BurstFireCharger
Closes #585
1 parent c0f4252 commit 380503f

File tree

4 files changed

+100
-100
lines changed

4 files changed

+100
-100
lines changed
Lines changed: 90 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,103 @@
11
package me.zombie_striker.qg.guns.chargers;
22

3-
import java.util.HashMap;
4-
import java.util.UUID;
5-
3+
import me.zombie_striker.qg.QAMain;
4+
import me.zombie_striker.qg.api.QualityArmory;
5+
import me.zombie_striker.qg.guns.Gun;
6+
import me.zombie_striker.qg.guns.utils.GunUtil;
67
import me.zombie_striker.qg.guns.utils.WeaponSounds;
78
import org.bukkit.entity.Player;
89
import org.bukkit.inventory.ItemStack;
9-
import org.bukkit.inventory.meta.ItemMeta;
1010
import org.bukkit.scheduler.BukkitRunnable;
1111
import org.bukkit.scheduler.BukkitTask;
1212

13-
import me.zombie_striker.qg.QAMain;
14-
import me.zombie_striker.qg.api.QualityArmory;
15-
import me.zombie_striker.qg.guns.Gun;
16-
import me.zombie_striker.qg.guns.utils.GunUtil;
13+
import java.util.HashMap;
14+
import java.util.UUID;
1715

1816
public class BurstFireCharger implements ChargingHandler {
1917

20-
public static HashMap<UUID, BukkitTask> shooters = new HashMap<>();
21-
22-
public BurstFireCharger() {
23-
ChargingManager.add(this);
24-
}
25-
26-
@Override
27-
public boolean isCharging(Player player) {
28-
return shooters.containsKey(player.getUniqueId());
29-
}
30-
31-
@Override
32-
public boolean shoot(final Gun g, final Player player, final ItemStack stack) {
33-
GunUtil.shootHandler(g, player,1);
34-
// final AttachmentBase attach = QualityArmory.getGunWithAttchments(stack);
35-
GunUtil.playShoot(g, player);
36-
shooters.put(player.getUniqueId(), new BukkitRunnable() {
37-
int slotUsed = player.getInventory().getHeldItemSlot();
38-
@SuppressWarnings("deprecation")
39-
boolean offhand = QualityArmory.isIronSights(player.getItemInHand());
40-
int shotCurrently = 1;
41-
42-
@Override
43-
@SuppressWarnings("deprecation")
44-
public void run() {
45-
int slot;
46-
if (offhand) {
47-
slot = -1;
48-
} else {
49-
slot = player.getInventory().getHeldItemSlot();
50-
}
51-
52-
int amount = Gun.getAmount(player);
53-
if (shotCurrently >= g.getBulletsPerShot() || slotUsed != player.getInventory().getHeldItemSlot()
54-
|| amount <= 0) {
55-
if (shooters.containsKey(player.getUniqueId()))
56-
shooters.remove(player.getUniqueId()).cancel();
57-
return;
58-
}
59-
60-
GunUtil.shootHandler(g, player,1);
61-
GunUtil.playShoot(g, player);
62-
if(QAMain.enableRecoil && g.getRecoil()>0) {
63-
GunUtil.addRecoil(player, g);
64-
}
65-
shotCurrently++;
66-
amount--;
67-
68-
if (amount < 0)
69-
amount = 0;
70-
71-
//if (QAMain.enableVisibleAmounts) {
72-
// stack.setAmount(amount > 64 ? 64 : amount == 0 ? 1 : amount);
73-
//}
74-
ItemMeta im = stack.getItemMeta();
75-
Gun.updateAmmo(g, player, amount);
76-
stack.setItemMeta(im);
77-
if (slot == -1) {
78-
try {
79-
if (QualityArmory.isIronSights(player.getItemInHand())) {
80-
if(QualityArmory.isGun(player.getInventory().getItemInOffHand()))
81-
player.getInventory().setItemInOffHand(stack);
82-
}
83-
} catch (Error e) {
84-
}
85-
} else {
86-
if(QualityArmory.isGun(player.getInventory().getItem(slot)))
87-
player.getInventory().setItem(slot, stack);
88-
}
89-
QualityArmory.sendHotbarGunAmmoCount(player, g, stack, false);
90-
}
91-
}.runTaskTimer(QAMain.getInstance(), 10 / g.getFireRate(), 10 / g.getFireRate()));
92-
return false;
93-
}
94-
95-
96-
@Override
97-
public String getName() {
98-
99-
return ChargingManager.BURSTFIRE;
100-
}
101-
@Override
102-
public String getDefaultChargingSound() {
103-
return WeaponSounds.RELOAD_BULLET.getSoundName();
104-
//g.getChargingSound()
105-
}
18+
public static HashMap<UUID, BukkitTask> shooters = new HashMap<>();
19+
20+
public BurstFireCharger() {
21+
ChargingManager.add(this);
22+
}
23+
24+
@Override
25+
public boolean isCharging(Player player) {
26+
return shooters.containsKey(player.getUniqueId());
27+
}
28+
29+
@Override
30+
public boolean shoot(final Gun g, final Player player, final ItemStack stack) {
31+
GunUtil.shootHandler(g, player, 1);
32+
// final AttachmentBase attach = QualityArmory.getGunWithAttchments(stack);
33+
GunUtil.playShoot(g, player);
34+
shooters.put(player.getUniqueId(), new BukkitRunnable() {
35+
final int slotUsed = player.getInventory().getHeldItemSlot();
36+
@SuppressWarnings("deprecation")
37+
final boolean offhand = QualityArmory.isIronSights(player.getItemInHand());
38+
int shotCurrently = 1;
39+
40+
@Override
41+
@SuppressWarnings("deprecation")
42+
public void run() {
43+
int slot;
44+
if (offhand) {
45+
slot = -1;
46+
} else {
47+
slot = player.getInventory().getHeldItemSlot();
48+
}
49+
50+
int amount = Gun.getAmount(player);
51+
if (shotCurrently >= g.getBulletsPerShot() || slotUsed != player.getInventory().getHeldItemSlot()
52+
|| amount <= 0) {
53+
if (shooters.containsKey(player.getUniqueId()))
54+
shooters.remove(player.getUniqueId()).cancel();
55+
return;
56+
}
57+
58+
GunUtil.shootHandler(g, player, 1);
59+
GunUtil.playShoot(g, player);
60+
if (QAMain.enableRecoil && g.getRecoil() > 0) {
61+
GunUtil.addRecoil(player, g);
62+
}
63+
shotCurrently++;
64+
amount--;
65+
66+
//if (QAMain.enableVisibleAmounts) {
67+
// stack.setAmount(amount > 64 ? 64 : amount == 0 ? 1 : amount);
68+
//}
69+
70+
Gun.updateAmmo(g, stack, amount);
71+
72+
if (slot == -1) {
73+
try {
74+
if (QualityArmory.isIronSights(player.getItemInHand())) {
75+
if (QualityArmory.isGun(player.getInventory().getItemInOffHand()))
76+
player.getInventory().setItemInOffHand(stack);
77+
}
78+
} catch (Error ignored) {
79+
}
80+
81+
} else {
82+
if (QualityArmory.isGun(player.getInventory().getItem(slot)))
83+
player.getInventory().setItem(slot, stack);
84+
}
85+
QualityArmory.sendHotbarGunAmmoCount(player, g, stack, false);
86+
}
87+
}.runTaskTimer(QAMain.getInstance(), 10 / g.getFireRate(), 10 / g.getFireRate()));
88+
return false;
89+
}
90+
91+
92+
@Override
93+
public String getName() {
94+
return ChargingManager.BURSTFIRE;
95+
}
96+
97+
@Override
98+
public String getDefaultChargingSound() {
99+
return WeaponSounds.RELOAD_BULLET.getSoundName();
100+
//g.getChargingSound()
101+
}
106102

107103
}

src/main/java/me/zombie_striker/qg/guns/chargers/DelayedBurstFireCharger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ public void run() {
8181
} else {
8282
slot = player.getInventory().getHeldItemSlot();
8383
}
84-
Gun.updateAmmo(g, player, amount);
8584
stack.setItemMeta(im);
85+
Gun.updateAmmo(g, stack, amount);
8686
if (slot == -1) {
8787
try {
8888
if (QualityArmory.isIronSights(player.getItemInHand())) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,8 @@ public static void basicShoot(boolean offhand, final Gun g, final Player player,
496496
boolean regularshoot = true;
497497

498498
if (g.getChargingHandler() != null) {
499-
QAMain.DEBUG("Charging shoot debug: " + g.getName() + " = " + g.getChargingHandler() == null ? "null"
500-
: g.getChargingHandler().getName());
499+
QAMain.DEBUG("Charging shoot debug: " + g.getName() + " = " + (g.getChargingHandler() == null ? "null"
500+
: g.getChargingHandler().getName()));
501501
regularshoot = g.getChargingHandler().shoot(g, player, firstGunInstance);
502502
}
503503

@@ -568,9 +568,9 @@ public void run() {
568568
&& (g.getReloadingingHandler() == null || !g.getReloadingingHandler().isReloading(player)))) {
569569
regularshoot = g.getChargingHandler().shoot(g, player, temp);
570570
QAMain.DEBUG(
571-
"Charging (rapidfire) shoot debug: " + g.getName() + " = " + g.getChargingHandler() == null
571+
"Charging (rapidfire) shoot debug: " + g.getName() + " = " + (g.getChargingHandler() == null
572572
? "null"
573-
: g.getChargingHandler().getName());
573+
: g.getChargingHandler().getName()));
574574
}
575575
if (regularshoot) {
576576
GunUtil.shootHandler(g, player);

src/main/resources/changelog.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
2.0.15
2+
- Fixed 1.21 support
3+
- Fixed BurstFire charging
4+
15
2.0.14.1
2-
- Fixed 1.21 incompatibility
6+
- Fixed 1.21 support
37

48
2.0.14
59
- 1.21 support

0 commit comments

Comments
 (0)