Skip to content

Commit

Permalink
added the ability to give backpack keys using the item:give command
Browse files Browse the repository at this point in the history
  • Loading branch information
drew6017 committed Dec 23, 2019
1 parent 30fa821 commit ca763d0
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 4 deletions.
Binary file modified .i18nExtractor/google-translate-cache-es
Binary file not shown.
Binary file modified .i18nExtractor/google-translate-cache-fr
Binary file not shown.
Binary file modified .i18nExtractor/google-translate-cache-it
Binary file not shown.
Binary file modified .i18nExtractor/google-translate-cache-pl
Binary file not shown.
Binary file modified .i18nExtractor/google-translate-cache-zh
Binary file not shown.
9 changes: 9 additions & 0 deletions src/main/java/com/divisionind/bprm/ACommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

public abstract class ACommand {

Expand All @@ -41,6 +42,13 @@ public abstract class ACommand {

public abstract void execute(CommandSender sender, String label, String[] args);

// TODO ensure that commands are processed on a single thread before doing this
// protected CommandSender currentSender;
//
// protected void respond(String msg) {
// respond(currentSender, msg);
// }

// recursively do these as to always have tab complete available
// if null, displays online players | if empty list, displays nothing
public List<String> tabComplete(CommandSender sender, Command command, String alias, String[] args) {
Expand Down Expand Up @@ -114,6 +122,7 @@ public static void validateArgsLength(String[] args, int length) {
public void call(CommandSender sender, String label, String[] args) {
if (hasPerm(sender)) {
try {
//this.currentSender = sender;
execute(sender, label, args);
} catch (PlayerRequiredException e) {
respond(sender, "&cYou must be a player to use this command.");
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/com/divisionind/bprm/commands/ItemGive.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.divisionind.bprm.ACommand;
import com.divisionind.bprm.BackpackObject;
import com.divisionind.bprm.BackpackRecipes;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
Expand All @@ -29,6 +30,9 @@
import java.util.List;

public class ItemGive extends ACommand {

public static final String KEY_NAME = "KEY";

@Override
public String alias() {
return "item:give";
Expand Down Expand Up @@ -71,7 +75,12 @@ public void execute(CommandSender sender, String label, String[] args) {
// attempt to resolve backpack type
BackpackObject item = BackpackObject.getByName(args[1]);
if (item == null) {
respondf(sender, "&cBackpack of type \"%s\" was not found.", args[1]);
if (KEY_NAME.equalsIgnoreCase(args[1])) {
p.getInventory().addItem(BackpackRecipes.BACKPACK_KEY);
respond(sender, "&eGave the player a backpack key.");
} else {
respondf(sender, "&cBackpack of type \"%s\" was not found.", args[1]);
}
return;
}

Expand All @@ -85,10 +94,14 @@ public List<String> tabComplete(CommandSender sender, Command command, String al
List<String> parts = new ArrayList<>();
if (args[1].equals("")) {
for (BackpackObject item : BackpackObject.values()) parts.add(item.name());
parts.add(KEY_NAME);
} else {
String typedLowercase = args[1].toLowerCase();
for (BackpackObject item : BackpackObject.values()) {
if (item.name().toLowerCase().startsWith(args[1].toLowerCase())) parts.add(item.name());
if (item.name().toLowerCase().startsWith(typedLowercase)) parts.add(item.name());
}

if (KEY_NAME.toLowerCase().startsWith(typedLowercase)) parts.add(KEY_NAME);
}
return parts;
} else return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@

public class BackpackFurnaceTickEvent implements Listener {

// does not necessarily have to be a ConcurrentHashMap because this is run in the game loop
// with inventory actions (only this way because of inefficient removal of entries)
// does not necessarily have to be a ConcurrentHashMap because this is only accessed in the game loop
// with inventory actions (only this way because of inefficient removal of entries during iteration)
public static Map<UUID, VirtualFurnace> VIRTUAL_FURNACES = new ConcurrentHashMap<>();

@EventHandler
Expand Down

0 comments on commit ca763d0

Please sign in to comment.