mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
I said, added a command!
This commit is contained in:
parent
fcf28fdf7f
commit
0fc0a0be29
@ -1,4 +1,76 @@
|
||||
package io.github.thebusybiscuit.slimefun4.core.commands.subcommands;
|
||||
|
||||
public class BackpackCommand {
|
||||
import io.github.thebusybiscuit.slimefun4.api.player.PlayerBackpack;
|
||||
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
|
||||
import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand;
|
||||
import io.github.thebusybiscuit.slimefun4.core.commands.SubCommand;
|
||||
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
|
||||
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class BackpackCommand extends SubCommand {
|
||||
|
||||
BackpackCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
|
||||
super(plugin, cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "backpack";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHidden() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(CommandSender sender, String[] args) {
|
||||
if (!(sender instanceof Player) || !(sender.hasPermission("slimefun.command.backpack"))) {
|
||||
SlimefunPlugin.getLocal().sendMessage(sender, "messages.no-permission", true);
|
||||
return;
|
||||
}
|
||||
if (args.length != 3) {
|
||||
SlimefunPlugin.getLocal().sendMessage(sender, "messages.usage", true, msg -> msg.replace("%usage%", "/sf backpack <Player> <Number>"));
|
||||
return;
|
||||
}
|
||||
|
||||
Player p = (Player) sender;
|
||||
String ownerName = args[1];
|
||||
int id = Integer.parseInt(args[2]);
|
||||
OfflinePlayer owner = Bukkit.getPlayer(ownerName);
|
||||
|
||||
if (owner == null) {
|
||||
owner = Bukkit.getOfflinePlayer(ownerName);
|
||||
if (!owner.hasPlayedBefore()) {
|
||||
SlimefunPlugin.getLocal().sendMessage(sender, "guide.backpack.player-never-joined");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
PlayerProfile.get(owner, profile -> {
|
||||
if (!profile.getBackpack(id).isPresent()) {
|
||||
SlimefunPlugin.getLocal().sendMessage(sender, "guide.backpack.backpack-does-not-exist");
|
||||
return;
|
||||
}
|
||||
PlayerBackpack bp = profile.getBackpack(id).get();
|
||||
//No point switching for size, would still miss soulbound
|
||||
ItemStack item = SlimefunItems.BACKPACK_MEDIUM;
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
List lore = meta.getLore();
|
||||
lore.set(2, ChatColor.GRAY + "ID: " + profile.getUUID().toString() + "#" + id);
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
Slimefun.runSync(() -> p.getInventory().addItem(item));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -25,5 +25,6 @@ public final class Commands {
|
||||
commands.add(new OpenGuideCommand(plugin, cmd));
|
||||
commands.add(new SearchCommand(plugin, cmd));
|
||||
commands.add(new DebugFishCommand(plugin, cmd));
|
||||
commands.add(new BackpackCommand(plugin,cmd));
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ commands:
|
||||
help: Displays this help screen
|
||||
cheat: Allows you to cheat Items
|
||||
give: Give somebody some Slimefun Items
|
||||
backpack: Retrieve an existing backpack
|
||||
guide: Gives yourself a Slimefun Guide
|
||||
timings: Lag-Info about your Server
|
||||
teleporter: See other Player's Waypoints
|
||||
@ -42,6 +43,10 @@ guide:
|
||||
|
||||
cheat:
|
||||
no-multiblocks: '&4You cannot cheat in Multiblocks, you have to build them!'
|
||||
|
||||
backpack:
|
||||
player-never-joined: '&4No player with that name has ever joined the server!'
|
||||
backpack-does-not-exist: '&4That backpack does not exist!'
|
||||
|
||||
pages:
|
||||
previous: 'Previous page'
|
||||
|
@ -37,6 +37,9 @@ permissions:
|
||||
slimefun.command.versions:
|
||||
description: Allows you to do /sf versions
|
||||
default: op
|
||||
slimefun.command.backpack:
|
||||
description: Allows you to do /sf backpack
|
||||
default: op
|
||||
slimefun.command.guide:
|
||||
description: Allows you to obtain the Slimefun guide book
|
||||
default: true
|
||||
|
Loading…
Reference in New Issue
Block a user