Utilities

Utilities are always an important thing when trying to get things done quickly. Here are all of the notable utilities and how to use them effectively

General Utilities

Here's the generic crap you never need until you need it

Timers

Time execution with the timer

T timer = new T()
{
    @Override
    public void onStop(long nsTime, double msTime)
    {
        s("Took " + msTime + "ms");
    }
};

timer.start();

//Do something

timer.stop(); //onStop was called

Basic Formatting

There are loads of formatting, utilities in the F class

//Comma format
F.f(1024); // returns "1,024"

//Format decimals
F.f(43.66666, 2); // returns "43.67"

//File sizes
F.fileSize(1024l); // returns "1 KB"

//Color back to bukkit characters 
F.color("&cRed Text");

//Percents
F.pc(0.44455); //returns "44%"
F.pc(0.44455, 2); //returns "44.46%"

NMS Utilities

NMS Utilities rely on reflection based on the version of the server and offer loads of helpful things that may be needed.

Particle Effects

Particle effects run on DarkBlade12's particle effect class, however, we've added some things to it and tweaked it a bit over time.

All Particle Effects
ParticleEffect.FIREWORKS_SPARK.display(0f, 0, Location, 24);

Pinging Players

Pinging can't get any simpler

NMSX.ping(Player);

Sleeping Animation

Play sleeping animation of a player to all nearby players

//Start sleeping animation
NMSX.playSleepAnimation(Player);

//Stop sleeping animation
NMSX.stopSleepAnimation(Player);

Play Records

Play records to players easily

NMSX.playRecord(Player, Material.RECORD_12);

Hide and Show Entities

You can show and hide entities via packets just like vanish. They will no longer exist to the client viewer

NMSX.hideEntity(Player viewer, Entity hide);
NMSX.showEntity(Player viewer, Entity show);

Launch Fireworks

You can launch fireworks very simply with color and different types

NMSX.launchFirework(Location);
NMSX.launchFirework(Location, Color);
NMSX.launchFirework(Location, Color, FireworkEffect.Type.BURST);
NMSX.launchFirework(Location, Color, Color, FireworkEffect.Type.CREEPER);

Pick Up Animation

You can show a pickup animation from any entity to any entity. A baby zombie could pick up a giant zombie in the perspective of the viewer

WARNING! The picked up entity will vanish but can still interact with the player who doesnt see it. The entity can even be heard and can damage you.

NMSX.showPickup(Player viewer, Entity entity, Entity pickedUp);

Show Demo Screen

Could prove useful for resource packed games

NMSX.showDemo(Player);

Show End Credits

You can show the end credits to a player

NMSX.showEnd(Player);

Change Weather Intensity

You can now change the weather intensity by changing brightness states

//0-1 (0 is normal) (1 is raining)
//Anything higher is simply LSDPCPPsilosybin
NMSX.showWeather(Player, 0f);

You can easily change the tablist header and footer

NMSX.sendTabTitle(Player, "tab header\ndoubleline", "tab footer\ndoubleline");

Change Block Break Animation level

you can change the block break animation level for a player. Use levels 0-9 to go through the texture index for break levels. Setting this to any other value outside of 0-9 will reset it to none.

NMSX.showBlockBreakAnimation(Player, Location, 0);

Title Messages

Send title messages with the title wrapper. You can construct all of this data, but in this example, the method setters are used

Title title = new Title();
title.setAction("Action bar!");
title.setSubTitle("Subtitle");
title.setTitle("Title");
title.setStayTime(4);
title.setFadeIn(2);
title.setFadeOut(300);

title.send(Player);

World Utilities

Worldly utilities all in the W class

Get Async World

You can get an async safe world like so

World world = W.getAsyncWorld("world");

Get a radius of chunks

Very simple to do

//Get a 3x3 set of chunks with the given chunk as the center
GList<Chunk> chunks = W.chunkRadius(Chunk, 1);

Get Border chunks

Get all the bordering chunks for the given chunk

GList<Chunk> chunks = W.chunkFaces(Chunk);

Get Border Blocks

Get all blocks touching the given block (every block, even air)

GList<Block> blocks = W.blockFaces(Block);

Difference in Vectors

Get a value difference in vectors

Double diff = W.differenceOfVectors(Vector, Vector)

Get MaterialBlock from String

Get a material with data from a given string

W.getMaterialBlock("Stone:5");
W.getMaterialBlock("4");
W.getMaterialBlock("1:4");
W.getMaterialBlock("comPASS");

Get Entity looking at Entity

Get an entity that a given entity is looking at or null

//Get the entity that the given entity is looking at
//Max range is 12
//Difference offset is 1.5 (can look away up to 1.5 blocks as padding)
W.getEntityLookingAt(Entity, 12, 1.5);

Get World Edit Selection

Get the cuboid world edit selection

//Cuboid selection from worldedit
Cuboid c = W.getSelection(Player)

Get Sync World from Async World

Make sure this is used on the main thread

W.getSyncWorld(World asyncOrSyncWorld);

Potion Effects

Quickly apply potion effects

//Apply a Potion Effect of Blindness with an amp of 4 and a duration of 500 ticks
//Then apply it to the given entity
PE.BLINDNESS.a(4).d(500).c(LivingEntity);

Raytracing

Simply ray race like so

new RayTrace(Location start, Vector direction, Double maxDist, Double step)
{
    @Override
    public void onTrace(Location location)
    {
        //Called per step
    }
}.trace();

results matching ""

    No results matching ""