[LIB] CharacterLibrary - Add special customizeable skills to players!

Discussion in 'Resources' started by NonameSL, Jul 9, 2014.

Thread Status:
Not open for further replies.
  1. Offline


    <font color="#0000ff">Character</font><font color="#333399">Library <font color="#00ccff">V1.1</font></font>
    <font color="#333399"><font color="#00ccff">~-~-~-~-~-~</font><font color="#3366ff">-~-~-~-~-~-</font><font color="#0000ff">~-~-~-~-~-~</font><font color="#000080">-~-~-~-~-~-~</font>-~</font>
    <font color="#008000">Contents:</font>
    1. <font color="#003300">What is CharacterLibrary?</font>
    2. <font color="#003300">News</font>
    3. Usage
    4. How to add your own ActionTrigger
    5. <font color="#339966">Source Code</font>
    6. <font color="#00ff00">Download & Adding CharacterLibrary to your plugin</font>
    7. <font color="#33cccc">FAQ</font>

    <font color="#ff6600">What is CharacterLibrary?</font>
    CharacterLibrary is a library created to make people have special skills activated on actions. By creating a MyCharacter, with a bunch of skills that are defined in CharacterActions and the action is definded by an ActionTrigger, which can define almost every action - player click, player sneak, player throw egg, item drop, hit by entity, splash potion, and much much more!

    <font color="#993300">News</font>

    <font color="#000000"></font>
    <font color="#000000"></font>
    <font color="#993300"></font>

    <font color="#ff0000"> Usage </font>

    2. import me.NonameSL.CharacterLibrary.CharacterLibrary.*;
    3. //Creating a character named "Egg Master" with 50 max health.
    4. MyCharacter myCharacter = new MyCharacter("Egg Master", 50);
    5. //Adding a skill that will activate on egg throw
    6. myCharacter.addSkill(new CharacterAction(){
    8. @Override
    9. //Every action has a following event. For a full list, look below. EGG_THROW is PlayerEggThrowEvent
    10. public void onCharacterAction(Player player, Event e) {
    11. //Casting the PlayerEggThrowEvent to the event
    12. if(!(e instanceof PlayerEggThrowEvent))return;//Just in case!
    13. PlayerEggThrowEvent eggEvent = (PlayerEggThrowEvent)e;
    14. //Getting the egg
    15. Egg egg = eggEvent.getEgg();
    16. //Messing with the egg a bit
    17. Cow cow = (Cow) player.getWorld().spawnEntity(egg.getLocation(), EntityType.COW);
    18. egg.setPassenger(cow);
    19. //Now we have spawned a cow to ride on the egg. Cool!
    20. //We can also save the egg in an egg list, and then call an event where the egg is hit, make it explode!
    21. }
    23. }, ActionTrigger.EGG_THROW);
    24. //Now that we added the skill, and we can add much more, we pack things up with the PlayerCharacter class.
    25. PlayerCharacter playerCharacter = new PlayerCharacter(p, myCharacter);
    26. //Now, the player is the character. Lets add all skills from the myCharacter using:
    27. playerCharacter.addAllSkillsFromSuper();
    28. //Or just add skills that have a certain actiontrigger.
    29. playerCharacter.addSkillToCharacter(ActionTrigger.EGG_THROW);
    30. //This will only add the actions that are with egg_throw.
    31. //We can register the skills using:
    32. playerCharacter.registerSkills(Main.getInstance()/*A Plugin object*/);
    33. //Now we can have a little fun, and set the players display name into a special one:
    34. playerCharacter.addSpecialDisplayName();//The player's display name is now [<Character name>]<Player Name>
    35. //And set the player list name to [<Character name>]<Player Name>
    36. playerCharacter.addSpecialPlayerListName();
    37. //And then send the player a message:
    38. p.sendMessage(ChatColor.BLUE+"Try to throw an egg and see what happens!");

    <font color="#339966">How to add your own ActionTrigger</font>

    <font color="#000000">Got an idea for a custom ActionTrigger that isn't in the code? What you should do is comment in the topic your ideas and I will add them in the next version.</font>
    <font color="#000000"> But in the meanwhile, you can create your custom ActionTrigger.</font>

    8. Go to the ActionTrigger in the source, and add your action name to the enum:
    9. Now, after you added your ActionTrigger, go to the CharacterListener, and create a new event with the name of your ActionTrigger, with the event of it. Lets say you are adding a BOW_SHOOT (which is already added :p), then the proper event will be EntityShootBowEvent. If your event isn't a player-related event, then validate what is suppose to be the player, like in the BOW_SHOOT, The entity needs to be instanceof Player. Your code should look like this:
    1. @EventHandler
    2. public void MY_NAME(EntityDoSomethingEvent e){
    3. if(!(e.getEntity() instanceof Player))return;
    4. Player p = (Player)e.getEntity();
    5. }

    10. Now, we need to check that the player doing the action is indeed the PlayerCharacter we are talking about.
    11. Next, we want to declare the CharacterAction of our custom actiontrigger:
    CharacterAction ca = (CharacterAction)ch.getSuperCharacter().getSkills().get(ActionTrigger.MY_NAME);
    12. Now, lets run the action!
    ca.onCharacterAction(p, e);
    13. Congrats! You now have your very own ActionTrigger!

    <font color="#ff6600">Source</font>

    CharacterLibrary.java - http://pastebin.com/CtXtZDBb
    <font color="#ffff00">Download & Adding the library to your plugin</font>
    <Edit by Moderator: Redacted mediafire url>
    <font color="#000000">To add the library to your plugin, follow these steps:</font>
    14. <font color="#000000"><font color="#000000">Add this to your plugin:</font></font>
    1. public boolean validateCharacterLibrary(){
    2. return getServer().getPluginManager().getPlugin("CharacterLibrary") != null;
    3. }

    15. If the plugin needs the library to work:In your onEnable(), check if(validateCharacterLibrary()), and if so - cancel the plugin. If the plugin needs the library only for certain features: In the features that do require CharacterLibrary, check if(validateCharacterLibrary()), and if so - return the method, and send a message that the plugin is not in the server. Also, if you want, you can broadcast to the server in the onEnable() that the plugin is not in the server.
    16. In your plugin.yml, add this:(If the plugin needs the library to work) depend: [CharacterLibrary] (If the plugin needs the library only for certain features) softdepend: [CharacterLibrary]

    <font color="#99cc00">FAQ</font>
    Q: <font color="#0000ff">I found a bug! What do I do?</font>

    A: <font color="#0000ff">Just send me a private message, or comment the bug in the topic, and I will fix it as soon as possible.</font>

    <font color="#0000ff"></font>

    Q: <font color="#0000ff">I created my own ActionTrigger, but now it isn't working!</font>

    A: <font color="#0000ff">Make sure you added the @EventHandler annonation, and the event is the proper one. If you can't find the problem - send me a private message.</font>
    Last edited by a moderator: Nov 2, 2016
  2. Offline


    Looks cool, waiting to check out the code. This could be very usefull to add some RPG elements to my servers.
  3. Offline


    I'm glad you think so. I uploaded the 4 java files (in pastebin currently), but you can always download the file, put it in your build path and use it .
  4. Offline


    NonameSL no maven? ;( will try it anyways when I have time.
  5. Offline


    I like the idea of for a small interface ...
    A good addition for my DragonSkills plugin ;)
Thread Status:
Not open for further replies.

Share This Page