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.
#Data doesn't get read from the library when loading it in a different plugin.
1 messages · Page 1 of 1 (latest)
Is the listener in your plugins the main class
Also what's getPrefix it's not shown anywhere
What do you mean ?
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?
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
As I've seen so far, I gotta use ServicesManager and have the values registered there if I want to use them somewhere else.
https://paste.md-5.net/ikuqasaras.java
This is my onEnable() for the main plugin
That's not a requirement
Nor is it common
Could you send the ChatFormatter class
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 ?
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");
Ofc, one sec.
java.lang.ClassCastException: class com.ancho.essentials.Essentials cannot be cast to class com.ancho.essentials.Essentials```
That confused me.
One sec.
It says that it expects to provice a class Essentials, but provides Plugin.
So I have to cast it.
Oh those I can call.
I also have the plugin shaded into gradle if that is even relevant ?
is the plugin name correct ?
No do not shade it
just import the lib
and specify that it depends on it in your pluginyml
show me your gradle config
depend
And which class do you want to call as Plugin ?
Because here, you call com.ancho.essentials.Essentials, is this part of AnchoLibrary ?
where does it come from ?
you do not need
to create a fatt jar
with your library
if it is loaded by the server
you only need to compileOnly
sure but quickly
Yeah ofc
i'm in general 1
The problem with shading here is that your calls are being directed to the shaded one, and not the one being loaded if you happen to include the shaded plugin on its own on the server as well