Add different message if the backpack was cleared by another player

This commit is contained in:
GeorgH93 2020-02-24 23:24:32 +01:00
parent 1a5adf8270
commit 160efba42e
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
3 changed files with 27 additions and 4 deletions

View File

@ -17,6 +17,8 @@ Language:
DontRemoveShortcut_SendMethod: "action_bar"
Clean:
BackpackCleaned: "Rucksack geleert."
BackpackCleanedBy: "Dein Rucksack wurde von {DisplayName}&r geleert"
BackpackCleanedOther: "Der Rucksack von {DisplayName}&r wurde geleert."
Open:
#Parameter: {TimeLeft} time in seconds till he can reopen his backpack
Cooldown: "&2Bitte warte noch {TimeLeft} Sekunden bis du deinen Rucksack wieder öffnest."

View File

@ -22,7 +22,9 @@ Language:
#Parameter: {CurrentGameMode}, {AllowedGameModes}
WrongGameMode: "You are not allowed to open your backpack in your current game-mode."
Clean:
BackpackCleaned: "Backpack cleaned."
BackpackCleaned: "Backpack cleared."
BackpackCleanedBy: "Your backpack has been cleared by {DisplayName}&r."
BackpackCleanedOther: "{DisplayName}'s&r backpack has been cleared."
Help:
Header: "&6### Minepacks Commands ###"
Footer: "&6#############################"

View File

@ -27,6 +27,7 @@
import at.pcgamingfreaks.Minepacks.Bukkit.Permissions;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -36,15 +37,17 @@
public class ClearCommand extends MinepacksCommand
{
private final Message messageBackpackCleaned;
private final Message messageCleared, messageClearedOther, messageClearedBy;
private final String helpParam, descriptionCleanOthers;
public ClearCommand(Minepacks plugin)
{
super(plugin, "clear", plugin.getLanguage().getTranslated("Commands.Description.Clean"), Permissions.CLEAN, plugin.getLanguage().getCommandAliases("Clean"));
messageBackpackCleaned = plugin.getLanguage().getMessage("Ingame.Clean.BackpackCleaned");
descriptionCleanOthers = plugin.getLanguage().getTranslated("Commands.Description.CleanOthers");
helpParam = "<" + plugin.getLanguage().get("Commands.PlayerNameVariable") + ">";
messageCleared = plugin.getLanguage().getMessage("Ingame.Clean.BackpackCleaned");
messageClearedBy = plugin.getLanguage().getMessage("Ingame.Clean.BackpackCleanedBy").replaceAll("\\{Name}", "%1\\$s").replaceAll("\\{DisplayName}", "%2\\$s");
messageClearedOther = plugin.getLanguage().getMessage("Ingame.Clean.BackpackCleanedOther").replaceAll("\\{Name}", "%1\\$s").replaceAll("\\{DisplayName}", "%2\\$s");
}
@Override
@ -67,7 +70,23 @@ public void onResult(Backpack backpack)
if(backpack != null)
{
backpack.clear();
messageBackpackCleaned.send(commandSender);
if(commandSender.equals(backpack.getOwner()))
{
messageCleared.send(commandSender);
}
else
{
if(backpack.getOwner().isOnline())
{
Player owner = backpack.getOwner().getPlayer();
messageClearedOther.send(commandSender, backpack.getOwner().getName(), owner.getDisplayName());
messageClearedBy.send(owner, commandSender.getName(), (commandSender instanceof Player) ? ((Player) commandSender).getDisplayName() : ChatColor.GRAY + commandSender.getName());
}
else
{
messageClearedOther.send(commandSender, backpack.getOwner().getName(), ChatColor.GRAY + backpack.getOwner().getName());
}
}
}
else
{