Tutorial Make a custom player wrapper, Just like Essentials!

Discussion in 'Resources' started by TheEnderCrafter9, Aug 25, 2016.

?

Was this helpful?

  1. Yes :D

    5 vote(s)
    100.0%
  2. No D:

    0 vote(s)
    0.0%
Thread Status:
Not open for further replies.
  1. Before the tutorial begins, I will answer a couple of questions:

    QUESTION: How do Wrappers work?
    ANSWER: Wrappers are classes that use constructors to hold on to a certain Object, then add new functionality. Essentially, you will make a wrapper class that needs a player to be defined, and from their, use a file system (by that I mean configs) just Like Essential's playerdata folder.

    QUESTION: Alrighty, should I store uuids or player names?
    ANSWER: Always uses uuids. Unless you are trying to actively discourage name changes because of some akward reason, store uuids.

    QUESTION: How long will this take?
    ANSWER: It really depends on who you are. If you copy & paste the code, 3 minutes. If you read it carefully and learn, 30 minutes at most.

    First of all, we will be using this class:
    http://hastebin.com/etidizuqis.avrasm

    With this class, you will be able to write the user class without using hashmaps and such.

    There are three things you need to do before actually making new functions for the user:

    [iron]1[iron] Making and assigning the playerConfig, the player and uuid.
    [gold]2[gold]Making the constructor check if the paths needed for the objects are NOT null
    [cookedmeat]3[cookedmeat]Actually making the variables

    So, the most basic constructor and a boolean I will be using is the popular isDank() and what this will do is when we /dank the all players online will be checked if the are dank. If not, they will be killed :D.

    User class:
    upload_2016-8-25_11-26-14.png
    Next, we do a foreach loop (for (String s: String[]) ) for players and player. Then we make a new user from the player, check if is dank. if not dank, we kill the player.

    Code:java
    1.  
    2. for (Player p: Bukkit.getOnlinePlayers()) {
    3. User u = new User(p);
    4. if (!u.isDank()) {
    5. p.setHealth(0.0);
    6. p.sendMessage("The system detected you were not dank.");
    7. }
    8. }
    9.  
     
  2. Offline

    ChipDev

    Isn't it a HBRUser? :p
     
  3. Why not? It can be whatever you want it to be. Unless it is offensive, then the cops will come.
     
  4. Offline

    xXkguyXx

    Nice idea. I personally don't like to read from the config EVERYTIME I need to get something.
     
Thread Status:
Not open for further replies.

Share This Page