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.
Related
I need to finish an application when it goes to the background, I'm using method finishAffinity() but it seems it does not work, someone can tell me another alternative
#Override
protected void onPause() {
finishAffinity()
super.onPause();
}
Here's answer
finishAffinity() is not used to "shutdown an application". It is used to remove a number of Activitys belonging to a specific application from the current task (which may contain Activitys belonging to multiple applications).
Even if you finish all of the Activitys in your application, the OS process hosting your app does not automatically go away (as it does when you call System.exit()). Android will eventually kill your process when it gets around to it. You have no control over this (and that is intentional).
you can use this
public void endTask() {
// Is the user running Lollipop or above?
if (Build.VERSION.SDK_INT >= 21) {
// If yes, run the fancy new function to end the app and
// remove it from the task list.
finishAndRemoveTask();
} else {
// If not, then just end the app without removing it from
// the task list.
finish();
}
}
Source and read more
For an xpage-application with java beans i need to check if a certain user(not current user) has reader-access to a document. All acceslevels above (Database ACL, XPage ACL...) can be taken for granted. Current User is always at least author.
Each document has one readerfield "readers" and three authorfields "creator","authors","AdminAuthor", last can be ignored,since it always only contains "[Admin]" for every document
Current idea is to get the groups of the user like showed here(Determine all groups for a defined user), loop through them and compare to the reader and author fields field content
Why i don't like it:
use of an undocumented API
horrible performance
Is there any better way to do so? Especially with nested groups in mind, so $ServerAccess view is not really an option.
Current code:
public boolean isReader(String notesName, String documentID){
try {
Vector<String> readers= getAllReaderFieldsValues(documentID);
if(readers.contains(notesName)){
return true;
}
lotus.notes.addins.DominoServer server = new lotus.notes.addins.DominoServer(DominoUtils.getCurrentSession().getServerName());
for(String group:(Vector<String>)server.getNamesList(notesName)){
if (readers.contains(group)){
return true;
}
}
} catch (NotesException e) {
//ErrorHandling
}
return false;
}
Thanks for any help
There are different ways to check if a user has access to a document, but all of these are undocumented (but still useable since a decade), so they won't fit your requirements (i.e. running in a different user context or a special view with a "$C1$" column, ...)
A "documented" way to do what you want is just to add a user to a reader field, if his name is not already in the list. There is no need to check if the user has access or not.
I still wondering about your scenario, because I don't understand what you are trying to realize: You are checking if a user is in a specific group which gives him access to a document. If the user is in one of these groups, you skip his name.
In the meantime, the user is removed from the group, and has no longer access to the document...
Why not working with groups or roles? No coding, just administration. Are you fixing organizational problems?
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.
I am currently trying to enhance the To-Do List tutorial from Play framework's website. I've added a login form, (and of course a User class acting as a model), and it works perfectly well. I also made a small "dashboard" in which the logged user is able to change his password and his email address. But when I submit the form, I get a "Datasource user is null ?" error (RuntimeException).
The whole problem came when I wanted to restrict the edition possibilities (I first used a whole User form, which is quite over the top (User do not need to edit their ID). So I made a small inner class in my Application file called UpdateUser which gathers the required informations, just as I did for the login system.
Searching this error gave me many results but people saw their problem fixed by uncommenting the ebean.default line in the conf file, which I already did.
Here is the method I used to update user's informations :
Firstly, I made a small class in my Application to hold the form (exactly like I did for the login thing).
Then I made a update function as found here in my user class :
public static String update(String id, User newuser) {
newuser.update(id);
return("Your profile has been updated");
}
which returns the String that will be in my flash and which is according to my compiler the problem function.
This function is called in my Application like this :
public static Result updateUser(String id)
{
Form<UpdateUser> filledForm = updateUserForm.bindFromRequest();
System.out.println("Updated User : "+filledForm.get().id);
if(filledForm.hasErrors())
{
flash("success","Error while updating");
}else{
User user = new User(filledForm.get().id, filledForm.get().email, User.find.byId(filledForm.get().id).name, User.find.byId(filledForm.get().id).surname, filledForm.get().password);
flash("success", User.update(id,user));
}
return redirect(routes.Application.dashboard());
}
I tracked the data in the Form and it is not null (I mean I can get everything from the form). But I wonder if I have to create another ebean or if it's my function which is wrong. I also wonder if it's not my User creation that fail. Or maybe I should take the updateUser function and put it in my inner UpdateUser class ?
I have to admit that I worked on that all of yesterday (and probably today too), and I can't find anything on the internet except the ebean.default thing.
------EDIT
I continued to search, so here's what I tried :
1) Getting the form result into an instance of UpdateUser in order to use it
2) Use this instance instead of getting the data from the form
But it failed too. What's really weird is that I've added a toString() method for User class, and calling it on the user I want to insert (as an update) gives me the full stuff. I think it must be a configuration problem, but I can't see it.
Another thing : when I come to the error page and when I try to come back to the application by modifying the URL, I am disconnected. Is it my ebean that closes himself ?
Last edit for the day, I'm getting tired of this. I tried to delay the action (i.e. making it happen after the user has logged out), the new data are correctly saved but I still get the error when calling the update function.
Alright, I finally found it, but totally by chance.
I just had to write this :
public static String update(String id, User user) {
user.update((Object)id);
return ("Your profile has been updated");
}
Because for some reason that I don't really understand, The id String needs to be cast to Object. The rest of the code was correct. But apparently, when using update() on this particular case (is it because my id is a String or because I get the informations from another class before using it as my Model), the parameter which is supposed to be a String (even in the documentation) HAS to be cast.
That's it.
I have a button in my program that, when pressed, is supposed to take you to my wiki page about the program. I used the following line to do so:
java.awt.Desktop.getDesktop().browse(new java.net.URI("http://supuh.wikia.com/wiki/BHT"));
The problem is that, no matter what environment in which the program is run, I always get the following error:
java.security.AccessControlException: access denied (java.awt.AWTPermission showWindowWithoutWarningBanner)
does anyone know how I can fix this? Note that this only works in the one program. Any other program I make can use the same method with no problem.
Exit hook
At the start of my program, this hook is added. The program runs fine without it...
System.setSecurityManager(new SecurityManager()
{
#Override
public void checkExit(int status)
{
closeFile(status);
}
});
this hook is needed, but the browse(URI uri) method in question won't work with it. Solutions?
This means you are running with a security manager:
SecurityException - if a security manager exists and it denies the AWTPermission("showWindowWithoutWarningBanner") permission, or the calling thread is not allowed to create a subprocess; and not invoked from within an applet or Java Web Started application
If this is an applet, or a Java Web Start app - sign your jar.
Update Adding a security manager to detect program exit is wrong. There are multiple ways to do this properly. In your case I guess this would be most appropriate:
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
#Override
public void run() {
closeFile();
}
));
Swing-specific solutions are:
if you don't have to perform extra actions, use frame.setDefaultCloseAction(Frame.EXIT_ON_CLOSE)
use addWindowStateListener and check for WindowEvent.WINDOW_CLOSED
That said, two notes:
you must not hold files open for a long time. Use try/catch/finally to open and close them whenever they are needed.
if you really need a security manager at some point, make sure you override the appropriate method of the SecurityManager that checks whether you can open the link. (won't tell you which one, so that you are not tempted to jump onto this solution, which is wrong)
To summarize, I'd go for setDefaultActionOnClose, and close each file right after I finish reading/writing it.
Update 2: After you linked to your original question describing what exactly are you trying to achieve, things change a bit. You are trying to prevent exit, so you do need a SecurityManager. This makes it so that you should override the checkPermission method and do nothing there (i.e. don't throw exceptions), at least when these permissions are checked (they are checked when browse is called):
new AWTPermission("showWindowWithoutWarningBanner")
new FilePermission("<<ALL FILES>>", SecurityConstants.FILE_EXECUTE_ACTION)
Update 3 Here's how exactly to override the method:
#Override
public void checkPermission(Permission permission) {
if (permission instanceof AWTPermission) {
if (permission.getName().equals("showWindowWithoutWarningBanner")) {
return;
}
}
if (permission instanceof FilePermission) {
if (permission.getActions().equalsIgnoreCase("execute")) {
return;
}
}
java.security.AccessController.checkPermission(permission);
}
(you can go without the outer if-s)
Update 4 The above method will work only if you have given permissions to your program. Otherwise it is a not-well documented behaviour of the JVM that overriding security managers are not allowed to be unprivileged. Take a look at this report - the comments say how to work it around.
To make your life simpler, you can simply #Override public void checkPermission(..) with an empty method body.
Instead of using your own SecurityManager, install a shutdown hook instead:
Runnable runnable = new Runnable() {
closeFile(status);
}
Runtime.getRuntime().addShutdownHook(new Thread (runnable, "Close file"));