1.1.1 - Added a sell multiplier feature!
This commit is contained in:
parent
b1d829a132
commit
908149c5ec
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>me.NVus</groupId>
|
||||
<artifactId>NVus_Prison</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<version>1.1.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>NVus_PrisonSetup</name>
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package me.nvus.nvus_prison_setup.AutoSell;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class EconomyHandler {
|
||||
|
||||
private Economy economy;
|
||||
private MultiplierManager multiplierManager;
|
||||
|
||||
public EconomyHandler(Economy economy, MultiplierManager multiplierManager) {
|
||||
this.economy = economy;
|
||||
this.multiplierManager = multiplierManager;
|
||||
}
|
||||
|
||||
public void giveMoney(Player player, double amount) {
|
||||
double multiplier = multiplierManager.getPlayerMultiplier(player.getUniqueId());
|
||||
economy.depositPlayer(player, amount * multiplier);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
package me.nvus.nvus_prison_setup.AutoSell;
|
||||
import me.nvus.nvus_prison_setup.PrisonSetup;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MultiplierManager implements CommandExecutor {
|
||||
|
||||
private final PrisonSetup plugin;
|
||||
private final Map<UUID, Double> multipliers = new HashMap<>();
|
||||
|
||||
// Store the scheduled tasks for removing multipliers
|
||||
private final Map<UUID, BukkitTask> removalTasks = new HashMap<>();
|
||||
|
||||
public MultiplierManager(PrisonSetup plugin) {
|
||||
this.plugin = plugin; // Store the passed plugin instance for later use
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!sender.hasPermission("multiplier.use")) {
|
||||
sender.sendMessage("You don't have permission to use this command.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length != 3) {
|
||||
sender.sendMessage("Usage: /multiplier <player> <multiplier> <duration in minutes>");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
if (target == null) {
|
||||
sender.sendMessage("Player not found.");
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
double multiplier = Double.parseDouble(args[1]);
|
||||
int duration = Integer.parseInt(args[2].replace("m", ""));
|
||||
applyMultiplier(target, multiplier, duration);
|
||||
sender.sendMessage("Applied a " + multiplier + "x multiplier to " + target.getName() + " for " + duration + " minutes.");
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendMessage("Invalid number format.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void applyMultiplier(Player player, double multiplier, int duration) {
|
||||
UUID playerId = player.getUniqueId();
|
||||
// Cancel any existing removal task
|
||||
if (removalTasks.containsKey(playerId)) {
|
||||
removalTasks.get(playerId).cancel();
|
||||
removalTasks.remove(playerId);
|
||||
}
|
||||
|
||||
// Apply the new multiplier
|
||||
multipliers.put(playerId, multiplier);
|
||||
|
||||
// Schedule a new removal task
|
||||
BukkitTask task = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
multipliers.remove(playerId);
|
||||
removalTasks.remove(playerId);
|
||||
player.sendMessage("Your selling multiplier has expired.");
|
||||
}
|
||||
}.runTaskLater(plugin, duration * 60 * 20); // Convert minutes to ticks
|
||||
|
||||
// Store the task for potential cancellation
|
||||
removalTasks.put(playerId, task);
|
||||
|
||||
player.sendMessage("Applied a " + multiplier + "x multiplier to you for " + duration + " minutes.");
|
||||
}
|
||||
|
||||
public double getPlayerMultiplier(UUID playerUuid) {
|
||||
return multipliers.getOrDefault(playerUuid, 1.0); // Default to 1.0, meaning no multiplier
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package me.nvus.nvus_prison_setup.AutoSell;
|
|||
|
||||
import me.nvus.nvus_prison_setup.Configs.ConfigManager;
|
||||
import me.nvus.nvus_prison_setup.PrisonSetup;
|
||||
import me.nvus.nvus_prison_setup.AutoSell.MultiplierManager;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
|
@ -18,24 +19,46 @@ import java.io.IOException;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
public class SellManager implements CommandExecutor {
|
||||
|
||||
private final HashMap<UUID, Boolean> autoSellStatus = new HashMap<>();
|
||||
private final HashMap<Material, Double> prices = new HashMap<>();
|
||||
private final ConfigManager configManager;
|
||||
|
||||
public SellManager(ConfigManager configManager) {
|
||||
private final Map<UUID, MultiplierInfo> playerMultipliers = new ConcurrentHashMap<>();
|
||||
private final ConfigManager configManager;
|
||||
private final MultiplierManager multiplierManager;
|
||||
|
||||
public SellManager(ConfigManager configManager, MultiplierManager multiplierManager) {
|
||||
this.configManager = configManager;
|
||||
this.multiplierManager = multiplierManager;
|
||||
loadPrices();
|
||||
}
|
||||
|
||||
private static class MultiplierInfo {
|
||||
double multiplier;
|
||||
LocalDateTime expiryTime;
|
||||
|
||||
MultiplierInfo(double multiplier, int durationMinutes) {
|
||||
this.multiplier = multiplier;
|
||||
this.expiryTime = LocalDateTime.now().plusMinutes(durationMinutes);
|
||||
}
|
||||
|
||||
boolean isExpired() {
|
||||
return LocalDateTime.now().isAfter(expiryTime);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("Only players can use this command.");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Player player = (Player) sender;
|
||||
|
||||
// Admin Commands:
|
||||
|
@ -170,11 +193,20 @@ public class SellManager implements CommandExecutor {
|
|||
|
||||
private void giveMoney(Player player, Material material, int quantity, double amount) {
|
||||
Economy economy = PrisonSetup.getEconomy();
|
||||
economy.depositPlayer(player, amount);
|
||||
double multiplier = multiplierManager.getPlayerMultiplier(player.getUniqueId());
|
||||
double finalAmount = amount * multiplier; // Apply the multiplier
|
||||
economy.depositPlayer(player, finalAmount);
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||
String.format("&a&lSold &d%dx &3%s &a&lfor $%.2f", quantity, material.toString().toLowerCase().replaceAll("_", " "), amount)));
|
||||
String.format("&a&lSold &d%dx &3%s &a&lfor $%.2f", quantity, material.toString().toLowerCase().replaceAll("_", " "), finalAmount)));
|
||||
}
|
||||
|
||||
// private void giveMoney(Player player, Material material, int quantity, double amount) {
|
||||
// Economy economy = PrisonSetup.getEconomy();
|
||||
// economy.depositPlayer(player, amount);
|
||||
// player.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||
// String.format("&a&lSold &d%dx &3%s &a&lfor $%.2f", quantity, material.toString().toLowerCase().replaceAll("_", " "), amount)));
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// public void sellItems(Player player) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package me.nvus.nvus_prison_setup;
|
||||
|
||||
import me.nvus.nvus_prison_setup.AutoSell.MultiplierManager;
|
||||
import me.nvus.nvus_prison_setup.Configs.ConfigManager;
|
||||
import me.nvus.nvus_prison_setup.Kit.KitManager;
|
||||
import me.nvus.nvus_prison_setup.Configs.SettingsMenu;
|
||||
|
@ -48,7 +49,9 @@ import java.sql.Statement;
|
|||
|
||||
public final class PrisonSetup extends JavaPlugin {
|
||||
|
||||
private static PrisonSetup instance;
|
||||
private ConfigManager configManager;
|
||||
private MultiplierManager multiplierManager;
|
||||
private DatabaseManager dbManager;
|
||||
private GangManager gangManager;
|
||||
|
||||
|
@ -121,9 +124,17 @@ public final class PrisonSetup extends JavaPlugin {
|
|||
// Register the Auto Sell and Sell All Listeners
|
||||
boolean autoSellEnabled = configManager.getConfig("config.yml").getBoolean("AutoSell", true);
|
||||
boolean sellAllEnabled = configManager.getConfig("config.yml").getBoolean("SellAll", true);
|
||||
SellManager sellManager = new SellManager(configManager);
|
||||
boolean sellMultiplierEnabled = configManager.getConfig("config.yml").getBoolean("SellMultiplier", true);
|
||||
|
||||
MultiplierManager multiplierManager = new MultiplierManager(this);
|
||||
SellManager sellManager = new SellManager(configManager,multiplierManager);
|
||||
this.getCommand("multiplier").setExecutor(multiplierManager);
|
||||
this.getCommand("setprice").setExecutor(sellManager);
|
||||
|
||||
// if (sellMultiplierEnabled) {
|
||||
// this.getCommand("multiplier").setExecutor(new MultiplierManager(this));
|
||||
// }
|
||||
|
||||
// If they are true, register the commands.
|
||||
if (autoSellEnabled) {
|
||||
// Register the autosell command.
|
||||
|
@ -264,4 +275,8 @@ public final class PrisonSetup extends JavaPlugin {
|
|||
public GangManager getGangManager() {
|
||||
return gangManager;
|
||||
}
|
||||
|
||||
public static PrisonSetup getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,11 @@ SellAll: true
|
|||
# You can see material prices in the item_pricing.yml file or in-game using /sellprice <price> with an item in your hand.
|
||||
# Only players/prisoners with the permission nvus.prisoner can use the /sellprice command and autosell toggle.
|
||||
|
||||
# Should we allow the use of multipliers for selling items? ie 1.5x, 2x etc.
|
||||
# These are admin commands that can be used by admins or other plugins like InfiniteVouchers etc. to give players a selling
|
||||
# multiplier for a set amount of time. | /multiplier <player> 1.5 15m
|
||||
SellMultiplier: True
|
||||
|
||||
########################################################################################
|
||||
# ARMOR SETTINGS #
|
||||
########################################################################################
|
||||
|
|
|
@ -59,6 +59,9 @@ commands:
|
|||
usage: |
|
||||
/autosell - Toggle auto selling all eligible items in your inventory.
|
||||
aliases: [ automaticsell ]
|
||||
multiplier:
|
||||
description: Apply a selling multiplier to a player.
|
||||
usage: /multiplier <player> <multiplier> <duration>
|
||||
setprice:
|
||||
description: Set the price of the block being held in item_prices.yml. Set the price to 0 to remove it from the list!
|
||||
usage: |
|
||||
|
|
Loading…
Reference in New Issue