Im getting an error when trying to detect the click of a form button using GeyserMC's API. This is what it says: Inconvertible types; cannot cast '' to 'org.geysermc.cumulus.response.SimpleFormResponse'
This is what i did/tried which is giving that error:
package org.centoricraft.centoriui23;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.geysermc.cumulus.SimpleForm;
import org.geysermc.floodgate.api.FloodgateApi;
import org.geysermc.floodgate.api.player.FloodgatePlayer;
import org.geysermc.cumulus.response.CustomFormResponse;
import org.geysermc.cumulus.response.SimpleFormResponse;
public class CentoriUI23 extends JavaPlugin implements Listener {
private FloodgateApi floodgateApi;
@Override
public void onEnable() {
if (getServer().getPluginManager().getPlugin("Floodgate") != null) {
floodgateApi = FloodgateApi.getInstance();
getServer().getPluginManager().registerEvents(this, this);
} else {
getLogger().warning("Floodgate plugin not found! Disabling plugin...");
getServer().getPluginManager().disablePlugin(this);
}
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if (floodgateApi.isFloodgatePlayer(player.getUniqueId())) {
Bukkit.getScheduler().runTaskLater(this, () -> {
FloodgatePlayer floodgatePlayer = floodgateApi.getPlayer(player.getUniqueId());
if (floodgatePlayer != null) {
SimpleForm form = SimpleForm.builder()
.title("Centori UI")
.button("Play")
.button("Discord")
.build();
form.setResponseHandler((formPlayer, responseData) -> {
if (responseData instanceof SimpleFormResponse) {
SimpleFormResponse response = (SimpleFormResponse) responseData;
int buttonId = response.getClickedButtonId();
if (buttonId == 0) {
// Handle "Play" button click
} else if (buttonId == 1) {
// Handle "Discord" button click
}
} else if (responseData instanceof CustomFormResponse) {
CustomFormResponse response = (CustomFormResponse) responseData;
// Handle custom form response
}
});
floodgatePlayer.sendForm(form);
}
}, 20L); // Delay for 1 second (20 ticks)
}
}
}
I don't know which Version you are using, so I am guessing the newest.
I think the line SimpleFormResponse response = (SimpleFormResponse) responseData;
is causing the problem.
After looking into the documentation, the way you are setting the ResponseHandler
is deprecated: https://github.com/GeyserMC/Cumulus/wiki/Updating-from-1.0-to-1.1-(and-2.0)#response-handling-changes
The deprecated way may still be implemented, but the lambda function you are using is only returning one String (probably responseData
) and not two (formPlayer, responseData
): https://github.com/GeyserMC/Cumulus/blob/master/src/main/java/org/geysermc/cumulus/Form.java