delete please.

Discussion in 'Resources' started by ImDeJay, Mar 2, 2014.

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

    ImDeJay

    delete please.
     
  2. Offline

    xTrollxDudex

    ImDeJay
    1 can be simplified
    2 toString called on a String.....................
    3 Expensive call
    4 Loop through char array and check isDigit will be 9x faster
     
  3. Offline

    ImDeJay

    xTrollxDudex
    Im here to help others, so explain your reasonings so i can fix them.

    1. How can it be simplified?
    2. Its a habit I have. Its not hurting anything but I'll remove it.
    3. Why?
    4. Example?
     
  4. Offline

    Cirno

    4 can be simplified by using matches() instead of looping.

    Code:java
    1. public boolean isPlayerOnline(String plyrName){
    2. return Bukkit.getPlayer(plyrName) != null;
    3. }


    Code:java
    1. public ItemStack playerHead(String targetPlayer){
    2. Player plyr = getServer().getPlayer(targetPlayer);
    3. ItemStack itm = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
    4. SkullMeta = (SkullMeta)itmm.getItemMeta();
    5. if(targetPlyr == null){
    6. meta.setOwner(targetPlayer);
    7. } else {
    8. meta.setOwner(plyr.getName());
    9. }
    10. }


    You create a new DateFormat, and then create a new Calender. Take from here: http://stackoverflow.com/questions/4142313/java-convert-milliseconds-to-time-format

    Code:java
    1.  
    2. long second =(millis /1000)%60;long minute =(millis /(1000*60))%60;long hour =(millis /(1000*60*60))%24;String time =String.format("%02d:%02d:%02d:%d", hour, minute, second, millis);


    I use this in one of my plugins:
    Code:text
    1. str.matches("-?\\d+(\\.\\d+)?");

    Returns true if it's a number (will return true for 1, 2, 2.5, 1.5, 3.141).
    Obviously returns false if it isn't.
     
  5. Offline

    xTrollxDudex

  6. Offline

    ImDeJay

  7. Offline

    Cirno

    I don't like to use loops for something like this; and the try-catch statement is only good for if it's being used in a lazy way; e.g not being called every tick; as it can get expensive creating Exception objects.
     
  8. Offline

    xTrollxDudex

    Cirno
    Hey, benchmarks show its 9x faster, I'LL USE IT!
     
Thread Status:
Not open for further replies.

Share This Page