Starts implementation

This commit is contained in:
zontreck 2025-03-20 12:07:04 -07:00
parent f9fdbf3a2e
commit 0189460694
8 changed files with 83 additions and 2 deletions

3
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
}

View file

@ -1 +1,5 @@
# A journey of 1,000 lines starts with a single char
# The amount of money to give out to online players
amountToGive: 0.25
# Give every <duration> seconds
duration: 60

Binary file not shown.

Binary file not shown.

View file

@ -1,6 +1,11 @@
package dev.zontreck.amp;
import io.papermc.lib.PaperLib;
import net.milkbowl.vault.economy.Economy;
import java.util.Timer;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
@ -10,11 +15,66 @@ import org.bukkit.plugin.java.JavaPlugin;
* @author Copyright (c) zontreck. Licensed under the GPLv3.
*/
public class AutoMoneyPlugin extends JavaPlugin {
Timer task = new Timer();
Economy economy = null;
@Override
public void onEnable() {
PaperLib.suggestPaper(this);
saveDefaultConfig();
reloadConfig();
// Apply configuration
Configuration.g_dPaymentAmount = getConfig().getDouble("amountToGive", 0.25);
Configuration.g_iPaymentInterval = getConfig().getInt("duration", 60);
// Setup the economy
if (!setupEconomy()) {
getLogger().severe("No economy plugin found. Disabling plugin.");
getServer().getPluginManager().disablePlugin(this);
return;
}
// Schedule the task
reschedule();
}
/**
* Sets up the vault economy.
*
* @return True if the economy was set up, false otherwise.
*/
private boolean setupEconomy() {
RegisteredServiceProvider<net.milkbowl.vault.economy.Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
if (economyProvider != null) {
economy = economyProvider.getProvider();
}
return economy != null;
}
public void reschedule() {
task.scheduleAtFixedRate(new java.util.TimerTask() {
@Override
public void run() {
if(Configuration.PaymentEnabled()) {
// Pay all online players
getServer().getOnlinePlayers().forEach(player -> {
//player.sendMessage("You have been paid " + Configuration.g_dPaymentAmount + " for being online.");
//player.giveExp((int) Configuration.g_dPaymentAmount);
});
}
}
}, 0L, Configuration.g_iPaymentInterval * 1000L);
}
@Override
public void onDisable() {
// Stop the timer task. Save configuration
saveConfig();
task.cancel();
}
}

View file

@ -0,0 +1,10 @@
package dev.zontreck.amp;
public class Configuration {
public static double g_dPaymentAmount = 0.0;
public static int g_iPaymentInterval = 0;
public static boolean PaymentEnabled() {
return g_iPaymentInterval > 0;
}
}

View file

@ -1 +1,5 @@
# A journey of 1,000 lines starts with a single char
# The amount of money to give out to online players
amountToGive: 0.25
# Give every <duration> seconds
duration: 60