Temp bans and player's UUID

Status
This thread has been locked.

EpicFooF

Digital Artist
Premium
Feedback score
13
Posts
1,438
Reactions
520
Resources
2
Hello everyone!
I am currently creating a new plugin (I am pretty new to this).

I need a li'l help.
So I am creating a plugin which bans and kicks and all those stuff.
I got stuck when I tried to temp ban someone, I dont really know how to do it temporary.
So if you know, please right it down.

In addition, I'd like to know how to ban player's UUID and not his name. how do I do it?
This is how I made the target: https://gyazo.com/e175973b877cbd48d64b3f5b1fb11f86

Thanks for everyone who will help me.
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

EpicFooF

Digital Artist
Premium
Feedback score
13
Posts
1,438
Reactions
520
Resources
2
Temporary Bans
1)
Store the current time in the data file with System.currentTimeMillis()
2) Get the time of the ban end time by converting however long the ban is to milliseconds and adding that with System.currentTimeMillis()
3) Store the end time of the ban
4) When a player joins the server, check if the end time of the ban is less than the current time (not the time when the player was banned) if it is remove the ban, and if you want to set the end & start time in the data file to 0.

UUIDS
1)
Get a player's UUID with #getUniqueId()
2) If you're trying to use it for something like data storing (which is what you would use), convert it to a string using #toString()

Additionally
If you want to get the remaining time of a ban here's how.
1) Find the difference between the ban end time and the current time (Make sure the end time is more than the current time)
2) Use the code snippet below to get the remaining time in hh:mm:ss format and split the string with ":"
3) Index 0 of the String[] is hours, 1 is minutes and 2 is seconds

Code:
public static String convertMS(Long millis) {
        String hms = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(millis),
                TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)),
                TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));
        return hms;
    }

Code:
long currentTime = System.currentTimeMillis();
                            long endTime = plugin.getConfig().getLong("End-Time");
                            long remainingTime = endTime - currentTime;
                            String[] calculatedTime = Misc.convertMS(remainingTime).split(":");

                            sender.sendMessage(Messages.remainingTime.replace("%world%", args[0]).replace("%hours%", calculatedTime[0]).replace("%minutes%", calculatedTime[1]).replace("%seconds%", calculatedTime[2]));
                            return true;

Let me know if you have any issues or don't understand the code I provided you, I don't want to spoon feed you so if you don't understand tell me and I'll happily explain it.​
Change player.getName(). to player.getUniqueId().

As said above, you need to set it so it stores the tempban data in a sb and ten when the player tries to join you make it call on that and if it's at 0 it changes the players status to setBanned(false).

Feel free to correct me if I'm wrong, I'm new to this too :p
Thank you guys.
But I dont understand where do I write the "getUniqueId()". Can you please rewrite the line so I can copy it into the code?
 

Satan

Devil#0666
Supreme
Feedback score
52
Posts
3,667
Reactions
1,442
Resources
0
What the devs or code experts are saying is that you want UUID but you are currently using usernames with the getName() method. You need to use getUniqueId as that is UUID (Unique user id) or something like that.
 

Satan

Devil#0666
Supreme
Feedback score
52
Posts
3,667
Reactions
1,442
Resources
0
Not when you're identifying who the target is.. You'd use it like this: player.getUniqueId().setBanned(true).

If you go to your code, you'd find that you probably use something like this rn: player.getName().setBanned(true).

If you want to be spoon-fed code, gtfo because no one will do that for you. You can't learn to code if we are doing it all for you.[DOUBLEPOST=1481658955][/DOUBLEPOST]
YW, if you need any further help, PM me.
I'm sure there are many spoon feeding forums that are nicer. honestly, spoonfeeding isn't bad as long as you learn every line by line. Just like javadocs (or code documentation if you wanna be general)
 

EpicFooF

Digital Artist
Premium
Feedback score
13
Posts
1,438
Reactions
520
Resources
2
Not when you're identifying who the target is.. You'd use it like this: player.getUniqueId().setBanned(true).

If you go to your code, you'd find that you probably use something like this rn: player.getName().setBanned(true).

If you want to be spoon-fed code, gtfo because no one will do that for you. You can't learn to code if we are doing it all for you.[DOUBLEPOST=1481658955][/DOUBLEPOST]
YW, if you need any further help, PM me.
Its says that the setbanned method is undefined for the type UUID
 

Satan

Devil#0666
Supreme
Feedback score
52
Posts
3,667
Reactions
1,442
Resources
0
finding random code on the internet and telling myself what each attribute does
is equal to
C n P it then continue on his merry way (no offence intended).

That's the only case where "spoonfeeding" is okay. I get your point, just wanted to make this distinction.
 

EpicFooF

Digital Artist
Premium
Feedback score
13
Posts
1,438
Reactions
520
Resources
2
It's bad when you don't know how to code and are asking people to write code so you can copy it in. I honestly learnt to code by finding random code on the internet and telling myself what each attribute does, but he won't be able to do that as he'll probably just C n P it then continue on his merry way (no offence intended).
I am still learning and I find it the best way to do it. I watched some youtube videos but not all of my questions are being answered by youtube. this is why i came to here
 
Status
This thread has been locked.
Top