-
-
Notifications
You must be signed in to change notification settings - Fork 698
#810 Add option to give looked up items into inventory #811
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
Open
MrSteppy
wants to merge
16
commits into
PlayPro:master
Choose a base branch
from
MrSteppy:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
bb24fb7
Add givable items to ItemUtils
d6d1fba
Improve performance of givable items methods
98f6f3d
Add ItemUtils#getItemStack
b24a852
Add ChatUtils#createGiveItemComponent
3b3cd43
Fix ChatUtils#createGiveItemComponent not returning empty String when…
d03adae
Add 'give item' components to StandardLookupThread
0ce3ec3
Add GivableItemIdParser
34d42b6
Add CommandParser#parseGivableItemId
0093c4d
Add Phrase#INVALID_ITEM_ID
bba4060
Add GiveCommand
2c9c317
Update permissions.md
17c9b7f
Fix itemId parsing
f090b5a
Improve performance of givable items methods
b1053e6
Update coreprotect.give permission to be false by default
5982a99
Only show give component if player has permission to use the command
d2bc9b3
Fix missing import which was accidentally removed during rebasing
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package net.coreprotect.command; | ||
|
|
||
| import net.coreprotect.language.Phrase; | ||
| import net.coreprotect.utility.Chat; | ||
| import net.coreprotect.utility.ChatMessage; | ||
| import net.coreprotect.utility.Color; | ||
| import net.coreprotect.utility.ItemUtils; | ||
| import org.bukkit.command.Command; | ||
| import org.bukkit.command.CommandSender; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.inventory.ItemStack; | ||
|
|
||
| public class GiveCommand { | ||
| public static void runCommand(CommandSender sender, Command command, boolean permission, String[] args) { | ||
| if (!permission) { | ||
| Chat.sendMessage(sender, new ChatMessage(Phrase.build(Phrase.NO_PERMISSION)).build()); | ||
| return; | ||
| } | ||
|
|
||
| Integer itemId = CommandParser.parseGivableItemId(args); | ||
| if (itemId == null) { | ||
| Chat.sendMessage(sender, new ChatMessage(Phrase.build(Phrase.MISSING_PARAMETERS, Color.WHITE, "/" + command.getName() + " give <itemId>")).build()); | ||
| return; | ||
| } | ||
|
|
||
| ItemStack item = ItemUtils.getGivableItem(itemId); | ||
| if (item == null) { | ||
| Chat.sendMessage(sender, new ChatMessage(Phrase.build(Phrase.INVALID_ITEM_ID)).build()); | ||
| return; | ||
| } | ||
|
|
||
| if (!(sender instanceof Player)) { | ||
| Chat.sendMessage(sender, new ChatMessage(Phrase.build(Phrase.ACTION_NOT_SUPPORTED)).build()); | ||
| return; | ||
| } | ||
|
|
||
| Player player = (Player) sender; | ||
| player.getInventory().addItem(item); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/net/coreprotect/command/parser/GivableItemIdParser.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package net.coreprotect.command.parser; | ||
|
|
||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| public class GivableItemIdParser { | ||
|
|
||
| protected static final Pattern PATTERN = Pattern.compile("#([0-9]+)"); | ||
|
|
||
| public static Integer parseGivableItemId(String[] inputArguments) { | ||
| for (String argument : inputArguments) { | ||
| Matcher matcher = PATTERN.matcher(argument); | ||
| if (matcher.find()) { | ||
| return Integer.parseInt(matcher.group(1)); | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
typo