Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4241b07ee1 | ||
|
|
44325dc2dd | ||
|
|
d398ca2d04 | ||
|
|
74bd9115f0 | ||
|
|
0b6ad1b1ec | ||
|
|
9656fe8051 | ||
|
|
00824f63d3 | ||
|
|
58010a3e47 | ||
|
|
569866324e | ||
|
|
e8ae4b4686 | ||
|
|
28cfec8433 |
No files matched your search
@@ -18,7 +18,6 @@ out/
|
||||
*.ctxt
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
jdk:
|
||||
- openjdk17
|
||||
Binary file not shown.
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.tcoded</groupId>
|
||||
<artifactId>PlayerBountiesPlus</artifactId>
|
||||
<version>1.4.7</version>
|
||||
<version>1.4.9</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>PlayerBountiesPlus</name>
|
||||
@@ -95,6 +95,14 @@
|
||||
<id>codemc-repo</id>
|
||||
<url>https://repo.codemc.org/repository/maven-public</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<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>
|
||||
@@ -117,9 +125,9 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.Loving11ish</groupId>
|
||||
<artifactId>ClansLite</artifactId>
|
||||
<version>v1.4.3</version>
|
||||
<groupId>com.github.CraptiCraft-Development</groupId>
|
||||
<artifactId>ClansLite-API</artifactId>
|
||||
<version>1.4.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -169,6 +177,19 @@
|
||||
<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>
|
||||
<artifactId>towny</artifactId>
|
||||
<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,8 +4,12 @@ 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.VaultHook;
|
||||
import com.tcoded.playerbountiesplus.hook.currency.EconomyHook;
|
||||
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;
|
||||
@@ -17,12 +21,22 @@ import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
import org.bukkit.plugin.ServicesManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class PlayerBountiesPlus extends JavaPlugin {
|
||||
|
||||
// Instance
|
||||
private static PlayerBountiesPlus instance;
|
||||
|
||||
public static PlayerBountiesPlus getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
// Utils
|
||||
private FoliaLib foliaLib;
|
||||
private LangUtil langUtil;
|
||||
@@ -31,8 +45,13 @@ public final class PlayerBountiesPlus extends JavaPlugin {
|
||||
private BountyDataManager bountyDataManager;
|
||||
|
||||
// Hooks
|
||||
private VaultHook vault;
|
||||
private AbstractTeamHook teamHook;
|
||||
private EconomyHook ecoHook;
|
||||
private TeamHook teamHook;
|
||||
private PlaceholderHook placeholderHook;
|
||||
|
||||
public PlayerBountiesPlus() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@@ -48,18 +67,20 @@ public final class PlayerBountiesPlus extends JavaPlugin {
|
||||
this.bountyDataManager = new BountyDataManager(this);
|
||||
this.bountyDataManager.init();
|
||||
|
||||
// Hooks
|
||||
this.vault = new VaultHook(this);
|
||||
boolean ecoPresent = this.vault.init();
|
||||
if (!ecoPresent) {
|
||||
getLogger().severe("No economy is present! Aborting startup!");
|
||||
return;
|
||||
}
|
||||
this.teamHook = AbstractTeamHook.findTeamHook(this);
|
||||
// Economy Hooks
|
||||
registerDefaultEcoHooks();
|
||||
if (!applyEcoHookRegistration()) return;
|
||||
|
||||
// Team Hooks
|
||||
this.teamHook = TeamHook.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) {
|
||||
@@ -114,16 +135,21 @@ public final class PlayerBountiesPlus extends JavaPlugin {
|
||||
@Override
|
||||
public void onDisable() {
|
||||
HandlerList.unregisterAll(this);
|
||||
this.placeholderHook.disable();
|
||||
}
|
||||
|
||||
public VaultHook getVaultHook() {
|
||||
return this.vault;
|
||||
public EconomyHook getEcoHook() {
|
||||
return this.ecoHook;
|
||||
}
|
||||
|
||||
public AbstractTeamHook getTeamHook() {
|
||||
public TeamHook getTeamHook() {
|
||||
return teamHook;
|
||||
}
|
||||
|
||||
public PlaceholderHook getPlaceholderHook() {
|
||||
return placeholderHook;
|
||||
}
|
||||
|
||||
public BountyDataManager getBountyDataManager() {
|
||||
return bountyDataManager;
|
||||
}
|
||||
@@ -160,4 +186,37 @@ public final class PlayerBountiesPlus extends JavaPlugin {
|
||||
|
||||
metrics.addCustomChart(new SimplePie("plugins_query_" + pluginNameQuery, () -> firstPluginFound));
|
||||
}
|
||||
|
||||
private void registerDefaultEcoHooks() {
|
||||
ServicesManager servicesManager = getServer().getServicesManager();
|
||||
|
||||
// Unregister old eco hooks
|
||||
servicesManager.unregisterAll(this);
|
||||
|
||||
// Register vault economy hook
|
||||
VaultHook vaultEcoHook = new VaultHook(this);
|
||||
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);
|
||||
}
|
||||
|
||||
public boolean applyEcoHookRegistration() {
|
||||
// Get economy hook
|
||||
ServicesManager servicesManager = getServer().getServicesManager();
|
||||
RegisteredServiceProvider<EconomyHook> ecoHookProvider = servicesManager.getRegistration(EconomyHook.class);
|
||||
if (ecoHookProvider == null) {
|
||||
getLogger().severe("No economy hook is present! Aborting startup!");
|
||||
return false;
|
||||
}
|
||||
|
||||
String hookName = ecoHookProvider.getProvider().getClass().getSimpleName();
|
||||
String hookPluginName = ecoHookProvider.getPlugin().getName();
|
||||
|
||||
getLogger().info("Using economy hook: " + hookName + " from plugin: " + hookPluginName);
|
||||
this.ecoHook = ecoHookProvider.getProvider();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
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;
|
||||
@@ -26,14 +27,16 @@ public class BountyCheckCmd {
|
||||
|
||||
UUID playerUUID = target.getUniqueId();
|
||||
|
||||
Integer amount = plugin.getBountyDataManager().getBounties().get(playerUUID);
|
||||
BountyDataManager bountyDataManager = plugin.getBountyDataManager();
|
||||
boolean hasBounty = bountyDataManager.hasBounty(playerUUID);
|
||||
|
||||
if (amount != null && amount > 0) {
|
||||
if (hasBounty) {
|
||||
// Confirmation
|
||||
int bounty = bountyDataManager.getBounty(playerUUID);
|
||||
sender.sendMessage(
|
||||
plugin.getLang().getColored("command.bounty.check.bounty-found")
|
||||
.replace("{target}", target.getName())
|
||||
.replace("{bounty}", amount.toString())
|
||||
.replace("{bounty}", Integer.toString(bounty))
|
||||
);
|
||||
} 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];
|
||||
int amount;
|
||||
float amount;
|
||||
try {
|
||||
amount = Integer.parseInt(args[2]);
|
||||
} catch (NumberFormatException ex) {
|
||||
@@ -52,7 +52,7 @@ public class BountySetCmd {
|
||||
// Check money
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
boolean allowed = plugin.getVaultHook().takeMoney(player, amount);
|
||||
boolean allowed = plugin.getEcoHook().takeEco(player, amount);
|
||||
|
||||
if (!allowed) {
|
||||
sender.sendMessage(plugin.getLang().getColored("command.bounty.set.not-enough-money"));
|
||||
@@ -61,7 +61,7 @@ public class BountySetCmd {
|
||||
}
|
||||
|
||||
// Apply bounty multiplier
|
||||
amount *= plugin.getConfig().getDouble("bounty-multiplier", 1.0);
|
||||
amount *= (float) 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
|
||||
ConcurrentHashMap<UUID, Integer> bounties = plugin.getBountyDataManager().getBounties();
|
||||
Integer bountyAlreadyPresent = bounties.getOrDefault(playerUUID, 0);
|
||||
int totalBounty = amount + bountyAlreadyPresent;
|
||||
bounties.put(playerUUID, totalBounty);
|
||||
BountyDataManager bountyDataManager = plugin.getBountyDataManager();
|
||||
int bountyAlreadyPresent = bountyDataManager.getBounty(playerUUID);
|
||||
int totalBounty = ((int) amount) + bountyAlreadyPresent;
|
||||
bountyDataManager.setBounty(playerUUID, totalBounty);
|
||||
|
||||
// Confirmation
|
||||
sender.sendMessage(
|
||||
@@ -104,7 +104,7 @@ public class BountySetCmd {
|
||||
);
|
||||
}
|
||||
|
||||
plugin.getBountyDataManager().saveBountiesAsync();
|
||||
bountyDataManager.saveBountiesAsync();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.tcoded.playerbountiesplus.hook.currency;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class DummyEcoHook implements EconomyHook {
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveEco(Player player, double amount) {
|
||||
throw new UnsupportedOperationException("Economy isn't setup. Dummy hook is the active fallback.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean takeEco(Player player, double amount) {
|
||||
throw new UnsupportedOperationException("Economy isn't setup. Dummy hook is the active fallback.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean takeEco(Player player, double amount, boolean force) {
|
||||
throw new UnsupportedOperationException("Economy isn't setup. Dummy hook is the active fallback.");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
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);
|
||||
|
||||
}
|
||||
+15
-9
@@ -1,15 +1,12 @@
|
||||
package com.tcoded.playerbountiesplus.hook;
|
||||
package com.tcoded.playerbountiesplus.hook.currency;
|
||||
|
||||
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.economy.EconomyResponse;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class VaultHook {
|
||||
public class VaultHook implements EconomyHook {
|
||||
|
||||
private final PlayerBountiesPlus plugin;
|
||||
|
||||
@@ -34,18 +31,27 @@ public class VaultHook {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void addMoney(Player player, double amount) {
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return eco != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveEco(Player player, double amount) {
|
||||
this.eco.depositPlayer(player, amount);
|
||||
}
|
||||
|
||||
public boolean takeMoney(Player player, double amount) {
|
||||
return this.takeMoney(player, amount, false);
|
||||
@Override
|
||||
public boolean takeEco(Player player, double amount) {
|
||||
return this.takeEco(player, amount, false);
|
||||
}
|
||||
|
||||
public boolean takeMoney(Player player, double amount, boolean force) {
|
||||
@Override
|
||||
public boolean takeEco(Player player, double amount, boolean force) {
|
||||
double balance = this.eco.getBalance(player);
|
||||
if (balance < amount && !force) return false;
|
||||
|
||||
return this.eco.withdrawPlayer(player, amount).type == EconomyResponse.ResponseType.SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.tcoded.playerbountiesplus.hook.placeholder;
|
||||
|
||||
public class DummyPlaceholderHook implements PlaceholderHook {
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
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";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
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,14 +1,12 @@
|
||||
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 {
|
||||
public abstract class AbstractTeamHook implements TeamHook {
|
||||
|
||||
protected PlayerBountiesPlus plugin;
|
||||
protected JavaPlugin teamPlugin;
|
||||
@@ -18,60 +16,23 @@ public abstract class AbstractTeamHook {
|
||||
this.teamPlugin = (JavaPlugin) teamPlugin;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
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,20 +1,23 @@
|
||||
package com.tcoded.playerbountiesplus.hook.team;
|
||||
|
||||
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
|
||||
import me.loving11ish.clans.models.Clan;
|
||||
import me.loving11ish.clans.utils.ClansStorageUtil;
|
||||
import me.loving11ish.clans.api.ClansLiteAPI;
|
||||
import me.loving11ish.clans.api.models.Clan;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ClansLiteHook extends AbstractTeamHook {
|
||||
|
||||
private final ClansLiteAPI api;
|
||||
|
||||
public ClansLiteHook(PlayerBountiesPlus plugin, Plugin teamPlugin) {
|
||||
super(plugin, teamPlugin);
|
||||
api = ClansLiteAPI.getInstance();
|
||||
}
|
||||
|
||||
public @Nullable String getClanId(Player player) {
|
||||
Clan clan = ClansStorageUtil.findClanByPlayer(player);
|
||||
Clan clan = api.getClanByBukkitPlayer(player);
|
||||
return clan == null ? null : clan.getClanFinalName();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
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);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.tcoded.playerbountiesplus.hook.team;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class TownyHook extends AbstractTeamHook {
|
||||
|
||||
public TownyHook(PlayerBountiesPlus plugin, Plugin teamPlugin) {
|
||||
super(plugin, teamPlugin);
|
||||
}
|
||||
|
||||
public Town getTown(Player player) {
|
||||
return TownyAPI.getInstance().getTown(player);
|
||||
}
|
||||
|
||||
public Nation getNation(Player player) {
|
||||
return TownyAPI.getInstance().getNation(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFriendly(Player player1, Player player2) {
|
||||
Town town = getTown(player1);
|
||||
Nation player1Nation = getNation(player1);
|
||||
Nation player2Nation = getNation(player2);
|
||||
boolean sameTown = town != null && town.hasResident(player2);
|
||||
boolean sameNation = player1Nation != null && player1Nation.equals(player2Nation);
|
||||
|
||||
return sameTown || sameNation;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.tcoded.playerbountiesplus.listener;
|
||||
|
||||
import com.tcoded.playerbountiesplus.PlayerBountiesPlus;
|
||||
import com.tcoded.playerbountiesplus.hook.team.AbstractTeamHook;
|
||||
import com.tcoded.playerbountiesplus.hook.team.TeamHook;
|
||||
import com.tcoded.playerbountiesplus.manager.BountyDataManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@@ -9,11 +10,10 @@ 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 PlayerBountiesPlus plugin;
|
||||
private final PlayerBountiesPlus plugin;
|
||||
|
||||
public DeathListener(PlayerBountiesPlus plugin) {
|
||||
this.plugin = plugin;
|
||||
@@ -25,17 +25,18 @@ public class DeathListener implements Listener {
|
||||
Player killer = victim.getKiller();
|
||||
|
||||
if (killer != null) {
|
||||
ConcurrentHashMap<UUID, Integer> bounties = this.plugin.getBountyDataManager().getBounties();
|
||||
BountyDataManager bountyDataManager = this.plugin.getBountyDataManager();
|
||||
UUID victimId = victim.getUniqueId();
|
||||
Integer bounty = bounties.get(victimId);
|
||||
|
||||
// Bounty check
|
||||
if (bounty == null || bounty == 0) {
|
||||
if (bountyDataManager.hasBounty(victimId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int bounty = bountyDataManager.getBounty(victimId);
|
||||
|
||||
// Clan check
|
||||
AbstractTeamHook teamHook = this.plugin.getTeamHook();
|
||||
TeamHook teamHook = this.plugin.getTeamHook();
|
||||
if (teamHook != null && teamHook.isFriendly(killer, victim)) {
|
||||
killer.sendMessage(plugin.getLang().getColored("death.same-team"));
|
||||
return;
|
||||
@@ -47,15 +48,15 @@ public class DeathListener implements Listener {
|
||||
double awardedAmount = bounty * claimMultiplier;
|
||||
|
||||
if (awardedAmount > 0) {
|
||||
this.plugin.getVaultHook().addMoney(killer, awardedAmount);
|
||||
this.plugin.getEcoHook().giveEco(killer, awardedAmount);
|
||||
} else if (awardedAmount < 0) {
|
||||
this.plugin.getVaultHook().takeMoney(killer, Math.abs(awardedAmount));
|
||||
this.plugin.getEcoHook().takeEco(killer, Math.abs(awardedAmount));
|
||||
}
|
||||
}
|
||||
|
||||
// Optional - Take from victim as punishment
|
||||
if (plugin.getConfig().getBoolean("bounty-take-from-victim", false)) {
|
||||
this.plugin.getVaultHook().takeMoney(victim, bounty, true);
|
||||
this.plugin.getEcoHook().takeEco(victim, bounty, true);
|
||||
}
|
||||
|
||||
// Announce Reward
|
||||
@@ -64,13 +65,13 @@ public class DeathListener implements Listener {
|
||||
plugin.getLang().getColored("death.announce-claimed")
|
||||
.replace("{killer}", killer.getName())
|
||||
.replace("{victim}", victim.getName())
|
||||
.replace("{bounty}", bounty.toString())
|
||||
.replace("{bounty}", String.valueOf(bounty))
|
||||
);
|
||||
}
|
||||
|
||||
// Remove bounty
|
||||
bounties.remove(victimId);
|
||||
this.plugin.getBountyDataManager().saveBountiesAsync();
|
||||
bountyDataManager.removeBounty(victimId);
|
||||
bountyDataManager.saveBountiesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,22 @@ 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
|
||||
@@ -92,4 +108,5 @@ public class BountyDataManager {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,6 +14,7 @@ softdepend:
|
||||
- Parties
|
||||
- BetterTeams
|
||||
- SimpleClans
|
||||
- Towny
|
||||
|
||||
commands:
|
||||
bounty:
|
||||
|
||||
Reference in new issue
Block a user