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
|
@Override
|
||||||
public void onExecute(CommandSender sender, String[] args) {
|
public void onExecute(CommandSender sender, String[] args) {
|
||||||
if (!(sender instanceof Player) || !sender.hasPermission("slimefun.command.backpack")) {
|
if (sender instanceof Player) {
|
||||||
SlimefunPlugin.getLocalization().sendMessage(sender, "messages.no-permission", true);
|
if (sender.hasPermission("slimefun.command.backpack")) {
|
||||||
return;
|
if (args.length != 3) {
|
||||||
}
|
SlimefunPlugin.getLocalization().sendMessage(sender, "messages.usage", true, msg -> msg.replace("%usage%", "/sf backpack <Player> <ID>"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (args.length != 3) {
|
if (!PatternUtils.NUMERIC.matcher(args[2]).matches()) {
|
||||||
SlimefunPlugin.getLocalization().sendMessage(sender, "messages.usage", true, msg -> msg.replace("%usage%", "/sf backpack <Player> <ID>"));
|
SlimefunPlugin.getLocalization().sendMessage(sender, "commands.backpack.invalid-id");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PatternUtils.NUMERIC.matcher(args[2]).matches()) {
|
@SuppressWarnings("deprecation")
|
||||||
SlimefunPlugin.getLocalization().sendMessage(sender, "commands.backpack.invalid-id");
|
OfflinePlayer backpackOwner = Bukkit.getOfflinePlayer(args[1]);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
if (!(backpackOwner instanceof Player) && !backpackOwner.hasPlayedBefore()) {
|
||||||
OfflinePlayer backpackOwner = Bukkit.getOfflinePlayer(args[1]);
|
SlimefunPlugin.getLocalization().sendMessage(sender, "commands.backpack.player-never-joined");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(backpackOwner instanceof Player) && !backpackOwner.hasPlayedBefore()) {
|
int id = Integer.parseInt(args[2]);
|
||||||
SlimefunPlugin.getLocalization().sendMessage(sender, "commands.backpack.player-never-joined");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 -> {
|
SlimefunPlugin.runSync(() -> {
|
||||||
if (!profile.getBackpack(id).isPresent()) {
|
ItemStack item = SlimefunItems.RESTORED_BACKPACK.clone();
|
||||||
SlimefunPlugin.getLocalization().sendMessage(sender, "commands.backpack.backpack-does-not-exist");
|
SlimefunPlugin.getBackpackListener().setBackpackId(backpackOwner, item, 2, id);
|
||||||
return;
|
((Player) sender).getInventory().addItem(item);
|
||||||
|
SlimefunPlugin.getLocalization().sendMessage(sender, "commands.backpack.restored-backpack-given");
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
SlimefunPlugin.runSync(() -> {
|
SlimefunPlugin.getLocalization().sendMessage(sender, "messages.no-permission", true);
|
||||||
ItemStack item = SlimefunItems.RESTORED_BACKPACK.clone();
|
}
|
||||||
SlimefunPlugin.getBackpackListener().setBackpackId(backpackOwner, item, 2, id);
|
}
|
||||||
((Player) sender).getInventory().addItem(item);
|
else {
|
||||||
SlimefunPlugin.getLocalization().sendMessage(sender, "commands.backpack.restored-backpack-given");
|
SlimefunPlugin.getLocalization().sendMessage(sender, "messages.only-players", true);
|
||||||
});
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user