· 8 years ago · Feb 28, 2018, 06:42 PM
1//method
2 @EventHandler(priority = EventPriority.HIGHEST)
3 public void onplace(BlockPlaceEvent e) {
4 Player p = e.getPlayer();
5 Block b = e.getBlockPlaced();
6 Location loc = e.getBlockPlaced().getLocation();
7 Date now = new Date();
8 WatchDog.inserdwd_Blocks(p, b, e.getBlockPlaced().getLocation().toString(), null, e.getEventName(), MiscUtils.getTime());
9 if (Main.getPlugin().getConfig().getString("devmode").equalsIgnoreCase("true")) {
10 Main.getPlugin().getLogger().info(Variables.watchdog + "a block has placed Player: " + p.getName() + " with UUID: " + p.getUniqueId() + " Block: " + b.getType() + " Location: " + e.getBlock().getLocation().toString() + " replaced to: nothing Type: " + e.getEventName() + " time: " + MiscUtils.getTime());
11 Main.sendDebug(Variables.watchdogcc + "&fa block has placed Player: " + p.getName() + " with UUID: " + p.getUniqueId() + " Block: " + b.getType() + " Location: " + e.getBlock().getLocation().toString() + " replaced to: nothing Type: " + e.getEventName() + " time: " + MiscUtils.getTime());
12 } else {
13
14 }
15 }
16//api
17 public static void inserdwd_Blocks(Player p, Block b, String s, String s1, String s2, String date) {
18 String sql = "INSERT INTO "+ watchdogblocks +"(UUID, Name, Block, Location, PreviousBlock, Type) VALUES (?,?,?,?,?,?)";
19 try {
20 PreparedStatement ps = MySQL.getStatement(sql);
21 ps.setString(1, p.getUniqueId().toString());
22 ps.setString(2, p.getName());
23 ps.setString(3, b.getType().toString());
24 ps.setString(4, s);
25 ps.setString(5, s1);
26 ps.setString(6, s2);
27 ps.executeUpdate();
28 } catch (SQLException e) {
29 e.printStackTrace();
30 }
31 }
32 public static void createwd_Blocks() {
33 String sql = "CREATE TABLE IF NOT EXISTS "+ watchdogblocks +"(UUID VARCHAR(64),Name VARCHAR(100),Block VARCHAR(200),Location VARCHAR(200),PreviousBlock VARCHAR(200),Type VARCHAR(200), Time VARCHAR(1000))";
34 try {
35 PreparedStatement ps = MySQL.getStatement(sql);
36 ps.executeUpdate();
37 console.sendMessage("Table WatchDog_Blocks Created with data: UUID, Name, Block, Location, Previous_Block, Type");
38 } catch (SQLException e) {
39 e.printStackTrace();
40 }
41 }
42//get time method
43 public static String getTime() {
44 Calendar cal = Calendar.getInstance();
45 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
46 return sdf.format(cal.getTime());
47 }