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
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 can be simplified by using matches() instead of looping. Code:java public boolean isPlayerOnline(String plyrName){ return Bukkit.getPlayer(plyrName) != null;} Code:java public ItemStack playerHead(String targetPlayer){ Player plyr = getServer().getPlayer(targetPlayer); ItemStack itm = new ItemStack(Material.SKULL_ITEM, 1, (short)3); SkullMeta = (SkullMeta)itmm.getItemMeta(); if(targetPlyr == null){ meta.setOwner(targetPlayer); } else { meta.setOwner(plyr.getName()); }} 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 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 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.
Cirno Use getServer() and getPlayerExact. This is what I mean by isDigit: http://jdevelopment.nl/efficient-determine-string-number/ 1st alternative. ImDeJay Why calenders are expensive http://cephas.net/blog/2006/02/25/the-cost-of-calendar-object-creation/ isDigit method http://jdevelopment.nl/efficient-determine-string-number/ Besides so, we already have several resources like this, ask to get yours on SoThatsIt 's post.
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.