-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
specify position instead of player #153
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,14 +122,19 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String | |
switch (args[0].toLowerCase()) { | ||
case "spawn": | ||
if (args.length == 1 || (args.length == 2 && !(sender instanceof Player))) { | ||
sender.sendMessage("Usage: /mob spawn <entity> <opt:player>"); | ||
sender.sendMessage("Usage: /mob spawn <entity> <opt:player> or <pos:x,y,z>"); | ||
break; | ||
} | ||
|
||
String mob = args[1]; | ||
Player playerThatSpawns; | ||
boolean toPos = false; | ||
|
||
if (args.length == 3) { | ||
if (args.length == 3 && args[2].contains(",")) { | ||
toPos = true; | ||
} | ||
|
||
if (args.length == 3 && toPos == false) { | ||
playerThatSpawns = this.getServer().getPlayer(args[2]); | ||
} else { | ||
playerThatSpawns = (Player) sender; | ||
|
@@ -138,10 +143,30 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String | |
if (playerThatSpawns != null) { | ||
Position pos = playerThatSpawns.getPosition(); | ||
|
||
if (toPos == true) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just readability, but am happy to change it. |
||
// specifying a position instead of a player | ||
String[] arg = args[2].split(","); | ||
playerThatSpawns = (Player) sender; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will give a ClassCastException if run from console There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will look into this, still pretty new to java. |
||
|
||
Position newpos = new Position | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
( | ||
Double.parseDouble(arg[0]), // x | ||
Double.parseDouble(arg[1]), // y | ||
Double.parseDouble(arg[2]), // z | ||
playerThatSpawns.getPosition().level | ||
); | ||
|
||
pos = newpos; | ||
} | ||
|
||
Entity ent; | ||
if ((ent = Entity.createEntity(mob, pos)) != null) { | ||
ent.spawnToAll(); | ||
sender.sendMessage("Spawned " + mob + " to " + playerThatSpawns.getName()); | ||
if (toPos == true) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just readability, but am happy to change it. |
||
sender.sendMessage("Spawned " + mob + " to " + args[2]); | ||
} else { | ||
sender.sendMessage("Spawned " + mob + " to " + playerThatSpawns.getName()); | ||
} | ||
} else { | ||
sender.sendMessage("Unable to spawn " + mob); | ||
} | ||
|
There was a problem hiding this comment.
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
?There was a problem hiding this comment.
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.