Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.zachbears27;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.entity.PlayerDeathEvent;
- import org.bukkit.plugin.java.JavaPlugin;
- import java.sql.Statement;
- import me.zachbears27.MySQL;
- import net.md_5.bungee.api.ChatColor;
- public class DeathLocation extends JavaPlugin implements Listener {
- 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");
- @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();
- }
- }
- public void registerConfig() {
- saveDefaultConfig();
- }
- @EventHandler
- public void onPlayerDeath(PlayerDeathEvent e) {
- if (e.getEntity() instanceof Player) {
- Player p = e.getEntity();
- Location loc = e.getEntity().getLocation();
- double x = loc.getBlockX() + 0.5;
- double y = loc.getBlockY();
- double z = loc.getBlockZ() + 0.5;
- String dr = e.getDeathMessage();
- String world = loc.getWorld().getName();
- java.util.Date dt = new java.util.Date();
- java.text.SimpleDateFormat sdf =
- new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String time = sdf.format(dt);
- String statementstring = "SELECT * FROM " + table + " WHERE PlayerName = '" + p.getName() +"';";
- String statementstring2 = "INSERT INTO "+ table + " (id, PlayerName, X, Y, Z, DeathReason, world,Time) VALUES (NULL, '" + p.getName() + "', '" + x + "', '" + y + "', '" + z + "', '" + dr + "', '" + world + "', '" + time + "');";
- try {
- Statement statement = c.createStatement();
- ResultSet res = statement.executeQuery(statementstring);
- if(res.next()) {
- String statementstring3 = "UPDATE " + table + " SET X='" + x + "', Y='" + y + "', Z='" + z + "', DeathReason='" + dr + "', world='" + world + "',Time='" + time + "' WHERE id='" + res.getInt("id") + "';";
- statement.executeUpdate(statementstring3);
- } else {
- statement.executeUpdate(statementstring2);
- }
- } catch (SQLException e2) {
- e2.printStackTrace();
- }
- }
- }
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- Player p = (Player)sender;
- if(cmd.getLabel().equalsIgnoreCase("death")) {
- if(args.length != 0) {
- if(args[0].equals("tp")) {
- if(p.hasPermission("death.deathlocation")) {
- String statementstring = "SELECT * FROM " + table + " WHERE PlayerName = '" + args[1].toString() +"';";
- try {
- Statement statement = c.createStatement();
- ResultSet res = statement.executeQuery(statementstring);
- if(res.next()) {
- Location l = new Location(Bukkit.getWorld(res.getString("world")), res.getDouble("X"), res.getInt("Y"), res.getDouble("Z"));
- p.teleport(l);
- p.sendMessage(ChatColor.GRAY + "You have been teleported to " + ChatColor.GOLD + "" + ChatColor.BOLD + res.getString("PlayerName") + ChatColor.GRAY + "'s death location at [" + ChatColor.GOLD + "" +
- res.getString("world") + ": " + res.getString("X") + ", " + res.getString("Y") + ", " + res.getString("Z") + ChatColor.GRAY + "] at: " + ChatColor.GOLD + "" +
- res.getString("time") + ChatColor.GRAY + ".");
- p.sendMessage(ChatColor.GRAY + "Cause of Death: " + ChatColor.GOLD + res.getString("DeathReason") + ChatColor.GRAY + "." );
- } else {
- p.sendMessage(ChatColor.RED + args[1] + " hasn't died! (yet :D)");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- } else {
- p.sendMessage(ChatColor.RED + "Panda & Jam Say You Have No Permission!");
- }
- } else
- {
- String statementstring = "SELECT * FROM " + table + " WHERE PlayerName = '" + args[0] +"';";
- try {
- Statement statement = c.createStatement();
- ResultSet res = statement.executeQuery(statementstring);
- if(res.next()) {
- if (p.getName() == args[1]) {
- p.sendMessage(ChatColor.GRAY + "Player " + ChatColor.GOLD + "" + ChatColor.BOLD + res.getString("PlayerName") + ChatColor.GRAY + " died at [" + ChatColor.GOLD + "" +
- res.getString("world") + ": " + res.getString("X") + ", " + res.getString("Y") + ", " + res.getString("Z") + ChatColor.GRAY + "] at: " + ChatColor.GOLD + "" +
- res.getString("time") + ChatColor.GRAY + ".");
- p.sendMessage(ChatColor.GRAY + "Cause of Death: " + ChatColor.GOLD + res.getString("DeathReason") + ChatColor.GRAY + "." );
- } else {
- p.sendMessage("Please Use Your Own Name");
- }
- } else {
- p.sendMessage(ChatColor.RED + args[0] + " hasn't died! (yet :D)");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- else
- {
- if(p.hasPermission("death.deathlocation")) {
- p.sendMessage(ChatColor.RED + "Please Specify A Player or Add TP Then A Player Name");
- } else
- {
- p.sendMessage(ChatColor.RED + "Please Specify A Player");
- }
- }
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement