package me.xastraah.welcomemoney; import java.util.ArrayList; import java.util.List; import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.EconomyResponse; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; public class WelcomeMoney extends JavaPlugin implements Listener { List ps = new ArrayList(); List sd = new ArrayList(); public static Economy econ = null; public void onEnable() { saveDefaultConfig(); Bukkit.getServer().getPluginManager().registerEvents(this, this); if (!setupEconomy() ) { getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName())); getServer().getPluginManager().disablePlugin(this); return; } } public void onDisable() { saveConfig(); } @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { final Player p = event.getPlayer(); if(p.hasPlayedBefore()) { return; } ps.add(p.getName()); Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { public void run() { ps.remove(p.getName()); } }, 140L); } @EventHandler public void onPlayerChat(AsyncPlayerChatEvent event) { final Player p = event.getPlayer(); if(event.getMessage().contains("Welcome") || event.getMessage().contains("welcome") && ps.isEmpty() == false) { if(sd.contains(p.getName())) { return; } sd.add(p.getName()); Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { public void run() { sd.remove(p.getName()); } }, 140L); if(!(getConfig().contains("Deposit"))) { getConfig().set("Deposit", 75); saveConfig(); } @SuppressWarnings("deprecation") EconomyResponse r = econ.depositPlayer(p.getName(), getConfig().getInt("Deposit")); if(r.transactionSuccess()) { Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { public void run() { p.sendMessage(ChatColor.GREEN + "You have recieved $" + getConfig().getInt("Deposit") + "!"); } }, 20L); } else { Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { public void run() { p.sendMessage(ChatColor.RED + "An error has occured please contact the developer!"); } }, 20L); } } } private boolean setupEconomy() { RegisteredServiceProvider economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); if(economyProvider != null) { econ = economyProvider.getProvider(); } return (econ != null); } }