olimoli123

Untitled

May 4th, 2012
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.50 KB | None | 0 0
  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. destroy.add(parseStringToLocation(key));
  124. HashSet<Location> locString = destroy;
  125. Location loc = parseStringToLocation(locString.toString());
  126. loc.getBlock().getWorld().dropItem(loc, null);
  127. loc.getBlock().getWorld().strikeLightning(loc);
  128. }
  129. }
  130. return destroy;
  131. }
  132.  
  133. private String parseLocationToString(Location loc) {
  134. // world:x,y,z
  135. return loc.getWorld().getName() + ":" + loc.getBlockX() + ","
  136. + loc.getBlockY() + "," + loc.getBlockZ();
  137. }
  138.  
  139. private Location parseStringToLocation(String loc) {
  140. // world:x,y,
  141. String[] world = loc.split(":");
  142. System.out.print(world.length);
  143. String[] coords = world[1].split(",");
  144. int x;
  145. int i = 0;
  146.  
  147. for(x=0;i<world.length;i++){
  148. System.out.print(world[x]);
  149. }
  150. return new Location(Bukkit.getWorld(world[0]),
  151. Integer.parseInt(coords[0]), Integer.parseInt(coords[1]),
  152. Integer.parseInt(coords[2]));
  153. }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment