As a little bukkitteer (about seven months ago), when I started developing bukkit plugins, there were many secrets that I could never figure out, but know how to use really well now. If anyone has other snippets that could go here, just comment below and I'll work something out By the way, better title... anyone? 1. Converting '&' symbols to ChatColors This happened to be so easy that I felt really dumb the moment I figured this one out... Code:java String colorstr = "&4Hi!";ChatColor.translateAlternateColorCodes('&', colorstr); 2. Getting comments in between the lines in my config.yml For this one, I just used basic java functions, opening up to my config.yml with a FileWriter, and writing the file line by line. If you want, you can replace the methods (getConfig(), reloadConfig()) with these by adding them, and putting these methods in there, and then putting the @Override annotation above those methods. http://pastebin.com/MfXGareh 3. Check if a player is within two locations Thanks to Ugleh for this one, it seems like something I could've used awhile ago http://pastebin.com/PxfuD2sM 4. Iterate through blocks between two locations Thanks again to Ugleh for this one, it's kinda like the thing they use in worldedit to set and replace a bunch of blocks with the wand... http://pastebin.com/ZGBjzJCs Is there anything else that someone feels should go here? If so, just comment Reserved EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Just title it "Code Snippets" Here is one. Check if player is within 2 locations First we turn the 2 locations into a CubedArea and then we do the check, Code:java public boolean playerWithin(Location l1, Location l2, Location pLoc) {int x1 = Math.min(l1.getBlockX(), l2.getBlockX());int y1 = Math.min(l1.getBlockY(), l2.getBlockY());int z1 = Math.min(l1.getBlockZ(), l2.getBlockZ());int x2 = Math.max(l1.getBlockX(), l2.getBlockX());int y2 = Math.max(l1.getBlockY(), l2.getBlockY());int z2 = Math.max(l1.getBlockZ(), l2.getBlockZ());l1 = new Location(l1.getWorld(), x1, y1, z1);l2 = new Location(l2.getWorld(), x2, y2, z2); return pLoc.getBlockX() >= l1.getBlockX()&& pLoc.getBlockX() <= l2.getBlockX()&& pLoc.getBlockY() >= l1.getBlockY()&& pLoc.getBlockY() <= l2.getBlockY()&& pLoc.getBlockZ() >= l1.getBlockZ()&& pLoc.getBlockZ() <= l2.getBlockZ();}}
Iterate through blocks between 2 locations. Code: public void loopThrough(Location loc1, Location loc2, World w) { int minx = Math.min(loc1.getBlockX(), loc2.getBlockX()), miny = Math.min(loc1.getBlockY(), loc2.getBlockY()), minz = Math.min(loc1.getBlockZ(), loc2.getBlockZ()), maxx = Math.max(loc1.getBlockX(), loc2.getBlockX()), maxy = Math.max(loc1.getBlockY(), loc2.getBlockY()), maxz = Math.max(loc1.getBlockZ(), loc2.getBlockZ()); for(int x = minx; x<=maxx;x++){ for(int y = miny; y<=maxy;y++){ for(int z = minz; z<=maxz;z++){ Block b = w.getBlockAt(x, y, z); //do somthing productive with b... } } } }
Ugleh No need for the world parameter, you can get it with: Code:java World world = loc<1/2>.getWorld();
what does this do? Code: loc<1/2> do you just mean loc1 or loc2 or is that an actual syntax for something?