Compare commits

..
1 Commits
Author SHA1 Message Date
LoginExceptionandTechnicallyCoded 0f152ecb74 Added PAPI support. (#12)
Co-authored-by: TechnicallyCoded <technicallycoded@gmail.com>
2024-06-04 01:45:58 +02:00
17 changed files with 159 additions and 261 deletions

No files matched your search

+11 -12
View File
@@ -6,7 +6,7 @@
<groupId>com.tcoded</groupId>
<artifactId>PlayerBountiesPlus</artifactId>
<version>1.4.9</version>
<version>1.4.8</version>
<packaging>jar</packaging>
<name>PlayerBountiesPlus</name>
@@ -71,6 +71,10 @@
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
@@ -99,10 +103,6 @@
<id>glaremasters repo</id>
<url>https://repo.glaremasters.me/repository/towny/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/releases/</url>
</repository>
</repositories>
<dependencies>
@@ -124,6 +124,12 @@
<version>23.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.CraptiCraft-Development</groupId>
<artifactId>ClansLite-API</artifactId>
@@ -177,7 +183,6 @@
<groupId>com.github.SaberLLC</groupId>
<artifactId>Saber-Factions</artifactId>
<version>4.1.2-STABLE</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.palmergames.bukkit.towny</groupId>
@@ -185,11 +190,5 @@
<version>0.100.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.6</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
@@ -4,18 +4,18 @@ import com.google.common.collect.ImmutableList;
import com.tcoded.folialib.FoliaLib;
import com.tcoded.playerbountiesplus.command.BountyCommand;
import com.tcoded.playerbountiesplus.command.PlayerBountiesPlusAdminCmd;
import com.tcoded.playerbountiesplus.hook.currency.EconomyHook;
import com.tcoded.playerbountiesplus.hook.PAPIExpansion;
import com.tcoded.playerbountiesplus.hook.currency.AbstractEconomyHook;
import com.tcoded.playerbountiesplus.hook.currency.DummyEcoHook;
import com.tcoded.playerbountiesplus.hook.currency.VaultHook;
import com.tcoded.playerbountiesplus.hook.placeholder.PlaceholderHook;
import com.tcoded.playerbountiesplus.hook.team.AbstractTeamHook;
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.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.file.FileConfiguration;
@@ -45,9 +45,10 @@ public final class PlayerBountiesPlus extends JavaPlugin {
private BountyDataManager bountyDataManager;
// Hooks
private EconomyHook ecoHook;
private TeamHook teamHook;
private PlaceholderHook placeholderHook;
private AbstractEconomyHook ecoHook;
private AbstractTeamHook teamHook;
private PAPIExpansion papiExpansion;
public PlayerBountiesPlus() {
instance = this;
@@ -72,15 +73,11 @@ public final class PlayerBountiesPlus extends JavaPlugin {
if (!applyEcoHookRegistration()) return;
// Team Hooks
this.teamHook = TeamHook.findTeamHook(this);
this.teamHook = AbstractTeamHook.findTeamHook(this);
if (this.teamHook == null) {
getLogger().warning("There is no supported team/clan/party plugin on the server! Feel free to request support for the plugin you use on GitHub or Discord!");
}
// Placeholder Hooks
this.placeholderHook = PlaceholderHook.findPlaceholderHook(this);
this.placeholderHook.enable();
// Commands
PluginCommand bountyCmd = this.getCommand("bounty");
if (bountyCmd != null) {
@@ -117,6 +114,11 @@ public final class PlayerBountiesPlus extends JavaPlugin {
findPluginWithQuery(plugins, metrics, "parties");
findPluginWithQuery(plugins, metrics, "guild");
findPluginWithQuery(plugins, metrics, "guilds");
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
papiExpansion = new PAPIExpansion(this);
papiExpansion.register();
}
}
public void reloadLang() {
@@ -135,21 +137,16 @@ public final class PlayerBountiesPlus extends JavaPlugin {
@Override
public void onDisable() {
HandlerList.unregisterAll(this);
this.placeholderHook.disable();
}
public EconomyHook getEcoHook() {
public AbstractEconomyHook getEcoHook() {
return this.ecoHook;
}
public TeamHook getTeamHook() {
public AbstractTeamHook getTeamHook() {
return teamHook;
}
public PlaceholderHook getPlaceholderHook() {
return placeholderHook;
}
public BountyDataManager getBountyDataManager() {
return bountyDataManager;
}
@@ -198,14 +195,14 @@ public final class PlayerBountiesPlus extends JavaPlugin {
boolean ecoPresent = vaultEcoHook.init();
// Register or fallback
if (ecoPresent) servicesManager.register(EconomyHook.class, vaultEcoHook, this, ServicePriority.Low);
else servicesManager.register(EconomyHook.class, new DummyEcoHook(), this, ServicePriority.Lowest);
if (ecoPresent) servicesManager.register(AbstractEconomyHook.class, vaultEcoHook, this, ServicePriority.Low);
else servicesManager.register(AbstractEconomyHook.class, new DummyEcoHook(), this, ServicePriority.Lowest);
}
public boolean applyEcoHookRegistration() {
// Get economy hook
ServicesManager servicesManager = getServer().getServicesManager();
RegisteredServiceProvider<EconomyHook> ecoHookProvider = servicesManager.getRegistration(EconomyHook.class);
RegisteredServiceProvider<AbstractEconomyHook> ecoHookProvider = servicesManager.getRegistration(AbstractEconomyHook.class);
if (ecoHookProvider == null) {
getLogger().severe("No economy hook is present! Aborting startup!");
return false;
@@ -1,7 +1,6 @@
package com.tcoded.playerbountiesplus.command.bounty;
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
import com.tcoded.playerbountiesplus.manager.BountyDataManager;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -27,16 +26,14 @@ public class BountyCheckCmd {
UUID playerUUID = target.getUniqueId();
BountyDataManager bountyDataManager = plugin.getBountyDataManager();
boolean hasBounty = bountyDataManager.hasBounty(playerUUID);
Integer amount = plugin.getBountyDataManager().getBounties().get(playerUUID);
if (hasBounty) {
if (amount != null && amount > 0) {
// Confirmation
int bounty = bountyDataManager.getBounty(playerUUID);
sender.sendMessage(
plugin.getLang().getColored("command.bounty.check.bounty-found")
.replace("{target}", target.getName())
.replace("{bounty}", Integer.toString(bounty))
.replace("{bounty}", amount.toString())
);
} else {
sender.sendMessage(
@@ -1,12 +1,12 @@
package com.tcoded.playerbountiesplus.command.bounty;
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
import com.tcoded.playerbountiesplus.manager.BountyDataManager;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class BountySetCmd {
@@ -17,7 +17,7 @@ public class BountySetCmd {
}
String playerNameArg = args[1];
float amount;
int amount;
try {
amount = Integer.parseInt(args[2]);
} catch (NumberFormatException ex) {
@@ -61,7 +61,7 @@ public class BountySetCmd {
}
// Apply bounty multiplier
amount *= (float) plugin.getConfig().getDouble("bounty-multiplier", 1.0);
amount *= plugin.getConfig().getDouble("bounty-multiplier", 1.0);
// Sanity check final amount
if (amount <= 0) {
@@ -72,10 +72,10 @@ public class BountySetCmd {
UUID playerUUID = target.getUniqueId();
// Calculate total bounty including previous bounties
BountyDataManager bountyDataManager = plugin.getBountyDataManager();
int bountyAlreadyPresent = bountyDataManager.getBounty(playerUUID);
int totalBounty = ((int) amount) + bountyAlreadyPresent;
bountyDataManager.setBounty(playerUUID, totalBounty);
ConcurrentHashMap<UUID, Integer> bounties = plugin.getBountyDataManager().getBounties();
Integer bountyAlreadyPresent = bounties.getOrDefault(playerUUID, 0);
int totalBounty = amount + bountyAlreadyPresent;
bounties.put(playerUUID, totalBounty);
// Confirmation
sender.sendMessage(
@@ -104,7 +104,7 @@ public class BountySetCmd {
);
}
bountyDataManager.saveBountiesAsync();
plugin.getBountyDataManager().saveBountiesAsync();
return true;
}
@@ -0,0 +1,42 @@
package com.tcoded.playerbountiesplus.hook;
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.text.DecimalFormat;
import java.util.UUID;
public class PAPIExpansion extends PlaceholderExpansion {
private static final String IDENTIFIER = "playerbountiesplus";
private final PlayerBountiesPlus plugin;
public PAPIExpansion(PlayerBountiesPlus plugin) {
this.plugin = plugin;
}
public @NotNull String getIdentifier() {
return IDENTIFIER;
}
public @NotNull String getAuthor() {
return plugin.getDescription().getAuthors().toString();
}
public @NotNull String getVersion() {
return plugin.getDescription().getVersion();
}
public @Nullable String onRequest(OfflinePlayer player, @NotNull String params) {
if (params.equals("bounty")) {
UUID uuid = player.getUniqueId();
return String.valueOf(plugin.getBountyDataManager().getBounties().getOrDefault(uuid, 0));
}
return null;
}
}
@@ -0,0 +1,15 @@
package com.tcoded.playerbountiesplus.hook.currency;
import org.bukkit.entity.Player;
public abstract class AbstractEconomyHook {
public abstract boolean isValid();
public abstract void giveEco(Player player, double amount);
public abstract boolean takeEco(Player player, double amount);
public abstract boolean takeEco(Player player, double amount, boolean force);
}
@@ -2,7 +2,7 @@ package com.tcoded.playerbountiesplus.hook.currency;
import org.bukkit.entity.Player;
public class DummyEcoHook implements EconomyHook {
public class DummyEcoHook extends AbstractEconomyHook {
@Override
public boolean isValid() {
@@ -1,15 +0,0 @@
package com.tcoded.playerbountiesplus.hook.currency;
import org.bukkit.entity.Player;
public interface EconomyHook {
boolean isValid();
void giveEco(Player player, double amount);
boolean takeEco(Player player, double amount);
boolean takeEco(Player player, double amount, boolean force);
}
@@ -6,7 +6,7 @@ import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider;
public class VaultHook implements EconomyHook {
public class VaultHook extends AbstractEconomyHook {
private final PlayerBountiesPlus plugin;
@@ -1,15 +0,0 @@
package com.tcoded.playerbountiesplus.hook.placeholder;
public class DummyPlaceholderHook implements PlaceholderHook {
@Override
public void enable() {
}
@Override
public void disable() {
}
}
@@ -1,61 +0,0 @@
package com.tcoded.playerbountiesplus.hook.placeholder;
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class PlaceholderAPIHook extends PlaceholderExpansion implements PlaceholderHook {
private final PlayerBountiesPlus pbpPlugin;
public PlaceholderAPIHook(PlayerBountiesPlus pbpPlugin, Plugin papiPlugin) {
this.pbpPlugin = pbpPlugin;
if (!(papiPlugin instanceof PlaceholderAPIPlugin)) {
throw new IllegalArgumentException("Plugin is not PlaceholderAPI");
}
}
@Override
public @NotNull String getIdentifier() {
return pbpPlugin.getName().toLowerCase();
}
@Override
public @NotNull String getAuthor() {
return pbpPlugin.getDescription().getAuthors().get(0);
}
@Override
public @NotNull String getVersion() {
return pbpPlugin.getDescription().getVersion();
}
@Override
public boolean persist() {
return true;
}
@Override
public void enable() {
this.register();
}
@Override
public void disable() {
this.unregister();
}
@Override
public @Nullable String onRequest(OfflinePlayer player, @NotNull String params) {
if (params.equals("bounty")) {
return String.valueOf(pbpPlugin.getBountyDataManager().getBounty(player.getUniqueId()));
}
return "INVALID-OPTION";
}
}
@@ -1,27 +0,0 @@
package com.tcoded.playerbountiesplus.hook.placeholder;
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.jetbrains.annotations.NotNull;
public interface PlaceholderHook {
@NotNull
static PlaceholderHook findPlaceholderHook(PlayerBountiesPlus plugin) {
PluginManager pluginManager = plugin.getServer().getPluginManager();
Plugin papiPlugin = pluginManager.getPlugin("PlaceholderAPI");
if (papiPlugin != null) {
return new PlaceholderAPIHook(plugin, papiPlugin);
}
plugin.getLogger().warning("PlaceholderAPI not found, placeholders will be unavailable.");
return new DummyPlaceholderHook();
}
void enable();
void disable();
}
@@ -1,12 +1,14 @@
package com.tcoded.playerbountiesplus.hook.team;
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.List;
public abstract class AbstractTeamHook implements TeamHook {
public abstract class AbstractTeamHook {
protected PlayerBountiesPlus plugin;
protected JavaPlugin teamPlugin;
@@ -16,23 +18,66 @@ public abstract class AbstractTeamHook implements TeamHook {
this.teamPlugin = (JavaPlugin) teamPlugin;
}
@Override
public static AbstractTeamHook findTeamHook(PlayerBountiesPlus plugin) {
PluginManager pluginManager = plugin.getServer().getPluginManager();
// loving11ish - ClansLite - https://www.spigotmc.org/resources/clanslite-1-19-4-support.97163/
Plugin clansLitePlugin = pluginManager.getPlugin("ClansLite");
if (clansLitePlugin != null && clansLitePlugin.isEnabled()) {
return new ClansLiteHook(plugin, clansLitePlugin);
}
// AlessioDP - Parties - https://www.spigotmc.org/resources/parties-an-advanced-parties-manager.3709/
Plugin partiesPlugin = pluginManager.getPlugin("Parties");
if (partiesPlugin != null && partiesPlugin.isEnabled()) {
return new AlessioPartiesHook(plugin, partiesPlugin);
}
// booksaw - BetterTeams - https://www.spigotmc.org/resources/better-teams.17129/
Plugin betterTeamsPlugin = pluginManager.getPlugin("BetterTeams");
if (betterTeamsPlugin != null && betterTeamsPlugin.isEnabled()) {
return new BetterTeamsHook(plugin, betterTeamsPlugin);
}
// RoinujNosde - SimpleClans - https://www.spigotmc.org/resources/simpleclans.71242/
Plugin simpleClansPlugin = pluginManager.getPlugin("SimpleClans");
if (simpleClansPlugin != null && simpleClansPlugin.isEnabled()) {
return new SimpleClansHook(plugin, simpleClansPlugin);
}
// SaberLLC - Factions (SaberFactions) - https://www.spigotmc.org/resources/simpleclans.71242/
Plugin saberFactionsPlugin = pluginManager.getPlugin("Factions");
if (saberFactionsPlugin != null &&
saberFactionsPlugin.getDescription().getMain().equals("com.massivecraft.factions.FactionsPlugin") &&
saberFactionsPlugin.isEnabled()) {
return new SaberFactionsHook(plugin, saberFactionsPlugin);
}
// LlmDl - Towny - https://www.spigotmc.org/resources/towny-advanced.72694/
Plugin townyPlugin = pluginManager.getPlugin("Towny");
if (townyPlugin != null && townyPlugin.isEnabled()) {
return new TownyHook(plugin, simpleClansPlugin);
}
return null;
}
public String getPluginName() {
return this.teamPlugin.getName();
}
@Override
public String getAuthor() {
List<String> authors = this.teamPlugin.getDescription().getAuthors();
if (authors.isEmpty()) return "N/A";
return authors.get(0);
}
@Override
public String[] getAuthors() {
List<String> authors = this.teamPlugin.getDescription().getAuthors();
if (authors.isEmpty()) return new String[0];
return authors.toArray(new String[0]);
}
public abstract boolean isFriendly(Player player1, Player player2);
}
@@ -1,62 +0,0 @@
package com.tcoded.playerbountiesplus.hook.team;
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
public interface TeamHook {
static AbstractTeamHook findTeamHook(PlayerBountiesPlus plugin) {
PluginManager pluginManager = plugin.getServer().getPluginManager();
// loving11ish - ClansLite - https://www.spigotmc.org/resources/clanslite-1-19-4-support.97163/
Plugin clansLitePlugin = pluginManager.getPlugin("ClansLite");
if (clansLitePlugin != null && clansLitePlugin.isEnabled()) {
return new ClansLiteHook(plugin, clansLitePlugin);
}
// AlessioDP - Parties - https://www.spigotmc.org/resources/parties-an-advanced-parties-manager.3709/
Plugin partiesPlugin = pluginManager.getPlugin("Parties");
if (partiesPlugin != null && partiesPlugin.isEnabled()) {
return new AlessioPartiesHook(plugin, partiesPlugin);
}
// booksaw - BetterTeams - https://www.spigotmc.org/resources/better-teams.17129/
Plugin betterTeamsPlugin = pluginManager.getPlugin("BetterTeams");
if (betterTeamsPlugin != null && betterTeamsPlugin.isEnabled()) {
return new BetterTeamsHook(plugin, betterTeamsPlugin);
}
// RoinujNosde - SimpleClans - https://www.spigotmc.org/resources/simpleclans.71242/
Plugin simpleClansPlugin = pluginManager.getPlugin("SimpleClans");
if (simpleClansPlugin != null && simpleClansPlugin.isEnabled()) {
return new SimpleClansHook(plugin, simpleClansPlugin);
}
// SaberLLC - Factions (SaberFactions) - https://www.spigotmc.org/resources/simpleclans.71242/
Plugin saberFactionsPlugin = pluginManager.getPlugin("Factions");
if (saberFactionsPlugin != null &&
saberFactionsPlugin.getDescription().getMain().equals("com.massivecraft.factions.FactionsPlugin") &&
saberFactionsPlugin.isEnabled()) {
return new SaberFactionsHook(plugin, saberFactionsPlugin);
}
// LlmDl - Towny - https://www.spigotmc.org/resources/towny-advanced.72694/
Plugin townyPlugin = pluginManager.getPlugin("Towny");
if (townyPlugin != null && townyPlugin.isEnabled()) {
return new TownyHook(plugin, simpleClansPlugin);
}
return null;
}
String getPluginName();
String getAuthor();
String[] getAuthors();
boolean isFriendly(Player player1, Player player2);
}
@@ -1,8 +1,7 @@
package com.tcoded.playerbountiesplus.listener;
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
import com.tcoded.playerbountiesplus.hook.team.TeamHook;
import com.tcoded.playerbountiesplus.manager.BountyDataManager;
import com.tcoded.playerbountiesplus.hook.team.AbstractTeamHook;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -10,10 +9,11 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class DeathListener implements Listener {
private final PlayerBountiesPlus plugin;
private PlayerBountiesPlus plugin;
public DeathListener(PlayerBountiesPlus plugin) {
this.plugin = plugin;
@@ -25,18 +25,17 @@ public class DeathListener implements Listener {
Player killer = victim.getKiller();
if (killer != null) {
BountyDataManager bountyDataManager = this.plugin.getBountyDataManager();
ConcurrentHashMap<UUID, Integer> bounties = this.plugin.getBountyDataManager().getBounties();
UUID victimId = victim.getUniqueId();
Integer bounty = bounties.get(victimId);
// Bounty check
if (bountyDataManager.hasBounty(victimId)) {
if (bounty == null || bounty == 0) {
return;
}
int bounty = bountyDataManager.getBounty(victimId);
// Clan check
TeamHook teamHook = this.plugin.getTeamHook();
AbstractTeamHook teamHook = this.plugin.getTeamHook();
if (teamHook != null && teamHook.isFriendly(killer, victim)) {
killer.sendMessage(plugin.getLang().getColored("death.same-team"));
return;
@@ -65,13 +64,13 @@ public class DeathListener implements Listener {
plugin.getLang().getColored("death.announce-claimed")
.replace("{killer}", killer.getName())
.replace("{victim}", victim.getName())
.replace("{bounty}", String.valueOf(bounty))
.replace("{bounty}", bounty.toString())
);
}
// Remove bounty
bountyDataManager.removeBounty(victimId);
bountyDataManager.saveBountiesAsync();
bounties.remove(victimId);
this.plugin.getBountyDataManager().saveBountiesAsync();
}
}
@@ -50,22 +50,6 @@ public class BountyDataManager {
return this.bounties;
}
public boolean hasBounty(UUID player) {
return this.bounties.containsKey(player) && this.bounties.get(player) > 0;
}
public void setBounty(UUID player, int amount) {
this.bounties.put(player, amount);
}
public int getBounty(UUID player) {
return this.bounties.getOrDefault(player, 0);
}
public void removeBounty(UUID player) {
this.bounties.remove(player);
}
public void saveBounties() {
synchronized (this.savingFileLock) {
// Clear existing
@@ -108,5 +92,4 @@ public class BountyDataManager {
}
});
}
}
+1
View File
@@ -15,6 +15,7 @@ softdepend:
- BetterTeams
- SimpleClans
- Towny
- PlaceholderAPI
commands:
bounty: