-
Notifications
You must be signed in to change notification settings - Fork 555
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
Added /slimefun drop command #2515
Conversation
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.
Two really minor remarks.
This doesnt have too many usecases but it can be really damn useful in certain areas.
src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/commands/DropCommandTest.java
Show resolved
Hide resolved
src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DropCommand.java
Outdated
Show resolved
Hide resolved
src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/commands/DropCommandTest.java
Outdated
Show resolved
Hide resolved
src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DropCommand.java
Outdated
Show resolved
Hide resolved
src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DropCommand.java
Outdated
Show resolved
Hide resolved
src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DropCommand.java
Outdated
Show resolved
Hide resolved
src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DropCommand.java
Outdated
Show resolved
Hide resolved
src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DropCommand.java
Show resolved
Hide resolved
…f-drop � Conflicts: � src/main/resources/languages/messages_en.yml
# Conflicts: # src/main/resources/languages/messages_en.yml
import com.google.common.base.Functions; | ||
import com.google.common.collect.Lists; |
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.
These are not used, remove
src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DropCommand.java
Show resolved
Hide resolved
|
||
if (amount > 0) { | ||
Bukkit.getWorld(world).dropItem(new Location(Bukkit.getWorld(world), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z)), new CustomItem(sfItem.getItem(), amount)); | ||
SlimefunPlugin.getLocalization().sendMessage(sender, "messages.drop-item", true, msg -> msg.replace(PLACEHOLDER_WORLD, args[1]).replace(PLACEHOLDER_X, args[2]).replace(PLACEHOLDER_Y, args[3]).replace(PLACEHOLDER_Z, args[4]).replace(PLACEHOLDER_ITEM, sfItem.getItemName()).replace(PLACEHOLDER_AMOUNT, String.valueOf(amount))); |
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.
This line is huge, please format nicely
int amount = parseAmount(args); | ||
|
||
if (amount > 0) { | ||
Bukkit.getWorld(world).dropItem(new Location(Bukkit.getWorld(world), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z)), new CustomItem(sfItem.getItem(), amount)); |
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.
There should be checks here or above that these are actually ints. PatternUtils.NUMERIC.matcher(s).matches()
} | ||
} | ||
|
||
private int parseAmount(String[] args) { |
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.
not sure why you pass an array here. Just pass a single string, can even use this for the x,y,z above.
int amount = 1; | ||
|
||
if (args.length == 7) { | ||
if (PatternUtils.NUMERIC.matcher(args[6]).matches()) { | ||
amount = Integer.parseInt(args[6]); | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
return amount; |
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.
int amount = 1; | |
if (args.length == 7) { | |
if (PatternUtils.NUMERIC.matcher(args[6]).matches()) { | |
amount = Integer.parseInt(args[6]); | |
} else { | |
return 0; | |
} | |
} | |
return amount; | |
if (PatternUtils.NUMERIC.matcher(s).matches()) { | |
return OptionalInt.of(Integer.parseInt(s)); | |
} else { | |
return OptionalInt.empty(); | |
} |
@@ -132,7 +134,6 @@ messages: | |||
no-tome-yourself: '&cYou cannot use the &4Tome of Knowledge &con yourself...' | |||
multimeter: '&bStored Energy: &3%stored% &b/ &3%capacity%' | |||
piglin-barter: '&4You cannot barter with piglins using Slimefun items' | |||
bee-suit-slow-fall: '&eYour Bee Wings will help you to get back to the ground safe and slow' |
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.
don't remove this
server.executeConsole("slimefun", "drop", "testworld", "0", "0", "0", "DROP_COMMAND_TEST_ITEM", "1"); | ||
for (Entity en : server.getWorld("testworld").getEntities()) { | ||
Assertions.assertEquals(SlimefunItem.getByItem(((Item) en).getItemStack()), TEST_ITEM.getItem()); | ||
} |
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.
There also should be tests to make sure validation works, so non-extistent world, invalid coords, invalid item, too high amount/0, etc
Closing this since there hasn't been a response in over a month now. |
Description
Adds
/sf drop
, a command which drops a Slimefun item with a selectable quantity at the specified coordinates. This is helpful for scripted actions, such as mob drops.Changes
Added the
DropCommand
subcommand and registered under subcommandsAdded
drop-item
tomessages_en.yml
Added
DropCommandTest
unit testRelated Issues
This was suggested on Discord so that MythicMobs could drop Slimefun items
Checklist
Nonnull
andNullable
annotations to my methods to indicate their behaviour for null values