· 9 years ago · Mar 25, 2017, 02:48 AM
1package me.zachbears27;
2import java.io.Console;
3import java.sql.Connection;
4import java.sql.ResultSet;
5import java.sql.SQLException;
6import org.bukkit.Bukkit;
7import org.bukkit.Location;
8import org.bukkit.Server;
9import org.bukkit.command.Command;
10import org.bukkit.command.CommandSender;
11import org.bukkit.command.ConsoleCommandSender;
12import org.bukkit.conversations.ConversationAbandonedListener;
13import org.bukkit.entity.Player;
14import org.bukkit.event.EventHandler;
15import org.bukkit.event.Listener;
16import org.bukkit.event.entity.PlayerDeathEvent;
17import org.bukkit.inventory.ItemStack;
18import org.bukkit.plugin.java.JavaPlugin;
19import java.sql.Statement;
20import java.text.ParseException;
21import java.text.SimpleDateFormat;
22import java.util.Date;
23import java.util.HashMap;
24import java.util.concurrent.TimeUnit;
25
26import me.zachbears27.MySQL;
27import 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
32public 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
39MySQL MySQLC = null;
40Connection c = null;
41
42String host = getConfig().getString("Hostname");
43String port = getConfig().getString("Port");
44String db = getConfig().getString("Database");
45String username = getConfig().getString("Username");
46String password = getConfig().getString("Password");
47String table = getConfig().getString("Table");
48String intro = ChatColor.GREEN + "" + ChatColor.BOLD + "Jumble Hill " + ChatColor.GRAY + "" + ChatColor.BOLD + ">> ";
49String 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
71System.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 nameselect = "SELECT id,owner FROM " + table + " WHERE shopname = '" + cleantext +"';";
188
189 p.sendMessage(nameselect + " ");
190
191 try {
192 Statement statement = c.createStatement();
193 ResultSet res = statement.executeQuery(nameselect);
194 if (res.next()) {
195 if(p.getName().equals(res.getString("owner"))) {
196 String itemselect = "SELECT * FROM " + itemtable + " WHERE shop_id = '" + res.getInt("id") +"';";
197 Statement statement2 = c.createStatement();
198 ResultSet res2 = statement2.executeQuery(itemselect);
199 if(res2.next()) {
200 if(res2.getString("itemamount").equals(args[2]) && res2.getString("itemname").equals(args[1])) {
201 // This item and amount are already in the database, just update the price
202 String itemupdate = "UPDATE " + itemtable + " SET (itemprice='" + args[3] + "') WHERE shop_id = '" + res.getInt("id") +"';";
203 Statement statement3 = c.createStatement();
204 statement3.executeUpdate(itemupdate);
205 p.sendMessage("Price Updated: " + args[2] + " " + args[1] + " now costs " + args[3] + "diamonds.");
206 } else {
207 // Add a new price for this shop
208 String iteminsert = "INSERT INTO "+ itemtable + " (id, shop_id, itemname, itemprice, itemamount) VALUES (NULL, '" + res.getInt("id") + "', '" + args[1] + "', '" + args[3] + "', '" + args[2] + "');";
209 Statement statement4 = c.createStatement();
210 statement4.executeUpdate(iteminsert);
211 p.sendMessage("Price Added: " + args[2] + " " + args[1] + " costs " + args[3] + "diamonds.");
212 }
213 } else {
214 p.sendMessage("Fuck");
215 }
216 } else {
217 // Oi! You don't own this shop, bugger off!
218 p.sendMessage("No Owner");
219 p.sendMessage(p.getName());
220 p.sendMessage(res.getString("owner"));
221 }
222 } else {
223 // Shop not found in database...?
224 p.sendMessage("Not Found");
225 }
226 } catch (SQLException e) {
227 // TODO Auto-generated catch block
228 e.printStackTrace();
229 }
230
231
232 return true;
233
234 }
235 }).setInputName("Shop Name").open();
236 } else {
237 p.sendMessage(intro + ChatColor.RED + "Incorrect Arguments! Please try: '/jumblehill add {item name} {item amount} {item price in diamonds}'");
238 }
239
240 }
241 }
242 } else {
243 console.sendMessage(ChatColor.DARK_RED + "[Critical Warning]" + ChatColor.RED + " This Is For Players Only");
244 }
245 return true;
246 }
247}