Advertisement
Guest User

Untitled

a guest
Mar 18th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.53 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. String statementstring4 = null;
  117. if(cmd.getLabel().equalsIgnoreCase("loadinv")) {
  118.  
  119. if(inventoryContents.containsKey(p.getName()) && inventoryArmorContents.containsKey(p.getName())){
  120. p.getInventory().clear();
  121. p.getInventory().setContents(inventoryContents.get(p.getName()));
  122. p.getInventory().setArmorContents(inventoryArmorContents.get(p.getName()));
  123. }
  124. } else if(cmd.getLabel().equalsIgnoreCase("death")) {
  125. if(args.length != 0) {
  126. if(args[0].equals("tp")) {
  127. if(p.hasPermission("death.teleport")) {
  128. String sanitised_arg = args[1].replace("\\","");
  129. sanitised_arg = sanitised_arg.replace("'","");
  130. statementstring4 = "SELECT * FROM " + table + " WHERE PlayerName = '" + sanitised_arg.toString() +"';";
  131. try {
  132. Statement statement = c.createStatement();
  133. ResultSet res = statement.executeQuery(statementstring4);
  134. if(res.next()) {
  135. Location l = new Location(Bukkit.getWorld(res.getString("world")), res.getDouble("X"), res.getInt("Y"), res.getDouble("Z"));
  136. p.teleport(l);
  137. p.sendMessage(ChatColor.GRAY + "You have been teleported to " + ChatColor.GOLD + "" + ChatColor.BOLD + res.getString("PlayerName") + ChatColor.GRAY + "'s death location at [" + ChatColor.GOLD + "" +
  138. res.getString("world") + ": " + res.getString("X") + ", " + res.getString("Y") + ", " + res.getString("Z") + ChatColor.GRAY + "] at: " + ChatColor.GOLD + "" +
  139. res.getString("time") + ChatColor.GRAY + ".");
  140. p.sendMessage(ChatColor.GRAY + "Cause of Death: " + ChatColor.GOLD + res.getString("DeathReason") + ChatColor.GRAY + "." );
  141. } else {
  142. p.sendMessage(ChatColor.RED + args[1] + " hasn't died! (yet :D)");
  143. }
  144. } catch (SQLException e) {
  145. e.printStackTrace();
  146. }
  147. } else {
  148. p.sendMessage(ChatColor.RED + "Panda & Jam Say You Have No Permission!");
  149. }
  150. tp = true;
  151. } else if (p.hasPermission("death.others")) {
  152. // Player used /death <name> and has permission to do so
  153. String sanitised_arg = args[0].replace("\\","");
  154. sanitised_arg = sanitised_arg.replace("'","");
  155. statementstring4 = "SELECT * FROM " + table + " WHERE PlayerName = '" + sanitised_arg +"';";
  156.  
  157. } else {
  158. // Player used /death <name> but doesn't have permission to do so
  159. statementstring4 = "SELECT * FROM " + table + " WHERE PlayerName = '" + p.getName() +"';";
  160. }
  161. } else {
  162. // Player just used /death with no args - use their own name
  163. statementstring4 = "SELECT * FROM " + table + " WHERE PlayerName = '" + p.getName() +"';";
  164. }
  165.  
  166. // If 'tp' wasn't used...
  167. if (!tp) {
  168. try {
  169. Statement statement = c.createStatement();
  170. ResultSet res = statement.executeQuery(statementstring4);
  171. if(res.next()) {
  172.  
  173. p.sendMessage(ChatColor.GRAY + "Player " + ChatColor.GOLD + "" + ChatColor.BOLD + res.getString("PlayerName") + ChatColor.GRAY + " died at [" + ChatColor.GOLD + "" +
  174. res.getString("world") + ": " + res.getString("X") + ", " + res.getString("Y") + ", " + res.getString("Z") + ChatColor.GRAY + "] at: " + ChatColor.GOLD + "" +
  175. res.getString("time") + ChatColor.GRAY + ".");
  176. p.sendMessage(ChatColor.GRAY + "Cause of Death: " + ChatColor.GOLD + res.getString("DeathReason") + ChatColor.GRAY + "." );
  177.  
  178. }else if(args.length != 0) {
  179. p.sendMessage(ChatColor.RED + args[0] + " hasn't died! (yet :D)");
  180. } else {
  181. p.sendMessage(ChatColor.RED + " You haven't died! (yet :D)");
  182. }
  183. } catch (SQLException e) {
  184.  
  185. e.printStackTrace();
  186. }
  187. }
  188. }
  189. return true;
  190. }
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement