Fix error when backpack is opened by more than one player on MC 1.14, 1.15 and 1.16

Add support for RGB colors in all messages
This commit is contained in:
GeorgH93 2020-07-06 00:11:10 +02:00
parent 5891a7da7c
commit 05de6aebbb
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
5 changed files with 27 additions and 16 deletions

View File

@ -38,7 +38,7 @@
<dependency>
<groupId>at.pcgamingfreaks</groupId>
<artifactId>PluginLib</artifactId>
<version>1.0.27-SNAPSHOT</version>
<version>1.0.28-SNAPSHOT</version>
</dependency>
<!-- BadRabbit -->
<dependency>

View File

@ -19,6 +19,7 @@
import at.pcgamingfreaks.Bukkit.MCVersion;
import at.pcgamingfreaks.Bukkit.NMSReflection;
import at.pcgamingfreaks.Bukkit.Utils;
import at.pcgamingfreaks.Minepacks.Bukkit.Database.Helper.InventoryCompressor;
import at.pcgamingfreaks.StringUtils;
@ -48,7 +49,7 @@ public class Backpack implements at.pcgamingfreaks.Minepacks.Bukkit.API.Backpack
private final static Field FIELD_TITLE = NMSReflection.getOBCField("inventory.CraftInventoryCustom$MinecraftInventory", "title");
@Setter(AccessLevel.PACKAGE) private static ShrinkApproach shrinkApproach = ShrinkApproach.COMPRESS;
private static Object titleOwn;
private static String titleOtherFormat, titleOther;
private static String titleOtherFormat, titleOther, titleOwnString;
private final OfflinePlayer owner;
private final Object titleOtherOBC;
private final Map<Player, Boolean> opened = new ConcurrentHashMap<>(); //Thanks Minecraft 1.14
@ -58,6 +59,7 @@ public class Backpack implements at.pcgamingfreaks.Minepacks.Bukkit.API.Backpack
public static void setTitle(final @NotNull String title, final @NotNull String titleOther)
{
titleOwnString = title;
titleOwn = prepareTitle(title);
titleOtherFormat = titleOther;
}
@ -194,6 +196,8 @@ public void open(@NotNull Player player, boolean editable, final @Nullable Strin
opened.put(player, editable);
//region Set backpack title
if(MCVersion.isOlderThan(MCVersion.MC_1_14))
{
// It's not perfect, but it is the only way of doing this.
// This sets the title of the inventory based on the person who is opening it.
// The owner will see an other title, then everyone else.
@ -210,9 +214,15 @@ public void open(@NotNull Player player, boolean editable, final @Nullable Strin
e.printStackTrace();
}
}
}
//endregion
player.openInventory(bp);
if(MCVersion.isNewerOrEqualThan(MCVersion.MC_1_14))
{
final String usedTitle = (title == null) ? (player.equals(owner) ? titleOwnString : titleOther) : title;
Bukkit.getScheduler().runTaskLater(Minepacks.getInstance(), () -> Utils.updateInventoryTitle(player, usedTitle), 2);
}
}
public void close(Player p)

View File

@ -19,5 +19,5 @@
public class MagicValues
{
public static final String MIN_PCGF_PLUGIN_LIB_VERSION = "1.0.27-SNAPSHOT";
public static final String MIN_PCGF_PLUGIN_LIB_VERSION = "1.0.28-SNAPSHOT";
}

View File

@ -105,6 +105,7 @@ public void onEnable()
updater = new ManagedUpdater(this);
instance = this;
config = new Config(this);
updater.setChannel(config.getUpdateChannel());
if(config.useUpdater()) updater.update();
if(!checkMcVersion()) return;

View File

@ -7,7 +7,7 @@
<packaging>pom</packaging>
<properties>
<revision>2.3.10</revision>
<revision>2.3.11</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>