Skip to content
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

Closed
wants to merge 8 commits into from

Conversation

NCBPFluffyBear
Copy link
Contributor

@NCBPFluffyBear NCBPFluffyBear commented Oct 28, 2020

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 subcommands
Added drop-item to messages_en.yml
Added DropCommandTest unit test

Related Issues

This was suggested on Discord so that MythicMobs could drop Slimefun items

Checklist

  • I have fully tested the proposed changes and promise that they will not break everything into chaos.
  • I have also tested the proposed changes in combination with various popular addons and can confirm my changes do not break them.
  • I followed the existing code standards and didn't mess up the formatting.
  • I did my best to add documentation to any public classes or methods I added.
  • I have added Nonnull and Nullable annotations to my methods to indicate their behaviour for null values
  • I added sufficient Unit Tests to cover my code.

@NCBPFluffyBear NCBPFluffyBear requested a review from a team as a code owner October 28, 2020 19:59
Copy link
Member

@svr333 svr333 left a 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.

@TheBusyBot TheBusyBot added the ⚡ Merge Conflicts This Pull Request has merged conflicts which need to be resolved! label Oct 31, 2020
@poma123 poma123 removed the ⚡ Merge Conflicts This Pull Request has merged conflicts which need to be resolved! label Oct 31, 2020
…f-drop

� Conflicts:
�	src/main/resources/languages/messages_en.yml
@TheBusyBiscuit TheBusyBiscuit added the ⏰ Waiting for response We are waiting for a response. label Dec 10, 2020
Comment on lines +24 to +25
import com.google.common.base.Functions;
import com.google.common.collect.Lists;
Copy link
Member

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


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)));
Copy link
Member

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));
Copy link
Member

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) {
Copy link
Member

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.

Comment on lines +75 to +85
int amount = 1;

if (args.length == 7) {
if (PatternUtils.NUMERIC.matcher(args[6]).matches()) {
amount = Integer.parseInt(args[6]);
} else {
return 0;
}
}

return amount;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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'
Copy link
Member

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());
}
Copy link
Member

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

@TheBusyBiscuit TheBusyBiscuit added the 🎈 Feature This Pull Request adds a new feature. label Jan 24, 2021
@TheBusyBiscuit
Copy link
Member

Closing this since there hasn't been a response in over a month now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎈 Feature This Pull Request adds a new feature. ⏰ Waiting for response We are waiting for a response.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants