diff --git a/pom.xml b/pom.xml
index ace3594..1e38c38 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,19 +6,19 @@
com.tcoded
PlayerBountiesPlus
- 1.0.0
+ 1.0.0-ALPHA-02
jar
PlayerBountiesPlus
Claim bounties only if you are not on the same clan
- 1.8
+ 11
UTF-8
- https://tcoded.com
+ clean package
org.apache.maven.plugins
@@ -86,11 +86,13 @@
org.jetbrains
annotations
23.0.0
+ provided
com.github.Loving11ish
ClansLite
- v1.3.6
+ v1.3.7
+ provided
diff --git a/src/main/java/com/tcoded/playerbountiesplus/PlayerBountiesPlus.java b/src/main/java/com/tcoded/playerbountiesplus/PlayerBountiesPlus.java
index a3b9c08..8662c7c 100644
--- a/src/main/java/com/tcoded/playerbountiesplus/PlayerBountiesPlus.java
+++ b/src/main/java/com/tcoded/playerbountiesplus/PlayerBountiesPlus.java
@@ -1,94 +1,177 @@
package com.tcoded.playerbountiesplus;
import com.tcoded.playerbountiesplus.command.BountyCommand;
-import com.tcoded.playerbountiesplus.hook.VaultHook;
-import com.tcoded.playerbountiesplus.hook.clan.AbstractClanHook;
+import com.tcoded.playerbountiesplus.command.BountyCommandTabCompleter;
+import com.tcoded.playerbountiesplus.files.BountiesFileManager;
+import com.tcoded.playerbountiesplus.hooks.VaultHook;
+import com.tcoded.playerbountiesplus.hooks.clan.AbstractClanHook;
import com.tcoded.playerbountiesplus.listener.DeathListener;
-import org.bukkit.command.PluginCommand;
-import org.bukkit.configuration.file.FileConfiguration;
-import org.bukkit.configuration.file.YamlConfiguration;
-import org.bukkit.event.HandlerList;
-import org.bukkit.plugin.java.JavaPlugin;
+import com.tcoded.playerbountiesplus.utils.BountiesStorageUtils;
+import com.tcoded.playerbountiesplus.utils.ColorUtils;
+import org.bukkit.Bukkit;
+import org.bukkit.plugin.PluginDescriptionFile;
+import org.bukkit.plugin.java.JavaPlugin;;
-import java.io.File;
import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
+import java.util.logging.Logger;
public final class PlayerBountiesPlus extends JavaPlugin {
- private File bountiesFile;
- private FileConfiguration bountiesConfig;
+ private final PluginDescriptionFile pluginInfo = getDescription();
+ private final String pluginVersion = pluginInfo.getVersion();
+ Logger logger = this.getLogger();
+
+ private static PlayerBountiesPlus plugin;
+ public BountiesFileManager bountiesFileManager;
- private HashMap bounties;
private VaultHook vault;
private AbstractClanHook clanHook;
@Override
public void onEnable() {
- // Config
+ //Plugin startup logic
+ plugin = this;
+
+ //Server version compatibility check
+ if (!(Bukkit.getServer().getVersion().contains("1.13")||Bukkit.getServer().getVersion().contains("1.14")||
+ Bukkit.getServer().getVersion().contains("1.15")||Bukkit.getServer().getVersion().contains("1.16")||
+ Bukkit.getServer().getVersion().contains("1.17")||Bukkit.getServer().getVersion().contains("1.18")||
+ Bukkit.getServer().getVersion().contains("1.19"))){
+ logger.warning(ColorUtils.translateColorCodes("&4-------------------------------------------"));
+ logger.warning(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4This plugin is only supported on the Minecraft versions listed below:"));
+ logger.warning(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &41.13.x"));
+ logger.warning(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &41.14.x"));
+ logger.warning(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &41.15.x"));
+ logger.warning(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &41.16.x"));
+ logger.warning(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &41.17.x"));
+ logger.warning(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &41.18.x"));
+ logger.warning(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &41.19.x"));
+ logger.warning(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Is now disabling!"));
+ logger.warning(ColorUtils.translateColorCodes("&4-------------------------------------------"));
+ Bukkit.getPluginManager().disablePlugin(this);
+ return;
+ }else {
+ logger.info(ColorUtils.translateColorCodes("&a-------------------------------------------"));
+ logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &aA supported Minecraft version has been detected"));
+ logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &6Continuing plugin startup"));
+ logger.info(ColorUtils.translateColorCodes("&a-------------------------------------------"));
+ }
+
+ //Load the plugin configs
+ getConfig().options().copyDefaults();
saveDefaultConfig();
- // Bounties file
- String bountiesFileName = "bounties.yml";
- bountiesFile = new File(bountiesFileName);
- this.saveResource(bountiesFileName, false);
- bountiesConfig = YamlConfiguration.loadConfiguration(bountiesFile);
+ //Load bounties.yml
+ this.bountiesFileManager = new BountiesFileManager();
+ bountiesFileManager.BountiesFileManager(this);
- // Load bounties
- Set keys = bountiesConfig.getKeys(false);
- for (String key: keys) {
+ //Restore bounties to hashmap
+ if (bountiesFileManager.getBountiesConfig().contains("bounties.data")){
try {
- this.bounties.put(UUID.fromString(key), bountiesConfig.getInt(key));
- } catch (Exception ex) {
- ex.printStackTrace();
+ BountiesStorageUtils bountiesStorageUtils = new BountiesStorageUtils();
+ bountiesStorageUtils.restoreBounties();
+ bountiesStorageUtils.runStrippedBountyValuePopulate();
+ } catch (IOException e) {
+ logger.severe(ColorUtils.translateColorCodes("-------------------------------------------"));
+ logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Failed to load data from bounties.yml!"));
+ logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4See below for errors!"));
+ logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Disabling Plugin!"));
+ e.printStackTrace();
+ logger.severe(ColorUtils.translateColorCodes("-------------------------------------------"));
+ Bukkit.getPluginManager().disablePlugin(this);
+ return;
}
}
- // Hooks
+ //Load plugin hooks
this.vault = new VaultHook(this);
- this.vault.init();
+ if (!this.vault.init()){
+ logger.severe(ColorUtils.translateColorCodes("-------------------------------------------"));
+ logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Failed to hooks into Vault"));
+ logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4This plugin requires Vault"));
+ logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Please install Vault and restart your server!"));
+ logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Disabling Plugin!"));
+ Bukkit.getPluginManager().disablePlugin(this);
+ logger.severe(ColorUtils.translateColorCodes("-------------------------------------------"));
+ return;
+ }else {
+ logger.info(ColorUtils.translateColorCodes("-------------------------------------------"));
+ logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &aSuccessfully hooked into Vault"));
+ logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &6Continuing startup"));
+ logger.info(ColorUtils.translateColorCodes("-------------------------------------------"));
+ }
this.clanHook = AbstractClanHook.findClanHook(this);
+ if (clanHook == null){
+ logger.severe(ColorUtils.translateColorCodes("-------------------------------------------"));
+ logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Failed to hooks into ClansLite"));
+ logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4This plugin requires ClansLite"));
+ logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Please install ClansLite and restart your server!"));
+ logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Disabling Plugin!"));
+ logger.severe(ColorUtils.translateColorCodes("-------------------------------------------"));
+ Bukkit.getPluginManager().disablePlugin(this);
+ return;
+ }else {
+ logger.info(ColorUtils.translateColorCodes("-------------------------------------------"));
+ logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &aSuccessfully hooked into ClansLite"));
+ logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &6Continuing startup"));
+ logger.info(ColorUtils.translateColorCodes("-------------------------------------------"));
+ }
- // Commands
- PluginCommand bountyCmd = this.getCommand("bounty");
- BountyCommand bountyExec = new BountyCommand(this);
- bountyCmd.setExecutor(bountyExec);
- bountyCmd.setTabCompleter(bountyExec);
+ //Register commands
+ this.getCommand("bounty").setExecutor(new BountyCommand());
- // Listener
- this.getServer().getPluginManager().registerEvents(new DeathListener(this), this);
- }
+ //Register tab completer
+ this.getCommand("bounty").setTabCompleter(new BountyCommandTabCompleter());
- @Override
- public void onDisable() {
- HandlerList.unregisterAll(this);
- }
+ //Register listeners
+ this.getServer().getPluginManager().registerEvents(new DeathListener(), this);
- public HashMap getBounties() {
- return this.bounties;
+ //Plugin startup message
+ logger.info(ColorUtils.translateColorCodes("-------------------------------------------"));
+ logger.info(ColorUtils.translateColorCodes("&6ClansLite: &3Plugin by: &b&lLoving11ish & TCoded"));
+ logger.info(ColorUtils.translateColorCodes("&6ClansLite: &3has been loaded successfully"));
+ logger.info(ColorUtils.translateColorCodes("&6ClansLite: &3Plugin Version: &d&l" + pluginVersion));
+ logger.info(ColorUtils.translateColorCodes("-------------------------------------------"));
}
- public void saveBounties() {
- // Clear existing
- Set keys = bountiesConfig.getKeys(false);
- for (String key: keys) {
- bountiesConfig.set(key, null);
- }
+ @Override
+ public void onDisable(){
+ //Plugin shutdown logic
+ BountiesStorageUtils bountiesStorageUtils = new BountiesStorageUtils();
- // Write changes
- for (Map.Entry entry : this.bounties.entrySet()) {
- this.bountiesConfig.set(entry.getKey().toString(), entry.getValue());
+ //Safely stop the background tasks if running
+ logger.info(ColorUtils.translateColorCodes("-------------------------------------------"));
+ logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &3Plugin by: &b&lLoving11ish & TCoded"));
+ try {
+ if (Bukkit.getScheduler().isCurrentlyRunning(bountiesStorageUtils.taskID1)||Bukkit.getScheduler().isQueued(bountiesStorageUtils.taskID1)){
+ Bukkit.getScheduler().cancelTask(bountiesStorageUtils.taskID1);
+ }
+ logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &3Background tasks have disabled successfully!"));
+ }catch (Exception e){
+ logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &3Background tasks have disabled successfully!"));
}
- // Save to file
- try {
- this.bountiesConfig.save(this.bountiesFile);
- } catch (IOException e) {
- e.printStackTrace();
+ //Save Bounties HashMap to bounties.yml
+ if (!bountiesStorageUtils.getRawBountiesList().isEmpty()){
+ try {
+ bountiesStorageUtils.saveBounties();
+ logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &3All bounties saved to bounties.yml successfully!"));
+ } catch (IOException e) {
+ logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Failed to save bounties to bounties.yml!"));
+ logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4See below error for reason!"));
+ e.printStackTrace();
+ }
}
+
+ //Final plugin shutdown message
+ logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &3Plugin Version: &d&l" + pluginVersion));
+ logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &3Has been shutdown successfully"));
+ logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &3Goodbye!"));
+ logger.info(ColorUtils.translateColorCodes("-------------------------------------------"));
+ }
+
+ public static PlayerBountiesPlus getPlugin() {
+ return plugin;
}
public VaultHook getVaultHook() {
diff --git a/src/main/java/com/tcoded/playerbountiesplus/command/BountyCheckCmd.java b/src/main/java/com/tcoded/playerbountiesplus/command/BountyCheckCmd.java
deleted file mode 100644
index b26c586..0000000
--- a/src/main/java/com/tcoded/playerbountiesplus/command/BountyCheckCmd.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.tcoded.playerbountiesplus.command;
-
-import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-import java.util.UUID;
-
-public class BountyCheckCmd {
- public static boolean handleCmd(PlayerBountiesPlus plugin, CommandSender sender, Command cmd, String cmdName, String[] args) {
- if (args.length < 2) {
- sender.sendMessage(ChatColor.RED + "You need to specify a player! /bounty check ");
- return true;
- }
-
- String playerNameArg = args[1];
-
- Player target = plugin.getServer().getPlayerExact(playerNameArg);
-
- if (target == null) {
- sender.sendMessage(ChatColor.RED + "That player is not online or doesn't exist!");
- return true;
- }
-
- UUID playerUUID = target.getUniqueId();
-
- Integer amount = plugin.getBounties().get(playerUUID);
-
- if (amount != null && amount > 0) {
- // Confirmation
- sender.sendMessage(ChatColor.GREEN + String.format("There is a bounty worth %s on %s's head!", amount, target.getName()));
- } else {
- sender.sendMessage(ChatColor.RED + String.format("There is no bounty on %s's head!", target.getName()));
- }
-
- return true;
- }
-}
diff --git a/src/main/java/com/tcoded/playerbountiesplus/command/BountyCommand.java b/src/main/java/com/tcoded/playerbountiesplus/command/BountyCommand.java
index 90bade1..c3e3100 100644
--- a/src/main/java/com/tcoded/playerbountiesplus/command/BountyCommand.java
+++ b/src/main/java/com/tcoded/playerbountiesplus/command/BountyCommand.java
@@ -1,85 +1,71 @@
package com.tcoded.playerbountiesplus.command;
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
-import org.bukkit.ChatColor;
+import com.tcoded.playerbountiesplus.command.subCommands.BountyCheckCmd;
+import com.tcoded.playerbountiesplus.command.subCommands.BountySetCmd;
+import com.tcoded.playerbountiesplus.command.subCommands.BountyTopCmd;
+import com.tcoded.playerbountiesplus.utils.ColorUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
-import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
+import java.util.logging.Logger;
-public class BountyCommand implements CommandExecutor, TabCompleter {
+public class BountyCommand implements CommandExecutor {
- private PlayerBountiesPlus plugin;
-
- public BountyCommand(PlayerBountiesPlus plugin) {
- this.plugin = plugin;
- }
+ Logger logger = PlayerBountiesPlus.getPlugin().getLogger();
@Override
public boolean onCommand(CommandSender sender, Command cmd, String cmdName, String[] args) {
- if (args.length < 1) {
- sender.sendMessage(ChatColor.RED + "You need to specify an action! /bounty ");
- return true;
- }
-
- String action = args[0].toLowerCase();
-
- switch (action) {
- case "set":
- return BountySetCmd.handleCmd(plugin, sender, cmd, cmdName, args);
- case "top":
- return BountyTopCmd.handleCmd(plugin, sender, cmd, cmdName, args);
- case "check":
- return BountyCheckCmd.handleCmd(plugin, sender, cmd, cmdName, args);
- default:
- sender.sendMessage(ChatColor.RED + "That's not a valid action!");
- }
-
- return true;
- }
-
+ if (sender instanceof Player){
+ Player player = (Player) sender;
+ if (args.length < 1) {
+ sender.sendMessage(ColorUtils.translateColorCodes("&6Bounty Commands Usage: &3" +
+ "\n/bounty set " +
+ "\n/bounty check " +
+ "\n/bounty top"));
+ return true;
+ }
- @Nullable
- @Override
- public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
- @Nullable List options = new ArrayList<>();
+ String action = args[0].toLowerCase();
- if (args.length < 2) {
- String arg0 = args[0].toLowerCase();
- String[] actions = {"set", "top", "check"};
- for (String action : actions) {
- if (action.startsWith(arg0)) {
- options.add(action);
- }
- }
- }
- else if (args.length == 2) {
- String arg0 = args[0].toLowerCase();
- String arg1 = args[1].toLowerCase();
- if (arg0.equals("set") || arg0.equals("check")) {
- this.plugin.getServer().getOnlinePlayers().stream()
- .map(Player::getName)
- .map(String::toLowerCase)
- .filter(name -> name.startsWith(arg1))
- .forEach(options::add);
- }
- }
- else if (args.length == 3) {
- String arg0 = args[0].toLowerCase();
- String arg2 = args[2].toLowerCase();
- if (arg0.equals("set")) {
- if (arg2.equals("")) options.add("");
+ switch (action) {
+ case "set":
+ if (args.length == 3){
+ if (args[2] != null){
+ int amount = Integer.parseInt(args[2]);
+ return new BountySetCmd().handleCmd(sender,args, amount);
+ }else {
+ player.sendMessage(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &3/bounty set "));
+ return true;
+ }
+ }else {
+ player.sendMessage(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &3/bounty set "));
+ return true;
+ }
+ case "check":
+ if (args.length == 2){
+ if (args[1] != null){
+ return new BountyCheckCmd().handleCmd(sender, args);
+ }else {
+ player.sendMessage(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &3/bounty check "));
+ return true;
+ }
+ }else {
+ player.sendMessage(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &3/bounty check "));
+ return true;
+ }
+ case "top":
+ return new BountyTopCmd().handleCmd(sender);
+ default:
+ player.sendMessage(ColorUtils.translateColorCodes("&cSorry, that command is not recognised.\n&cPlease use &3/bounty"));
}
+ }else {
+ logger.warning(ColorUtils.translateColorCodes("&cSorry, that command can only be used in game."));
+ return true;
}
-
- return options;
+ return true;
}
}
diff --git a/src/main/java/com/tcoded/playerbountiesplus/command/BountyCommandTabCompleter.java b/src/main/java/com/tcoded/playerbountiesplus/command/BountyCommandTabCompleter.java
new file mode 100644
index 0000000..f24c626
--- /dev/null
+++ b/src/main/java/com/tcoded/playerbountiesplus/command/BountyCommandTabCompleter.java
@@ -0,0 +1,36 @@
+package com.tcoded.playerbountiesplus.command;
+
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.TabCompleter;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class BountyCommandTabCompleter implements TabCompleter {
+
+ List arguments = new ArrayList<>();
+
+ @Nullable
+ @Override
+ public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
+
+ if (arguments.isEmpty()) {
+ arguments.add("set");
+ arguments.add("check");
+ arguments.add("top");
+ }
+ List result = new ArrayList<>();
+ if (args.length == 1){
+ for (String a : arguments){
+ if (a.toLowerCase().startsWith(args[0].toLowerCase())){
+ result.add(a);
+ }
+ }
+ return result;
+ }
+ return null;
+ }
+}
diff --git a/src/main/java/com/tcoded/playerbountiesplus/command/BountySetCmd.java b/src/main/java/com/tcoded/playerbountiesplus/command/BountySetCmd.java
deleted file mode 100644
index 32d992a..0000000
--- a/src/main/java/com/tcoded/playerbountiesplus/command/BountySetCmd.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package com.tcoded.playerbountiesplus.command;
-
-import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-import java.util.UUID;
-
-public class BountySetCmd {
-
- public static boolean handleCmd(PlayerBountiesPlus plugin, CommandSender sender, Command cmd, String cmdName, String[] args) {
- if (args.length < 3) {
- sender.sendMessage(ChatColor.RED + "You need to specify a player and an amount! /bounty set ");
- return true;
- }
-
- String playerNameArg = args[1];
- int amount;
- try {
- amount = Integer.parseInt(args[2]);
- } catch (NumberFormatException ex) {
- sender.sendMessage("That's not a valid number!");
- return true;
- }
-
- Player target = plugin.getServer().getPlayerExact(playerNameArg);
-
- if (target == null) {
- sender.sendMessage(ChatColor.RED + "That player is not online or doesn't exist!");
- return true;
- }
-
- // Check money
- if (sender instanceof Player) {
- Player player = (Player) sender;
- boolean allowed = plugin.getVaultHook().takeMoney(player, amount);
-
- if (!allowed) {
- sender.sendMessage(ChatColor.RED + "You don't have enough money for that!");
- return true;
- }
- }
-
- UUID playerUUID = target.getUniqueId();
-
- plugin.getBounties().put(playerUUID, amount);
-
- // Confirmation
- sender.sendMessage(ChatColor.GREEN + String.format("You placed a bounty of %s on %s's head!", amount, target.getName()));
-
- // Announce
- plugin.getServer().broadcastMessage(ChatColor.DARK_RED.toString() + ChatColor.BOLD +
- String.format("\nA bounty of %s was placed on %s's head by %s!\n", amount, target.getName(), sender.getName()));
-
- plugin.saveBounties();
-
- return true;
- }
-}
diff --git a/src/main/java/com/tcoded/playerbountiesplus/command/BountyTopCmd.java b/src/main/java/com/tcoded/playerbountiesplus/command/BountyTopCmd.java
deleted file mode 100644
index 9258474..0000000
--- a/src/main/java/com/tcoded/playerbountiesplus/command/BountyTopCmd.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package com.tcoded.playerbountiesplus.command;
-
-import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
-import net.milkbowl.vault.chat.Chat;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandSender;
-
-import java.util.*;
-
-public class BountyTopCmd {
-
- public static boolean handleCmd(PlayerBountiesPlus plugin, CommandSender sender, Command cmd, String cmdName, String[] args) {
-
- Set> bountiesSet = plugin.getBounties().entrySet();
- List> bounties = new ArrayList<>(bountiesSet);
-
- bounties.sort(Comparator.comparingInt(Map.Entry::getValue));
-
- StringBuilder strb = new StringBuilder();
- strb.append(ChatColor.YELLOW);
- strb.append("Top 10 bounties:\n");
- if (bounties.size() > 0) {
- for (int i = 0; i < 10; i++) {
- strb.append(ChatColor.GRAY);
- strb.append(" - ");
- Map.Entry entry = bounties.get(i);
- strb.append(plugin.getServer().getOfflinePlayer(entry.getKey()).getName());
- strb.append(": ");
- strb.append(entry.getKey());
- strb.append('\n');
- }
- }
- else {
- strb.append(ChatColor.RED);
- strb.append(" No bounties were set!\n");
- }
-
- String message = strb.toString();
- message = message.substring(0, message.length() - 2); // remove \n
- sender.sendMessage(message);
-
- return true;
- }
-
-}
diff --git a/src/main/java/com/tcoded/playerbountiesplus/command/subCommands/BountyCheckCmd.java b/src/main/java/com/tcoded/playerbountiesplus/command/subCommands/BountyCheckCmd.java
new file mode 100644
index 0000000..bef4370
--- /dev/null
+++ b/src/main/java/com/tcoded/playerbountiesplus/command/subCommands/BountyCheckCmd.java
@@ -0,0 +1,39 @@
+package com.tcoded.playerbountiesplus.command.subCommands;
+
+import com.tcoded.playerbountiesplus.models.Bounty;
+import com.tcoded.playerbountiesplus.utils.BountiesStorageUtils;
+import com.tcoded.playerbountiesplus.utils.ColorUtils;
+import org.bukkit.Bukkit;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class BountyCheckCmd {
+
+ BountiesStorageUtils bountiesStorageUtils = new BountiesStorageUtils();
+
+ public boolean handleCmd(CommandSender sender, String[] args) {
+
+ if (sender instanceof Player){
+ Player player = (Player) sender;
+ if (args.length < 2) {
+ player.sendMessage(ColorUtils.translateColorCodes("&cYou need to specify a player and an amount! /bounty check [player]"));
+ return true;
+ }
+
+ String targetName = args[1];
+ Player target = Bukkit.getServer().getPlayerExact(targetName);
+
+ if (target != null){
+ if (bountiesStorageUtils.hasExistingBounty(target)){
+ Bounty bounty = bountiesStorageUtils.findBountyByOnlineTarget(target);
+ int amount = bounty.getBountyValue();
+ player.sendMessage(ColorUtils.translateColorCodes("&aThere is a bounty worth &e&l" + amount + "&aon &e&l" + targetName +"'s &ahead!"));
+ }else {
+ player.sendMessage(ColorUtils.translateColorCodes("&cThere is no bounty on &b&l" + targetName +"'s &chead!"));
+ }
+ return true;
+ }
+ }
+ return true;
+ }
+}
diff --git a/src/main/java/com/tcoded/playerbountiesplus/command/subCommands/BountySetCmd.java b/src/main/java/com/tcoded/playerbountiesplus/command/subCommands/BountySetCmd.java
new file mode 100644
index 0000000..7a2904d
--- /dev/null
+++ b/src/main/java/com/tcoded/playerbountiesplus/command/subCommands/BountySetCmd.java
@@ -0,0 +1,69 @@
+package com.tcoded.playerbountiesplus.command.subCommands;
+
+import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
+import com.tcoded.playerbountiesplus.models.Bounty;
+import com.tcoded.playerbountiesplus.utils.BountiesStorageUtils;
+import com.tcoded.playerbountiesplus.utils.ColorUtils;
+import org.bukkit.Bukkit;
+import org.bukkit.command.CommandSender;
+import org.bukkit.configuration.file.FileConfiguration;
+import org.bukkit.entity.Player;
+
+public class BountySetCmd {
+
+ FileConfiguration configFile = PlayerBountiesPlus.getPlugin().getConfig();
+ BountiesStorageUtils bountiesStorageUtils = new BountiesStorageUtils();
+
+ public boolean handleCmd(CommandSender sender, String[] args, int amount) {
+
+ if (sender instanceof Player){
+ Player player = (Player) sender;
+ if (args.length < 3) {
+ player.sendMessage(ColorUtils.translateColorCodes("&cYou need to specify a player and an amount! /bounty set [player] [amount]"));
+ return true;
+ }
+
+ String targetName = args[1];
+ Player onlineTarget = Bukkit.getPlayerExact(targetName);
+
+ if (onlineTarget != null){
+ if (amount < configFile.getInt("bounty.min-bounty-value")){
+ player.sendMessage(ColorUtils.translateColorCodes("&cPlease provide a larger bounty value."));
+ return true;
+ }
+ boolean allowed = PlayerBountiesPlus.getPlugin().getVaultHook().takeMoney(player, amount);
+ if (allowed){
+ Bounty bounty = bountiesStorageUtils.findBountyByOnlineTarget(onlineTarget);
+ if (bounty != null){
+ if (bountiesStorageUtils.findBountyByOnlineTarget(onlineTarget).getBountyValue() >= configFile.getInt("bounty.max-bounty-value")){
+ player.sendMessage(ColorUtils.translateColorCodes("&cThat player already has the maximum allowed bounty set!"));
+ return true;
+ }
+ }
+ if (!bountiesStorageUtils.hasExistingBounty(onlineTarget)){
+ if (bountiesStorageUtils.createOnlineBounty(onlineTarget, player, amount) != null){
+ player.sendMessage(ColorUtils.translateColorCodes("&aYou placed a bounty of &e&l" + amount + " &aon &e&l" + targetName + "'s &ahead!"));
+ Bukkit.getServer().broadcastMessage(ColorUtils.translateColorCodes("\n&4&lA bounty of &b&l" + amount + "&4&lwas placed on &b&l" + targetName + "'s &4&lhead by &e&l" + player.getName()+ "&4&l!\n"));
+ return true;
+ }
+ }else {
+ bountiesStorageUtils.updateOnlineBountyValue(onlineTarget, amount);
+ player.sendMessage(ColorUtils.translateColorCodes("&aYou updated &e&l" + targetName + "'s &abounty to &e&l" + amount));
+ Bukkit.getServer().broadcastMessage(ColorUtils.translateColorCodes(
+ "\n&4&lThe bounty on &b&l" + targetName + "'s &4&lhead was updated by &e&l" + player.getName()+ "&4&l!\n"
+ + "&4&lThe new bounty is &b&l" + amount + "\n"));
+ return true;
+ }
+ }else {
+ player.sendMessage(ColorUtils.translateColorCodes("&cYou don't have enough money for that!"));
+ return true;
+ }
+ }else {
+ player.sendMessage(ColorUtils.translateColorCodes("&cSorry, &d" + targetName + " &cdoes not appear to be online."));
+ return true;
+ }
+ return true;
+ }
+ return true;
+ }
+}
diff --git a/src/main/java/com/tcoded/playerbountiesplus/command/subCommands/BountyTopCmd.java b/src/main/java/com/tcoded/playerbountiesplus/command/subCommands/BountyTopCmd.java
new file mode 100644
index 0000000..30ee0d6
--- /dev/null
+++ b/src/main/java/com/tcoded/playerbountiesplus/command/subCommands/BountyTopCmd.java
@@ -0,0 +1,45 @@
+package com.tcoded.playerbountiesplus.command.subCommands;
+
+import com.tcoded.playerbountiesplus.utils.BountiesStorageUtils;
+import com.tcoded.playerbountiesplus.utils.ColorUtils;
+import org.bukkit.Bukkit;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import java.util.*;
+
+public class BountyTopCmd {
+
+ BountiesStorageUtils bountiesStorageUtils = new BountiesStorageUtils();
+
+ public boolean handleCmd(CommandSender sender) {
+
+ if (sender instanceof Player){
+ Player player = (Player) sender;
+
+ Set> bountiesSet = bountiesStorageUtils.getStrippedBounties();
+ List> bounties = new ArrayList<>(bountiesSet);
+
+ bounties.sort(Comparator.comparingInt(Map.Entry::getValue));
+
+ StringBuilder messageString = new StringBuilder();
+ messageString.append(ColorUtils.translateColorCodes("&eTop 10 Bounties:\n"));
+ messageString.append(ColorUtils.translateColorCodes("&f\n"));
+ if (bounties.size() > 0){
+ for (int i = 0; i < 10; i++){
+ messageString.append(ColorUtils.translateColorCodes("&7 - "));
+ String playerName = Bukkit.getOfflinePlayer(bounties.get(i).getKey()).getName();
+ messageString.append(ColorUtils.translateColorCodes("&3" + playerName));
+ messageString.append(ColorUtils.translateColorCodes("&7: "));
+ messageString.append(ColorUtils.translateColorCodes("&6$" + bounties.get(i).getValue() + "&f\n"));
+ }
+ }else {
+ messageString.append(ColorUtils.translateColorCodes("&cNo bounties have been set!\n"));
+ messageString.append(ColorUtils.translateColorCodes("&3Use /bounty to see available commands."));
+ }
+ player.sendMessage(messageString.toString());
+ return true;
+ }
+ return true;
+ }
+}
diff --git a/src/main/java/com/tcoded/playerbountiesplus/files/BountiesFileManager.java b/src/main/java/com/tcoded/playerbountiesplus/files/BountiesFileManager.java
new file mode 100644
index 0000000..c7dc95f
--- /dev/null
+++ b/src/main/java/com/tcoded/playerbountiesplus/files/BountiesFileManager.java
@@ -0,0 +1,68 @@
+package com.tcoded.playerbountiesplus.files;
+
+import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
+import com.tcoded.playerbountiesplus.utils.ColorUtils;
+import org.bukkit.configuration.file.FileConfiguration;
+import org.bukkit.configuration.file.YamlConfiguration;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.logging.Logger;
+
+public class BountiesFileManager {
+
+ private PlayerBountiesPlus plugin;
+ private FileConfiguration dataConfig = null;
+ private File configFile = null;
+
+ Logger logger = PlayerBountiesPlus.getPlugin().getLogger();
+
+ public void BountiesFileManager(PlayerBountiesPlus plugin){
+ this.plugin = plugin;
+ saveDefaultBountiesConfig();
+ }
+
+ public void reloadBountiesConfig(){
+
+ if (this.configFile == null){
+ this.configFile = new File(plugin.getDataFolder(), "bounties.yml");
+ }
+ this.dataConfig = YamlConfiguration.loadConfiguration(this.configFile);
+ InputStream defaultStream = this.plugin.getResource("bounties.yml");
+ if (defaultStream != null){
+ YamlConfiguration defaultConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(defaultStream));
+ this.dataConfig.setDefaults(defaultConfig);
+ }
+ }
+
+ public FileConfiguration getBountiesConfig(){
+ if (this.dataConfig == null){
+ this.reloadBountiesConfig();
+ }
+ return this.dataConfig;
+ }
+
+ public void saveBountiesConfig() {
+ if (this.dataConfig == null||this.configFile == null){
+ return;
+ }
+ try {
+ this.getBountiesConfig().save(this.configFile);
+ }catch (IOException e){
+ logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Could not save bounties.yml"));
+ logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Check the below message for the reasons!"));
+ e.printStackTrace();
+ }
+ }
+
+ public void saveDefaultBountiesConfig(){
+ if (this.configFile == null){
+ this.configFile = new File(plugin.getDataFolder(), "bounties.yml");
+ }
+ if (!this.configFile.exists()){
+ this.plugin.saveResource("bounties.yml", false);
+ }
+ }
+}
diff --git a/src/main/java/com/tcoded/playerbountiesplus/hook/VaultHook.java b/src/main/java/com/tcoded/playerbountiesplus/hooks/VaultHook.java
similarity index 91%
rename from src/main/java/com/tcoded/playerbountiesplus/hook/VaultHook.java
rename to src/main/java/com/tcoded/playerbountiesplus/hooks/VaultHook.java
index 63e0592..88d6b7c 100644
--- a/src/main/java/com/tcoded/playerbountiesplus/hook/VaultHook.java
+++ b/src/main/java/com/tcoded/playerbountiesplus/hooks/VaultHook.java
@@ -1,13 +1,10 @@
-package com.tcoded.playerbountiesplus.hook;
+package com.tcoded.playerbountiesplus.hooks;
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.entity.Player;
-import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
-import java.util.UUID;
-
public class VaultHook {
private final PlayerBountiesPlus plugin;
diff --git a/src/main/java/com/tcoded/playerbountiesplus/hook/clan/AbstractClanHook.java b/src/main/java/com/tcoded/playerbountiesplus/hooks/clan/AbstractClanHook.java
similarity index 93%
rename from src/main/java/com/tcoded/playerbountiesplus/hook/clan/AbstractClanHook.java
rename to src/main/java/com/tcoded/playerbountiesplus/hooks/clan/AbstractClanHook.java
index 2d6ecbf..b40851b 100644
--- a/src/main/java/com/tcoded/playerbountiesplus/hook/clan/AbstractClanHook.java
+++ b/src/main/java/com/tcoded/playerbountiesplus/hooks/clan/AbstractClanHook.java
@@ -1,4 +1,4 @@
-package com.tcoded.playerbountiesplus.hook.clan;
+package com.tcoded.playerbountiesplus.hooks.clan;
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
import org.bukkit.entity.Player;
diff --git a/src/main/java/com/tcoded/playerbountiesplus/hook/clan/ClansLiteHook.java b/src/main/java/com/tcoded/playerbountiesplus/hooks/clan/ClansLiteHook.java
similarity index 89%
rename from src/main/java/com/tcoded/playerbountiesplus/hook/clan/ClansLiteHook.java
rename to src/main/java/com/tcoded/playerbountiesplus/hooks/clan/ClansLiteHook.java
index fe778ff..f16c597 100644
--- a/src/main/java/com/tcoded/playerbountiesplus/hook/clan/ClansLiteHook.java
+++ b/src/main/java/com/tcoded/playerbountiesplus/hooks/clan/ClansLiteHook.java
@@ -1,10 +1,9 @@
-package com.tcoded.playerbountiesplus.hook.clan;
+package com.tcoded.playerbountiesplus.hooks.clan;
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.Nullable;
-import xyz.gamlin.clans.Clans;
import xyz.gamlin.clans.utils.ClansStorageUtil;
public class ClansLiteHook extends AbstractClanHook {
diff --git a/src/main/java/com/tcoded/playerbountiesplus/listener/DeathListener.java b/src/main/java/com/tcoded/playerbountiesplus/listener/DeathListener.java
index da30a28..7ccded9 100644
--- a/src/main/java/com/tcoded/playerbountiesplus/listener/DeathListener.java
+++ b/src/main/java/com/tcoded/playerbountiesplus/listener/DeathListener.java
@@ -1,47 +1,63 @@
package com.tcoded.playerbountiesplus.listener;
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
-import com.tcoded.playerbountiesplus.hook.clan.AbstractClanHook;
-import org.bukkit.ChatColor;
+import com.tcoded.playerbountiesplus.hooks.clan.AbstractClanHook;
+import com.tcoded.playerbountiesplus.utils.BountiesStorageUtils;
+import com.tcoded.playerbountiesplus.utils.ColorUtils;
+import org.bukkit.Bukkit;
+import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
-public class DeathListener implements Listener {
+import java.io.IOException;
+import java.util.UUID;
+import java.util.logging.Logger;
- private PlayerBountiesPlus plugin;
+public class DeathListener implements Listener {
- public DeathListener(PlayerBountiesPlus plugin) {
- this.plugin = plugin;
- }
+ Logger logger = PlayerBountiesPlus.getPlugin().getLogger();
+ BountiesStorageUtils bountiesStorageUtils = new BountiesStorageUtils();
@EventHandler
- public void onDeath(PlayerDeathEvent event) {
+ public void onDeath(PlayerDeathEvent event){
Player victim = event.getEntity();
+ UUID victimUUID = victim.getUniqueId();
+ OfflinePlayer offlineVictim = Bukkit.getOfflinePlayer(victimUUID);
Player killer = victim.getKiller();
if (killer != null) {
- Integer bounty = this.plugin.getBounties().get(victim.getUniqueId());
+ int bounty = bountiesStorageUtils.findBountyByOnlineTarget(victim).getBountyValue();
+ String victimName = victim.getName();
+ String killerName = killer.getName();
- // Bounty check
- if (bounty == null || bounty == 0) {
+ //Bounty check
+ if (bounty == 0) {
return;
}
- // Clan check
- AbstractClanHook clanHook = this.plugin.getClanHook();
+ //Clan check
+ AbstractClanHook clanHook = PlayerBountiesPlus.getPlugin().getClanHook();
String clanIdVictim = clanHook.getClanId(victim);
if (clanIdVictim != null && clanIdVictim.equals(clanHook.getClanId(killer))) {
- killer.sendMessage(ChatColor.GREEN + "The player you killed has an active bounty but you are in the same clan as they are!");
+ killer.sendMessage(ColorUtils.translateColorCodes(
+ "&aThe player you killed has an active bounty but you are in the same clan as they are!"));
return;
}
- // Apply rewards!
- this.plugin.getVaultHook().addMoney(killer, bounty);
- this.plugin.getServer().broadcastMessage(ChatColor.DARK_RED.toString() + ChatColor.BOLD +
- String.format("%s claimed the bounty that was placed on %s worth %s", killer.getName(), victim.getName(), bounty));
+ //Apply rewards
+ PlayerBountiesPlus.getPlugin().getVaultHook().addMoney(killer, bounty);
+ try {
+ if (bountiesStorageUtils.removeOfflineBounty(offlineVictim)){
+ Bukkit.getServer().broadcastMessage(ColorUtils.translateColorCodes(
+ "&b&l" + killerName +" &4claimed the bounty that was placed on &b&l" + victimName +" &4worth &b&l$" + bounty));
+ }
+ } catch (IOException e) {
+ logger.severe(xyz.gamlin.clans.utils.ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Failed to update bounties in bounties.yml!"));
+ logger.severe(xyz.gamlin.clans.utils.ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4See below error for reason!"));
+ e.printStackTrace();
+ }
}
}
-
}
diff --git a/src/main/java/com/tcoded/playerbountiesplus/models/Bounty.java b/src/main/java/com/tcoded/playerbountiesplus/models/Bounty.java
new file mode 100644
index 0000000..a30d12d
--- /dev/null
+++ b/src/main/java/com/tcoded/playerbountiesplus/models/Bounty.java
@@ -0,0 +1,39 @@
+package com.tcoded.playerbountiesplus.models;
+
+public class Bounty {
+
+ private String targetUUID;
+ private String bountyCreator;
+ private int bountyValue;
+
+ public Bounty(String targetUUID, String bountyCreator, int bountyValue){
+ this.targetUUID = targetUUID;
+ this.bountyCreator = bountyCreator;
+ this.bountyValue = bountyValue;
+
+ }
+
+ public String getTargetUUID() {
+ return targetUUID;
+ }
+
+ public void setTargetUUID(String targetUUID) {
+ this.targetUUID = targetUUID;
+ }
+
+ public String getBountyCreator() {
+ return bountyCreator;
+ }
+
+ public void setBountyCreator(String bountyCreator) {
+ this.bountyCreator = bountyCreator;
+ }
+
+ public int getBountyValue() {
+ return bountyValue;
+ }
+
+ public void setBountyValue(int bountyValue) {
+ this.bountyValue = bountyValue;
+ }
+}
diff --git a/src/main/java/com/tcoded/playerbountiesplus/utils/BountiesStorageUtils.java b/src/main/java/com/tcoded/playerbountiesplus/utils/BountiesStorageUtils.java
new file mode 100644
index 0000000..16b0607
--- /dev/null
+++ b/src/main/java/com/tcoded/playerbountiesplus/utils/BountiesStorageUtils.java
@@ -0,0 +1,209 @@
+package com.tcoded.playerbountiesplus.utils;
+
+import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
+import com.tcoded.playerbountiesplus.models.Bounty;
+import org.bukkit.Bukkit;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.configuration.file.FileConfiguration;
+import org.bukkit.entity.Player;
+
+import java.io.IOException;
+import java.util.*;
+import java.util.logging.Logger;
+
+public class BountiesStorageUtils {
+
+ public int taskID1;
+
+ Logger logger = PlayerBountiesPlus.getPlugin().getLogger();
+
+ FileConfiguration bountiesFile = PlayerBountiesPlus.getPlugin().bountiesFileManager.getBountiesConfig();
+
+ private HashMap bountiesMap = new HashMap<>();
+ private HashMap strippedBountyValues = new HashMap<>();
+
+ public void runStrippedBountyValuePopulate(){
+ taskID1 = Bukkit.getScheduler().scheduleSyncDelayedTask(PlayerBountiesPlus.getPlugin(), new Runnable() {
+ @Override
+ public void run() {
+ for (Map.Entry bountyEntry : bountiesMap.entrySet()){
+ UUID uuid = UUID.fromString(bountyEntry.getValue().getTargetUUID());
+ int bountyValue = bountyEntry.getValue().getBountyValue();
+ strippedBountyValues.put(uuid, bountyValue);
+ }
+ }
+ }, 10);
+ }
+
+
+ public void saveBounties() throws IOException{
+ for (Map.Entry entry : bountiesMap.entrySet()){
+ bountiesFile.set("bounties.data." + entry.getKey() + ".targetUUID", entry.getValue().getTargetUUID());
+ bountiesFile.set("bounties.data." + entry.getKey() + ".creatorUUID", entry.getValue().getBountyCreator());
+ bountiesFile.set("bounties.data." + entry.getKey() + ".bountyValue", entry.getValue().getBountyValue());
+ }
+ PlayerBountiesPlus.getPlugin().bountiesFileManager.saveBountiesConfig();
+ }
+
+ public void restoreBounties() throws IOException{
+ bountiesMap.clear();
+ bountiesFile.getConfigurationSection("bounties.data").getKeys(false).forEach(key ->{
+ UUID uuid = UUID.fromString(key);
+ String targetUUID = bountiesFile.getString("bounties.data." + key + ".targetUUID");
+ String creatorUUID = bountiesFile.getString("bounties.data." + key + ".creatorUUID");
+ int bountyValue = bountiesFile.getInt("bounties.data." + key + ".bountyValue");
+
+ Bounty bounty = new Bounty(targetUUID, creatorUUID, bountyValue);
+
+ bountiesMap.put(uuid, bounty);
+ });
+ }
+
+ public Bounty createOnlineBounty(Player bountyTarget, Player bountyCreator, int bountyValue){
+ UUID targetUUID = bountyTarget.getUniqueId();
+ String targetUUIDString = targetUUID.toString();
+ UUID creatorUUID = bountyCreator.getUniqueId();
+ String creatorUUIDString = creatorUUID.toString();
+
+ Bounty bounty = new Bounty(targetUUIDString, creatorUUIDString, bountyValue);
+
+ bountiesMap.put(targetUUID, bounty);
+
+ return bounty;
+ }
+
+ public Bounty createOfflineBounty(OfflinePlayer offlineBountyTarget, Player bountyCreator, int bountyValue){
+ UUID targetUUID = offlineBountyTarget.getUniqueId();
+ String targetUUIDString = targetUUID.toString();
+ UUID creatorUUID = bountyCreator.getUniqueId();
+ String creatorUUIDString = creatorUUID.toString();
+
+ Bounty bounty = new Bounty(targetUUIDString, creatorUUIDString, bountyValue);
+
+ bountiesMap.put(targetUUID, bounty);
+
+ return bounty;
+ }
+
+ public boolean hasExistingBounty(Player bountyTarget){
+ UUID uuid = bountyTarget.getUniqueId();
+ return bountiesMap.containsKey(uuid);
+ }
+
+ public boolean hasExistingBounty(OfflinePlayer offlineBountyTarget){
+ UUID uuid = offlineBountyTarget.getUniqueId();
+ return bountiesMap.containsKey(uuid);
+ }
+
+ public boolean removeOnlineBounty(Player bountyTarget) throws IOException{
+ UUID uuid = bountyTarget.getUniqueId();
+ String key = uuid.toString();
+ if (findBountyByOnlineTarget(bountyTarget) != null){
+ if (bountiesMap.containsKey(uuid)){
+ bountiesMap.remove(uuid);
+ bountiesFile.set("bounties.data." + key, null);
+ PlayerBountiesPlus.getPlugin().bountiesFileManager.saveBountiesConfig();
+ return true;
+ }else {
+ logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Could not save bounties.yml"));
+ return false;
+ }
+ }
+ return false;
+ }
+
+ public boolean removeOfflineBounty(OfflinePlayer offlineBountyTarget) throws IOException{
+ UUID uuid = offlineBountyTarget.getUniqueId();
+ String key = uuid.toString();
+ if (findBountyByOfflineTarget(offlineBountyTarget) != null){
+ if (bountiesMap.containsKey(uuid)){
+ bountiesMap.remove(uuid);
+ bountiesFile.set("bounties.data." + key, null);
+ PlayerBountiesPlus.getPlugin().bountiesFileManager.saveBountiesConfig();
+ return true;
+ }else {
+ logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Could not save bounties.yml"));
+ return false;
+ }
+ }
+ return false;
+ }
+
+ public Bounty findBountyByOnlineTarget(Player bountyTarget){
+ UUID uuid = bountyTarget.getUniqueId();
+ return bountiesMap.get(uuid);
+ }
+
+ public Bounty findBountyByOfflineTarget(OfflinePlayer bountyTarget){
+ UUID uuid = bountyTarget.getUniqueId();
+ return bountiesMap.get(uuid);
+ }
+
+ public Bounty findBountyByOnlineCreator(Player bountyCreator){
+ for (Bounty bounty : bountiesMap.values()){
+ if (findBountyByOnlineTarget(bountyCreator) != null){
+ return bounty;
+ }
+ if (bounty.getBountyCreator().equals(bountyCreator.getUniqueId().toString())){
+ return bounty;
+ }
+ }
+ return null;
+ }
+
+ public Bounty findBountyByOfflineCreator(OfflinePlayer offlineBountyCreator){
+ for (Bounty bounty : bountiesMap.values()){
+ if (findBountyByOfflineTarget(offlineBountyCreator) != null){
+ return bounty;
+ }
+ if (bounty.getBountyCreator().equals(offlineBountyCreator.getUniqueId().toString())){
+ return bounty;
+ }
+ }
+ return null;
+ }
+
+ public void updateOnlineBountyValue(Player bountyTarget, int newBountyValue){
+ UUID uuid = bountyTarget.getUniqueId();
+ if (!hasExistingBounty(bountyTarget)){
+ logger.warning(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &cPlayer &d" + bountyTarget.getName() + " &cdoes not have a bounty already set!"));
+ return;
+ }
+ Bounty bounty = bountiesMap.get(uuid);
+ if (bounty.getBountyValue() > 0){
+ bounty.setBountyValue(bounty.getBountyValue() + newBountyValue);
+ }else {
+ bounty.setBountyValue(newBountyValue);
+ }
+ }
+
+ public void updateOfflineBountyValue(OfflinePlayer offlineBountyTarget, int newBountyValue){
+ UUID uuid = offlineBountyTarget.getUniqueId();
+ if (!hasExistingBounty(offlineBountyTarget)){
+ logger.warning(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &cPlayer &d" + offlineBountyTarget.getName() + " &cdoes not have a bounty already set!"));
+ return;
+ }
+ Bounty bounty = bountiesMap.get(uuid);
+ if (bounty.getBountyValue() >= newBountyValue){
+ bounty.setBountyValue(newBountyValue);
+ }else {
+ bounty.setBountyValue(bounty.getBountyValue() + newBountyValue);
+ }
+ }
+
+ public Set> getBounties(){
+ return bountiesMap.entrySet();
+ }
+
+ public Set getRawBountiesList(){
+ return bountiesMap.keySet();
+ }
+
+ public Collection getBountiesList(){
+ return bountiesMap.values();
+ }
+
+ public Set> getStrippedBounties(){
+ return strippedBountyValues.entrySet();
+ }
+}
diff --git a/src/main/java/com/tcoded/playerbountiesplus/utils/ColorUtils.java b/src/main/java/com/tcoded/playerbountiesplus/utils/ColorUtils.java
new file mode 100644
index 0000000..0b2676a
--- /dev/null
+++ b/src/main/java/com/tcoded/playerbountiesplus/utils/ColorUtils.java
@@ -0,0 +1,31 @@
+package com.tcoded.playerbountiesplus.utils;
+
+import org.bukkit.ChatColor;
+
+public class ColorUtils {
+
+ static public final String WITH_DELIMITER = "((?<=%1$s)|(?=%1$s))";
+
+ /**
+ * @param text The string of text to apply color/effects to
+ * @return Returns a string of text with color/effects applied
+ */
+
+ public static String translateColorCodes(String text){
+ String[] texts = text.split(String.format(WITH_DELIMITER, "&"));
+ StringBuilder finalText = new StringBuilder();
+ for (int i = 0; i < texts.length; i++){
+ if (texts[i].equalsIgnoreCase("&")){
+ i++;
+ if (texts[i].charAt(0) == '#'){
+ finalText.append(net.md_5.bungee.api.ChatColor.of(texts[i].substring(0, 7)) + texts[i].substring(7));
+ }else{
+ finalText.append(ChatColor.translateAlternateColorCodes('&', "&" + texts[i]));
+ }
+ }else{
+ finalText.append(texts[i]);
+ }
+ }
+ return finalText.toString();
+ }
+}
diff --git a/src/main/resources/bounties.yml b/src/main/resources/bounties.yml
index e69de29..4ea35cb 100644
--- a/src/main/resources/bounties.yml
+++ b/src/main/resources/bounties.yml
@@ -0,0 +1,2 @@
+bounties:
+ data:
\ No newline at end of file
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index e69de29..e398f6a 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -0,0 +1,16 @@
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
+# ----[PlayerBountiesPlus]---- #
+# ----[By Loving11ish & TCoded]---- #
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
+# ----[Plugin Config File]---- #
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
+#PlayerBountiesPlus config for ${version}
+
+bounty:
+ #What is the maximum bounty value that can be set? [Default value: 1000000000]
+ max-bounty-value: 1000000000
+ #What is the minimum bounty value that can be set? (Value cannot be a decimal) [Default value: 1]
+ min-bounty-value: 1
+
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 5eb97ca..2f08bd8 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,13 +1,16 @@
name: PlayerBountiesPlus
version: '${project.version}'
main: com.tcoded.playerbountiesplus.PlayerBountiesPlus
-api-version: 1.19
-authors: [ TechnicallyCoded ]
+api-version: 1.13
+authors: [ Loving11ish, TechnicallyCoded ]
+softdepend: [ Vault, ClansLite ]
description: Claim bounties only if you are not on the same clan
website: https://tcoded.com
commands:
bounty:
+ usage: "/bounty [set|check|top]"
+ description: "The main command for the plugin."
permission: playerbountiesplus.command.bounty
permissions: