Skip to content

Commit cf2c447

Browse files
v1.4.13 - Add bounty events
1 parent cd3e2bc commit cf2c447

File tree

5 files changed

+144
-1
lines changed

5 files changed

+144
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.tcoded</groupId>
88
<artifactId>PlayerBountiesPlus</artifactId>
9-
<version>1.4.12</version>
9+
<version>1.4.13</version>
1010
<packaging>jar</packaging>
1111

1212
<name>PlayerBountiesPlus</name>

src/main/java/com/tcoded/playerbountiesplus/command/bounty/BountySetCmd.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.tcoded.playerbountiesplus.command.bounty;
22

33
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
4+
import com.tcoded.playerbountiesplus.event.BountySetEvent;
45
import com.tcoded.playerbountiesplus.manager.BountyDataManager;
56
import org.bukkit.command.Command;
67
import org.bukkit.command.CommandSender;
@@ -63,6 +64,17 @@ public static boolean handleCmd(PlayerBountiesPlus plugin, CommandSender sender,
6364
// Apply bounty multiplier
6465
amount *= (float) plugin.getConfig().getDouble("bounty-multiplier", 1.0);
6566

67+
// Trigger bounty set event
68+
BountySetEvent event = new BountySetEvent(sender instanceof Player ? (Player) sender : null, target, amount);
69+
plugin.getServer().getPluginManager().callEvent(event);
70+
amount = event.getAmount();
71+
72+
// Check if event was cancelled
73+
if (event.isCancelled()) {
74+
sender.sendMessage(plugin.getLang().getColored("command.bounty.set.cancelled"));
75+
return true;
76+
}
77+
6678
// Sanity check final amount
6779
if (amount <= 0) {
6880
sender.sendMessage(plugin.getLang().getColored("command.bounty.set.internal-invalid-value"));
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.tcoded.playerbountiesplus.event;
2+
3+
import org.bukkit.entity.Player;
4+
import org.bukkit.event.Cancellable;
5+
import org.bukkit.event.Event;
6+
import org.bukkit.event.HandlerList;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
public class BountyClaimEvent extends Event implements Cancellable {
10+
11+
private static final HandlerList handlers = new HandlerList();
12+
13+
private final Player claimant;
14+
private final Player victim;
15+
private final double amount;
16+
17+
private boolean cancelled;
18+
19+
public BountyClaimEvent(@NotNull Player claimant, @NotNull Player victim, double amount) {
20+
this.claimant = claimant;
21+
this.victim = victim;
22+
this.amount = amount;
23+
this.cancelled = false;
24+
}
25+
26+
@Override
27+
public boolean isCancelled() {
28+
return cancelled;
29+
}
30+
31+
@Override
32+
public void setCancelled(boolean cancel) {
33+
this.cancelled = cancel;
34+
}
35+
36+
public Player getClaimant() {
37+
return claimant;
38+
}
39+
40+
public Player getVictim() {
41+
return victim;
42+
}
43+
44+
public double getAmount() {
45+
return amount;
46+
}
47+
48+
@Override
49+
public @NotNull HandlerList getHandlers() {
50+
return handlers;
51+
}
52+
53+
public static HandlerList getHandlerList() {
54+
return handlers;
55+
}
56+
57+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.tcoded.playerbountiesplus.event;
2+
3+
import org.bukkit.entity.Player;
4+
import org.bukkit.event.Cancellable;
5+
import org.bukkit.event.Event;
6+
import org.bukkit.event.HandlerList;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
public class BountySetEvent extends Event implements Cancellable {
10+
11+
private static final HandlerList handlers = new HandlerList();
12+
13+
private final Player setter;
14+
private final Player target;
15+
16+
private float amount;
17+
private boolean cancelled;
18+
19+
public BountySetEvent(Player setter, @NotNull Player target, float amount) {
20+
this.setter = setter;
21+
this.target = target;
22+
this.amount = amount;
23+
this.cancelled = false;
24+
}
25+
26+
/**
27+
* @return The player who set the bounty or null if it's set by console/command block.
28+
*/
29+
public Player getSetter() {
30+
return setter;
31+
}
32+
33+
public Player getTarget() {
34+
return target;
35+
}
36+
37+
public float getAmount() {
38+
return amount;
39+
}
40+
41+
public void setAmount(float amount) {
42+
this.amount = amount;
43+
}
44+
45+
@Override
46+
public boolean isCancelled() {
47+
return cancelled;
48+
}
49+
50+
@Override
51+
public void setCancelled(boolean cancel) {
52+
this.cancelled = cancel;
53+
}
54+
55+
@Override
56+
public @NotNull HandlerList getHandlers() {
57+
return handlers;
58+
}
59+
60+
public static HandlerList getHandlerList() {
61+
return handlers;
62+
}
63+
64+
}

src/main/java/com/tcoded/playerbountiesplus/listener/DeathListener.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.tcoded.playerbountiesplus.listener;
22

33
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
4+
import com.tcoded.playerbountiesplus.event.BountyClaimEvent;
45
import com.tcoded.playerbountiesplus.hook.team.TeamHook;
56
import com.tcoded.playerbountiesplus.manager.BountyDataManager;
67
import org.bukkit.entity.Player;
@@ -42,6 +43,15 @@ public void onDeath(PlayerDeathEvent event) {
4243
return;
4344
}
4445

46+
// Trigger Bounty Claimed Event
47+
BountyClaimEvent claimEvent = new BountyClaimEvent(killer, victim, bounty);
48+
this.plugin.getServer().getPluginManager().callEvent(claimEvent);
49+
50+
// Check if event is cancelled
51+
if (claimEvent.isCancelled()) {
52+
return;
53+
}
54+
4555
// Give reward!
4656
if (plugin.getConfig().getBoolean("bounty-claimable", true)) {
4757
double claimMultiplier = plugin.getConfig().getDouble("bounty-claim-multiplier", 1.0);

0 commit comments

Comments
 (0)