JDA override method is grayed out - java

I am trying to create a bot that checks if a user attempts to enter a new voice channel, but when trying to override the onVoiceChannelUpdate method, it stays grayed out and gives me error that I don't have the parameters class.
This is the code I have for this method:
#Override
public void onVoiceChannelUpdate(VoiceChannelUpdateEvent event) {
User user = event.getUser();
VoiceChannel oldVoiceChannel = event.getOldVoiceChannel();
VoiceChannel newVoiceChannel = event.getNewVoiceChannel();
if (checkUserVoiceChannelRequest(user, oldVoiceChannel)) {
System.out.println(user.getName() + " has left the voice channel " + oldVoiceChannel.getName() + " and entered " + newVoiceChannel.getName() + ".");
}
}
I tried multiple ways of doing it, but all the methods have the exact same problem. I have some methods from before that check messages and all that and they work, but for any of the other methods that I use, the parameter class is not existent.
Errors showing:
Tried with onGuildVoiceUpdate method also, but it has the same issue:

can you try
public class Test extends ListenerAdapter {
#Override
public void onGuildVoiceUpdate(GuildVoiceUpdateEvent event) {
AudioChannel oldChannel = event.getChannelLeft();
AudioChannel newChannel = event.getChannelJoined();
}
}
Using JDA 5.0.0-beta.2.
If that does not work it might be an issue with your IDE so try to invalidate your cache.

You're looking for the GuildVoiceUpdateEvent instead.
#Override
public void onGuildVoiceUpdate(GuildVoiceUpdateEvent event) {
AudioChannel oldChannel = event.getChannelLeft();
AudioChannel newChannel = event.getChannelJoined();
...
}

Related

Set Home Location - DJI Android Mobile SDK

I've succeeded to add a Marker on Google Maps by using the public void onMapClick(LatLng point).
I stored the value of " point " into a private LatLng mLatLngHOME = point; ( which will be used for the method initFlightController() to set Home location).
private void initFlightController() {
if (isFlightControllerSupported()) {
mFlightController = ((Aircraft) DJISDKManager.getInstance().getProduct()).getFlightController();
mFlightController.setStateCallback(new FlightControllerState.Callback() {
#Override
public void onUpdate(FlightControllerState djiFlightControllerCurrentState) {
djiFlightControllerCurrentState.setHomeLocation(new LocationCoordinate2D(mLatLngHOME.latitude, mLatLngHOME.longitude));
}
});
}
}
private boolean isFlightControllerSupported() {
return DJISDKManager.getInstance().getProduct() != null &&
DJISDKManager.getInstance().getProduct() instanceof Aircraft &&
((Aircraft) DJISDKManager.getInstance().getProduct()).getFlightController() != null;
}
Using a DJI Demo Application (DJIDemoApplication.java & MApplication.java), I created a Broadcast Receiver in the MainActivity.java.
In the Broadcast, I call a method updateFlightController() where I'm displaying some Toast message :
private void updateFlightController() {
if (isFlightControllerSupported()) {
mFlightController = ((Aircraft) DJISDKManager.getInstance().getProduct()).getFlightController();
mFlightController.setStateCallback(new FlightControllerState.Callback() {
#Override
public void onUpdate(FlightControllerState djiFlightControllerCurrentState) {
// TEST
showToast("mLatLngHOME = " + mLatLngHOME);
showToast("Latitude / Longitude = " + mLatLngHOME.latitude + " / " + mLatLngHOME.longitude);
}
});
}
}
The issue is, they display mLatLngHOME = null and Latitude / Longitude = NaN / NaN.
As if in the updateFlightController() method, it stays into a loop
and keep some old values.
Did I miss something ?
This doesn't appear to be an issue with DJI's SDK since the class and points you are using do not originate with DJI's products.
The mLatLngHOME variable is never updated in the onUpdate() method of the FlightController's setStateCallback , so it's definitely keep the old values. Please check the code below for reference:
if (mFlightController != null) {
mFlightController.setStateCallback(new FlightControllerState.Callback() {
#Override
public void onUpdate(FlightControllerState djiFlightControllerCurrentState) {
droneLocationLat = djiFlightControllerCurrentState.getAircraftLocation().getLatitude();
droneLocationLng = djiFlightControllerCurrentState.getAircraftLocation().getLongitude();
updateDroneLocation();
}
});
}
For more details of using DJIFlightController, you can check this tutorial: https://developer.dji.com/mobile-sdk/documentation/android-tutorials/GSDemo-Google-Map.html#locating-aircraft-on-google-map
I had the same issue. It means It can not get the location and I faced with it when I was using DJI Assistant 2 for a simulation drone flight in my room.
To solve it just set a location for your drone in the simulator and also turn off the RTK if your drone has it.
By doing this your problem will be solved.

Bukkit plugin Syntax error, multiple classes

i'm trying to create plugin with multiple classes, but when I type the command in Minecraft, it shows me command syntax error msg (Syntax error! Simply type /ct create.). I think it is silly misstake somewhere, but i can't find it.
My core.java:
public class Core extends JavaPlugin {
public ArrayList<Block> chests = new ArrayList<>();
public boolean createMode = false;
public void onEnabled() {
getCommand("ct").setExecutor(new Commands(this));
getServer().getPluginManager().registerEvents(new Listeners(this), this);
}
}
My Commands.java:
public class Commands implements CommandExecutor {
private Core plugin;
public Commands(Core core) {
this.plugin = core;
}
#Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("ct")) {
sender.sendMessage("lol");
if(args.length > 0) {
sender.sendMessage("hi");
if(args[0].equalsIgnoreCase("create")) {
plugin.createMode = true;
sender.sendMessage(ChatColor.GOLD + "[ChestTreasure] " + ChatColor.RESET + "Now rightclick the chest");
}
} else {
sender.sendMessage(ChatColor.GOLD + "[ChestTreasure] " + ChatColor.RESET + "Too few arguments!");
}
}
return false;
}
}
My plugin.yml:
name: ChestTreasure
description: this plugin...
main: me.sudoman281.chestTreasure.Core
version: 1.0
author: sudoman281
commands:
ct:
description: ...
permission: ct.create
usage: Syntax error! Simply type /ct create.
You have to correctly override the method by having the same exact name and method signature/return type. To do this you must do the following:
Your onEnabled method should be onEnable per the Bukkit API
You should always use the #Override annotation to signify that you are overriding a superclass method. (Optional but highly recommended for finding errors and convention. It will work without this)
Your onEnable should look like this:
#Override
public void onEnable() {
/* Do stuff when plugin starts */
}

Java RMI with JFrame - Get text from client to GUI

Hey i just started with Java, RMI and JFrame about 2 weeks ago.
I'm doing a game, it works fine as a console but now i'm adding a GUI and i'm getting confused about how to get the Remote Client messages to my Text Area
Remote Client Interface
public interface IRemoteClientObject extends Remote {
public void notifyLogin(String player) throws RemoteException;
public void notifyLogout(String player) throws RemoteException;
public void notifyStatus(String player, PlayerStatus status) throws RemoteException;
public boolean challenge(String player) throws RemoteException;
}
Remote Client
public class RemoteClientObject extends UnicastRemoteObject implements
IRemoteClientObject {
/**
*
*/
private static final long serialVersionUID = -7209335248515276286L;
/**
* #throws RemoteException
*/
public RemoteClientObject() throws RemoteException {
}
#Override
public void notifyLogin(String player) throws RemoteException {
System.out.println("\n" + player + " joined the game");
}
#Override
public void notifyLogout(String player) throws RemoteException {
System.out.println("\n" + player + " left the game");
}
#Override
public void notifyStatus(String player, PlayerStatus status) throws RemoteException {
if (status.equals(PlayerStatus.PLAYING))
{
System.out.println("\n" + player + " is now playing");
}
else if (status.equals(PlayerStatus.READY))
{
System.out.println("\n" + player + " is available to play");
}
else
{
System.out.println("\n" + player + " is unavailable to play");
}
}
}
In my program without any GUI, for example when a player login (it sends a message to all players with that notification)
for (Player player : serverObject.getPlayers())
{
player.getClient().notifyLogin(username);
}
But now i don't want that text in the System.out, i want it in a text area
So can anyone make me a description about how to do this?Code is not the most important, i just want to understand how this works from a remote client to GUI (JTextArea)?
I'm not sure exactly what you have already. If the GUI in the picture is already built and you have your JTextArea object created, then just replace the line System.out.println(...) with myTextArea.setText(...) or myTextArea.append(...) depending if you want to keep previous content or replace it.
With my understanding you would have to add a button listener to a button (or a mouse listener for the text box) that would look for a certain keystroke (maybe the enter button) or you could even add a JButton to your GUI that the user would click to "submit" their text in that text area.
In the button listener you would just write something like JTextArea.getText(); (the "JTextArea" would just be whatever you called the text area variable.

Why behaviour stop working with propertyModel inside autocompleteField

In my application I have autocompleteTextField. I need to get id of player when text in input changed. I am trying to play with models which are recommended by this question: using AutoCompleteTextField in wicket without String as the generic type but with no success. Behaviour stop working when I use PropertyModel or when I set class Player.class instead of null. I dont understand why.
final AutoCompleteTextField<Player> playersField = new AutoCompleteTextField<Player>("players",
new Model<Player>(selectedPlayer), null, new AbstractAutoCompleteRenderer<Player>() {
#Override
protected void renderChoice(Player player, Response response, String criteria) {
response.write(getTextValue(player));
}
#Override
protected String getTextValue(Player player) {
return player.getName() + " " + player.getSurname() + " "
+ player.getPlayerDiscriminator();
}
}
, settings) {
#Override
protected Iterator<Player> getChoices(String prefix) {
List<Player> choices = getPlayers();
return choices.iterator();
}
};
add(playersField);
playersField.add(new AjaxFormComponentUpdatingBehavior("onchange") {
#Override
protected void onUpdate(AjaxRequestTarget target) {
System.out.println("do something");
// All I need here is just Id of player
}
}
});
From the question you linked to:
You probably already know this but if your custom class is really custom, you'll also need an IConverter that handles the String<->Someclass conversions: you can either register it with the application or override your component's getConverter(Class clazz ) method to return it.
Did you do that?
Also, if this doesn't fix the problem, please describe how it "stops working" in more details.

SMack API in java

public void processMessage(Chat chat, Message message) {
if (message.getType() == Message.Type.chat)
System.out.println(chat.getParticipant() + " says: "+ message.getBody());
**processmsg** = message.getBody();
System.out.println("Message from Friend -----:"+**processmsg**);
}
Hi.how to use this processmsg String in another method.if i use outside this method i get null value. plz reply soon
Store processmsg as an instance variable in the class that contains processMessage
class Foo {
private String processmsg;
public void processMessage(Chat char, Message message) {
processmsg = message.getBody();
}
public void bar() {
// do whatever you want
}
}
Obviously you'll need to check that it's been assigned and so on before you use it (e.g. you couldn't use bar before processMessage), but you get the idea!

Categories