Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.HashMap;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.AsyncPlayerChatEvent;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Main extends JavaPlugin implements Listener{
- private static HashMap<String, String> words = new HashMap<String, String>();
- @Override
- public void onEnable() {
- getServer().getPluginManager().registerEvents(this, this);
- readAll();
- getCommand("mysql").setExecutor(new Commandes());
- }
- @EventHandler
- public void onChat(AsyncPlayerChatEvent e){
- for(String s : words.keySet()){
- if(e.getMessage().contains(s)){
- e.setCancelled(true);
- e.getPlayer().sendMessage("§c"+words.get(s));
- }
- }
- }
- public static void insert(String word, String phrase){
- MySQL.connection();
- PreparedStatement sts;
- try {
- sts = MySQL.getConnection().prepareStatement("INSERT INTO words (word, phrase) VALUES(?, ?)");
- sts.setString(1, word);
- sts.setString(2, phrase);
- sts.executeUpdate();
- sts.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- MySQL.deconnection();
- }
- public static void readAll(){
- MySQL.connection();
- PreparedStatement sts;
- try {
- sts = MySQL.getConnection().prepareStatement("SELECT * FROM words");
- ResultSet result = sts.executeQuery();
- while(result.next()){
- String word, phrase;
- word = result.getString("word");
- phrase = result.getString("phrase");
- System.out.println("LE MOT: " +word+ " est sur la même ligne que "+phrase);
- words.put(word, phrase);
- }
- sts.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- MySQL.deconnection();
- }
- public static void read(String word){
- MySQL.connection();
- PreparedStatement sts;
- try {
- sts = MySQL.getConnection().prepareStatement("SELECT phrase FROM words WHERE word = ?");
- sts.setString(1, word);
- ResultSet result = sts.executeQuery();
- while(result.next()){
- String word_retour, phrase;
- word_retour = result.getString("word");
- phrase = result.getString("phrase");
- System.out.println("La phrase du mot " +word_retour+ " est: "+phrase);
- }
- sts.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- MySQL.deconnection();
- }
- public static void update(String word, String phrase){
- MySQL.connection();
- PreparedStatement sts;
- try {
- sts = MySQL.getConnection().prepareStatement("UPDATE words SET phrase = ? WHERE word = ?");
- sts.setString(1, phrase);
- sts.setString(2, word);
- sts.executeUpdate();
- sts.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- MySQL.deconnection();
- }
- public static void delete(String word){
- MySQL.connection();
- PreparedStatement sts;
- try {
- sts = MySQL.getConnection().prepareStatement("DELETE FROM words WHERE word = ?");
- sts.setString(1, word);
- sts.executeUpdate();
- sts.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- MySQL.deconnection();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment