mirror of
https://github.com/zontreck/AutoMoneyPlugin
synced 2025-06-18 18:03:55 +00:00
Starts implementation
This commit is contained in:
parent
f9fdbf3a2e
commit
0189460694
8 changed files with 83 additions and 2 deletions
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"java.configuration.updateBuildConfiguration": "interactive"
|
||||
}
|
|
@ -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
|
BIN
bin/main/dev/zontreck/amp/AutoMoneyPlugin$1.class
Normal file
BIN
bin/main/dev/zontreck/amp/AutoMoneyPlugin$1.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
bin/main/dev/zontreck/amp/Configuration.class
Normal file
BIN
bin/main/dev/zontreck/amp/Configuration.class
Normal file
Binary file not shown.
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
10
src/main/java/dev/zontreck/amp/Configuration.java
Normal file
10
src/main/java/dev/zontreck/amp/Configuration.java
Normal 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;
|
||||
}
|
||||
}
|
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue