Don't like ads? PRO users don't see any ads ;-)

Untitled

By: olimoli123 on May 4th, 2012  |  syntax: None  |  size: 5.66 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package com.olimoli123.icraftsmp;
  2.  
  3. import java.sql.Time;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Date;
  6. import java.util.HashSet;
  7. import java.util.logging.Level;
  8. import java.util.logging.Logger;
  9.  
  10. import net.milkbowl.vault.Vault;
  11. import net.milkbowl.vault.economy.Economy;
  12. import net.milkbowl.vault.economy.EconomyResponse;
  13. import net.minecraft.server.World;
  14.  
  15. import org.bukkit.Bukkit;
  16. import org.bukkit.Location;
  17. import org.bukkit.command.Command;
  18. import org.bukkit.command.CommandSender;
  19. import org.bukkit.entity.Player;
  20. import org.bukkit.event.EventHandler;
  21. import org.bukkit.event.block.SignChangeEvent;
  22. import org.bukkit.event.player.PlayerEvent;
  23. import org.bukkit.plugin.Plugin;
  24. import org.bukkit.plugin.RegisteredServiceProvider;
  25. import org.bukkit.plugin.java.JavaPlugin;
  26.  
  27.  
  28. public class iCraftRP extends JavaPlugin {
  29.  
  30.     final static Logger log = Logger.getLogger("Minecraft");
  31.     private Vault vault = null;
  32.     public Economy econ = null;
  33.         private MoneyPrinter moneyPrinter = null;
  34.         public configLoad loadConfig = null;
  35.     @Override
  36.         public void onEnable()
  37.     {
  38.         loadConfig = new configLoad(this);
  39.         moneyPrinter = new MoneyPrinter(this);
  40.         loadConfig.getPrintersConfig();
  41.         loadConfig.savePrintersConfig();
  42.         loadConfig.getDataConfig();
  43.         loadConfig.saveDataConfig();
  44.         getServer().getPluginManager().registerEvents(moneyPrinter, this);
  45.                    Plugin x = this.getServer().getPluginManager().getPlugin("Vault");
  46.                 if(x != null & x instanceof Vault) {
  47.                     vault = (Vault) x;
  48.                     log.info(String.format("[%s] Hooked %s %s", getDescription().getName(), vault.getDescription().getName(), vault.getDescription().getVersion()));
  49.                 } else {
  50.                     log.warning(String.format("[%s] Vault was _NOT_ found! Disabling plugin.", getDescription().getName()));
  51.                     getPluginLoader().disablePlugin(this);
  52.                     return;
  53.                 }
  54.         }
  55.         public void onDisable()
  56.         {
  57.                
  58.         }      
  59.     public boolean setupEconomy() {
  60.         if (getServer().getPluginManager().getPlugin("Vault") == null) {
  61.             return false;
  62.         }
  63.         RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
  64.         if (rsp == null) {
  65.             return false;
  66.         }
  67.         econ = rsp.getProvider();
  68.         return econ != null;
  69.     }
  70.  
  71.         public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
  72.         if(!(sender instanceof Player)) {
  73.             log.info("Only Players can Silly..");
  74.             return true;
  75.         }
  76.         Player player = (Player) sender;
  77.                 return false;
  78.         }
  79.         public void moneyAdd(int Amount)
  80.         {
  81.                 econ.depositPlayer("Player", Amount);
  82.         }
  83.        
  84.     public HashSet<Location> readLocationsByPlayerName(String player) {
  85.         HashSet<Location> result = new HashSet<Location>();
  86.  
  87.         for (String key : loadConfig.getPrintersConfig().getConfigurationSection("locations")
  88.                         .getKeys(true)) {
  89.                 if (loadConfig.getPrintersConfig().getString("locations." + key).equals(player)) {
  90.                         result.add(parseStringToLocation(key));
  91.                 }
  92.         }
  93.         return result;
  94. }
  95.  
  96. public HashSet<Location> destroyPrinter(String player){
  97.     HashSet<Location> result = new HashSet<Location>();
  98.     for (String key : loadConfig.getPrintersConfig().getConfigurationSection("locations")
  99.                     .getKeys(true)) {
  100.             if (loadConfig.getPrintersConfig().getString("locations." + key).equals(player)) {
  101.                 loadConfig.getPrintersConfig().set("locations." + key, null);
  102.                 loadConfig.savePrintersConfig();
  103.             }
  104.     }
  105.         return result;
  106. }
  107.  
  108. public String readPlayerNameByLocation(Location loc) {
  109.         return loadConfig.getPrintersConfig().getString("locations." + parseLocationToString(loc));
  110. }
  111. public void set(Player player, Location loc) {
  112.     loadConfig.getPrintersConfig().set("locations." + parseLocationToString(loc),
  113.             player.getName());
  114. loadConfig.savePrintersConfig();
  115. log.info("[Printer] Printer added to list.");
  116. }
  117. public HashSet<Location> destroy(String player) {
  118.     HashSet<Location> destroy = new HashSet<Location>();
  119.  
  120.     for (String key : loadConfig.getPrintersConfig().getConfigurationSection("locations")
  121.             .getKeys(true)) {
  122.     if (loadConfig.getPrintersConfig().getString("locations." + key).equals(player)) {
  123.         System.out.print("Key: "+key);
  124.             destroy.add(parseStringToLocation(key));
  125.             HashSet<Location> locString = destroy;
  126.             Location loc = parseStringToLocation(key);
  127.            // loc.getBlock().getWorld().dropItem(loc, null);
  128.             //loc.getBlock().getWorld().strikeLightning(loc);
  129.     }
  130.     }
  131.     return destroy;
  132. }
  133.  
  134. private String parseLocationToString(Location loc) {
  135.         // world:x,y,z
  136.         return loc.getWorld().getName() + ":" + loc.getBlockX() + ","
  137.                         + loc.getBlockY() + "," + loc.getBlockZ();
  138. }
  139.  
  140. private Location parseStringToLocation(String loc) {
  141.     // world:x,y,
  142.             System.out.print("In: "+loc);
  143.     String[] world = loc.split(":");
  144.     System.out.print(world.length);
  145.     for (String x:world){
  146.             System.out.print("Section: "+x);
  147.     }
  148.     String[] coords = world[1].split(",");
  149.     for (String x:coords){
  150.             System.out.print("Section1: "+x);
  151.     }
  152.    
  153.     /*for(x=0;i<world.length;i++){
  154.         System.out.print(world[x]);
  155.     }*/
  156.     return new Location(getServer().getWorld(world[0]),
  157.                     Integer.parseInt(coords[0]), Integer.parseInt(coords[1]),
  158.                     Integer.parseInt(coords[2]));
  159.     }
  160. }