Advertisement
Guest User

Main file

a guest
Jul 1st, 2014
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.95 KB | None | 0 0
  1. package me.ArsenArsen.tentmod;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6. import java.util.Arrays;
  7. import java.util.logging.Logger;
  8.  
  9. import me.ArsenArsen.tentmod.Updater;
  10. import net.milkbowl.vault.economy.Economy;
  11. import net.milkbowl.vault.economy.EconomyResponse;
  12.  
  13. import org.bukkit.Bukkit;
  14. import org.bukkit.ChatColor;
  15. import org.bukkit.Material;
  16. import org.bukkit.Server;
  17. import org.bukkit.command.Command;
  18. import org.bukkit.command.CommandSender;
  19. import org.bukkit.entity.Player;
  20. import org.bukkit.event.player.PlayerInteractEvent;
  21. import org.bukkit.inventory.ItemStack;
  22. import org.bukkit.inventory.meta.ItemMeta;
  23. import org.bukkit.plugin.PluginDescriptionFile;
  24. import org.bukkit.plugin.PluginManager;
  25. import org.bukkit.plugin.RegisteredServiceProvider;
  26. import org.bukkit.plugin.java.JavaPlugin;
  27.  
  28. import com.sk89q.worldedit.CuboidClipboard;
  29. import com.sk89q.worldedit.EditSession;
  30. import com.sk89q.worldedit.MaxChangedBlocksException;
  31. import com.sk89q.worldedit.Vector;
  32. import com.sk89q.worldedit.bukkit.BukkitWorld;
  33. import com.sk89q.worldedit.data.DataException;
  34. import com.sk89q.worldedit.foundation.World;
  35.  
  36. public class Main extends JavaPlugin
  37. {
  38.    
  39.     public static RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
  40.     public ArrayList<String> lt = new ArrayList<String>();
  41.     public static Economy econ = rsp.getProvider();
  42.     public static Economy eco = null;
  43.     public static PluginManager  plmanager = Bukkit.getPluginManager();
  44.     public static boolean sucess;
  45.     public static String pp = "tentmod.";
  46.     public static boolean payment;
  47.     public static String np = ChatColor.BOLD + "[TentMod] " + ChatColor.RESET;
  48.    
  49.     public static void init() {
  50.         if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) return;
  51.         RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
  52.         econ = rsp.getProvider();
  53.     }
  54.    
  55.     public void warning(String text) {
  56.         logger.warning(text);
  57.        
  58.     }
  59.  
  60.     public void severe(String text) {
  61.         logger.severe(text);
  62.        
  63.     }
  64.    
  65.     public static boolean pay(String playername, double amount) {  
  66.         EconomyResponse r = econ.withdrawPlayer(playername, amount);
  67.         return r.transactionSuccess();
  68.            
  69.         }
  70.  
  71.    
  72.     public void onDisable()
  73.     {
  74.         PluginDescriptionFile pdfFile = getDescription();
  75.         logger.info(np + pdfFile.getName() + " Has Been Disabled");
  76.     }
  77.  
  78.     public void onEnable()
  79.     {
  80.         this.getConfig().options().copyDefaults(true);
  81.         if(tent != null ){
  82.             severe(np + "You need tent.schematic in folder TendMod to run this plugin!");
  83.         }else{
  84.             init();
  85.             PluginDescriptionFile pdfFile = getDescription();
  86.             logger.info(np + pdfFile.getName() + " V." + pdfFile.getVersion() + " Has Been Enabled");
  87.             onUpdate();
  88.         }
  89.        
  90.     }
  91.     public final Logger logger = Logger.getLogger("Minecraft");
  92.    
  93.     public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
  94.     {
  95.         String amountforpay = this.getConfig().getString("tent-price");
  96.         double amountforpayd = Double.parseDouble(amountforpay);
  97.         Player p = (Player)sender;
  98.         if (commandLabel.equalsIgnoreCase("tentmod")) {
  99.             String name = p.getName();
  100.             PluginDescriptionFile pdf = this.getDescription();
  101.             if(args.length == 0){
  102.                 sender.sendMessage(ChatColor.GOLD + "[TentMod]" + ChatColor.DARK_RED + " /tentmod [givetent <playername>|version|reload]");
  103.         }else if(args.length == 1){
  104.                 if(args[0] == "givetent"){
  105.                     if(sender instanceof Player)
  106.                     {
  107.                         if(p.hasPermission("tentmod.give")){
  108.                             if(p.hasPermission("tentmod.give.payoverride")){
  109.                                 ItemStack tent = new ItemStack(Material.getMaterial(this.getConfig().getString("tent-item")));
  110.                                 ItemMeta tm = tent.getItemMeta();
  111.                                 ArrayList<String> lt = new ArrayList<String>();
  112.                                 tm.setDisplayName(ChatColor.BOLD + "" + ChatColor.ITALIC + "" + ChatColor.UNDERLINE + "Tent");
  113.                                 lt.add(ChatColor.GOLD + "TentItem");
  114.                                 lt.add(ChatColor.UNDERLINE + "Place tent with right-click");
  115.                                 tm.setLore(lt);
  116.                                 tent.setItemMeta(tm);
  117.                                 p.getInventory().addItem(new ItemStack (tent));
  118.                             } else {
  119.                                
  120.                                 if(Bukkit.getServer().getPluginManager().isPluginEnabled("Vault")){
  121.                                     pay(name, amountforpayd);
  122.                                     ItemStack tent = new ItemStack(Material.getMaterial(this.getConfig().getString("tent-item")));
  123.                                     ItemMeta tm = tent.getItemMeta();
  124.                                     ArrayList<String> lt = new ArrayList<String>();
  125.                                     tm.setDisplayName(ChatColor.BOLD + "" + ChatColor.ITALIC + "" + ChatColor.UNDERLINE + "Tent");
  126.                                     lt.add(ChatColor.GOLD + "TentItem");
  127.                                     lt.add(ChatColor.UNDERLINE + "Place tent with right-click");
  128.                                     tm.setLore(lt);
  129.                                     tent.setItemMeta(tm);
  130.                                     p.getInventory().addItem(new ItemStack (tent));
  131.                                 } else {
  132.                                     warning("You do NOT have enabled Vault, So we cannot do payment!");
  133.                                     ItemStack tent = new ItemStack(Material.getMaterial(this.getConfig().getString("tent-item")));
  134.                                     ItemMeta tm = tent.getItemMeta();
  135.                                     ArrayList<String> lt = new ArrayList<String>();
  136.                                     tm.setDisplayName(ChatColor.BOLD + "" + ChatColor.ITALIC + "" + ChatColor.UNDERLINE + "Tent");
  137.                                     lt.add(ChatColor.GOLD + "TentItem");
  138.                                     lt.add(ChatColor.UNDERLINE + "Place tent with right-click");
  139.                                     tm.setLore(lt);
  140.                                     tent.setItemMeta(tm);
  141.                                    
  142.                                     p.getInventory().addItem(new ItemStack (tent));
  143.                                 }
  144.                             }
  145.                         }
  146.                         else{
  147.                             p.sendMessage(ChatColor.DARK_RED + "You need more perms to give tents!");
  148.                         }
  149.                        
  150.                     }
  151.                     else{
  152.                         sender.sendMessage("You must be player or add second arguement!");
  153.                         if(args.length == 2){
  154.                         ItemStack tent = new ItemStack(Material.getMaterial(this.getConfig().getString("tent-item")));
  155.                         ItemMeta tm = tent.getItemMeta();
  156.                        
  157.                         tm.setDisplayName(ChatColor.BOLD + "" + ChatColor.ITALIC + "" + ChatColor.UNDERLINE + "Tent");
  158.                         lt.add(ChatColor.GOLD + "TentItem");
  159.                         lt.add(ChatColor.UNDERLINE + "Place tent with right-click");
  160.                         tm.setLore(lt);
  161.                         tent.setItemMeta(tm);
  162.                         Player targetp = Bukkit.getServer().getPlayer(args[1]);
  163.                         if(targetp != null){
  164.                             sender.sendMessage("Player is offline!");
  165.                         }else{
  166.                             targetp.getInventory().addItem(new ItemStack (tent));
  167.                         }
  168.                         }
  169.                     }
  170.                    
  171.                 } else if(args[0] == "reload"){
  172.                     if(sender instanceof Player){
  173.                         if(sender.hasPermission("tentmod.reload")){
  174.                             this.reloadConfig();
  175.                         } else {
  176.                             sender.sendMessage(ChatColor.DARK_RED + "You do not have perm to reload TentMod!");
  177.                         }
  178.                     }else this.reloadConfig();
  179.                    
  180.                 } else if(args[0] == "version"){
  181.                     if(sender instanceof Player){
  182.                         if(sender.hasPermission("tentmod.version")){
  183.                             sender.sendMessage(ChatColor.GOLD + "[" + ChatColor.YELLOW + "TentMod" + ChatColor.GOLD + "]" + ChatColor.DARK_AQUA + " TentMod V." + pdf.getVersion() + " developed by ArsenArsen (A.k.a ArsenArsen1)");
  184.                         } else {
  185.                             sender.sendMessage(ChatColor.DARK_RED + "You do not have perm to see version of TentMod!");
  186.                         }
  187.                     }else sender.sendMessage(ChatColor.GOLD + "[" + ChatColor.YELLOW + "TentMod" + ChatColor.GOLD + "]" + ChatColor.DARK_AQUA + " TentMod V." + pdf.getVersion() + " developed by ArsenArsen (A.k.a ArsenArsen1)");
  188.                    
  189.                 }
  190.         }
  191.            
  192.         return false;
  193.     }
  194.         return true;
  195. }
  196.     public void onUpdate(){
  197.         if (getConfig().getString("updater").equals("true"))
  198.         {
  199.             if (getConfig().getString("update-type").equals("download"))
  200.             {
  201.                 Updater updater = new Updater(this, 81135, this.getFile(), Updater.UpdateType.DEFAULT, false);
  202.             }
  203.             else
  204.             {
  205.                 if (getConfig().getString("update-type").equals("no-download"))
  206.                 {
  207.                     Updater updater = new Updater(this, 81135, this.getFile(), Updater.UpdateType.NO_DOWNLOAD, false);
  208.                 }
  209.         }
  210.         }
  211.     }
  212.     public static final Vector ONE = new Vector(3, 3, 3);
  213.     public World world;
  214.     public File tent = new File(this.getDataFolder(), "tent.schematic");
  215.    
  216.     private void loadArea(World world, File file,Vector origin) throws DataException, IOException, MaxChangedBlocksException{
  217.         EditSession es = new EditSession(new BukkitWorld((org.bukkit.World) world), 999999999);
  218.         CuboidClipboard cc = CuboidClipboard.loadSchematic(file);
  219.         cc.paste(es, origin, false);
  220.    
  221.  
  222.     }
  223.     public void onPlace(PlayerInteractEvent evt) throws MaxChangedBlocksException, DataException, IOException{
  224.         if(evt.getClickedBlock() != null){
  225.             Player p = evt.getPlayer();
  226.             if(evt.getClickedBlock().getType() == Material.AIR){
  227.                 p.sendMessage(ChatColor.DARK_RED + "You cant place tent on sky!" + ChatColor.AQUA + " LOL!");
  228.                 } else if(p.getPlayer().getItemInHand().hasItemMeta() == true){
  229.                     ItemStack hand = p.getPlayer().getInventory().getItemInHand();
  230.                     ItemMeta meta = hand.getItemMeta();
  231.                     String [] lore = lt.toArray(new String[lt.size()]);
  232.                     if(meta.getLore() == Arrays.asList(lore)){
  233.                         loadArea(world, tent, ONE);
  234.                     }
  235.                 }
  236.             }
  237.     }
  238. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement