#Data doesn't get read from the library when loading it in a different plugin.

1 messages · Page 1 of 1 (latest)

pallid cypress
#

public static HashMap<UUID, PlayerData> playerDataList = new HashMap<>();

    public static PlayerData loadPlayerData(Player player, Connection connection) throws SQLException {
        PreparedStatement ps = connection.prepareStatement("SELECT * FROM player_data WHERE uuid = ?");
        ps.setString(1, player.getUniqueId().toString());
        ResultSet rs = ps.executeQuery();

        if (rs.next()) {
            PlayerData playerData = new PlayerData(
                    UUID.fromString(rs.getString("uuid")),
                    rs.getDouble("money"),
                    rs.getDouble("tokens"),
                    rs.getDouble("credits"),
                    rs.getDouble("rubies"),
                    rs.getDouble("multi"),
                    rs.getInt("prestige"),
                    rs.getString("suffix"),
                    rs.getDate("join_date")
            );
            playerDataList.put(player.getUniqueId(), playerData);
            return playerData;
        }  else {
            PlayerData playerData = new PlayerData(player.getUniqueId());
            playerDataList.put(player.getUniqueId(), playerData);
            return playerData;
        }
    }```


```java
// This is the first plugin loading it
JavaPlugin plugin = Essentials.plugin;

    @EventHandler
    public  void onJoin(PlayerJoinEvent event) throws SQLException {

        try (Connection connection = new ConnectionFactory(plugin).getConnection()){
            if (connection != null) {
                System.out.println("Player data loaded for " + event.getPlayer().getName());
                PlayerDataManager.loadPlayerData(event.getPlayer(), connection);
            } else {
                System.out.println("Failed to connect to the database!");
            }
        }
    }```

```java
// This is me trying to use it in a different plugin
JavaPlugin plugin = Essentials.plugin;

    @EventHandler
    public  void onJoin(PlayerJoinEvent event) throws SQLException {

        try (Connection connection = new ConnectionFactory(plugin).getConnection()){
            if (connection != null) {
                System.out.println("Player data loaded for " + event.getPlayer().getName());
                PlayerDataManager.loadPlayerData(event.getPlayer(), connection);
            } else {
                System.out.println("Failed to connect to the database!");
            }
        }
    }```

For whatever reason, it says that the getPrefix, or any data in the PlayerDataHandler.playerDataList is null, it doesn't read the data that I'm loading in a different plugin.
weak whale
#

Also what's getPrefix it's not shown anywhere

pallid cypress
#

Okay so, how do I make it so I have the code in the library, load it in a plugin and it still gets loaded in the library as well?
Because I'd like to use it in other plugins as well but for whatever reason I cannot?
Could someone provide me with a short code snippet or something?

weak whale
#

What you've done with that static method and map should work fine. That's not the problem

#

What exactly is null, show the code causing the issue

#

Also use paste

#

?paste

true pathBOT
pallid cypress
#

As I've seen so far, I gotta use ServicesManager and have the values registered there if I want to use them somewhere else.

weak whale
#

Nor is it common

weak whale
pallid cypress
digital stump
#
 Cannot invoke "com.ancho.library.spigot.player.PlayerData.getSuffix()" because the return value of "java.util.HashMap.get(Object)" is null

Can you provide where do you call getSuffix() ? @pallid cypress

#

are you sure that the user you get from the map is properly loaded ? Can you print out the content of the hashmap in the console before making that call ?

pallid cypress
#

I found that problem, the new one I'm facing is getting an instance of the Essentials plugin that is already loaded on the server using
Bukkit.getPluginManaget().getPlugin("Essentials");
But for whatever reason it seems to give me an error whenever I try to cast it to (Essentials)
Essentials example = (Essentials) Bukkit.getPluginManager().getPlugin("Essentials");

digital stump
#

what error

#

can you provide it

pallid cypress
#

Ofc, one sec.

#
java.lang.ClassCastException: class com.ancho.essentials.Essentials cannot be cast to class com.ancho.essentials.Essentials```
#

That confused me.

digital stump
#

when you remove the cast, can you call your class specific methods ?

#

on example

pallid cypress
#

One sec.

#

It says that it expects to provice a class Essentials, but provides Plugin.

#

So I have to cast it.

pallid cypress
#

Oh those I can call.

#

I also have the plugin shaded into gradle if that is even relevant ?

digital stump
#

is the plugin name correct ?

digital stump
#

just import the lib

#

and specify that it depends on it in your pluginyml

pallid cypress
#

Well I have it soft-depend?

#

Or do I have to DEPEND it ?

digital stump
#

show me your gradle config

digital stump
pallid cypress
digital stump
#
implementation 'com.ancho.library:AnchoLibrary:1.0'
#

that is your lib right ?

pallid cypress
#

Yeap.

#

Using maven local.

digital stump
#

And which class do you want to call as Plugin ?

pallid cypress
#

The main essentials class.

#

So the main plugin class.

digital stump
#

Because here, you call com.ancho.essentials.Essentials, is this part of AnchoLibrary ?

pallid cypress
#

One that extends from JavaPlugin.

#

Nope.

digital stump
#

where does it come from ?

#

you do not need

#

to create a fatt jar

#

with your library

#

if it is loaded by the server

weak whale
#

Yeah this is what I suspected

#

You've shaded the library

digital stump
#

you only need to compileOnly

pallid cypress
#

I'm kinda lost, can we VC? 😂

#

I can explain that way better?

weak whale
#

Replace implementation with compileOnly

#

in your build gradle file

digital stump
pallid cypress
digital stump
#

i'm in general 1

cursive ledge