- package com.olimoli123.icraftsmp;
- import java.sql.Time;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.HashSet;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import net.milkbowl.vault.Vault;
- import net.milkbowl.vault.economy.Economy;
- import net.milkbowl.vault.economy.EconomyResponse;
- import net.minecraft.server.World;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.block.SignChangeEvent;
- import org.bukkit.event.player.PlayerEvent;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.plugin.RegisteredServiceProvider;
- import org.bukkit.plugin.java.JavaPlugin;
- public class iCraftRP extends JavaPlugin {
- final static Logger log = Logger.getLogger("Minecraft");
- private Vault vault = null;
- public Economy econ = null;
- private MoneyPrinter moneyPrinter = null;
- public configLoad loadConfig = null;
- @Override
- public void onEnable()
- {
- loadConfig = new configLoad(this);
- moneyPrinter = new MoneyPrinter(this);
- loadConfig.getPrintersConfig();
- loadConfig.savePrintersConfig();
- loadConfig.getDataConfig();
- loadConfig.saveDataConfig();
- getServer().getPluginManager().registerEvents(moneyPrinter, this);
- Plugin x = this.getServer().getPluginManager().getPlugin("Vault");
- if(x != null & x instanceof Vault) {
- vault = (Vault) x;
- log.info(String.format("[%s] Hooked %s %s", getDescription().getName(), vault.getDescription().getName(), vault.getDescription().getVersion()));
- } else {
- log.warning(String.format("[%s] Vault was _NOT_ found! Disabling plugin.", getDescription().getName()));
- getPluginLoader().disablePlugin(this);
- return;
- }
- }
- public void onDisable()
- {
- }
- public boolean setupEconomy() {
- if (getServer().getPluginManager().getPlugin("Vault") == null) {
- return false;
- }
- RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
- if (rsp == null) {
- return false;
- }
- econ = rsp.getProvider();
- return econ != null;
- }
- public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
- if(!(sender instanceof Player)) {
- log.info("Only Players can Silly..");
- return true;
- }
- Player player = (Player) sender;
- return false;
- }
- public void moneyAdd(int Amount)
- {
- econ.depositPlayer("Player", Amount);
- }
- public HashSet<Location> readLocationsByPlayerName(String player) {
- HashSet<Location> result = new HashSet<Location>();
- for (String key : loadConfig.getPrintersConfig().getConfigurationSection("locations")
- .getKeys(true)) {
- if (loadConfig.getPrintersConfig().getString("locations." + key).equals(player)) {
- result.add(parseStringToLocation(key));
- }
- }
- return result;
- }
- public HashSet<Location> destroyPrinter(String player){
- HashSet<Location> result = new HashSet<Location>();
- for (String key : loadConfig.getPrintersConfig().getConfigurationSection("locations")
- .getKeys(true)) {
- if (loadConfig.getPrintersConfig().getString("locations." + key).equals(player)) {
- loadConfig.getPrintersConfig().set("locations." + key, null);
- loadConfig.savePrintersConfig();
- }
- }
- return result;
- }
- public String readPlayerNameByLocation(Location loc) {
- return loadConfig.getPrintersConfig().getString("locations." + parseLocationToString(loc));
- }
- public void set(Player player, Location loc) {
- loadConfig.getPrintersConfig().set("locations." + parseLocationToString(loc),
- player.getName());
- loadConfig.savePrintersConfig();
- log.info("[Printer] Printer added to list.");
- }
- public HashSet<Location> destroy(String player) {
- HashSet<Location> destroy = new HashSet<Location>();
- for (String key : loadConfig.getPrintersConfig().getConfigurationSection("locations")
- .getKeys(true)) {
- if (loadConfig.getPrintersConfig().getString("locations." + key).equals(player)) {
- System.out.print("Key: "+key);
- destroy.add(parseStringToLocation(key));
- HashSet<Location> locString = destroy;
- Location loc = parseStringToLocation(key);
- // loc.getBlock().getWorld().dropItem(loc, null);
- //loc.getBlock().getWorld().strikeLightning(loc);
- }
- }
- return destroy;
- }
- private String parseLocationToString(Location loc) {
- // world:x,y,z
- return loc.getWorld().getName() + ":" + loc.getBlockX() + ","
- + loc.getBlockY() + "," + loc.getBlockZ();
- }
- private Location parseStringToLocation(String loc) {
- // world:x,y,
- System.out.print("In: "+loc);
- String[] world = loc.split(":");
- System.out.print(world.length);
- for (String x:world){
- System.out.print("Section: "+x);
- }
- String[] coords = world[1].split(",");
- for (String x:coords){
- System.out.print("Section1: "+x);
- }
- /*for(x=0;i<world.length;i++){
- System.out.print(world[x]);
- }*/
- return new Location(getServer().getWorld(world[0]),
- Integer.parseInt(coords[0]), Integer.parseInt(coords[1]),
- Integer.parseInt(coords[2]));
- }
- }

