mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Merge pull request #2350 from TheSilentPro/backpack-changes
Separate player-only and no-permission messages
This commit is contained in:
commit
dc551907d2
@ -26,43 +26,48 @@ class BackpackCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public void onExecute(CommandSender sender, String[] args) {
|
||||
if (!(sender instanceof Player) || !sender.hasPermission("slimefun.command.backpack")) {
|
||||
SlimefunPlugin.getLocalization().sendMessage(sender, "messages.no-permission", true);
|
||||
return;
|
||||
}
|
||||
if (sender instanceof Player) {
|
||||
if (sender.hasPermission("slimefun.command.backpack")) {
|
||||
if (args.length != 3) {
|
||||
SlimefunPlugin.getLocalization().sendMessage(sender, "messages.usage", true, msg -> msg.replace("%usage%", "/sf backpack <Player> <ID>"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length != 3) {
|
||||
SlimefunPlugin.getLocalization().sendMessage(sender, "messages.usage", true, msg -> msg.replace("%usage%", "/sf backpack <Player> <ID>"));
|
||||
return;
|
||||
}
|
||||
if (!PatternUtils.NUMERIC.matcher(args[2]).matches()) {
|
||||
SlimefunPlugin.getLocalization().sendMessage(sender, "commands.backpack.invalid-id");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!PatternUtils.NUMERIC.matcher(args[2]).matches()) {
|
||||
SlimefunPlugin.getLocalization().sendMessage(sender, "commands.backpack.invalid-id");
|
||||
return;
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer backpackOwner = Bukkit.getOfflinePlayer(args[1]);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer backpackOwner = Bukkit.getOfflinePlayer(args[1]);
|
||||
if (!(backpackOwner instanceof Player) && !backpackOwner.hasPlayedBefore()) {
|
||||
SlimefunPlugin.getLocalization().sendMessage(sender, "commands.backpack.player-never-joined");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(backpackOwner instanceof Player) && !backpackOwner.hasPlayedBefore()) {
|
||||
SlimefunPlugin.getLocalization().sendMessage(sender, "commands.backpack.player-never-joined");
|
||||
return;
|
||||
}
|
||||
int id = Integer.parseInt(args[2]);
|
||||
|
||||
int id = Integer.parseInt(args[2]);
|
||||
PlayerProfile.get(backpackOwner, profile -> {
|
||||
if (!profile.getBackpack(id).isPresent()) {
|
||||
SlimefunPlugin.getLocalization().sendMessage(sender, "commands.backpack.backpack-does-not-exist");
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerProfile.get(backpackOwner, profile -> {
|
||||
if (!profile.getBackpack(id).isPresent()) {
|
||||
SlimefunPlugin.getLocalization().sendMessage(sender, "commands.backpack.backpack-does-not-exist");
|
||||
return;
|
||||
SlimefunPlugin.runSync(() -> {
|
||||
ItemStack item = SlimefunItems.RESTORED_BACKPACK.clone();
|
||||
SlimefunPlugin.getBackpackListener().setBackpackId(backpackOwner, item, 2, id);
|
||||
((Player) sender).getInventory().addItem(item);
|
||||
SlimefunPlugin.getLocalization().sendMessage(sender, "commands.backpack.restored-backpack-given");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
SlimefunPlugin.runSync(() -> {
|
||||
ItemStack item = SlimefunItems.RESTORED_BACKPACK.clone();
|
||||
SlimefunPlugin.getBackpackListener().setBackpackId(backpackOwner, item, 2, id);
|
||||
((Player) sender).getInventory().addItem(item);
|
||||
SlimefunPlugin.getLocalization().sendMessage(sender, "commands.backpack.restored-backpack-given");
|
||||
});
|
||||
});
|
||||
else {
|
||||
SlimefunPlugin.getLocalization().sendMessage(sender, "messages.no-permission", true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
SlimefunPlugin.getLocalization().sendMessage(sender, "messages.only-players", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user