@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { if (event.getBlock().getType() != Material.OBSIDIAN) return; Block block = event.getBlock(); ArrayList<PortalLocation> portals = SQLite.obsidian_checker(block); for (PortalLocation portal : portals) { if (PortalCheck.is_valid_portal(portal.block, block) == false) { Portals.instance .getLogger() .info( "Query returned positive. " + "Disabling this portal at " + portal.block.getWorld().getName() + " " + portal.block.getX() + " " + portal.block.getY() + " " + portal.block.getZ()); SQLite.delete_portal_pair(portal.id); } } }
public String removeFromDB() { if (!wordExists()) { return String.valueOf( ChatColor.RED + "The word " + ChatColor.GOLD + word.getName() + ChatColor.RED + " does not exist!"); } else { // ResultSet rs = null; if (sqltype.equals(SQLType.SQLite)) { sqlite.query(Query.DELETE_FROM.value() + "name='" + word.getName() + "'"); } if (sqltype.equals(SQLType.MySQL)) { mysql.query(Query.DELETE_FROM.value() + "name='" + word.getName() + "'"); } /*if (rs.equals(null)){ return String.valueOf(ChatColor.RED+"Error occured while deleting the word '"+word.getName()+"' Please check console for more info."); }*/ return String.valueOf( ChatColor.GREEN + "Word " + ChatColor.GOLD + word.getName() + ChatColor.GREEN + " has been deleted."); } }
public String addToDB() { if (wordExists()) { return String.valueOf( ChatColor.RED + "The word " + ChatColor.GOLD + word.getName() + ChatColor.RED + " already exists!"); } else { try { Connection con = null; if (sqltype.equals(SQLType.SQLite)) con = sqlite.getConnection(); if (sqltype.equals(SQLType.MySQL)) con = mysql.getConnection(); PreparedStatement p = con.prepareStatement(Query.INSERT_INTO.value()); p.setString(1, word.getName()); p.setString(2, word.getGroup()); p.addBatch(); con.setAutoCommit(false); p.executeBatch(); con.setAutoCommit(true); return String.valueOf( ChatColor.GREEN + "Word " + ChatColor.GOLD + word.getName() + ChatColor.GREEN + " has been successfully added!"); } catch (SQLException e) { plugin.sendErr( "Error while adding the word '" + word.getName() + "' to the database. Error message: " + e.getMessage() + " ERROR CODE: " + e.getErrorCode()); e.printStackTrace(); return String.valueOf( ChatColor.RED + "Error adding the word '" + ChatColor.GOLD + word.getName() + ChatColor.RED + "' Please check the console for more info."); } catch (Exception e) { plugin.sendErr( "Unknown error while adding the word " + word.getName() + " to the database. Stacktrace:"); e.printStackTrace(); return String.valueOf( ChatColor.RED + "Error adding the word '" + ChatColor.GOLD + word.getName() + ChatColor.RED + "' Please check the console for more info."); } } }
public String getWordGroup() { ResultSet rs = null; if (sqltype.equals(SQLType.SQLite)) rs = sqlite.query(Query.SELECT_GROUPNAME.value() + " name='" + word.getName() + "'"); if (sqltype.equals(SQLType.MySQL)) rs = mysql.query(Query.SELECT_GROUPNAME.value() + "name='" + word.getName() + "'"); try { String s = null; while (rs.next()) { s = rs.getString(1); } return s; } catch (SQLException e) { plugin.sendErr( "SQLException while getting the word " + word.getName() + "'s group from the database. Error message: " + e.getMessage() + " ERROR CODE: " + e.getErrorCode()); e.printStackTrace(); return null; } }
public ArrayList<String> getWords() { ResultSet rs = null; ArrayList<String> w = new ArrayList<String>(); if (sqltype.equals(SQLType.SQLite)) rs = sqlite.query(Query.SELECT_NAME.value()); if (sqltype.equals(SQLType.MySQL)) rs = mysql.query(Query.SELECT_NAME.value()); try { while (rs.next()) { w.add(rs.getString(1)); } return w; } catch (SQLException e) { if (e.getMessage().contains("Illegal operation on empty result")) return null; plugin.send( "SQLException while getting words from the database. Error message: " + e.getMessage() + " ERROR CODE: " + e.getErrorCode()); e.printStackTrace(); } return null; }