Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.stoneminer02.blockprotection;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.block.BlockBreakEvent;
- import org.bukkit.event.block.BlockPlaceEvent;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Main extends JavaPlugin
- {
- private Plugin plugin;
- code.husky.mysql.MySQL MySQL = new code.husky.mysql.MySQL(plugin,
- getConfig().getString("hostname"), getConfig().getString("port"),
- getConfig().getString("database"), getConfig()
- .getString("username"), getConfig().getString("password"));
- Connection c = null;
- Statement statement = null;
- public void onEnable()
- {
- plugin = this;
- try
- {
- c = MySQL.openConnection();
- } catch (Exception ex)
- {
- ex.printStackTrace();
- }
- try
- {
- statement = c.createStatement();
- } catch (SQLException e)
- {
- e.printStackTrace();
- }
- saveDefaultConfig();
- }
- @EventHandler
- public void onBlockPlace(BlockPlaceEvent event) throws SQLException
- {
- Player player = (Player) event.getPlayer();
- String location = event.getBlockPlaced().getLocation().toString();
- statement.executeUpdate("INSERT INTO blocks (`PlayerName`, `Location`) VALUES ('" + player.getName() + "', '"+ location +"');");
- }
- @EventHandler
- public void onBlockBreak(BlockBreakEvent event) throws SQLException
- {
- Player player = (Player) event.getPlayer();
- ResultSet res = statement.executeQuery("SELECT * FROM blocks WHERE PlayerName = '" + player.getName() + "';");
- res.next();
- if(player.getName() != res.getString("PlayerName"))
- {
- String location = res.getString("Location");
- if(event.getBlock().getLocation().toString() == location)
- {
- player.sendMessage("NOPE!");
- event.setCancelled(true);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement