Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.agil.plugins.chestwatcher;
- import com.mysql.jdbc.Statement;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.block.Block;
- import org.bukkit.block.ContainerBlock;
- import org.bukkit.event.Event;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.util.config.Configuration;
- import java.io.File;
- import java.io.IOException;
- import java.util.Calendar;
- import java.util.HashMap;
- import java.util.logging.Logger;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import javax.persistence.Version;
- import org.bukkit.configuration.file.FileConfiguration;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.List;
- /**
- * ChestWatcher for Bukkit
- *
- * @author robin0van0der0v
- */
- public class Chestwatcher extends JavaPlugin {
- public static final Logger log = Logger.getLogger("Minecraft");
- private final ChestwatcherBlockListener blockListener = new ChestwatcherBlockListener(this);
- private final ChestwatcherEntityListener entityListener = new ChestwatcherEntityListener(this);
- private final ChestwatcherPlayerListener playerListener = new ChestwatcherPlayerListener(this);
- private final ChestwatcherInventoryListener inventoryListener = new ChestwatcherInventoryListener(this);
- public Boolean usingpermissions = false;
- public static HashMap<String, Block> lastBlock = new HashMap<String, Block>();
- public String pluginDirPath;
- public File configFile;
- public ChestWatcherConfig config;
- public void onEnable() {
- log.info(getDescription().getName() + " version " + getDescription().getVersion() + " is enabled!");
- PluginManager pm = getServer().getPluginManager();
- pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Event.Priority.Normal, this);
- pm.registerEvent(Event.Type.BLOCK_BURN, blockListener, Event.Priority.Normal, this);
- pm.registerEvent(Event.Type.BLOCK_FADE, blockListener, Event.Priority.Normal, this);
- pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Event.Priority.Normal, this);
- pm.registerEvent(Event.Type.PLAYER_CHAT, playerListener, Event.Priority.Normal, this);
- pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Event.Priority.Normal, this);
- pm.registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Event.Priority.Normal, this);
- pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Event.Priority.Normal, this);
- pm.registerEvent(Event.Type.FURNACE_BURN, playerListener, Event.Priority.Normal, this);
- pm.registerEvent(Event.Type.FURNACE_SMELT, inventoryListener, Event.Priority.Normal, this);
- this.pluginDirPath = this.getDataFolder().getAbsolutePath();
- this.configFile = new File(this.pluginDirPath + File.separator + "config.yml");
- this.config = new ChestWatcherConfig(this.configFile);
- Connection con = null;
- Statement st = null;
- ResultSet rs = null;
- String url = config.getString("mysql.mysqlurl");
- String user = config.getString("mysql.mysqluser");
- String password= config.getString("mysql.mysqlpassword");
- try {
- con = DriverManager.getConnection(url, user, password);
- st = (Statement) con.createStatement();
- rs = st.executeQuery("SELECT VERSION()");
- if (rs.next()) {
- System.out.println(rs.getString(1));
- }
- } catch (SQLException ex) {
- Logger lgr = Logger.getLogger(Version.class.getName());
- lgr.log(Level.SEVERE, ex.getMessage(), ex);
- } finally {
- try {
- if (rs != null) {
- rs.close();
- }
- if (st != null) {
- st.close();
- }
- if (con != null) {
- con.close();
- }
- } catch (SQLException ex) {
- Logger lgr = Logger.getLogger(Version.class.getName());
- lgr.log(Level.WARNING, ex.getMessage(), ex);
- }
- }
- }
- public void onDisable() {
- log.info(getDescription().getName() + " version " + getDescription().getVersion() + " is disabled!");
- }
- public String getTimestamp() {
- Calendar calendar = Calendar.getInstance();
- return calendar.get(Calendar.DAY_OF_MONTH) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-" + calendar.get(Calendar.YEAR) + "-" + calendar.get(Calendar.HOUR_OF_DAY) + "-" + calendar.get(Calendar.MINUTE) + "-" + calendar.get(Calendar.SECOND);
- }
- public void updateContainer(Block block, Boolean clear, String lastAccessed) {
- if (block.getState() instanceof ContainerBlock) {
- try {
- File dir = new File(getDataFolder().getAbsolutePath());
- File file = new File(getDataFolder().getAbsolutePath() + File.separator + "container.log");
- if (!dir.exists()) {
- dir.mkdirs();
- }
- if (!file.exists()) {
- file.createNewFile();
- }
- Configuration configuration = new Configuration(file);
- configuration.load();
- if (clear) {
- configuration.setProperty(block.getX() + ":" + block.getY() + ":" + block.getZ() + ":" + block.getWorld().getName(), "");
- } else {
- ItemStack[] items = ((ContainerBlock) block.getState()).getInventory().getContents();
- String itemstring = "";
- for (ItemStack item : items) {
- if (item != null) {
- itemstring = itemstring + ":" + item.getTypeId() + "," + item.getDurability() + "," + item.getAmount();
- } else {
- itemstring = itemstring + ":" + 0 + "," + 0 + "," + 0;
- }
- }
- if (lastAccessed == "") {
- lastAccessed = configuration.getString(block.getX() + ":" + block.getY() + ":" + block.getZ() + ":" + block.getWorld().getName(), "");
- if (lastAccessed != "" && lastAccessed != null) {
- lastAccessed = lastAccessed.split(":")[0];
- if (lastAccessed == "" || lastAccessed == null) {
- lastAccessed = "*";
- }
- } else {
- lastAccessed = "*";
- }
- }
- configuration.setProperty(block.getX() + ":" + block.getY() + ":" + block.getZ() + ":" + block.getWorld().getName(), lastAccessed + ":" + block.getTypeId() + itemstring);
- }
- configuration.save();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment