Help with something

Discussion in 'Spigot Plugin Development' started by IllegalSloth, Jun 12, 2017.

  1. Im making a XP system where you get 6 or 7 Mining XP if you mine a coal ore.
    If you reach a cirtan amount then something will happen..

    So what would i need to do

    - What i need: Something like
    Code (Text):
    p.addexp(100) - Example
    Code (Text):
    p.getExp
     
  2. If you want to add experience to your player, you can do it with
    Code (Text):
    player.giveExp(100)
    // Or if you want to add levels you can do
    player.giveExpLevels(2)
    and if you want monitor level changes you can use the PlayerLevelChangeEvent
     
  3. No i want a custom system.
     
  4. What do you mean by 'a custom system'? What's wrong with the.. eh.. Bukkit API's "system"?
     
  5. A system wich will give them an interger of XP not a minecraft XP system
     
  6. BockBreakEvent {
    when player breaks coalore {
    get xp from config + 6
    save the config
    }
    }
     
  7. So... Where is the problem then?

    Create a custom class with custom properties. (Well a Integer is enough maybe)
    Make methods to access and modify them and create a HashMap (e.g HashMap<UUID, CustomClass>) where you store the mining experience for each player.
     
  8. Code (Java):

    Plugin pl;

    @EventHandler
    public void blockBreakEvent(BlockBreakEvent e) {
        Block b = e.getBlock(); //b is the broken block this can be any block so we need to check if it was a COAL_ORE.
        Player p = e.getPlayer(); //The player who broke the block.

        if(b.getType() == Material.COAL_ORE) { //Let's check if the block the player broke was a COAL_ORE and if it is COAL_ORE add the xp
            int xp = pl.getConfig().getInt("Players." + p.getName() + ".xp"); //Integer xp is the curent XP value in the config file.
            pl.getConfig().set("Players." + p.getName() + ".xp", xp + 6); //We set the xp level with xp + the 6 new xp;
            pl.saveConfig(); //Don't forget to save the config!
            return;
        }
    }
     
    if you save your stuff in a config you can try this.
     
    #8 Rob.pizza, Jun 12, 2017
    Last edited: Jun 12, 2017
  9. Mas

    Mas

    Thanks for spoonfeeding the OP, I'm sure they'll learn a lot.

    /s
     
    • Agree Agree x 3