Compare commits

...
11 Commits
15 changed files with 441 additions and 23 deletions

No files matched your search

+6 -18
View File
@@ -6,7 +6,7 @@
<groupId>com.tcoded</groupId>
<artifactId>PlayerBountiesPlus</artifactId>
<version>1.4.9</version>
<version>1.4.14</version>
<packaging>jar</packaging>
<name>PlayerBountiesPlus</name>
@@ -79,18 +79,6 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>devmart-other</id>
<url>https://nexuslite.gcnt.net/repos/other/</url>
</repository>
<repository>
<id>devmart-public</id>
<url>https://nexuslite.gcnt.net/repos/public/</url>
</repository>
<repository>
<id>devmart-tcoded</id>
<url>https://nexuslite.gcnt.net/repos/tcoded/</url>
</repository>
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.org/repository/maven-public</url>
@@ -131,9 +119,9 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.tcoded</groupId>
<groupId>com.github.TechnicallyCoded</groupId>
<artifactId>FoliaLib</artifactId>
<version>0.2.6</version>
<version>0.4.3</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -150,9 +138,9 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.tcoded.lightlibs</groupId>
<groupId>com.github.LightLibs</groupId>
<artifactId>SpigotUpdateChecker</artifactId>
<version>1.1.2</version>
<version>1.1.3</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -176,7 +164,7 @@
<dependency>
<groupId>com.github.SaberLLC</groupId>
<artifactId>Saber-Factions</artifactId>
<version>4.1.2-STABLE</version>
<version>4.1.4-STABLE</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -2,6 +2,7 @@ package com.tcoded.playerbountiesplus;
import com.google.common.collect.ImmutableList;
import com.tcoded.folialib.FoliaLib;
import com.tcoded.lightlibs.updatechecker.SimpleUpdateChecker;
import com.tcoded.playerbountiesplus.command.BountyCommand;
import com.tcoded.playerbountiesplus.command.PlayerBountiesPlusAdminCmd;
import com.tcoded.playerbountiesplus.hook.currency.EconomyHook;
@@ -13,7 +14,6 @@ import com.tcoded.playerbountiesplus.hook.team.TeamHook;
import com.tcoded.playerbountiesplus.listener.DeathListener;
import com.tcoded.playerbountiesplus.manager.BountyDataManager;
import com.tcoded.playerbountiesplus.util.LangUtil;
import com.tcoded.updatechecker.SimpleUpdateChecker;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
import org.bukkit.ChatColor;
@@ -128,7 +128,7 @@ public final class PlayerBountiesPlus extends JavaPlugin {
this,
ChatColor.translateAlternateColorCodes('&', "&f[&bPlayerBountiesPlus&f] "),
108637,
runnable -> this.getFoliaLib().getImpl().runAsync(runnable)
runnable -> this.getFoliaLib().getScheduler().runAsync(wt -> runnable.run())
);
}
@@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
import com.tcoded.playerbountiesplus.command.admin.PlayerBountiesPlusReloadCmd;
import com.tcoded.playerbountiesplus.command.admin.PlayerBountiesPlusVersionCmd;
import com.tcoded.playerbountiesplus.command.admin.bounty.AdminBountyCmd;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@@ -17,7 +18,7 @@ import java.util.List;
import java.util.stream.Collectors;
public class PlayerBountiesPlusAdminCmd implements CommandExecutor, TabCompleter {
private static final ArrayList<String> completions = Lists.newArrayList("reload", "version", "help");
private static final ArrayList<String> completions = Lists.newArrayList("reload", "version", "admin", "help");
private final PlayerBountiesPlus plugin;
@@ -40,6 +41,8 @@ public class PlayerBountiesPlusAdminCmd implements CommandExecutor, TabCompleter
return PlayerBountiesPlusReloadCmd.handleCmd(plugin, sender, command, label, args);
case "version":
return PlayerBountiesPlusVersionCmd.handleCmd(plugin, sender, command, label, args);
case "admin":
return AdminBountyCmd.handleCmd(plugin, sender, command, label, args);
default:
sendHelpMsg(sender);
return true;
@@ -52,6 +55,10 @@ public class PlayerBountiesPlusAdminCmd implements CommandExecutor, TabCompleter
"&fAdmin Commands:\n" +
"&f/pbp reload &7- Reload the configuration file and the messages.\n" +
"&f/pbp version &7- Check the version of the plugin.\n" +
"&f/pbp bounty set <player> <amount> &7- Set a player's bounty.\n" +
"&f/pbp bounty add <player> <amount> &7- Add to a player's bounty.\n" +
"&f/pbp bounty remove <player> <amount> &7- Remove from a player's bounty.\n" +
"&f/pbp bounty delete <player> &7- Delete a player's bounty.\n" +
"&f/pbp help &7- Get this message."
));
}
@@ -0,0 +1,58 @@
package com.tcoded.playerbountiesplus.command.admin.bounty;
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
import com.tcoded.playerbountiesplus.manager.BountyDataManager;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import java.util.UUID;
public class AdminBountyAddCmd {
private static final String PERMISSION = "playerbountiesplus.command.playerbountiesplus.admin.add";
public static boolean handleCmd(PlayerBountiesPlus plugin, CommandSender sender, Command cmd, String label, String[] args) {
if (!sender.hasPermission(PERMISSION)) {
String noPerm = plugin.getLang().getColored("command.no-permission");
String noPermDetailed = plugin.getLang().getColored("command.no-permission-detailed")
.replace("{no-permission-msg}", noPerm)
.replace("{permission}", PERMISSION);
sender.sendMessage(noPermDetailed);
return true;
}
if (args.length < 4) {
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.add.missing-args"));
return true;
}
String playerName = args[2];
int amount;
try {
amount = Integer.parseInt(args[3]);
} catch (NumberFormatException ex) {
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.add.amount-nan"));
return true;
}
OfflinePlayer target = plugin.getServer().getOfflinePlayer(playerName);
if (target == null || (!target.hasPlayedBefore() && !target.isOnline())) {
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.add.player-not-found"));
return true;
}
UUID uuid = target.getUniqueId();
BountyDataManager m = plugin.getBountyDataManager();
int current = m.getBounty(uuid);
int total = current + amount;
m.setBounty(uuid, total);
m.saveBountiesAsync();
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.add.success")
.replace("{target}", target.getName())
.replace("{amount}", String.valueOf(amount))
.replace("{total}", String.valueOf(total)));
return true;
}
}
@@ -0,0 +1,30 @@
package com.tcoded.playerbountiesplus.command.admin.bounty;
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
public class AdminBountyCmd {
public static boolean handleCmd(PlayerBountiesPlus plugin, CommandSender sender, Command cmd, String label, String[] args) {
if (args.length < 2) {
sender.sendMessage(plugin.getLang().getColored("command.bounty.no-action"));
return true;
}
String action = args[1].toLowerCase();
switch (action) {
case "set":
return AdminBountySetCmd.handleCmd(plugin, sender, cmd, label, args);
case "add":
return AdminBountyAddCmd.handleCmd(plugin, sender, cmd, label, args);
case "remove":
return AdminBountyRemoveCmd.handleCmd(plugin, sender, cmd, label, args);
case "delete":
return AdminBountyDeleteCmd.handleCmd(plugin, sender, cmd, label, args);
default:
sender.sendMessage(plugin.getLang().getColored("command.bounty.invalid-action"));
return true;
}
}
}
@@ -0,0 +1,46 @@
package com.tcoded.playerbountiesplus.command.admin.bounty;
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
import com.tcoded.playerbountiesplus.manager.BountyDataManager;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import java.util.UUID;
public class AdminBountyDeleteCmd {
private static final String PERMISSION = "playerbountiesplus.command.playerbountiesplus.admin.delete";
public static boolean handleCmd(PlayerBountiesPlus plugin, CommandSender sender, Command cmd, String label, String[] args) {
if (!sender.hasPermission(PERMISSION)) {
String noPerm = plugin.getLang().getColored("command.no-permission");
String noPermDetailed = plugin.getLang().getColored("command.no-permission-detailed")
.replace("{no-permission-msg}", noPerm)
.replace("{permission}", PERMISSION);
sender.sendMessage(noPermDetailed);
return true;
}
if (args.length < 3) {
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.delete.missing-args"));
return true;
}
String playerName = args[2];
OfflinePlayer target = plugin.getServer().getOfflinePlayer(playerName);
if (target == null || (!target.hasPlayedBefore() && !target.isOnline())) {
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.delete.player-not-found"));
return true;
}
UUID uuid = target.getUniqueId();
BountyDataManager m = plugin.getBountyDataManager();
m.removeBounty(uuid);
m.saveBountiesAsync();
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.delete.success")
.replace("{target}", target.getName()));
return true;
}
}
@@ -0,0 +1,63 @@
package com.tcoded.playerbountiesplus.command.admin.bounty;
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
import com.tcoded.playerbountiesplus.manager.BountyDataManager;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import java.util.UUID;
public class AdminBountyRemoveCmd {
private static final String PERMISSION = "playerbountiesplus.command.playerbountiesplus.admin.remove";
public static boolean handleCmd(PlayerBountiesPlus plugin, CommandSender sender, Command cmd, String label, String[] args) {
if (!sender.hasPermission(PERMISSION)) {
String noPerm = plugin.getLang().getColored("command.no-permission");
String noPermDetailed = plugin.getLang().getColored("command.no-permission-detailed")
.replace("{no-permission-msg}", noPerm)
.replace("{permission}", PERMISSION);
sender.sendMessage(noPermDetailed);
return true;
}
if (args.length < 4) {
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.remove.missing-args"));
return true;
}
String playerName = args[2];
int amount;
try {
amount = Integer.parseInt(args[3]);
} catch (NumberFormatException ex) {
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.remove.amount-nan"));
return true;
}
OfflinePlayer target = plugin.getServer().getOfflinePlayer(playerName);
if (target == null || (!target.hasPlayedBefore() && !target.isOnline())) {
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.remove.player-not-found"));
return true;
}
UUID uuid = target.getUniqueId();
BountyDataManager m = plugin.getBountyDataManager();
int current = m.getBounty(uuid);
int total = current - amount;
if (total <= 0) {
m.removeBounty(uuid);
total = 0;
} else {
m.setBounty(uuid, total);
}
m.saveBountiesAsync();
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.remove.success")
.replace("{target}", target.getName())
.replace("{amount}", String.valueOf(amount))
.replace("{total}", String.valueOf(total)));
return true;
}
}
@@ -0,0 +1,55 @@
package com.tcoded.playerbountiesplus.command.admin.bounty;
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
import com.tcoded.playerbountiesplus.manager.BountyDataManager;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import java.util.UUID;
public class AdminBountySetCmd {
private static final String PERMISSION = "playerbountiesplus.command.playerbountiesplus.admin.set";
public static boolean handleCmd(PlayerBountiesPlus plugin, CommandSender sender, Command cmd, String label, String[] args) {
if (!sender.hasPermission(PERMISSION)) {
String noPerm = plugin.getLang().getColored("command.no-permission");
String noPermDetailed = plugin.getLang().getColored("command.no-permission-detailed")
.replace("{no-permission-msg}", noPerm)
.replace("{permission}", PERMISSION);
sender.sendMessage(noPermDetailed);
return true;
}
if (args.length < 4) {
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.set.missing-args"));
return true;
}
String playerName = args[2];
int amount;
try {
amount = Integer.parseInt(args[3]);
} catch (NumberFormatException ex) {
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.set.amount-nan"));
return true;
}
OfflinePlayer target = plugin.getServer().getOfflinePlayer(playerName);
if (target == null || (!target.hasPlayedBefore() && !target.isOnline())) {
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.set.player-not-found"));
return true;
}
UUID uuid = target.getUniqueId();
BountyDataManager m = plugin.getBountyDataManager();
m.setBounty(uuid, amount);
m.saveBountiesAsync();
sender.sendMessage(plugin.getLang().getColored("command.admin.bounty.set.success")
.replace("{target}", target.getName())
.replace("{bounty}", String.valueOf(amount)));
return true;
}
}
@@ -1,6 +1,7 @@
package com.tcoded.playerbountiesplus.command.bounty;
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
import com.tcoded.playerbountiesplus.event.BountySetEvent;
import com.tcoded.playerbountiesplus.manager.BountyDataManager;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -63,6 +64,17 @@ public class BountySetCmd {
// Apply bounty multiplier
amount *= (float) plugin.getConfig().getDouble("bounty-multiplier", 1.0);
// Trigger bounty set event
BountySetEvent event = new BountySetEvent(sender instanceof Player ? (Player) sender : null, target, amount);
plugin.getServer().getPluginManager().callEvent(event);
amount = event.getAmount();
// Check if event was cancelled
if (event.isCancelled()) {
sender.sendMessage(plugin.getLang().getColored("command.bounty.set.cancelled"));
return true;
}
// Sanity check final amount
if (amount <= 0) {
sender.sendMessage(plugin.getLang().getColored("command.bounty.set.internal-invalid-value"));
@@ -0,0 +1,57 @@
package com.tcoded.playerbountiesplus.event;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class BountyClaimEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final Player claimant;
private final Player victim;
private final double amount;
private boolean cancelled;
public BountyClaimEvent(@NotNull Player claimant, @NotNull Player victim, double amount) {
this.claimant = claimant;
this.victim = victim;
this.amount = amount;
this.cancelled = false;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
public Player getClaimant() {
return claimant;
}
public Player getVictim() {
return victim;
}
public double getAmount() {
return amount;
}
@Override
public @NotNull HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}
@@ -0,0 +1,64 @@
package com.tcoded.playerbountiesplus.event;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class BountySetEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final Player setter;
private final Player target;
private float amount;
private boolean cancelled;
public BountySetEvent(Player setter, @NotNull Player target, float amount) {
this.setter = setter;
this.target = target;
this.amount = amount;
this.cancelled = false;
}
/**
* @return The player who set the bounty or null if it's set by console/command block.
*/
public Player getSetter() {
return setter;
}
public Player getTarget() {
return target;
}
public float getAmount() {
return amount;
}
public void setAmount(float amount) {
this.amount = amount;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
@Override
public @NotNull HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}
@@ -1,6 +1,7 @@
package com.tcoded.playerbountiesplus.listener;
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
import com.tcoded.playerbountiesplus.event.BountyClaimEvent;
import com.tcoded.playerbountiesplus.hook.team.TeamHook;
import com.tcoded.playerbountiesplus.manager.BountyDataManager;
import org.bukkit.entity.Player;
@@ -29,7 +30,7 @@ public class DeathListener implements Listener {
UUID victimId = victim.getUniqueId();
// Bounty check
if (bountyDataManager.hasBounty(victimId)) {
if (!bountyDataManager.hasBounty(victimId)) {
return;
}
@@ -42,6 +43,15 @@ public class DeathListener implements Listener {
return;
}
// Trigger Bounty Claimed Event
BountyClaimEvent claimEvent = new BountyClaimEvent(killer, victim, bounty);
this.plugin.getServer().getPluginManager().callEvent(claimEvent);
// Check if event is cancelled
if (claimEvent.isCancelled()) {
return;
}
// Give reward!
if (plugin.getConfig().getBoolean("bounty-claimable", true)) {
double claimMultiplier = plugin.getConfig().getDouble("bounty-claim-multiplier", 1.0);
@@ -99,7 +99,7 @@ public class BountyDataManager {
}
// Save
this.plugin.getFoliaLib().getImpl().runAsync(() -> {
this.plugin.getFoliaLib().getScheduler().runAsync(wt -> {
this.saveBounties();
this.savingAsync.set(false);
+20
View File
@@ -10,6 +10,26 @@ command:
reloaded: "&aSuccessfully reloaded the configuration files!"
version:
no-permission: "&7(Version not visible: Missing permission)"
bounty:
set:
missing-args: "&cUsage: /pbp bounty set <player> <amount>"
amount-nan: "&cThat's not a valid number!"
player-not-found: "&cThat player is not online or doesn't exist!"
success: "&aSet {target}'s bounty to {bounty}."
add:
missing-args: "&cUsage: /pbp bounty add <player> <amount>"
amount-nan: "&cThat's not a valid number!"
player-not-found: "&cThat player is not online or doesn't exist!"
success: "&aAdded {amount} bounty to {target}. Total: {total}."
remove:
missing-args: "&cUsage: /pbp bounty remove <player> <amount>"
amount-nan: "&cThat's not a valid number!"
player-not-found: "&cThat player is not online or doesn't exist!"
success: "&aRemoved {amount} bounty from {target}. Total: {total}."
delete:
missing-args: "&cUsage: /pbp bounty delete <player>"
player-not-found: "&cThat player is not online or doesn't exist!"
success: "&aDeleted bounty for {target}."
bounty:
no-action: "&cYou need to specify an action! /bounty <set/top/check>"
invalid-action: "&cThat's not a valid action!"
+8
View File
@@ -32,3 +32,11 @@ permissions:
default: true
playerbountiesplus.command.playerbountiesplus.reload:
default: op
playerbountiesplus.command.playerbountiesplus.admin.set:
default: op
playerbountiesplus.command.playerbountiesplus.admin.add:
default: op
playerbountiesplus.command.playerbountiesplus.admin.remove:
default: op
playerbountiesplus.command.playerbountiesplus.admin.delete:
default: op