Skip to content

Commit

Permalink
Allow playername placeholder in own title.
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgH93 committed Jan 16, 2024
1 parent 5f3b803 commit 6d0022e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
23 changes: 15 additions & 8 deletions Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Backpack.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 GeorgH93
* Copyright (C) 2024 GeorgH93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -12,7 +12,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package at.pcgamingfreaks.Minepacks.Bukkit;
Expand All @@ -21,9 +21,7 @@
import at.pcgamingfreaks.Bukkit.Util.InventoryUtils;
import at.pcgamingfreaks.Minepacks.Bukkit.Database.Helper.InventoryCompressor;
import at.pcgamingfreaks.Util.StringUtils;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
Expand All @@ -33,6 +31,10 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand All @@ -42,8 +44,9 @@
public class Backpack implements at.pcgamingfreaks.Minepacks.Bukkit.API.Backpack
{
@Setter(AccessLevel.PACKAGE) private static ShrinkApproach shrinkApproach = ShrinkApproach.COMPRESS;
private static Object titleOwn;
private static String titleOtherFormat;
private static Object titleOwnGlobal;
private static String titleFormat, titleOtherFormat;
private final Object titleOwn;
private final String titleOther;
@Getter private final UUID ownerId;
private final Map<Player, Boolean> opened = new ConcurrentHashMap<>(); //Thanks Minecraft 1.14
Expand All @@ -54,7 +57,8 @@ public class Backpack implements at.pcgamingfreaks.Minepacks.Bukkit.API.Backpack

public static void setTitle(final @NotNull String title, final @NotNull String titleOther)
{
titleOwn = InventoryUtils.prepareTitleForOpenInventoryWithCustomTitle(title);
titleOwnGlobal = title.contains("%s") ? null : InventoryUtils.prepareTitleForOpenInventoryWithCustomTitle(title);
titleFormat = title;
titleOtherFormat = titleOther;
}

Expand All @@ -80,6 +84,9 @@ public Backpack(OfflinePlayer owner, int size, int ID)
bp = Bukkit.createInventory(this, size, titleOther);
this.size = size;
ownerDatabaseId = ID;

if (titleOwnGlobal != null) titleOwn = titleOwnGlobal;
else titleOwn = InventoryUtils.prepareTitleForOpenInventoryWithCustomTitle(String.format(titleFormat, owner.getName()));
}

public Backpack(final OfflinePlayer owner, ItemStack[] backpack, final int ID)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 GeorgH93
* Copyright (C) 2024 GeorgH93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -12,7 +12,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package at.pcgamingfreaks.Minepacks.Bukkit.Database;
Expand All @@ -31,6 +31,7 @@
import at.pcgamingfreaks.Minepacks.Bukkit.ShrinkApproach;
import at.pcgamingfreaks.Minepacks.MagicValues;
import at.pcgamingfreaks.Version;

import org.bukkit.*;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -175,7 +176,7 @@ public String getBPTitleOther()

public String getBPTitle()
{
return ChatColor.translateAlternateColorCodes('&', getConfigE().getString("BackpackTitle", "Backpack"));
return ChatColor.translateAlternateColorCodes('&', getConfigE().getString("BackpackTitle", "Backpack").replace("%", "%%").replace("{OwnerName}", "%s"));
}

public boolean getDropOnDeath()
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<packaging>pom</packaging>

<properties>
<revision>2.4.25</revision>
<revision>2.4.26</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

Expand Down

0 comments on commit 6d0022e

Please sign in to comment.