Method Library

Discussion in 'Resources' started by Tster, Aug 3, 2011.

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


    Please post your methods as a topic, and send me a message if you would like to include them here:

    Tster's damageCauseToString (open)

    Converts damage causes in to strings!
        public String damageCauseToString(DamageCause cause){
            if(cause.toString().equalsIgnoreCase(DamageCause.BLOCK_EXPLOSION.toString())){//if explosion by tnt
                return "Died from an explosion";
            else if(cause.toString().equalsIgnoreCase(DamageCause.DROWNING.toString())){//drowned in water
                return "Drowned to death";
            else if(cause.toString().equalsIgnoreCase(DamageCause.ENTITY_ATTACK.toString())){//killed by some entity
                return "Was brutally attacked";
            else if(cause.toString().equalsIgnoreCase(DamageCause.ENTITY_EXPLOSION.toString())){//killed by creeper
                return "Got nerfed by a creeper";
            else if(cause.toString().equalsIgnoreCase(DamageCause.FALL.toString())){//killed by fall damage
                return "Fell to there death";
            else if(cause.toString().equalsIgnoreCase(DamageCause.FIRE.toString())){//killed by inital fire
                return "Was burnt to death";
            else if(cause.toString().equalsIgnoreCase(DamageCause.FIRE_TICK.toString())){//killed by lingering
                return "Got smoked";
            else if(cause.toString().equalsIgnoreCase(DamageCause.LAVA.toString())){//killed by lava
                return "Went swimming in magma";
            else if(cause.toString().equalsIgnoreCase(DamageCause.LIGHTNING.toString())){//killed by lightning strike
                return "Was electrocuted";
            else if(cause.toString().equalsIgnoreCase(DamageCause.SUFFOCATION.toString())){//killed by suffocation (inside a block)
                return "Suffocated";
            else if(cause.toString().equalsIgnoreCase(DamageCause.VOID.toString())){//killed by going below the map
                return "Fell into the void";
            else if(cause.toString().equalsIgnoreCase(DamageCause.CONTACT.toString())){//killed by some type of contact
                return "Was squished";
            else if(cause.toString().equalsIgnoreCase(DamageCause.CUSTOM.toString())){//killed by some other know reason
                return "Strangely died";
            }else{//if no specific reason, just died, maybe a plugin set health to 0?
                return "Died";

    Coryf88's toBlock (open)

    Get the block that dropped an itemstack!
        public static ItemStack getDrop(Block block) throws RuntimeException {
            if (block == null) return null;
            int blockTypeId = block.getTypeId();
            if (blockTypeId < 1 || blockTypeId > 255) return null;
            try {
                net.minecraft.server.Block b = net.minecraft.server.Block.byId[blockTypeId];
                int typeId = b.a(blockTypeId, BlockHelper.random);
                if (typeId < 1) return null;
                int dropCount = b.a(BlockHelper.random);
                if (dropCount < 1) return null;
                Method m = BlockHelper.getMethod(b.getClass(), "a_", new Class[] {int.class});
                byte dropData = ((Integer)m.invoke(b, block.getData())).byteValue();
                return new ItemStack(typeId, dropCount, dropData);
            } catch (Exception e) {
                throw new RuntimeException("A severe error occured while retreiving the data dropped.", e);

    Bergerkiller's Move (open)

    Moves the given location in the direction it is looking!
    public static Location move(Location loc, Vector offset) {
            // Convert rotation to radians
            float ryaw = -loc.getYaw() / 180f * (float) Math.PI;
            float rpitch = loc.getPitch() / 180f * (float) Math.PI;
            //Conversions found by (a lot of) testing
            double x = loc.getX();
            double y = loc.getY();
            double z = loc.getZ();
            z -= offset.getX() * Math.sin(ryaw);
            z += offset.getY() * Math.cos(ryaw) * Math.sin(rpitch);
            z += offset.getZ() * Math.cos(ryaw) * Math.cos(rpitch);
            x += offset.getX() * Math.cos(ryaw);
            x += offset.getY() * Math.sin(rpitch) * Math.sin(ryaw);
            x += offset.getZ() * Math.sin(ryaw) * Math.cos(rpitch);
            y += offset.getY() * Math.cos(rpitch);
            y -= offset.getZ() * Math.sin(rpitch);
            return new Location(loc.getWorld(), x, y, z, loc.getYaw(), loc.getPitch());

    Coryf88's isRelativeTo (open)

    Checks if a block is relative to xyz and returns the block face!
    private BlockFace isRelativeTo(Block block, Material material) {
        BlockFace[] blockFaces = new BlockFace[] {BlockFace.UP, BlockFace.NORTH, BlockFace.WEST, BlockFace.EAST, BlockFace.SOUTH, BlockFace.DOWN};
        for (BlockFace blockFace : blockFaces) {
            if (block.getRelative(blockFace).getType() == material) {
                return blockFace;
        return null;
  2. Offline

    tha d0ctor

  3. Offline


    Now I remember why I made this, I need the relative to method now LD
  4. Offline


    Thanks for using my move function. :p
    Also, I got a giant class full of methods, but most use the 3D matrix class which makes it useless.

    Also, I think Bukkit should be a lot more open. You should be able to place your own functions in there, if needed in a separate class. It is useless to have the same functions in multiple plugins, and no one will ever reference an external library. It makes it 'less compatible'. The one thing I dislike about Bukkit...

    -Or someone starts a full-scale function plugin which other plugins can use. For example the 'Extras' Library, only got the idea no one uses it, thus no one references it. (that's in my case)
Thread Status:
Not open for further replies.

Share This Page