Skip to content

Instantly share code, notes, and snippets.

@HimbeersaftLP
Last active November 18, 2016 15:57
Show Gist options
  • Save HimbeersaftLP/a0d0528c298d319cfbda73d41b026bfd to your computer and use it in GitHub Desktop.
Save HimbeersaftLP/a0d0528c298d319cfbda73d41b026bfd to your computer and use it in GitHub Desktop.
AutoMoney for EconomyAPI
name: AutoMoney
main: AutoMoney\main
version: 1.0
api: [2.1.0]
author: HimbeersaftLP
description: Give players money automatically!
# Intervall in minutes to give money
time: 5
# How many money?
money: 10
# What message to send to the player:
msg: "You got 10 money!"
<?php
namespace AutoMoney;
use pocketmine\event\Listener;
use pocketmine\plugin\PluginBase;
class Main extends PluginBase implements Listener{
public function onEnable(){
$this->saveDefaultConfig();
$server = $this->getServer();
$server->getPluginManager()->registerEvents($this, $this);
$server->getScheduler()->scheduleRepeatingTask(new MoneyTask($this, $config = $this->getConfig()->getAll()), $config["time"]*400);
}
}
<?php
namespace AutoMoney;
use pocketmine\scheduler\PluginTask;
use onebone\economyapi\EconomyAPI;
class MoneyTask extends PluginTask {
private $plugin;
public $config;
public function __construct($plugin, $config){
parent::__construct($plugin);
$this->plugin = $this->getOwner();
$this->config = $config;
}
public function onRun($currentTick){
$this->eco = EconomyAPI::getInstance();
foreach($this->plugin->getServer()->getOnlinePlayers() as $p) {
$this->eco->addMoney($p->getName(), $this->config["money"]);
$p->sendMessage($this->config["msg"]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment