Advertisement
Guest User

Untitled

a guest
Mar 19th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.52 KB | None | 0 0
  1. package me.zachbears27;
  2. import java.sql.Connection;
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.Location;
  7. import org.bukkit.command.Command;
  8. import org.bukkit.command.CommandSender;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.event.EventHandler;
  11. import org.bukkit.event.Listener;
  12. import org.bukkit.event.entity.PlayerDeathEvent;
  13. import org.bukkit.inventory.ItemStack;
  14. import org.bukkit.plugin.java.JavaPlugin;
  15. import java.sql.Statement;
  16. import java.util.HashMap;
  17.  
  18. import me.zachbears27.MySQL;
  19. import net.md_5.bungee.api.ChatColor;
  20.  
  21. //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
  22. //Plugin by A_Brave_Panda & Jamdoggy
  23.  
  24. public class DeathLocation extends JavaPlugin implements Listener {
  25.  
  26. HashMap<String, ItemStack[]> inventoryContents = new HashMap<String, ItemStack[]>();
  27. HashMap<String, ItemStack[]> inventoryArmorContents = new HashMap<String, ItemStack[]>();
  28.  
  29. MySQL MySQLC = null;
  30. Connection c = null;
  31.  
  32. String host = getConfig().getString("Hostname");
  33. String port = getConfig().getString("Port");
  34. String db = getConfig().getString("Database");
  35. String username = getConfig().getString("Username");
  36. String password = getConfig().getString("Password");
  37. String table = getConfig().getString("Table");
  38.  
  39.  
  40. @Override
  41. public void onDisable() {
  42.  
  43. }
  44.  
  45. @Override
  46. public void onEnable() {
  47. getServer().getPluginManager().registerEvents(this, this);
  48. registerConfig();
  49. MySQL MySQLC = new MySQL(host, port, db, username, password);
  50. try {
  51. c = MySQLC.openConnection();
  52. } catch (ClassNotFoundException e) {
  53. e.printStackTrace();
  54. } catch (SQLException e) {
  55.  
  56. e.printStackTrace();
  57. }
  58.  
  59. }
  60.  
  61. public void registerConfig() {
  62. saveDefaultConfig();
  63.  
  64.  
  65.  
  66.  
  67. }
  68.  
  69. @EventHandler
  70. public void onPlayerDeath(PlayerDeathEvent e) {
  71. if (e.getEntity() instanceof Player) {
  72. Player p = e.getEntity();
  73. Location loc = e.getEntity().getLocation();
  74. double x = loc.getBlockX() + 0.5;
  75. double y = loc.getBlockY();
  76. double z = loc.getBlockZ() + 0.5;
  77. String dr = e.getDeathMessage();
  78. String world = loc.getWorld().getName();
  79. java.util.Date dt = new java.util.Date();
  80.  
  81. java.text.SimpleDateFormat sdf =
  82. new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  83.  
  84. String time = sdf.format(dt);
  85. inventoryContents.put(p.getName(), p.getInventory().getContents());
  86. inventoryArmorContents.put(p.getName(), p.getInventory().getArmorContents());
  87.  
  88. int deathcount = 0;
  89.  
  90. String statementstring = "SELECT * FROM " + table + " WHERE PlayerName = '" + p.getName() +"';";
  91. String statementstring2 = "INSERT INTO "+ table + " (id, PlayerName, X, Y, Z, DeathReason, world,Time, deathcount,inv,armor) VALUES (NULL, '" + p.getName() + "', '" + x + "', '" + y + "', '" + z + "', '" + dr + "', '" + world + "', '" + time + "', '" + deathcount + "', '" + inventoryContents + "', '" + inventoryArmorContents + "');";
  92.  
  93. try {
  94. Statement statement = c.createStatement();
  95. ResultSet res = statement.executeQuery(statementstring);
  96. if(res.next()) {
  97. String statementstring3 = "UPDATE " + table + " SET X='" + x + "', Y='" + y + "', Z='" + z + "', DeathReason='" + dr + "', world='" + world + "',Time='" + time + "', deathcount='" + (res.getInt("deathcount") + 1) + "', inv='" + inventoryContents + "', armor='" + inventoryArmorContents + "' WHERE id='" + res.getInt("id") + "';";
  98. p.sendMessage(statementstring3);
  99. statement.executeUpdate(statementstring3);
  100. } else {
  101. statement.executeUpdate(statementstring2);
  102. }
  103. } catch (SQLException e2) {
  104.  
  105. e2.printStackTrace();
  106. }
  107. }
  108.  
  109. }
  110.  
  111.  
  112.  
  113. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  114. Player p = (Player)sender;
  115. boolean tp = false;
  116. boolean load = false;
  117. String statementstring4 = null;
  118. if(cmd.getLabel().equalsIgnoreCase("death")) {
  119. if(args.length != 0) {
  120. if(args[0].equals("load")) {
  121. load = true;
  122. if(p.hasPermission("death.teleport")) {
  123. String sanitised_arg = args[1].replace("\\","");
  124. sanitised_arg = sanitised_arg.replace("'","");
  125. statementstring4 = "SELECT * FROM " + table + " WHERE PlayerName = '" + sanitised_arg.toString() +"';";
  126. try {
  127. Statement statement = c.createStatement();
  128. ResultSet res = statement.executeQuery(statementstring4);
  129. if(res.next()) {
  130.  
  131. p.sendMessage("Sucess");
  132. p.sendMessage(load + " ");
  133. if(inventoryContents.containsKey(p.getName()) && inventoryArmorContents.containsKey(p.getName())){
  134. p.getInventory().clear();
  135. p.getInventory().setContents(inventoryContents.get(p.getName()));
  136. p.getInventory().setArmorContents(inventoryArmorContents.get(p.getName()));
  137. }
  138. } else {
  139. p.sendMessage(ChatColor.RED + args[1] + " hasn't died! (yet :D)");
  140. }
  141. } catch (SQLException e) {
  142. e.printStackTrace();
  143. }
  144. } else {
  145. p.sendMessage(ChatColor.RED + "Panda & Jam Say You Have No Permission!");
  146. }
  147.  
  148. } else
  149. if(args[0].equals("tp")) {
  150. if(p.hasPermission("death.teleport")) {
  151. String sanitised_arg = args[1].replace("\\","");
  152. sanitised_arg = sanitised_arg.replace("'","");
  153. statementstring4 = "SELECT * FROM " + table + " WHERE PlayerName = '" + sanitised_arg.toString() +"';";
  154. try {
  155. Statement statement = c.createStatement();
  156. ResultSet res = statement.executeQuery(statementstring4);
  157. if(res.next()) {
  158. Location l = new Location(Bukkit.getWorld(res.getString("world")), res.getDouble("X"), res.getInt("Y"), res.getDouble("Z"));
  159. p.teleport(l);
  160. p.sendMessage(ChatColor.GRAY + "You have been teleported to " + ChatColor.GOLD + "" + ChatColor.BOLD + res.getString("PlayerName") + ChatColor.GRAY + "'s death location at [" + ChatColor.GOLD + "" +
  161. res.getString("world") + ": " + res.getString("X") + ", " + res.getString("Y") + ", " + res.getString("Z") + ChatColor.GRAY + "] at: " + ChatColor.GOLD + "" +
  162. res.getString("time") + ChatColor.GRAY + ".");
  163. p.sendMessage(ChatColor.GRAY + "Cause of Death: " + ChatColor.GOLD + res.getString("DeathReason") + ChatColor.GRAY + "." );
  164. } else {
  165. p.sendMessage(ChatColor.RED + args[1] + " hasn't died! (yet :D)");
  166. }
  167. } catch (SQLException e) {
  168. e.printStackTrace();
  169. }
  170. } else {
  171. p.sendMessage(ChatColor.RED + "Panda & Jam Say You Have No Permission!");
  172. }
  173. tp = true;
  174. } else if (p.hasPermission("death.others")) {
  175. // Player used /death <name> and has permission to do so
  176. String sanitised_arg = args[0].replace("\\","");
  177. sanitised_arg = sanitised_arg.replace("'","");
  178. statementstring4 = "SELECT * FROM " + table + " WHERE PlayerName = '" + sanitised_arg +"';";
  179.  
  180. } else {
  181. // Player used /death <name> but doesn't have permission to do so
  182. statementstring4 = "SELECT * FROM " + table + " WHERE PlayerName = '" + p.getName() +"';";
  183. }
  184. } else {
  185. // Player just used /death with no args - use their own name
  186. statementstring4 = "SELECT * FROM " + table + " WHERE PlayerName = '" + p.getName() +"';";
  187. }
  188.  
  189.  
  190. // If 'tp' wasn't used...
  191. if (tp == false || load == false) {
  192. try {
  193. Statement statement = c.createStatement();
  194. ResultSet res = statement.executeQuery(statementstring4);
  195. if(res.next()) {
  196.  
  197. p.sendMessage(ChatColor.GRAY + "Player " + ChatColor.GOLD + "" + ChatColor.BOLD + res.getString("PlayerName") + ChatColor.GRAY + " died at [" + ChatColor.GOLD + "" +
  198. res.getString("world") + ": " + res.getString("X") + ", " + res.getString("Y") + ", " + res.getString("Z") + ChatColor.GRAY + "] at: " + ChatColor.GOLD + "" +
  199. res.getString("time") + ChatColor.GRAY + ".");
  200. p.sendMessage(ChatColor.GRAY + "Cause of Death: " + ChatColor.GOLD + res.getString("DeathReason") + ChatColor.GRAY + "." );
  201.  
  202. }else if(args.length != 0) {
  203. p.sendMessage(ChatColor.RED + args[0] + " hasn't died! (yet :D)");
  204. } else {
  205. p.sendMessage(ChatColor.RED + "You haven't died! (yet :D)");
  206. }
  207. } catch (SQLException e) {
  208.  
  209. e.printStackTrace();
  210. }
  211. }
  212. }
  213. return true;
  214. }
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement