/level [Simple]

Discussion in 'Archived: Plugin Requests' started by MarcuzEssence, Mar 28, 2012.

  1. Offline

    MarcuzEssence

    Hey! Is anyone able to please build this simple plugin? :)

    Levels Plugin - Display yours and others level used for enchanting via command

    /level <name> (Shows the Players current level)

    /level top (Shows the top 5-10 Players levels on the server, offline and online)

    Thank you very much, I hope someone is able to create this :D
     
  2. Offline

    luke100

    hmm sould be easy, gonna try to code it in the 25 miutes i got=)

    ok nearly ready, will send it to you later if it works

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
    MarcuzEssence likes this.
  3. Offline

    stuntguy3000

    Haha i love how you did it in 25 min :D

    (Also could you post the source, it would provide a educational resource to many :))
     
  4. Offline

    MarcuzEssence

    Thank you, I love how this community is so friendly and helpful! :D


    "Also could you post the source, it would provide a educational resource to many :) "

    Including me :p
     
  5. Offline

    luke100

    ok the plugin is written i only have to wite the plugin.yml and one litte idea i got to improve, the prob, i really need to learn for my final exams so please be patient=) ill do it as soon as possible=)

    This is the code so far, i get no errors the only problem is that the server kinda trolls me and telling me im not instance of player but instance of CraftPlayer which is not included in bukkit ...so i loled and dont have any idea how to fix this ill try to find a solution
    PHP:
    package me.scharnhorst.explevel;
     
    import java.util.Arrays;
    import java.util.Collection;
    import java.util.LinkedList;
    import java.util.List;
    import java.util.TreeMap;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Server;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
     
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class explevel extends JavaPlugin {
     
    private TreeMap<Float, Player> exmap;
     
    @Override
    public void onEnable() {
     
    }
     
    @Override
    public void onDisable() {
     
    }
     
    public boolean onCommand(CommandSender sender, Command command,
    String label, String[] args) {
     
    if (sender instanceof Player) {
     
     
     
    Player player = (Player) sender;
     
    if (command.equals("level") && player.hasPermission("exp.own")) {
    float f = player.getExp();
    String exp = String.valueOf(f);
    player.sendMessage(exp);
    return true;
    } else if (command.equals("leveltop")
    && player.hasPermission("exp.top")) {
    exmap = new TreeMap<Float, Player>();
     
    List<Player> i = new LinkedList<Player>();
    i.addAll((Collection<? extends Player>) Arrays
    .asList(getServer().getOfflinePlayers()));
     
    for (
    int g 0<= i.size(); g++) {
    exmap.put(i.get(g).getExp(), i.get(g));
    }
     
    float current 0;
    String currentstring null;
     
    current exmap.lastKey();
    currentstring "1. " exmap.lastEntry().getValue().toString()
    ": " String.valueOf(current);
    player.sendMessage(ChatColor.GREEN currentstring);
     
    for (
    int y 2<= 5y++) {
     
    current exmap.lastKey();
     
    if (
    current != 0) {
    currentstring String.valueOf(y) + ". "
    exmap.lastEntry().getValue().toString()
    ": " String.valueOf(current);
    player.sendMessage(ChatColor.GREEN currentstring);
    } else {
    player.sendMessage(ChatColor.RED
    "No more registred players on this LowBob Server *Trololol*");
    }
    }
    return 
    true;

    else { 
    sender.sendMessage("No Player, you are a "+
    sender.getClass().toString());
     
     return 
    false; }
     
     
    }
    return 
    false;
    }
     
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  6. Offline

    MarcuzEssence

    Thank you! good luck with your exams! :D
     
  7. Offline

    luke100

    thanks and no problem, i think it improved ma programming skills but, i stilll need to find out why im CraftPlayer...
     
  8. Offline

    Mr Washington

    luke100 Im fixing your code for you, this will fix the CraftPlayer problem!
    Code:
    package me.scharnhorst.explevel;
     
    import java.util.Arrays;
    import java.util.Collection;
    import java.util.LinkedList;
    import java.util.List;
    import java.util.TreeMap;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Server;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
     
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class explevel extends JavaPlugin {
     
    private TreeMap<Float, Player> exmap;
     
    @Override
    public void onEnable() {
     
    }
     
    @Override
    public void onDisable() {
     
    }
     
    public boolean onCommand(CommandSender sender, Command command,
    String label, String[] args) {
     
    Player player = (Player) sender;
    if (sender instanceof Player) {
     
     
    if (command.equals("level") && player.hasPermission("exp.own")) {
    float f = player.getExp();
    String exp = String.valueOf(f);
    player.sendMessage(exp);
    return true;
    } else if (command.equals("leveltop")
    && player.hasPermission("exp.top")) {
    exmap = new TreeMap<Float, Player>();
     
    List<Player> i = new LinkedList<Player>();
    i.addAll((Collection<? extends Player>) Arrays
    .asList(getServer().getOfflinePlayers()));
     
    for (int g = 0; g <= i.size(); g++) {
    exmap.put(i.get(g).getExp(), i.get(g));
    }
     
    float current = 0;
    String currentstring = null;
     
    current = exmap.lastKey();
    currentstring = "1. " + exmap.lastEntry().getValue().toString()
    + ": " + String.valueOf(current);
    player.sendMessage(ChatColor.GREEN + currentstring);
     
    for (int y = 2; y <= 5; y++) {
     
    current = exmap.lastKey();
     
    if (current != 0) {
    currentstring = String.valueOf(y) + ". "
    + exmap.lastEntry().getValue().toString()
    + ": " + String.valueOf(current);
    player.sendMessage(ChatColor.GREEN + currentstring);
    } else {
    player.sendMessage(ChatColor.RED
    + "No more registred players on this LowBob Server *Trololol*");
    }
    }
    return true;
    }
    else { sender.sendMessage("No Player, you are a "+
    sender.getClass().toString());
     
    return false; }
     
     
    }
    return false;
    }
     
    }
    Your problem was that you typed the Player player = (Player) sender AFTER you check if the ender is an instance of Player!

    Cheers!
     
  9. Offline

    Perdog

    Actually that isn't a problem. Your supposed to cast the sender to a player AFTER you check to see if it is in fact a player. Put it this way, with the way your doing it, if someone tried to use the command from console, the plugin would try to create a player object of the console, which doesn't work.
     
  10. Offline

    Scyntrus

    i guess this is a roundabout workaround, but you could go sender.getName() and server.getPlayer(name).
     

Share This Page