Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.60 KB | None | 0 0
  1. package me.zachbears27;
  2. import java.io.Console;
  3. import java.sql.Connection;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.Location;
  8. import org.bukkit.Server;
  9. import org.bukkit.command.Command;
  10. import org.bukkit.command.CommandSender;
  11. import org.bukkit.command.ConsoleCommandSender;
  12. import org.bukkit.conversations.ConversationAbandonedListener;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.event.EventHandler;
  15. import org.bukkit.event.Listener;
  16. import org.bukkit.event.entity.PlayerDeathEvent;
  17. import org.bukkit.inventory.ItemStack;
  18. import org.bukkit.plugin.java.JavaPlugin;
  19. import java.sql.Statement;
  20. import java.text.ParseException;
  21. import java.text.SimpleDateFormat;
  22. import java.util.Date;
  23. import java.util.HashMap;
  24. import java.util.concurrent.TimeUnit;
  25.  
  26. import me.zachbears27.MySQL;
  27. import net.md_5.bungee.api.ChatColor;
  28.  
  29. //This Plugin Is Made For MumboCraft & It's Players & Staff.. Any misuse or re-distribution of this plugin will call for said plugin to be removed
  30. //Plugin by A_Brave_Panda & Jamdoggy
  31.  
  32. public class JumbleHill extends JavaPlugin implements Listener {
  33.    
  34.       HashMap<String, ItemStack[]> inventoryContents = new HashMap<String, ItemStack[]>();
  35.       HashMap<String, ItemStack[]> inventoryArmorContents = new HashMap<String, ItemStack[]>();
  36.       Server server = Bukkit.getServer();
  37.       ConsoleCommandSender console = server.getConsoleSender();
  38.  
  39. MySQL MySQLC = null;
  40. Connection c = null;
  41.  
  42. String host = getConfig().getString("Hostname");
  43. String port = getConfig().getString("Port");
  44. String db = getConfig().getString("Database");
  45. String username = getConfig().getString("Username");
  46. String password = getConfig().getString("Password");
  47. String table = getConfig().getString("Table");
  48. String intro = ChatColor.GREEN + "" + ChatColor.BOLD + "Jumble Hill " + ChatColor.GRAY + "" + ChatColor.BOLD + ">> ";
  49. String itemtable = "items";
  50.            
  51.  
  52.  @Override
  53.  public void onDisable() {
  54.  
  55.  }
  56.  
  57.  @Override
  58.  public void onEnable() {
  59.       getServer().getPluginManager().registerEvents(this, this);
  60.       registerConfig();
  61.       MySQL MySQLC = new MySQL(host, port, db, username, password);
  62.   try {
  63.     c = MySQLC.openConnection();
  64. } catch (ClassNotFoundException e) {
  65.     e.printStackTrace();
  66. } catch (SQLException e) {
  67.  
  68.     e.printStackTrace();
  69. }
  70.  
  71. System.out.print("[JumbleHill] Plugin Has Been Loaded!");
  72.  
  73. }
  74.  
  75.  public void registerConfig() {
  76.     saveDefaultConfig();
  77.    
  78.    
  79.    
  80.        
  81.     }
  82.  
  83.  
  84.  java.util.Date dt = new java.util.Date();
  85.  
  86.  java.text.SimpleDateFormat sdf =
  87.       new java.text.SimpleDateFormat("MM/dd/yy HH:mm:ss");
  88.     Date now = new Date();
  89.      SimpleDateFormat format = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
  90.  
  91.  
  92.   public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  93.     if (sender instanceof Player) {
  94.         Player p = (Player)sender;
  95.  if(cmd.getLabel().equalsIgnoreCase("jumblehill")) {
  96.       if(args.length == 0) {
  97.           p.sendMessage(intro + ChatColor.RED + " Incorrect Arguments! Please try: '/jumblehill help'");
  98.       } else if(args[0].equals("help")) {
  99.           p.sendMessage(intro + ChatColor.AQUA + " /jumblehill search");
  100.           p.sendMessage(intro + ChatColor.AQUA + " /jumblehill stats");
  101.           p.sendMessage(intro + ChatColor.AQUA + " /jumblehill set");
  102.           p.sendMessage(intro + ChatColor.AQUA + " /jumblehill add {item name} {item amount} {item price in diamonds}");
  103.       } else if(args[0].equals("search")) {
  104.          
  105.         /*   new AnvilGUI(this, p, new AnvilGUI.AnvilClickHandler() {
  106.                  @Override
  107.                  public boolean onClick(AnvilGUI menu, String text){
  108.                      menu.getPlayer().sendMessage(intro + ChatColor.GOLD + "You have chosen: " + ChatColor.AQUA + text);
  109.                  String select = "SELECT * FROM " + table + " WHERE shopname = '" + text.replace("'", "").replace("Shop Name", "") +"';";
  110.                      try {
  111.                     Statement statement = c.createStatement();
  112.                     ResultSet res = statement.executeQuery(select);
  113.                     if(res.next()) {
  114.                         //If shop exists, update location
  115.                         menu.getPlayer().sendMessage(intro + ChatColor.GREEN + "Shop Location Updated!");
  116.                         String UpdateShopName = "UPDATE " + table + " SET shopname='" + text.replace("'", "").replace("Shop Name", "") + "', owner='" + p.getName() + "', x='" + x + "', y='" + y + "', z='" + z + "' WHERE id='" + res.getInt("id") + "';";
  117.                         statement.executeUpdate(UpdateShopName);
  118.                         } else {
  119.                             //if it doesnt, create it
  120.                             statement.executeUpdate(ShopName);
  121.                         }
  122.                 } catch (SQLException e2) {                
  123.                     e2.printStackTrace();
  124.                 }
  125.  
  126.                      return true;
  127.  
  128.                  
  129.                      
  130.                  }
  131.              }).setInputName("Enter An Item Name").open(); */
  132.       } else if(args[0].equals("set")) {
  133.  
  134.              Location l = p.getLocation();
  135.              double x = l.getX();
  136.              double y = l.getY();
  137.              double z = l.getZ();
  138.          
  139.              new AnvilGUI(this, p, new AnvilGUI.AnvilClickHandler() {
  140.                  @Override
  141.                  public boolean onClick(AnvilGUI menu, String text){
  142.                      String cleantext = text.replace("'", "").replace("Shop Name", "");
  143.                      String ShopName = "INSERT INTO "+ table + " (id, shopname, owner, x, y, z) VALUES (NULL, '" + cleantext + "', '" + p.getName() + "', '" + x + "', '" + y + "', '" + z + "');";
  144.                      String select = "SELECT * FROM " + table + " WHERE shopname = '" + cleantext +"';";
  145.                      try {
  146.                     Statement statement = c.createStatement();
  147.                     ResultSet res = statement.executeQuery(select);
  148.                 //If shop exists, update location
  149.                     if(res.next()) {
  150.                         //shop exists
  151.                         //if owner of shop equals player making shop then do it
  152.                         if(menu.getPlayer().getName().equalsIgnoreCase(res.getString("owner"))) {
  153.                             menu.getPlayer().sendMessage(intro + ChatColor.GOLD + "Your shop is called: " + ChatColor.AQUA + cleantext);
  154.                              menu.getPlayer().sendMessage(intro + ChatColor.GOLD + "Your shop is now located at: " + ChatColor.AQUA + x + " " + y + " " + z);
  155.                              menu.getPlayer().sendMessage(intro + ChatColor.GOLD + "Remember, you can always use this command again to re-update your shop location!");
  156.                         menu.getPlayer().sendMessage(intro + ChatColor.GREEN + "Shop Location Updated!");
  157.                         String UpdateShopName = "UPDATE " + table + " SET shopname='" + cleantext + "', owner='" + p.getName() + "', x='" + x + "', y='" + y + "', z='" + z + "' WHERE id='" + res.getInt("id") + "';";
  158.                         statement.executeUpdate(UpdateShopName);
  159.                         } else {
  160.                             menu.getPlayer().sendMessage(intro + ChatColor.RED + "You must own " + cleantext + " to remove it!");
  161.                         }
  162.                         } else {
  163.                             //shop doesnt
  164.                              menu.getPlayer().sendMessage(intro + ChatColor.GOLD + "Your shop is called: " + ChatColor.AQUA + cleantext);
  165.                              menu.getPlayer().sendMessage(intro + ChatColor.GOLD + "Your shop is located at: " + ChatColor.AQUA + x + " " + y + " " + z);
  166.                              menu.getPlayer().sendMessage(intro + ChatColor.GOLD + "Remember, you can always use this command again to re-update your shop location!");
  167.                             statement.executeUpdate(ShopName);
  168.                             menu.getPlayer().sendMessage(intro + ChatColor.GREEN + "Shop Location Created!");
  169.                         }
  170.                 } catch (SQLException e2) {                
  171.                     e2.printStackTrace();
  172.                 }
  173.  
  174.                      return true;
  175.  
  176.                  }
  177.              }).setInputName("Shop Name").open();
  178.                  
  179.                
  180.       } else if(args[0].equals("add")) {
  181.           if(!(args.length < 4)) {
  182.  
  183.              new AnvilGUI(this, p, new AnvilGUI.AnvilClickHandler() {
  184.                  @Override
  185.                  public boolean onClick(AnvilGUI menu, String text){
  186.                      String cleantext = text.replace("'", "").replace("Shop Name", "");
  187.                      String ShopName = "INSERT INTO "+ itemtable + " (id, shopname, itemname, itemprice, itemamount) VALUES (NULL, '" + cleantext + "', '" + args[1] + "', '" + args[3] + "', '" + args[2] + "');";
  188.                      String itemselect = "SELECT * FROM " + itemtable + " WHERE shopname = '" + cleantext +"';";
  189.                      String nameselect = "SELECT * FROM " + table + " WHERE shopname = '" + cleantext +"';";       
  190.                      
  191.                      p.sendMessage(nameselect + " ");
  192.                      return true;
  193.  
  194.                  }
  195.              }).setInputName("Shop Name").open();
  196.           } else {
  197.               p.sendMessage(intro + ChatColor.RED + "Incorrect Arguments! Please try: '/jumblehill add {item name} {item amount} {item price in diamonds}'");
  198.           }
  199.                
  200.       }
  201.  }
  202.  } else {
  203.      console.sendMessage(ChatColor.DARK_RED + "[Critical Warning]" + ChatColor.RED + " This Is For Players Only");
  204.  }
  205.     return true;
  206.   }
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement