#[IMMPORTANT] Error(the PlayerQuitEvent Included)
1 messages · Page 1 of 1 (latest)
[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
that deserialize should be static and return an instance iirc
wdym?
no, thats void, it should return an instance
I already told you, you gotta register your seriazable class
wdym by returning an instance you mean public static HypixelPlayer deserialize? and return this;?
done
in onEnable
where? I don't see it in your code
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);
}
public static HypixelPlayer deserialize(Map<String, Object> map) {
return this(map);
}
public HypixelPlayer(Map<String, Object> map) {
this.whatever= map.get("whatever")
}
your deserialize method must be static
i will do it rn
should i add that at the end of my deserialize method?
or the deserialize will be that
thats an example to follow DRY
oh fuck java whoever made java was a fucking bitch
no not really
who should i listen to you or @waxen walrus
you say i just make my method static
my deserialize is static, and it also follows dry
wdym by dry?
dont repeat yourself
oh
oh im so fucking dumb
i got it
i got an error. should i make the costructor private?
?paste ur new class
that website doesnt work for me
use any other paste site then
done fixed the error realated to creating a new HypixelPlayer with this:
public HypixelPlayer(){}
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
no thats for the other places where i create a HypixelPlayer()
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(){}
return new HypixelPlayer(m); then
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
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
https://mclo.gs/JY27z8A
https://mclo.gs/mtjiPbU
https://mclo.gs/ftw3F1b
managed to go through a whole join and leave without errors but after the join it gave an error
the stats / skills were still there though
lemme restart the server...
it doesn seem that anything has been saved on the players nbt data
?nocode
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.
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
?paste the WHOLE hypixel player class
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
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
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
@ashen grail thanks for wasting 9 hours of your life helping me fix this stupid typo