Solved JoinEvent Problem getPlayer

Discussion in 'Spigot Plugin Development' started by Ilario42, Apr 3, 2020.

  1. Hi, I was implementing my coins with FeatherBoard. Everything works ... The problem!
    If a player enters after me I see the coins of the last entered and not mine.
    How can I see my coins and not those of the last one who joined the {windycore_coins} ?

    Thanks friends, good evening!


    Code (Text):
    @EventHandler
        public void onPlayerJoin(PlayerLoginEvent e) {
            Player p = e.getPlayer();
            if(!e.getPlayer().hasPlayedBefore()) {
                API.addCoins(p.getName(), Integer.valueOf(1));
            }
            try {
                PreparedStatement st = MySQL.con.prepareStatement("SELECT * FROM CoinsGlobal WHERE UUID = ?");
                st.setString(1, p.getName());
                ResultSet rs = st.executeQuery();
                while (rs.next()) {
                    int c = rs.getInt("coins");
                    String cs = String.valueOf(c);
                    PlaceholderAPI.registerPlaceholder(this, "windycore_coins", new PlaceholderReplacer() {
                        public String onPlaceholderReplace(PlaceholderReplaceEvent event) {  
                            return cs;
                        }
                       
                    });
                   
                }
       
            } catch (SQLException e1) {
                e1.printStackTrace();
            }
        }
     
  2. Hi, Hi, I'm using https://www.spigotmc.org/resources/mvdwplaceholderapi.11182/, and not PlaceHolderAPI. I took a look at the guide but didn't understand how to fix it
     
  3. Ahh, that explains why it looked different. If you do event.getPlayer() on PlaceholderReplaceEvent then you can get the player who used the placeholder. Then you calculate the result of "cs".
     
  4. My friend, thank you, you were right! Thank you so much.
    Thanks