Skip to content

specify position instead of player#153

Open
tgwaste wants to merge 1 commit intoNukkit-coders:masterfrom
tgwaste:master
Open

specify position instead of player#153
tgwaste wants to merge 1 commit intoNukkit-coders:masterfrom
tgwaste:master

Conversation

@tgwaste
Copy link
Copy Markdown

@tgwaste tgwaste commented May 14, 2020

Allow player to do (for example):
/mob spawn Zombie x,y,z

toPos = true;
}

if (args.length == 3 && toPos == false) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why toPos == false instead of !toPos ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just readability, but am happy to change it.

if (playerThatSpawns != null) {
Position pos = playerThatSpawns.getPosition();

if (toPos == true) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just if (toPos) {?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just readability, but am happy to change it.

if (toPos == true) {
// specifying a position instead of a player
String[] arg = args[2].split(",");
playerThatSpawns = (Player) sender;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will give a ClassCastException if run from console

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will look into this, still pretty new to java.

String[] arg = args[2].split(",");
playerThatSpawns = (Player) sender;

Position newpos = new Position
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should catch the exception which comes if player gives invalid coordinates?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will look into this, at this point I do not know how to validate coordinates.

if ((ent = Entity.createEntity(mob, pos)) != null) {
ent.spawnToAll();
sender.sendMessage("Spawned " + mob + " to " + playerThatSpawns.getName());
if (toPos == true) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just if (toPos) {?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just readability, but am happy to change it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants