Solved Problem with my plugin

Discussion in 'Spigot Plugin Development' started by Deitog, Aug 9, 2019.

Thread Status:
Not open for further replies.
  1. I'm doing a hypixel language plugin ...
    And when testing the plugin API I found a bug that doesn't detect the player's language.
    I don't see the problem with the code

    Code (Text):
    package net.deitog.lapi.api;

    import net.deitog.lapi.plugin.MainLangsAPI;

    import org.bukkit.entity.Player;

    public class LangsAPI {
        private MainLangsAPI pl = MainLangsAPI.getMainClass();
       
        public void setDefaultLanguage(String lang){
            if(lang!=null){
                pl.getConfig().set("Default.lang", lang);
                pl.saveConfig();
            }
        }
        public String getPlayerLanguage(Player p){
            if(pl.getConfig().contains("ReData."+p.getUniqueId().toString()+".language")){
                return pl.getConfig().getString("ReData."+p.getUniqueId().toString()+".language");
            }else {
                return pl.getConfig().getString("Default.lang");
            }
           
        }
       
        public boolean ifPlayerConfiguredLanguage(Player p){
            if(pl.getConfig().contains("ReData."+p.getUniqueId().toString()+".language")){
                return true;
            }else{
                return false;
            }
        }
       
        public boolean isPlayerLanguage(Player p,String lang){
            String uuid = p.getUniqueId().toString();
            if(lang == null){
                return false;
            }
            if(lang.equalsIgnoreCase(pl.getConfig().getString("ReData."+uuid+".language"))){
                return true;
            }else{
                return false;
            }
        }
       
        public void setPlayerLanguage(Player p,String language){
            if(language == null){
                return;
            }
            if(language.equalsIgnoreCase("en") || language.equalsIgnoreCase("english") || language.equalsIgnoreCase("ingles")){
                pl.getConfig().set("ReData."+p.getUniqueId().toString()+".language", Language.EN);
                pl.saveConfig();
            }else if(language.equalsIgnoreCase("es") || language.equalsIgnoreCase("espaƱol") || language.equalsIgnoreCase("spanish")){
                pl.getConfig().set("ReData."+p.getUniqueId().toString()+".language", Language.ES);
                pl.saveConfig();
            }else if(language.equalsIgnoreCase("fr") || language.equalsIgnoreCase("frances") || language.equalsIgnoreCase("french")){
                pl.getConfig().set("ReData."+p.getUniqueId().toString()+".language", Language.FR);
                pl.saveConfig();
            }else if(language.equalsIgnoreCase("de") || language.equalsIgnoreCase("deustch")){
                pl.getConfig().set("ReData."+p.getUniqueId().toString()+".language", Language.DE);
                pl.saveConfig();
            }else if(language.equalsIgnoreCase("ja") || language.equalsIgnoreCase("japones") || language.equalsIgnoreCase("japanese")){
                pl.getConfig().set("ReData."+p.getUniqueId().toString()+".language", Language.JA);
                pl.saveConfig();
            }else if(language.equalsIgnoreCase("br") || language.equalsIgnoreCase("portugues") || language.equalsIgnoreCase("portuguese")){
                pl.getConfig().set("ReData."+p.getUniqueId().toString()+".language", Language.BR);
                pl.saveConfig();
            }else if(language.equalsIgnoreCase("ch") || language.equalsIgnoreCase("chino") || language.equalsIgnoreCase("chinese")){
                pl.getConfig().set("ReData."+p.getUniqueId().toString()+".language", Language.CH);
                pl.saveConfig();
            }else{
                pl.getConfig().set("ReData."+p.getUniqueId().toString()+".language", Language.DEFAULT);
                pl.saveConfig();
            }
        }
    }
     
    Code (Text):
    package net.deitog.lapi.api;

    import net.deitog.lapi.plugin.MainLangsAPI;

    public class Language {
       
        public static String EN = EN();
        public static String ES = ES();
        public static String FR = FR();
        public static String DE = DE();
        public static String BR = BR();
        public static String JA = JA();
        public static String CH = CH();
        public static String DEFAULT = DEFAULT();
       
        private static String EN(){return "es";}
        private static String ES(){return "es";}
        private static String FR(){return "fr";}
        private static String DE(){return "de";}
        private static String BR(){return "br";}
        private static String JA(){return "ja";}
        private static String CH(){return "ch";}
        private static String DEFAULT(){return MainLangsAPI.getMainClass().getConfig().getString("Default.lang");}
    }
     
    Code (Text):
    package net.deitog.lapi.plugin.events;

    import net.deitog.lapi.api.LangsAPI;
    import net.deitog.lapi.api.Language;
    import net.deitog.lapi.plugin.util.API;

    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;

    public class OnJoin implements Listener{
       
        @EventHandler
        public void event(PlayerJoinEvent e){
            LangsAPI api = new LangsAPI();
            if(api.isPlayerLanguage(e.getPlayer(), Language.EN)){
                e.getPlayer().sendMessage(API.color("&eWelcome to &9Local&bHost &6Network"));
            }else if(api.isPlayerLanguage(e.getPlayer(), Language.ES)){
                e.getPlayer().sendMessage(API.color("&eBienvenido a &9Local&bHost &6Network"));
            }else{
                e.getPlayer().sendMessage(API.color(" "));
            }
        }
    }
     
    What do I have to fix?
     
  2. You could simply set the language by getting the player location by looking up ip address geolocation.
     
  3. You have any crash? Maybe their language is "null" because you don't set their language default and you don't return the default language if is not saved, or I can't see it in the code.
     
  4. I'm going to do a plugin / api like hypixel

    I don't get console errors. If the language is equal to "null" it will return to the default


    When I test in the event, it does not send the message with the selected language, if not .. it executes the if. Try setting the default to another language but nothing
     
  5. So, without explanation?
     
  6. What did you get and what are you expecting?

    Btw
    Why don't just
    public static String CH = "CH";
     
    • Agree Agree x 1
  7. I don't see it, is true that you return the default if the player's language is not saved in "getPlayerLanguage(Player)", but I don't see the same for "isPlayerLanguage(Player,String)".
     
  8. Already solved!
    upload_2019-8-10_17-43-14.png
    It was a very stupid mistake
     
Thread Status:
Not open for further replies.