Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.zachbears27;
- import java.io.Console;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.Server;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.command.ConsoleCommandSender;
- import org.bukkit.conversations.ConversationAbandonedListener;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.entity.PlayerDeathEvent;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.plugin.java.JavaPlugin;
- import java.sql.Statement;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.UUID;
- import java.util.concurrent.TimeUnit;
- import me.zachbears27.MySQL;
- import net.md_5.bungee.api.ChatColor;
- //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
- //Plugin by A_Brave_Panda & Jamdoggy
- public class JumbleHill extends JavaPlugin implements Listener {
- HashMap<String, ItemStack[]> inventoryContents = new HashMap<String, ItemStack[]>();
- HashMap<String, ItemStack[]> inventoryArmorContents = new HashMap<String, ItemStack[]>();
- Server server = Bukkit.getServer();
- ConsoleCommandSender console = server.getConsoleSender();
- MySQL MySQLC = null;
- Connection c = null;
- String host = getConfig().getString("Hostname");
- String port = getConfig().getString("Port");
- String db = getConfig().getString("Database");
- String username = getConfig().getString("Username");
- String password = getConfig().getString("Password");
- String table = getConfig().getString("Table");
- String intro = ChatColor.GREEN + "" + ChatColor.BOLD + "Jumble Hill " + ChatColor.GRAY + "" + ChatColor.BOLD + ">> ";
- String itemtable = "items";
- @Override
- public void onDisable() {
- }
- @Override
- public void onEnable() {
- getServer().getPluginManager().registerEvents(this, this);
- registerConfig();
- MySQL MySQLC = new MySQL(host, port, db, username, password);
- try {
- c = MySQLC.openConnection();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- System.out.print("[JumbleHill] Plugin Has Been Loaded!");
- }
- public void registerConfig() {
- saveDefaultConfig();
- }
- java.util.Date dt = new java.util.Date();
- java.text.SimpleDateFormat sdf =
- new java.text.SimpleDateFormat("MM/dd/yy HH:mm:ss");
- Date now = new Date();
- SimpleDateFormat format = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- if (sender instanceof Player) {
- Player p = (Player)sender;
- if(cmd.getLabel().equalsIgnoreCase("jumblehill")) {
- if(args.length == 0) {
- p.sendMessage(intro + ChatColor.RED + " Incorrect Arguments! Please try: '/jumblehill help'");
- } else if(args[0].equals("help")) {
- p.sendMessage(intro + ChatColor.AQUA + " /jumblehill search");
- p.sendMessage(intro + ChatColor.AQUA + " /jumblehill stats");
- p.sendMessage(intro + ChatColor.AQUA + " /jumblehill set");
- p.sendMessage(intro + ChatColor.AQUA + " /jumblehill add {item name} {item amount} {item price in diamonds}");
- p.sendMessage(intro + ChatColor.AQUA + " /jumblehill remove {item name}");
- p.sendMessage(intro + ChatColor.AQUA + " /jumblehill list");
- } else if(args[0].equals("search")) {
- /* new AnvilGUI(this, p, new AnvilGUI.AnvilClickHandler() {
- @Override
- public boolean onClick(AnvilGUI menu, String text){
- menu.getPlayer().sendMessage(intro + ChatColor.GOLD + "You have chosen: " + ChatColor.AQUA + text); */
- String itemselect = "SELECT * FROM " + itemtable + " WHERE itemname = '" + args[1] +"' ORDER BY shop_id;";
- String shopselect = "";
- try {
- Statement statement = c.createStatement();
- ResultSet res2 = null;
- Statement statement2 = c.createStatement();
- ResultSet res = statement2.executeQuery(itemselect);
- int count = 0;
- int shopcount = 0;
- int lastID = 0;
- p.sendMessage("Searching for: " + args[1]);
- while(res.next()) {
- count++;
- // New Shop ID - show the name
- if (lastID != res.getInt("shop_id")) {
- lastID = res.getInt("shop_id");
- shopcount++;
- // Grab shop details
- shopselect = "SELECT * FROM " + table + " WHERE id = '" + res.getInt("shop_id") +"';";
- res2 = statement.executeQuery(shopselect);
- if(res2.next()) {
- p.sendMessage(intro + ChatColor.GOLD + "Shop: " + ChatColor.GREEN + ChatColor.BOLD + res2.getString("shopname") + ChatColor.GOLD + " at" + ChatColor.GREEN + ChatColor.BOLD + " [" + res2.getInt("x") + ", " + res2.getInt("y") + ", " + res2.getInt("z") + "]" + ChatColor.GOLD + " owned by " + ChatColor.GREEN + ChatColor.BOLD + res2.getString("owner"));
- } else {
- p.sendMessage(shopselect);
- p.sendMessage("Invalid Shop");
- }
- }
- p.sendMessage("* " + res.getInt("itemamount") + " " + res.getString("itemname") + " = " + res.getInt("itemprice") + " diamonds.");
- }
- //if it cant find a shop with it
- if (count == 0) {
- p.sendMessage("Sorry, no shops in Jumble Hill sell that item.");
- } else {
- p.sendMessage(intro + ChatColor.GREEN + "" + ChatColor.BOLD + count + ChatColor.GOLD + " Trades In Jumble Hill Have Been Found.");
- p.sendMessage(intro + ChatColor.GREEN + "" + ChatColor.BOLD + shopcount + ChatColor.GOLD + " Shops Are Selling That Item.");
- }
- }
- catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- /* return true;
- }
- }).setInputName("Enter An Item Name").open(); */
- } else if(args[0].equals("set")) {
- Location l = p.getLocation();
- double x = l.getX();
- double y = l.getY();
- double z = l.getZ();
- new AnvilGUI(this, p, new AnvilGUI.AnvilClickHandler() {
- @Override
- public boolean onClick(AnvilGUI menu, String text){
- String cleantext = text.replace("'", "").replace("Shop Name", "");
- String ShopName = "INSERT INTO "+ table + " (id, shopname, owner, x, y, z) VALUES (NULL, '" + cleantext + "', '" + p.getUniqueId() + "', '" + x + "', '" + y + "', '" + z + "');";
- String select = "SELECT * FROM " + table + " WHERE shopname = '" + cleantext +"';";
- try {
- Statement statement = c.createStatement();
- ResultSet res = statement.executeQuery(select);
- //If shop exists, update location
- if(res.next()) {
- //shop exists
- //if owner of shop equals player making shop then do it
- if(menu.getPlayer().getName().equalsIgnoreCase(res.getString("owner"))) {
- menu.getPlayer().sendMessage(intro + ChatColor.GOLD + "Your shop is called: " + ChatColor.AQUA + cleantext);
- menu.getPlayer().sendMessage(intro + ChatColor.GOLD + "Your shop is now located at: " + ChatColor.AQUA + (int)x + ", " + (int)y + ", " + (int)z);
- menu.getPlayer().sendMessage(intro + ChatColor.GOLD + "Remember, you can always use this command again to re-update your shop location!");
- menu.getPlayer().sendMessage(intro + ChatColor.GREEN + "Shop Location Updated!");
- String UpdateShopName = "UPDATE " + table + " SET shopname='" + cleantext + "', owner='" + p.getUniqueId() + "', x='" + x + "', y='" + y + "', z='" + z + "' WHERE id='" + res.getInt("id") + "';";
- statement.executeUpdate(UpdateShopName);
- } else {
- menu.getPlayer().sendMessage(intro + ChatColor.RED + "You must own " + cleantext + " to remove it!");
- }
- } else {
- //shop doesnt
- menu.getPlayer().sendMessage(intro + ChatColor.GOLD + "Your shop is called: " + ChatColor.AQUA + cleantext);
- menu.getPlayer().sendMessage(intro + ChatColor.GOLD + "Your shop is located at: " + ChatColor.AQUA + x + " " + y + " " + z);
- menu.getPlayer().sendMessage(intro + ChatColor.GOLD + "Remember, you can always use this command again to re-update your shop location!");
- statement.executeUpdate(ShopName);
- menu.getPlayer().sendMessage(intro + ChatColor.GREEN + "Shop Location Created!");
- }
- } catch (SQLException e2) {
- e2.printStackTrace();
- }
- return true;
- }
- }).setInputName("Shop Name").open();
- } else if(args[0].equals("add")) {
- if(!(args.length < 4)) {
- new AnvilGUI(this, p, new AnvilGUI.AnvilClickHandler() {
- @Override
- public boolean onClick(AnvilGUI menu, String text){
- String cleantext = text.replace("'", "").replace("Shop Name", "");
- String nameselect = "SELECT id,owner FROM " + table + " WHERE shopname = '" + cleantext +"';";
- try {
- Statement statement = c.createStatement();
- ResultSet res = statement.executeQuery(nameselect);
- if (res.next()) {
- if(p.getName().equals(res.getString("owner"))) {
- String itemselect = "SELECT * FROM " + itemtable + " WHERE shop_id = '" + res.getInt("id") +"';";
- Statement statement2 = c.createStatement();
- ResultSet res2 = statement2.executeQuery(itemselect);
- if(res2.next()) {
- if(res2.getString("itemamount").equals(args[2]) && res2.getString("itemname").equals(args[1])) {
- // This item and amount are already in the database, just update the price
- String itemupdate = "UPDATE " + itemtable + " SET itemprice='" + args[3] + "' WHERE shop_id = '" + res.getInt("id") +"';";
- p.sendMessage(itemupdate);
- Statement statement3 = c.createStatement();
- statement3.executeUpdate(itemupdate);
- p.sendMessage(intro + ChatColor.GOLD + "Price Updated: " + ChatColor.GREEN + ChatColor.BOLD + args[2] + " " + args[1] + ChatColor.GOLD + " Now Costs " + ChatColor.GREEN + ChatColor.BOLD + args[3] + ChatColor.GOLD + " Diamond(s).");
- } else {
- // Add a new price for this shop
- String iteminsert = "INSERT INTO "+ itemtable + " (id, shop_id, itemname, itemprice, itemamount) VALUES (NULL, '" + res.getInt("id") + "', '" + args[1] + "', '" + args[3] + "', '" + args[2] + "');";
- Statement statement4 = c.createStatement();
- statement4.executeUpdate(iteminsert);
- p.sendMessage(intro + ChatColor.GOLD + "Price Added: " + ChatColor.GREEN + ChatColor.BOLD + args[2] + " " + args[1] + ChatColor.GOLD + " Costs "+ ChatColor.GREEN + ChatColor.BOLD + args[3] + ChatColor.GOLD + " Diamond(s).");
- }
- } else {
- // There are no prices in the database for this shop, so let's add the first one!
- String iteminsert2 = "INSERT INTO "+ itemtable + " (id, shop_id, itemname, itemprice, itemamount) VALUES (NULL, '" + res.getInt("id") + "', '" + args[1] + "', '" + args[3] + "', '" + args[2] + "');";
- Statement statement5 = c.createStatement();
- statement5.executeUpdate(iteminsert2);
- p.sendMessage(intro + ChatColor.GOLD + "Price Added: " + ChatColor.GREEN + ChatColor.BOLD + args[2] + " " + args[1] + ChatColor.GOLD + " Costs "+ ChatColor.GREEN + ChatColor.BOLD + args[3] + ChatColor.GOLD + " Diamond(s).");
- p.sendMessage(intro + ChatColor.GREEN + "Congratulations on adding your first price to your shop!");
- }
- } else {
- // Oi! You don't own this shop, bugger off!
- p.sendMessage(intro + ChatColor.RED + "Oi! You don't own this shop, bugger off!" + ChatColor.DARK_RED + " - Jamdoggy @ 2017" );
- }
- } else {
- // Shop not found in database...?
- p.sendMessage(intro + ChatColor.RED + "That Shop Doesn't Exist!");
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return true;
- }
- }).setInputName("Shop Name").open();
- } else {
- p.sendMessage(intro + ChatColor.RED + "Incorrect Arguments! Please try: '/jumblehill add {item name} {item amount} {item price in diamonds}'");
- }
- } else if(args[0].equals("remove")) {
- if(!(args.length == 1)) {
- new AnvilGUI(this, p, new AnvilGUI.AnvilClickHandler() {
- @Override
- public boolean onClick(AnvilGUI menu, String text){
- String cleantext = text.replace("'", "").replace("Shop Name", "");
- String nameselect = "SELECT * FROM " + table + " WHERE shopname = '" + cleantext +"';";
- String itemselect = "SELECT * FROM " + itemtable + " WHERE itemname = '" + args[1] +"';";
- try {
- Statement statement = c.createStatement();
- ResultSet res = statement.executeQuery(nameselect);
- Statement statement2 = c.createStatement();
- ResultSet res2 = statement2.executeQuery(itemselect);
- if(res.next()) {
- if(res.getString("owner").equals(p.getName())) {
- if(res2.next()) {
- if(res2.getString("itemname").equals(args[1]) ) {
- String itemremove = "DELETE FROM " + itemtable + " WHERE itemname = '" + args[1] +"' and shop_id = '" + res.getInt("id") + "' LIMIT 1;";
- Statement statement3 = c.createStatement();
- statement3.executeUpdate(itemremove);
- p.sendMessage(intro + ChatColor.GREEN + "Item Sucessfully Removed!");
- }
- } else {
- p.sendMessage(intro + ChatColor.RED + "This Item Isn't In That Shop!");
- }
- } else {
- p.sendMessage(intro + ChatColor.RED + "Sorry, You Don't Own This Shop!");
- }
- } else {
- p.sendMessage(intro + ChatColor.RED + "Error! No Shop With That Name Exists!");
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return true;
- }
- }).setInputName("Shop Name").open();
- } else {
- p.sendMessage(intro + ChatColor.RED + "Incorrect Arguments! Please try: '/jumblehill remove {item name}'");
- }
- } else if(args[0].equals("list")) {
- new AnvilGUI(this, p, new AnvilGUI.AnvilClickHandler() {
- @Override
- public boolean onClick(AnvilGUI menu, String text){
- String cleantext = text.replace("'", "").replace("Shop Name", "");
- String nameselect = "SELECT * FROM " + table + " WHERE shopname = '" + cleantext +"';";
- try {
- Statement statement = c.createStatement();
- ResultSet res = statement.executeQuery(nameselect);
- if(res.next()) {
- int shop_id = res.getInt("id");
- String itemselect = "SELECT * FROM " + itemtable + " WHERE shop_id = '" + shop_id +"';";
- Statement statement2 = c.createStatement();
- ResultSet res2 = statement2.executeQuery(itemselect);
- p.sendMessage(intro + ChatColor.GREEN + "" + ChatColor.BOLD + res.getString("shopname") + ChatColor.GOLD + " Owned By: " + ChatColor.GREEN + ChatColor.BOLD + res.getString("owner") + ChatColor.GOLD + " Located At: [" + ChatColor.GREEN + ChatColor.BOLD + res.getString("x") + ", " + res.getString("y") + ", " + res.getString("z") + ChatColor.GOLD + "]");
- while(res2.next()) {
- p.sendMessage(intro + ChatColor.GRAY + " - " + ChatColor.GREEN + "" + ChatColor.BOLD + "x" + res2.getString("itemamount") + " " + res2.getString("itemname") + ChatColor.GOLD + " For " + ChatColor.GREEN + ChatColor.BOLD + res2.getString("itemprice") + ChatColor.GOLD + " Diamond(s)!");
- }
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return true;
- }
- }).setInputName("Shop Name").open();
- } else if(args[0].equals("stats")) {
- String shoplist = "SELECT * FROM " + table + ";";
- if(p.hasPermission("jumblehill.stats")) {
- try {
- Statement statement = c.createStatement();
- ResultSet res = statement.executeQuery(shoplist);
- // Go through list of shops
- while(res.next()) {
- int shop_id = res.getInt("id");
- // Output this Shop's Info
- p.sendMessage(ChatColor.GRAY + "[----------------------]");
- p.sendMessage(intro + ChatColor.GREEN + ChatColor.BOLD + res.getString("shopname") + ChatColor.GOLD + " Owned By: " + ChatColor.GREEN + ChatColor.BOLD + res.getString("owner") + ChatColor.GOLD + " Located At: [" + ChatColor.GREEN + ChatColor.BOLD + res.getString("x") + ", " + res.getString("y") + ", " + res.getString("z") + ChatColor.GOLD + "]");
- // Get the list of items in this shop
- String itemselect = "SELECT * FROM " + itemtable + " WHERE shop_id = '" + shop_id +"';";
- Statement statement2 = c.createStatement();
- ResultSet res2 = statement2.executeQuery(itemselect);
- Boolean noitems = true;
- while(res2.next()) {
- noitems = false;
- p.sendMessage(intro + ChatColor.GRAY + " - " + ChatColor.GREEN + "" + ChatColor.BOLD + "x" + res2.getString("itemamount") + " " + res2.getString("itemname") + ChatColor.GOLD + " For " + ChatColor.GREEN + ChatColor.BOLD + res2.getString("itemprice") + ChatColor.GOLD + " Diamond(s)!");
- }
- if (noitems) {
- p.sendMessage(intro + ChatColor.GRAY + " -" + ChatColor.RED + " Shop has no items!");
- }
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- } else {
- p.sendMessage(intro + ChatColor.RED + "Sorry, you do not have permission to list all shops");
- }
- }
- }
- } else {
- console.sendMessage(ChatColor.DARK_RED + "[Critical Warning]" + ChatColor.RED + " This Is For Players Only");
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement