#[IMMPORTANT] Error(the PlayerQuitEvent Included)

1 messages · Page 1 of 1 (latest)

eternal swallow
#

[IMMPORTANT] Error(the PlayerQuitEvent Included)

#

playerjoin i meant

#
@EventHandler
    public void onPlayerJoin(PlayerJoinEvent e){
        HypixelSkillCore plugin = HypixelSkillCore.getInstance();
        Player player = e.getPlayer();
        if(player.getPersistentDataContainer().get(plugin.getKey(), plugin.getType()) != null){
            if(plugin.getPlayer(player.getUniqueId()) != null) return;
            plugin.setPlayer(player.getUniqueId(), player.getPersistentDataContainer().get(plugin.getKey(), plugin.getType()));
        }
        if(plugin.getPlayer(player.getUniqueId()) == null){
            plugin.createPlayer(player.getUniqueId());
            player.getPersistentDataContainer().set(plugin.getKey() , plugin.getType(), plugin.getPlayer(player.getUniqueId()));
            player.sendMessage(ChatColor.GREEN + "Welcome To server! Your SkyblockSkills Account Has Been Created");
        }
    }
#

happened after a rejoin

#
public void onPlayerLeave(PlayerQuitEvent e){
        Player player = e.getPlayer();
        HypixelSkillCore plugin = HypixelSkillCore.getInstance();
        player.getPersistentDataContainer().set(plugin.getKey() , plugin.getType(), plugin.getPlayer(player.getUniqueId()));
    }

playerquit if needed

#
public final class HypixelSkillCore extends JavaPlugin {
    private HashMap<UUID, HypixelPlayer> uuidToPlayerMap = new HashMap<>();
    private static HypixelSkillCore plugin;

    private ConfigurationSerializableDataType<HypixelPlayer> type = new ConfigurationSerializableDataType<>(HypixelPlayer.class);
    private NamespacedKey key;

    @Override
    public void onEnable() {
        plugin = this;
        key = new NamespacedKey(this, "key");
        registerClasses();
        enableListeners();
        this.getCommand("skillstext").setExecutor(new SkillsText());
        getLogger().info("HypixelSkillCore for ");
        new BukkitRunnable(){
            @Override
            public void run(){
                ArrayList<HypixelPlayer> array = new ArrayList<>(uuidToPlayerMap.values());
                for (HypixelPlayer player: array) {
                    try {
                        player.setTrueStats();
                        player.getSkillBossBar().setVisible(true);
                        if (player.getSkillBossBar().getPlayers().size() != 0) {
                            player.getSkillBossBar().removePlayer(getServer().getPlayer(player.getUuid()));
                        }
                    }catch(Throwable rock){}
                }
            }
        }.runTaskTimer(this, 1L, 80L);
    }

    public static HypixelSkillCore getInstance() {
        return plugin;
    }

    public void createPlayer(UUID uuid){
discord limit
    }

    public void setPlayer(UUID uuid, HypixelPlayer player){
        uuidToPlayerMap.put(uuid, player);
    }

    public HypixelPlayer getPlayer(UUID uuid){
        return uuidToPlayerMap.get(uuid);
    }

    public ConfigurationSerializableDataType<HypixelPlayer> getType() {
        return type;
    }

    public NamespacedKey getKey() {
        return key;
    }

    private void enableListeners(){
  removed due to discord limit
    }

    private void registerClasses(){
   removed due to discord limit
    }

#
public class HypixelPlayer implements ConfigurationSerializable {
    private Farming farming = new Farming();
    private Mining mining = new Mining();
    private Woodcutting woodcutting = new Woodcutting();
    private Combat combat = new Combat();

    BossBar skillBossBar = Bukkit.createBossBar("+69 SKILLNAME SKILLXP/REQSKILLXP", BarColor.GREEN, BarStyle.SOLID);

    private UUID uuid;

    private double damage = 1;
    private double health = 20;
    private double defense = 1;

    //.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, 10, (int)Math.floor(health), false));
    public void setTrueStats(){
        HypixelSkillCore.getInstance().getServer().getPlayer(uuid).setMaxHealth(health);
    }

removed getters and setters for discord limitation

    public Map<String, Object> serialize(){
        return Map.of(
            "uuid",uuid,
            "skill_woodcutting",woodcutting,
            "skill_mining",mining,
            "skill_farming",farming,
            "skill_combat",combat,
            "stats_heath",health,
            "stats_damage",damage,
            "stats_defense",defense
            );
    }

    public void deserialize(Map<String, Object> m){
        uuid = (UUID) m.get("uuid");
        woodcutting = (Woodcutting) m.get("skill_woodcutting");
        mining = (Mining) m.get("skill_mining");
        farming = (Farming) m.get("skill_farming");
        combat = (Combat) m.get("skill_combat");
        health = (Double) m.get("stats_health");
        damage = (Double) m.get("stats_damage");
        defense = (Double) m.get("stats_defense");
    }
}
#

the problem is in deserializing the class

#

yes i registered them

#

and made the skill classes ConfigurationSerializable

waxen walrus
#

that deserialize should be static and return an instance iirc

eternal swallow
#

wdym?

waxen walrus
eternal swallow
#

public static void deserialize

#

?

waxen walrus
#

no, thats void, it should return an instance

ashen grail
eternal swallow
#

wdym by returning an instance you mean public static HypixelPlayer deserialize? and return this;?

ashen grail
#

in onEnable

ashen grail
eternal swallow
#

private void registerClasses(){
ConfigurationSerialization.registerClass(HypixelPlayer.class);
ConfigurationSerialization.registerClass(Combat.class);
ConfigurationSerialization.registerClass(Farming.class);
ConfigurationSerialization.registerClass(Mining.class);
ConfigurationSerialization.registerClass(Woodcutting.class);
}

#

private void registerClasses(){
ConfigurationSerialization.registerClass(HypixelPlayer.class);
ConfigurationSerialization.registerClass(Combat.class);
ConfigurationSerialization.registerClass(Farming.class);
ConfigurationSerialization.registerClass(Mining.class);
ConfigurationSerialization.registerClass(Woodcutting.class);
}

waxen walrus
#
public static HypixelPlayer deserialize(Map<String, Object> map) {
    return this(map);
}

public HypixelPlayer(Map<String, Object> map) {
    this.whatever= map.get("whatever")
}
ashen grail
eternal swallow
#

i will do it rn

eternal swallow
#

or the deserialize will be that

waxen walrus
#

thats an example to follow DRY

eternal swallow
#

oh fuck java whoever made java was a fucking bitch

waxen walrus
#

no not really

eternal swallow
#

you say i just make my method static

waxen walrus
#

my deserialize is static, and it also follows dry

eternal swallow
#

wdym by dry?

waxen walrus
#

dont repeat yourself

eternal swallow
#

oh

#

oh im so fucking dumb

#

i got it

#

i got an error. should i make the costructor private?

waxen walrus
#

?paste ur new class

inland willowBOT
waxen walrus
#

oh fun

#

cafebabe works in threads

eternal swallow
#

that website doesnt work for me

waxen walrus
#

use any other paste site then

eternal swallow
#

done fixed the error realated to creating a new HypixelPlayer with this:
public HypixelPlayer(){}

waxen walrus
#

if it doesnt take the map you just have to handle the deserializing in the method and it would break if it trys to use the constructor

eternal swallow
#

the other constructor is there

#

return this(m); doesnt work

#

Call to 'this()' must be first statement in constructor body

#

public static HypixelPlayer deserialize(Map<String, Object> m){
return this(m);
}

public HypixelPlayer(Map<String, Object> m){
    this.uuid = (UUID) m.get("uuid");
    this.woodcutting = (Woodcutting) m.get("skill_woodcutting");
    this.mining = (Mining) m.get("skill_mining");
    this.farming = (Farming) m.get("skill_farming");
    this.combat = (Combat) m.get("skill_combat");
    this.health = (Double) m.get("stats_health");
    this.damage = (Double) m.get("stats_damage");
    this.defense = (Double) m.get("stats_defense");
}

public HypixelPlayer(){}
waxen walrus
#

return new HypixelPlayer(m); then

eternal swallow
#

done before you could tell me

#

now its time to do it with all the skill classes. oh fck

#

//TODO fix the deserialization with the tips from EpicEbic
too tired

eternal swallow
#

all the deserializing code done

#

time to test it ou

#

t

#

im not gonna share the log rn. lemme see if the playerdata has been saved on pdc or not

#

lemme restart the server...

#

it doesn seem that anything has been saved on the players nbt data

ashen grail
#

?nocode

inland willowBOT
#

It’s hard to answer a programming question without code
Oh no! You ran into a problem. But no worries, people are willing to help, but first they need to see your code. This is because otherwise, they would be providing help based on guesses instead of concrete knowledge. Whether it be a compile error, runtime error, or an unexpected output, I'm sure that if you were to provide code, you'd receive a quick solution.

eternal swallow
#

okay

#

which parts of the plugin?

#

@ashen grail

#
@EventHandler
    public void onPlayerJoin(PlayerJoinEvent e){
        HypixelSkillCore plugin = HypixelSkillCore.getInstance();
        Player player = e.getPlayer();
        if(player.getPersistentDataContainer().get(plugin.getKey(), plugin.getType()) != null){
            if(plugin.getPlayer(player.getUniqueId()) != null) return;
            plugin.setPlayer(player.getUniqueId(), player.getPersistentDataContainer().get(plugin.getKey(), plugin.getType()));
        }
        if(plugin.getPlayer(player.getUniqueId()) == null){
            plugin.createPlayer(player.getUniqueId());
            player.getPersistentDataContainer().set(plugin.getKey() , plugin.getType(), plugin.getPlayer(player.getUniqueId()));
            player.sendMessage(ChatColor.GREEN + "Welcome To server! Your SkyblockSkills Account Has Been Created");
        }
    }

onPlayerJoin

#
@EventHandler
    public void onPlayerLeave(PlayerQuitEvent e){
        Player player = e.getPlayer();
        HypixelSkillCore plugin = HypixelSkillCore.getInstance();
        player.getPersistentDataContainer().set(plugin.getKey() , plugin.getType(), plugin.getPlayer(player.getUniqueId()));
    }

playerLeave

#
private ConfigurationSerializableDataType<HypixelPlayer> type = new ConfigurationSerializableDataType<>(HypixelPlayer.class);
    private NamespacedKey key;

creating the key and the type

#

key = new NamespacedKey(this, "key");
setting the key

#

in onEnable

ashen grail
#

?paste the WHOLE hypixel player class

inland willowBOT
eternal swallow
#

i have to use another pastebin

#

wait wtf

#

cannot resolve symbol combat?

#

who made intellij idea

#

i want to talk with him... just talk nothing else

#

i got more serious problems this one for later

#

can i just paste the code on a public repository of mine in github?

#

@ashen grail here u go

ashen grail
#

the map passed to the map constructor doesnt contain "stats_defense" or sth. Not 100% sure because you changed your code after you got the stacktrace

#

one of these does not exist in the map

eternal swallow
#

leme check the serialize method...

#

heath... WTF IS WRONG WITH ME WHAT IS HEATH ITS HEALTH

#

i stayed awake 9+ hours to fix a stupid spelling mistake

#

leme just replace my deprecated way of setting the player health and then i will test it out

eternal swallow
#

@ashen grail thanks for wasting 9 hours of your life helping me fix this stupid typo