I'm having troubles with Gamepad Support.
try // to create the Controllers
{
Controllers.create();
}
catch(Exception exep)
{}
int allControllers=0;
allControllers=Controllers.getControllerCount(); //finding out how much
//of it do we have
It says that I have 3 Controllers.
But the Gamepad is the Controller number 0.
Because when I poll n1 or n2 Controller -- game just crashes.
Does anyone knows hot to automatically pick working gamepad from this list and evade the Crash?
Looks like nobody else can do it. I've been working on it for good, and there is only one solution so far. Here it is:
for(int co=0;co<allControllers;co++)
{
gamepad = Controllers.getController(co);
GamePadName=gamepad.getName();
if(GamePadName.charAt(0)!='H' && GamePadName.charAt(0)!='U')
Keys=checkGamepad(Keys);
}
There are two controllers that can't be polled. On some PC's they are called "HID something", on other they are called "USB Keybord", "USB Mouse". Maybe on other PC's they will be called in other way. So we are not polling these Controllers, and game is not crashing... seems to be a bad solution, but I see no better.
Related
I am creating a Minecraft server using minestom which is a server building library, it had so no code and you have to make everything yourself. So im trying to make it so players can place water but it doesnt work sometimes. If im falling and place it then it gets placed client side but not server side sometimes, when its placed server side it says "placed block" in the chat.
globalEventHandler.addListener(PlayerUseItemOnBlockEvent.class, event -> {
final Player player = event.getPlayer();
if (event.getItemStack().getMaterial() != Material.WATER_BUCKET) {
return;
}
if (player.getInstance().getBlock(new Vec(event.getPosition().x(),
event.getPosition().y(),
event.getPosition().z())) == Block.IRON_BLOCK
&& event.getBlockFace().normalY() == 1) {
Point placedPos = event.getPosition();
placedPos.withX(placedPos.x() + event.getBlockFace().normalX());
placedPos.withY(placedPos.y() + event.getBlockFace().normalY());
placedPos.withZ(placedPos.z() + event.getBlockFace().normalZ());
player.getInstance().setBlock(placedPos, Block.WATER);
player.sendMessage("placed water");
}
player.getInventory().update();
});
Video - Ignore the platform disappearing, bug that I know how to fix but havent just yet but that also only happens when the water is placed server side too
https://youtu.be/njH58gbXPlE
I believe on the look vector is the next tick’s look vector for placing water, but the server hasn’t gotten this new look vector so it uses the old one
I am working on a spigot 1.8 plugin that manages permissions. The problem is when a staff member joins the server lags for about 10 seconds and they wait in the login screen for a while, but if normal players join they join instantly and don't lag.
I managed to limit it down to the method that removes permissions that are denied to the user.
My methods are
public void removePermission(String permission){
for (PermissionAttachmentInfo paInfo : getEffectivePermissions()) {
if (paInfo.getAttachment() != null && paInfo.getAttachment().getPlugin().equals(ServerCore.getPlugin())) {
paInfo.getAttachment().unsetPermission(permission);
paInfo.getAttachment().setPermission(permission, false);
}
}
}
public Set<PermissionAttachmentInfo> getEffectivePermissions(){
return player.getEffectivePermissions();
}
Is there a better way to remove permissions from users without causing so much lag?
I don't have much experience in permisison plugins, but when you remove a permission, you should just use unsetPermission, don't use setPermission.
The removePermission() method should NOT be called on the player join event, so I suggest posting that code instead of the method you posted.
Also, getEffectivePermissions() is just a useless method, if a method is less than one line its better to just delete it or make it a variable.
When making the application full screen with the following call:
Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
I no longer have signals from my controller. The issue is not solved by changing the display back from full screen like:
Gdx.graphics.setWindowedMode(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
I'm using Gdx version: 1.9.8. It appears this was an issue fixed in a previous version, but I'm not sure what the necessary steps are to get the work around functioning.
Here's some posts I found about the issue:
https://github.com/libgdx/libgdx/issues/4723
https://github.com/GoranM/bdx/issues/518
(this one is old) http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=10692
Any help is much appreciated.
*Edit: This is using the controller extension that can be checked from the libgdx set up application. *
Edit2: I can get a responsive controller if I re-poll the controllers like the following:
Array<Controller> controllers = Controllers.getControllers();
However, this cannot be done instantly after changing the display mode; I have to wait some amount of time after. I'm not sure what I need to poll to determine how long I have to wait until the controller instances are valid (also, when it is valid to assign a listener).
Edit3: The only solution I've been able to come up with is to set a flag inside the resize callback like the following
#Override
public void resize(int width, int height) {
resizeDirty = true;
resizeTimestamp = System.currentTimeMillis();
}
Then in my main loop call:
private void controllerCheck() {
if (resizeDirty) {
long currentTime = System.currentTimeMillis();
if (currentTime > resizeTimestamp + controllerResetDelay) {
resizeDirty = false;
//get new controller instance | re-add a controller listener
}
}
}
This isn't ideal, I'd rather find a way to listen to when the change in context is done initializing then update the controllers. But I haven't been able to find a hook for that. I'd appreciate it if anyone knows a better way to go about maintaining controllers with change in display mode.
Why don't you try to use the immersive fullscreen?
If the objective is to set the fullscreen mode, I think this is the better way to.
Hi any one help me on this.
I am new to Swing based applications. Actually in my application using IVisualExecutionContext interface to show the long-drawn processes and
I've created 2 to 3 IVisualExecutionContext objects and resetting on top of
previous one. In reset method if I put JProgressBar.setValue(0) progress bar
getting struck and if I make that 0 to 10 it never strucks. Let me know what is
the difference between JProgressBar.setValue(0) and JProgressBar.setValue(10).
sample code :
IVisualExecutionContext veCtxt = view.getVisualExecutionContext();
if (veCtxt != null) {
veCtxt.reset();
veCtxt.setMessage(" ");
}
i'm somewhat new to jinput and java in general and was wondering, what's the easiest way to set up multiple xbox 360 controllers (particularly 4) with jinput? currently, i'm currently going off of theuzo007's tutorial on jinput with controllers, and have a basic working controller setup going on. it would be fantastic if i could set what controller moves certain entities around. (i'm using my friend's homemade library, just so you know.)
screenshot -
http://imgur.com/a/1Ocu5
top one is the main block of code, last one is the header (sorry for putting them in the wrong order, imgur does that sometimes!)
if anyone could help me out, that would be great, thanks!
edit: if there's no possible way to do it, if anyone could try to reccomend a new library to me, that would be cool.
There is a possible way
That tutorial is pretty good. Furthermore, I think you can do the 4 controllers stuff by copy-pasting some code inside the zip theuzo007 provides you and a bit more. By the way, that page that you liked says that there is a better version of that tutorial where you can download an also better version of his code -> theuzo007's JInput tutorial V2
Once you download the code you can see that in JoystickTest.java there is a method called searchForControllers() that you can put (With the corresponding private ArrayList<Controller> foundControllers; as field) in a class called ControllerChecker or some cooler name. Make them all static and you will get something like this:
public class ControllerChecker {
private static ArrayList<Controller> foundControllers = null;
/**
* Just used for checking all available controllers.
*/
private static void searchForControllers() {
Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers();
for(int i = 0; i < controllers.length; i++){
Controller controller = controllers[i];
if (
controller.getType() == Controller.Type.STICK ||
controller.getType() == Controller.Type.GAMEPAD ||
controller.getType() == Controller.Type.WHEEL ||
controller.getType() == Controller.Type.FINGERSTICK
)
{
// Add new controller to the list of all controllers.
foundControllers.add(controller);
// Add new controller to the list on the window.
window.addControllerName(controller.getName() + " - " + controller.getType().toString() + " type");
}
}
}
/**
* Returns null if there is no controller available. Otherwise, it retrieves the last controller in the list by removing it.
*/
public static Controller getController() {
if(foundControllers == null) {
foundControllers = new ArrayList<Controller>();
searchForControllers();
}
return foundControllers.size() == 0 ? null : foundControllers.remove(foundControllers.size() - 1);
}
}
You would use the static method getController() to make the players have a different controller, checking if the returned controller is null, meaning that there is no available controller. Also you can change my code and check for controllers everytime you ask for one, but you have to check if the controller is already in use.
I hope this helps you in your purpose. This solution just checks for all available controllers and returns then in the last order it found them (maybe using a Stack is more efficient). But probably you will want more functionality like being able to tell the program to select a specific controller by pressing a button, maybe in a screen that says "Please, connect your controller and press any key/button". This can be achieve easily if you understand theuzo007's code (the JoystickTest.java has a lot of useful lines!).
Also you can make some mechanism to detect unpluged controllers and just by plugging in them again the system recognize it. Maybe there is some controller id, I haven't found it yet.
Finally, there is more code here.