mirror of
https://github.com/TotalFreedomMC/OpenInv.git
synced 2024-12-23 00:15:08 +00:00
Migrate API-only functions out of PlayerDataManager
With the update to 1.16 there's no need to maintain multiple copies of the same code. Additionally, in 1.16 the action bar now supports JSON text.
This commit is contained in:
parent
1d5a836fd0
commit
6563b4f6ce
3 changed files with 20 additions and 39 deletions
|
@ -22,16 +22,13 @@ import com.lishid.openinv.internal.OpenInventoryView;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import net.minecraft.server.v1_16_R3.ChatComponentText;
|
import net.minecraft.server.v1_16_R3.ChatComponentText;
|
||||||
import net.minecraft.server.v1_16_R3.ChatMessageType;
|
|
||||||
import net.minecraft.server.v1_16_R3.Container;
|
import net.minecraft.server.v1_16_R3.Container;
|
||||||
import net.minecraft.server.v1_16_R3.Containers;
|
import net.minecraft.server.v1_16_R3.Containers;
|
||||||
import net.minecraft.server.v1_16_R3.Entity;
|
import net.minecraft.server.v1_16_R3.Entity;
|
||||||
import net.minecraft.server.v1_16_R3.EntityPlayer;
|
import net.minecraft.server.v1_16_R3.EntityPlayer;
|
||||||
import net.minecraft.server.v1_16_R3.MinecraftServer;
|
import net.minecraft.server.v1_16_R3.MinecraftServer;
|
||||||
import net.minecraft.server.v1_16_R3.PacketPlayOutChat;
|
|
||||||
import net.minecraft.server.v1_16_R3.PacketPlayOutOpenWindow;
|
import net.minecraft.server.v1_16_R3.PacketPlayOutOpenWindow;
|
||||||
import net.minecraft.server.v1_16_R3.PlayerInteractManager;
|
import net.minecraft.server.v1_16_R3.PlayerInteractManager;
|
||||||
import net.minecraft.server.v1_16_R3.SystemUtils;
|
|
||||||
import net.minecraft.server.v1_16_R3.World;
|
import net.minecraft.server.v1_16_R3.World;
|
||||||
import net.minecraft.server.v1_16_R3.WorldServer;
|
import net.minecraft.server.v1_16_R3.WorldServer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@ -237,24 +234,4 @@ public class PlayerDataManager implements IPlayerDataManager {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendSystemMessage(@NotNull Player player, @NotNull String message) {
|
|
||||||
int newline = message.indexOf('\n');
|
|
||||||
if (newline != -1) {
|
|
||||||
// No newlines in action bar chat.
|
|
||||||
message = message.substring(0, newline);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (message.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityPlayer nmsPlayer = getHandle(player);
|
|
||||||
|
|
||||||
// For action bar chat, color codes are still supported but JSON text color is not allowed. Do not convert text.
|
|
||||||
if (nmsPlayer.playerConnection != null) {
|
|
||||||
nmsPlayer.playerConnection.sendPacket(new PacketPlayOutChat(new ChatComponentText(message), ChatMessageType.GAME_INFO, SystemUtils.b));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,8 @@ import java.util.Map;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
|
@ -299,9 +301,21 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
||||||
public void sendSystemMessage(@NotNull Player player, @NotNull String key) {
|
public void sendSystemMessage(@NotNull Player player, @NotNull String key) {
|
||||||
String message = this.languageManager.getValue(key, getLocale(player));
|
String message = this.languageManager.getValue(key, getLocale(player));
|
||||||
|
|
||||||
if (message != null) {
|
if (message == null) {
|
||||||
this.accessor.getPlayerDataManager().sendSystemMessage(player, message);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int newline = message.indexOf('\n');
|
||||||
|
if (newline != -1) {
|
||||||
|
// No newlines in action bar chat.
|
||||||
|
message = message.substring(0, newline);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable String getLocalizedMessage(@NotNull CommandSender sender, @NotNull String key) {
|
public @Nullable String getLocalizedMessage(@NotNull CommandSender sender, @NotNull String key) {
|
||||||
|
@ -314,7 +328,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
||||||
|
|
||||||
private @Nullable String getLocale(@NotNull CommandSender sender) {
|
private @Nullable String getLocale(@NotNull CommandSender sender) {
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
return this.accessor.getPlayerDataManager().getLocale((Player) sender);
|
return ((Player) sender).getLocale();
|
||||||
} else {
|
} else {
|
||||||
return this.getConfig().getString("settings.locale", "en_us");
|
return this.getConfig().getString("settings.locale", "en_us");
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,16 +32,14 @@ public interface IPlayerDataManager {
|
||||||
* @param offline the OfflinePlayer
|
* @param offline the OfflinePlayer
|
||||||
* @return the Player loaded
|
* @return the Player loaded
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable Player loadPlayer(@NotNull OfflinePlayer offline);
|
||||||
Player loadPlayer(@NotNull OfflinePlayer offline);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Player from an existing one that will function slightly better offline.
|
* Creates a new Player from an existing one that will function slightly better offline.
|
||||||
*
|
*
|
||||||
* @return the Player
|
* @return the Player
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull Player inject(@NotNull Player player);
|
||||||
Player inject(@NotNull Player player);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens an ISpecialInventory for a Player.
|
* Opens an ISpecialInventory for a Player.
|
||||||
|
@ -51,8 +49,7 @@ public interface IPlayerDataManager {
|
||||||
*`
|
*`
|
||||||
* @return the InventoryView opened
|
* @return the InventoryView opened
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory);
|
||||||
InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a raw slot number into a player inventory slot number.
|
* Convert a raw slot number into a player inventory slot number.
|
||||||
|
@ -66,11 +63,4 @@ public interface IPlayerDataManager {
|
||||||
*/
|
*/
|
||||||
int convertToPlayerSlot(InventoryView view, int rawSlot);
|
int convertToPlayerSlot(InventoryView view, int rawSlot);
|
||||||
|
|
||||||
void sendSystemMessage(@NotNull Player player, @NotNull String message);
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
default String getLocale(Player player) {
|
|
||||||
return player.getLocale();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue