Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
53701da34f | ||
|
9cf4712813 | ||
|
abe8fccdb5 | ||
|
4499bb5453 | ||
|
5405b7d7b9 | ||
|
34199d12a4 | ||
|
67131ab9f9 | ||
|
723381cb2b | ||
|
34e7252d77 | ||
|
a1b2df74cc |
@@ -80,6 +80,14 @@ OpenInv is a [Bukkit plugin](https://dev.bukkit.org/bukkit-plugins/openinv/) whi
|
||||
<td>OpenInv.editinv</td>
|
||||
<td>Required to make changes to open inventories.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.openonline</td>
|
||||
<td>Allows users to open online players' inventories. For compatibility reasons this is granted by the nodes OpenInv.openinv and OpenInv.openender.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.openoffline</td>
|
||||
<td>Allows users to open offline players' inventories. For compatibility reasons this is granted by the nodes OpenInv.openinv and OpenInv.openender.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.openender</td>
|
||||
<td>Required to use /openender.</td>
|
||||
|
@@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvparent</artifactId>
|
||||
<version>4.1.0</version>
|
||||
<version>4.1.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvapi</artifactId>
|
||||
|
@@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvparent</artifactId>
|
||||
<version>4.1.1-SNAPSHOT</version>
|
||||
<version>4.1.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvassembly</artifactId>
|
||||
|
@@ -20,7 +20,7 @@
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvparent</artifactId>
|
||||
<version>4.1.1-SNAPSHOT</version>
|
||||
<version>4.1.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvinternal</artifactId>
|
||||
|
@@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvinternal</artifactId>
|
||||
<version>4.1.1-SNAPSHOT</version>
|
||||
<version>4.1.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvadapter1_14_R1</artifactId>
|
||||
@@ -38,7 +38,7 @@
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvplugincore</artifactId>
|
||||
<version>4.1.1-SNAPSHOT</version>
|
||||
<version>4.1.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@@ -20,18 +20,26 @@ import com.lishid.openinv.OpenInv;
|
||||
import com.lishid.openinv.internal.IPlayerDataManager;
|
||||
import com.lishid.openinv.internal.ISpecialInventory;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import net.minecraft.server.v1_14_R1.ChatComponentText;
|
||||
import net.minecraft.server.v1_14_R1.ChatMessageType;
|
||||
import net.minecraft.server.v1_14_R1.Container;
|
||||
import net.minecraft.server.v1_14_R1.Containers;
|
||||
import net.minecraft.server.v1_14_R1.DimensionManager;
|
||||
import net.minecraft.server.v1_14_R1.Entity;
|
||||
import net.minecraft.server.v1_14_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_14_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_14_R1.MinecraftServer;
|
||||
import net.minecraft.server.v1_14_R1.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_14_R1.PacketPlayOutChat;
|
||||
import net.minecraft.server.v1_14_R1.PacketPlayOutOpenWindow;
|
||||
import net.minecraft.server.v1_14_R1.PlayerInteractManager;
|
||||
import net.minecraft.server.v1_14_R1.PlayerInventory;
|
||||
import net.minecraft.server.v1_14_R1.WorldNBTStorage;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Server;
|
||||
@@ -49,6 +57,18 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
private Field bukkitEntity;
|
||||
|
||||
public PlayerDataManager() {
|
||||
try {
|
||||
bukkitEntity = Entity.class.getDeclaredField("bukkitEntity");
|
||||
} catch (NoSuchFieldException e) {
|
||||
System.out.println("Unable to obtain field to inject custom save process - players' mounts may be deleted when loaded.");
|
||||
e.printStackTrace();
|
||||
bukkitEntity = null;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static EntityPlayer getHandle(final Player player) {
|
||||
if (player instanceof CraftPlayer) {
|
||||
@@ -78,11 +98,18 @@ public class PlayerDataManager implements IPlayerDataManager {
|
||||
}
|
||||
|
||||
// Create a profile and entity to load the player data
|
||||
GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName());
|
||||
GameProfile profile = new GameProfile(offline.getUniqueId(),
|
||||
offline.getName() != null ? offline.getName() : offline.getUniqueId().toString());
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(DimensionManager.OVERWORLD), profile,
|
||||
new PlayerInteractManager(server.getWorldServer(DimensionManager.OVERWORLD)));
|
||||
|
||||
try {
|
||||
injectPlayer(entity);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
@@ -93,6 +120,63 @@ public class PlayerDataManager implements IPlayerDataManager {
|
||||
return target;
|
||||
}
|
||||
|
||||
void injectPlayer(EntityPlayer player) throws IllegalAccessException {
|
||||
if (bukkitEntity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
bukkitEntity.setAccessible(true);
|
||||
|
||||
bukkitEntity.set(player, new CraftPlayer(player.server.server, player) {
|
||||
@Override
|
||||
public void saveData() {
|
||||
super.saveData();
|
||||
// See net.minecraft.server.WorldNBTStorage#save(EntityPlayer)
|
||||
try {
|
||||
WorldNBTStorage worldNBTStorage = (WorldNBTStorage) player.server.getPlayerList().playerFileData;
|
||||
|
||||
NBTTagCompound playerData = player.save(new NBTTagCompound());
|
||||
|
||||
if (!isOnline()) {
|
||||
// Special case: save old vehicle data
|
||||
NBTTagCompound oldData = worldNBTStorage.load(player);
|
||||
|
||||
if (oldData != null && oldData.hasKeyOfType("RootVehicle", 10)) {
|
||||
// See net.minecraft.server.PlayerList#a(NetworkManager, EntityPlayer) and net.minecraft.server.EntityPlayer#b(NBTTagCompound)
|
||||
playerData.set("RootVehicle", oldData.getCompound("RootVehicle"));
|
||||
}
|
||||
}
|
||||
|
||||
File file = new File(worldNBTStorage.getPlayerDir(), player.getUniqueIDString() + ".dat.tmp");
|
||||
File file1 = new File(worldNBTStorage.getPlayerDir(), player.getUniqueIDString() + ".dat");
|
||||
|
||||
NBTCompressedStreamTools.a(playerData, new FileOutputStream(file));
|
||||
|
||||
if (file1.exists()) {
|
||||
file1.delete();
|
||||
}
|
||||
|
||||
file.renameTo(file1);
|
||||
} catch (Exception e) {
|
||||
LogManager.getLogger().warn("Failed to save player data for {}", player.getDisplayName().getString());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Player inject(@NotNull Player player) {
|
||||
try {
|
||||
EntityPlayer nmsPlayer = getHandle(player);
|
||||
injectPlayer(nmsPlayer);
|
||||
return nmsPlayer.getBukkitEntity();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) {
|
||||
@@ -106,19 +190,16 @@ public class PlayerDataManager implements IPlayerDataManager {
|
||||
String title;
|
||||
if (inventory instanceof SpecialEnderChest) {
|
||||
HumanEntity owner = (HumanEntity) ((SpecialEnderChest) inventory).getBukkitOwner();
|
||||
title = OpenInv.getPlugin(OpenInv.class).getLocalizedMessage(player, "container.enderchest");
|
||||
title = OpenInv.getPlugin(OpenInv.class).getLocalizedMessage(player, "container.enderchest", "%player%", owner.getName());
|
||||
if (title == null) {
|
||||
title = "%player%'s Ender Chest";
|
||||
title = owner.getName() + "'s Ender Chest";
|
||||
}
|
||||
//noinspection ConstantConditions - owner name can be null if loaded by UUID
|
||||
title = title.replace("%player%", owner.getName() != null ? owner.getName() : owner.getUniqueId().toString());
|
||||
} else if (inventory instanceof SpecialPlayerInventory) {
|
||||
EntityHuman owner = ((PlayerInventory) inventory).player;
|
||||
title = OpenInv.getPlugin(OpenInv.class).getLocalizedMessage(player, "container.player");
|
||||
title = OpenInv.getPlugin(OpenInv.class).getLocalizedMessage(player, "container.player", "%player%", owner.getName());
|
||||
if (title == null) {
|
||||
title = "%player%'s Inventory";
|
||||
title = owner.getName() + "'s Inventory";
|
||||
}
|
||||
title = title.replace("%player%", owner.getName() != null ? owner.getName() : owner.getUniqueID().toString());
|
||||
} else {
|
||||
return player.openInventory(inventory.getBukkitInventory());
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvinternal</artifactId>
|
||||
<version>4.1.1-SNAPSHOT</version>
|
||||
<version>4.1.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvadapter1_15_R1</artifactId>
|
||||
@@ -38,7 +38,7 @@
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvplugincore</artifactId>
|
||||
<version>4.1.1-SNAPSHOT</version>
|
||||
<version>4.1.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@@ -20,18 +20,26 @@ import com.lishid.openinv.OpenInv;
|
||||
import com.lishid.openinv.internal.IPlayerDataManager;
|
||||
import com.lishid.openinv.internal.ISpecialInventory;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import net.minecraft.server.v1_15_R1.ChatComponentText;
|
||||
import net.minecraft.server.v1_15_R1.ChatMessageType;
|
||||
import net.minecraft.server.v1_15_R1.Container;
|
||||
import net.minecraft.server.v1_15_R1.Containers;
|
||||
import net.minecraft.server.v1_15_R1.DimensionManager;
|
||||
import net.minecraft.server.v1_15_R1.Entity;
|
||||
import net.minecraft.server.v1_15_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_15_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_15_R1.MinecraftServer;
|
||||
import net.minecraft.server.v1_15_R1.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_15_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_15_R1.PacketPlayOutChat;
|
||||
import net.minecraft.server.v1_15_R1.PacketPlayOutOpenWindow;
|
||||
import net.minecraft.server.v1_15_R1.PlayerInteractManager;
|
||||
import net.minecraft.server.v1_15_R1.PlayerInventory;
|
||||
import net.minecraft.server.v1_15_R1.WorldNBTStorage;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Server;
|
||||
@@ -49,6 +57,18 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
private Field bukkitEntity;
|
||||
|
||||
public PlayerDataManager() {
|
||||
try {
|
||||
bukkitEntity = Entity.class.getDeclaredField("bukkitEntity");
|
||||
} catch (NoSuchFieldException e) {
|
||||
System.out.println("Unable to obtain field to inject custom save process - players' mounts may be deleted when loaded.");
|
||||
e.printStackTrace();
|
||||
bukkitEntity = null;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static EntityPlayer getHandle(final Player player) {
|
||||
if (player instanceof CraftPlayer) {
|
||||
@@ -79,11 +99,19 @@ public class PlayerDataManager implements IPlayerDataManager {
|
||||
}
|
||||
|
||||
// Create a profile and entity to load the player data
|
||||
GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName());
|
||||
// See net.minecraft.server.PlayerList#attemptLogin
|
||||
GameProfile profile = new GameProfile(offline.getUniqueId(),
|
||||
offline.getName() != null ? offline.getName() : offline.getUniqueId().toString());
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(DimensionManager.OVERWORLD), profile,
|
||||
new PlayerInteractManager(server.getWorldServer(DimensionManager.OVERWORLD)));
|
||||
|
||||
try {
|
||||
injectPlayer(entity);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
@@ -94,6 +122,63 @@ public class PlayerDataManager implements IPlayerDataManager {
|
||||
return target;
|
||||
}
|
||||
|
||||
void injectPlayer(EntityPlayer player) throws IllegalAccessException {
|
||||
if (bukkitEntity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
bukkitEntity.setAccessible(true);
|
||||
|
||||
bukkitEntity.set(player, new CraftPlayer(player.server.server, player) {
|
||||
@Override
|
||||
public void saveData() {
|
||||
super.saveData();
|
||||
// See net.minecraft.server.WorldNBTStorage#save(EntityPlayer)
|
||||
try {
|
||||
WorldNBTStorage worldNBTStorage = (WorldNBTStorage) player.server.getPlayerList().playerFileData;
|
||||
|
||||
NBTTagCompound playerData = player.save(new NBTTagCompound());
|
||||
|
||||
if (!isOnline()) {
|
||||
// Special case: save old vehicle data
|
||||
NBTTagCompound oldData = worldNBTStorage.load(player);
|
||||
|
||||
if (oldData != null && oldData.hasKeyOfType("RootVehicle", 10)) {
|
||||
// See net.minecraft.server.PlayerList#a(NetworkManager, EntityPlayer) and net.minecraft.server.EntityPlayer#b(NBTTagCompound)
|
||||
playerData.set("RootVehicle", oldData.getCompound("RootVehicle"));
|
||||
}
|
||||
}
|
||||
|
||||
File file = new File(worldNBTStorage.getPlayerDir(), player.getUniqueIDString() + ".dat.tmp");
|
||||
File file1 = new File(worldNBTStorage.getPlayerDir(), player.getUniqueIDString() + ".dat");
|
||||
|
||||
NBTCompressedStreamTools.a(playerData, new FileOutputStream(file));
|
||||
|
||||
if (file1.exists()) {
|
||||
file1.delete();
|
||||
}
|
||||
|
||||
file.renameTo(file1);
|
||||
} catch (Exception e) {
|
||||
LogManager.getLogger().warn("Failed to save player data for {}", player.getDisplayName().getString());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Player inject(@NotNull Player player) {
|
||||
try {
|
||||
EntityPlayer nmsPlayer = getHandle(player);
|
||||
injectPlayer(nmsPlayer);
|
||||
return nmsPlayer.getBukkitEntity();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) {
|
||||
@@ -107,19 +192,16 @@ public class PlayerDataManager implements IPlayerDataManager {
|
||||
String title;
|
||||
if (inventory instanceof SpecialEnderChest) {
|
||||
HumanEntity owner = (HumanEntity) ((SpecialEnderChest) inventory).getBukkitOwner();
|
||||
title = OpenInv.getPlugin(OpenInv.class).getLocalizedMessage(player, "container.enderchest");
|
||||
title = OpenInv.getPlugin(OpenInv.class).getLocalizedMessage(player, "container.enderchest", "%player%", owner.getName());
|
||||
if (title == null) {
|
||||
title = "%player%'s Ender Chest";
|
||||
title = owner.getName() + "'s Ender Chest";
|
||||
}
|
||||
//noinspection ConstantConditions - owner name can be null if loaded by UUID
|
||||
title = title.replace("%player%", owner.getName() != null ? owner.getName() : owner.getUniqueId().toString());
|
||||
} else if (inventory instanceof SpecialPlayerInventory) {
|
||||
EntityHuman owner = ((PlayerInventory) inventory).player;
|
||||
title = OpenInv.getPlugin(OpenInv.class).getLocalizedMessage(player, "container.player");
|
||||
title = OpenInv.getPlugin(OpenInv.class).getLocalizedMessage(player, "container.player", "%player%", owner.getName());
|
||||
if (title == null) {
|
||||
title = "%player%'s Inventory";
|
||||
title = owner.getName() + "'s Inventory";
|
||||
}
|
||||
title = title.replace("%player%", owner.getName() != null ? owner.getName() : owner.getUniqueID().toString());
|
||||
} else {
|
||||
return player.openInventory(inventory.getBukkitInventory());
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvinternal</artifactId>
|
||||
<version>4.1.1-SNAPSHOT</version>
|
||||
<version>4.1.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvadapter1_8_R3</artifactId>
|
||||
@@ -37,7 +37,7 @@
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvplugincore</artifactId>
|
||||
<version>4.1.1-SNAPSHOT</version>
|
||||
<version>4.1.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@@ -19,11 +19,19 @@ package com.lishid.openinv.internal.v1_8_R3;
|
||||
import com.lishid.openinv.internal.IPlayerDataManager;
|
||||
import com.lishid.openinv.internal.ISpecialInventory;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import net.minecraft.server.v1_8_R3.ChatComponentText;
|
||||
import net.minecraft.server.v1_8_R3.Entity;
|
||||
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_8_R3.MinecraftServer;
|
||||
import net.minecraft.server.v1_8_R3.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagCompound;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
|
||||
import net.minecraft.server.v1_8_R3.PlayerInteractManager;
|
||||
import net.minecraft.server.v1_8_R3.WorldNBTStorage;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Server;
|
||||
@@ -36,6 +44,18 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
private Field bukkitEntity;
|
||||
|
||||
public PlayerDataManager() {
|
||||
try {
|
||||
bukkitEntity = Entity.class.getDeclaredField("bukkitEntity");
|
||||
} catch (NoSuchFieldException e) {
|
||||
System.out.println("Unable to obtain field to inject custom save process - players' mounts may be deleted when loaded.");
|
||||
e.printStackTrace();
|
||||
bukkitEntity = null;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static EntityPlayer getHandle(Player player) {
|
||||
if (player instanceof CraftPlayer) {
|
||||
@@ -66,11 +86,18 @@ public class PlayerDataManager implements IPlayerDataManager {
|
||||
}
|
||||
|
||||
// Create a profile and entity to load the player data
|
||||
GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName());
|
||||
GameProfile profile = new GameProfile(offline.getUniqueId(),
|
||||
offline.getName() != null ? offline.getName() : offline.getUniqueId().toString());
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile,
|
||||
new PlayerInteractManager(server.getWorldServer(0)));
|
||||
|
||||
try {
|
||||
injectPlayer(entity);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
@@ -81,6 +108,64 @@ public class PlayerDataManager implements IPlayerDataManager {
|
||||
return target;
|
||||
}
|
||||
|
||||
void injectPlayer(EntityPlayer player) throws IllegalAccessException {
|
||||
if (bukkitEntity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
bukkitEntity.setAccessible(true);
|
||||
|
||||
bukkitEntity.set(player, new CraftPlayer(player.server.server, player) {
|
||||
@Override
|
||||
public void saveData() {
|
||||
super.saveData();
|
||||
// See net.minecraft.server.WorldNBTStorage#save(EntityHuman)
|
||||
try {
|
||||
WorldNBTStorage worldNBTStorage = (WorldNBTStorage) player.server.getPlayerList().playerFileData;
|
||||
|
||||
NBTTagCompound playerData = new NBTTagCompound();
|
||||
player.e(playerData);
|
||||
|
||||
if (!isOnline()) {
|
||||
// Special case: save old vehicle data
|
||||
NBTTagCompound oldData = worldNBTStorage.load(player);
|
||||
|
||||
if (oldData != null && oldData.hasKeyOfType("Riding", 10)) {
|
||||
// See net.minecraft.server.PlayerList#a(NetworkManager, EntityPlayer) and net.minecraft.server.EntityPlayer#b(NBTTagCompound)
|
||||
playerData.set("Riding", oldData.getCompound("Riding"));
|
||||
}
|
||||
}
|
||||
|
||||
File file = new File(worldNBTStorage.getPlayerDir(), player.getUniqueID().toString() + ".dat.tmp");
|
||||
File file1 = new File(worldNBTStorage.getPlayerDir(), player.getUniqueID().toString() + ".dat");
|
||||
|
||||
NBTCompressedStreamTools.a(playerData, new FileOutputStream(file));
|
||||
|
||||
if (file1.exists()) {
|
||||
file1.delete();
|
||||
}
|
||||
|
||||
file.renameTo(file1);
|
||||
} catch (Exception e) {
|
||||
LogManager.getLogger().warn("Failed to save player data for {}", player.getName());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Player inject(@NotNull Player player) {
|
||||
try {
|
||||
EntityPlayer nmsPlayer = getHandle(player);
|
||||
injectPlayer(nmsPlayer);
|
||||
return nmsPlayer.getBukkitEntity();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) {
|
||||
|
@@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvparent</artifactId>
|
||||
<version>4.1.1-SNAPSHOT</version>
|
||||
<version>4.1.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvplugincore</artifactId>
|
||||
@@ -31,7 +31,7 @@
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvapi</artifactId>
|
||||
<version>4.1.1-SNAPSHOT</version>
|
||||
<version>4.1.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
|
@@ -313,6 +313,10 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
||||
return this.languageManager.getValue(key, getLocale(sender));
|
||||
}
|
||||
|
||||
public @Nullable String getLocalizedMessage(@NotNull CommandSender sender, @NotNull String key, String... replacements) {
|
||||
return this.languageManager.getValue(key, getLocale(sender), replacements);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getLocale(@NotNull CommandSender sender) {
|
||||
if (sender instanceof Player) {
|
||||
@@ -465,6 +469,9 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
||||
return;
|
||||
}
|
||||
|
||||
// Replace stored player with our own version
|
||||
this.playerCache.put(key, this.accessor.getPlayerDataManager().inject(player));
|
||||
|
||||
if (this.inventories.containsKey(key)) {
|
||||
this.inventories.get(key).setPlayerOffline();
|
||||
}
|
||||
|
@@ -104,10 +104,20 @@ public class OpenInvCommand implements TabExecutor {
|
||||
boolean online = target.isOnline();
|
||||
|
||||
if (!online) {
|
||||
if (Permissions.OPENOFFLINE.hasPermission(player)) {
|
||||
// Try loading the player's data
|
||||
onlineTarget = this.plugin.loadPlayer(target);
|
||||
} else {
|
||||
plugin.sendMessage(player, "messages.error.permissionPlayerOffline");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (Permissions.OPENONLINE.hasPermission(player)) {
|
||||
onlineTarget = target.getPlayer();
|
||||
} else {
|
||||
plugin.sendMessage(player, "messages.error.permissionPlayerOnline");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (onlineTarget == null) {
|
||||
|
@@ -40,12 +40,18 @@ public class SearchInvCommand implements TabExecutor {
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
|
||||
Material material = null;
|
||||
int count = 1;
|
||||
|
||||
if (args.length >= 1) {
|
||||
material = Material.getMaterial(args[0].toUpperCase());
|
||||
}
|
||||
|
||||
if (material == null) {
|
||||
plugin.sendMessage(sender, "messages.error.invalidMaterial", "%target%", args.length > 0 ? args[0] : "null");
|
||||
return false;
|
||||
}
|
||||
|
||||
int count = 1;
|
||||
|
||||
if (args.length >= 2) {
|
||||
try {
|
||||
count = Integer.parseInt(args[1]);
|
||||
@@ -55,11 +61,6 @@ public class SearchInvCommand implements TabExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
if (material == null) {
|
||||
plugin.sendMessage(sender, "messages.error.invalidMaterial", "%target%", args[0]);
|
||||
return false;
|
||||
}
|
||||
|
||||
StringBuilder players = new StringBuilder();
|
||||
boolean searchInv = command.getName().equals("searchinv");
|
||||
for (Player player : plugin.getServer().getOnlinePlayers()) {
|
||||
|
@@ -35,6 +35,14 @@ public interface IPlayerDataManager {
|
||||
@Nullable
|
||||
Player loadPlayer(@NotNull OfflinePlayer offline);
|
||||
|
||||
/**
|
||||
* Creates a new Player from an existing one that will function slightly better offline.
|
||||
*
|
||||
* @return the Player
|
||||
*/
|
||||
@NotNull
|
||||
Player inject(@NotNull Player player);
|
||||
|
||||
/**
|
||||
* Opens an ISpecialInventory for a Player.
|
||||
*
|
||||
|
@@ -99,6 +99,11 @@ public class LanguageManager {
|
||||
|
||||
if (!newKeys.isEmpty()) {
|
||||
plugin.getLogger().info("[LanguageManager] Added new language keys: " + String.join(", ", newKeys));
|
||||
try {
|
||||
localeConfig.save(file);
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().log(Level.WARNING, "[LanguageManager] Unable to save resource " + locale + ".yml", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -33,7 +33,9 @@ public enum Permissions {
|
||||
SEARCH("search"),
|
||||
EDITINV("editinv"),
|
||||
EDITENDER("editender"),
|
||||
OPENSELF("openself");
|
||||
OPENSELF("openself"),
|
||||
OPENONLINE("openonline"),
|
||||
OPENOFFLINE("openoffline");
|
||||
|
||||
private final String permission;
|
||||
|
||||
|
@@ -9,6 +9,8 @@ messages:
|
||||
permissionEnderAll: '&cYou''re not allowed to access other players'' ender chests.'
|
||||
permissionExempt: '&c%target%''s inventory is protected.'
|
||||
permissionCrossWorld: '&c%target% is not in your world.'
|
||||
permissionPlayerOnline: '&cYou''re not allowed to open the inventory of online players.'
|
||||
permissionPlayerOffline: '&cYou''re not allowed to open the inventory of offline players.'
|
||||
commandException: '&cAn error occurred. Please check console for details.'
|
||||
info:
|
||||
containerBlocked: 'You are opening a blocked container.'
|
||||
@@ -25,4 +27,4 @@ messages:
|
||||
off: 'off'
|
||||
container:
|
||||
player: '%player%''s Inventory'
|
||||
enderchest: '%Player''s Ender Chest'
|
||||
enderchest: '%player%''s Ender Chest'
|
||||
|
@@ -25,6 +25,18 @@ permissions:
|
||||
OpenInv.anychest: true
|
||||
OpenInv.searchenchant: true
|
||||
OpenInv.searchcontainer: true
|
||||
OpenInv.openonline: true
|
||||
OpenInv.openoffline: true
|
||||
OpenInv.openinv:
|
||||
default: op
|
||||
children:
|
||||
OpenInv.openonline: true
|
||||
OpenInv.openoffline: true
|
||||
OpenInv.openender:
|
||||
default: op
|
||||
children:
|
||||
OpenInv.openonline: true
|
||||
OpenInv.openoffline: true
|
||||
|
||||
commands:
|
||||
openinv:
|
||||
|
30
plugin/src/main/resources/pt_br.yml
Normal file
30
plugin/src/main/resources/pt_br.yml
Normal file
@@ -0,0 +1,30 @@
|
||||
messages:
|
||||
error:
|
||||
consoleUnsupported: 'Voce nao consegue usar esse comando pelo console.'
|
||||
lootNotGenerated: '&cPilhagem nao gerada! Por favor desabilite &b/silentcontainer&c.'
|
||||
invalidMaterial: '&cMaterial invalido: "%target%"'
|
||||
invalidNumber: '&cNumero invalido: "%target%"'
|
||||
invalidPlayer: '&cJogador nao encontrado!'
|
||||
permissionOpenSelf: '&cVoce nao pode abrir seu proprio inventario.'
|
||||
permissionEnderAll: '&cVoce nao tem permissao para abrir baus de ender de outros jogadores.'
|
||||
permissionExempt: '&cO inventario de %target% e protegido.'
|
||||
permissionCrossWorld: '&c%target% nao esta no seu mundo.'
|
||||
permissionPlayerOnline: '&cVoce nao tem permissao para abrir o inventario de jogadores online.'
|
||||
permissionPlayerOffline: '&cVoce nao tem permissao para abrir o inventario de jogadores offline.'
|
||||
commandException: '&cUm erro ocorreu. Por favor cheque o console para detalhes.'
|
||||
info:
|
||||
containerBlocked: 'Voce esta abrindo um recipiente bloqueado.'
|
||||
containerBlockedSilent: 'Voce esta abrindo um recipiente bloqueado silenciosamente.'
|
||||
containerSilent: 'Voce esta abrindo um recipiente silenciosamente.'
|
||||
settingState: '%setting%: %state%'
|
||||
player:
|
||||
noMatches: 'Nenhum jogador encontrado com %target%.'
|
||||
matches: 'Jogadores segurando %target%: %detail%'
|
||||
container:
|
||||
noMatches: 'Nenhum recipiente encontrado com %target%.'
|
||||
matches: 'Recipientes contendo %target%: %detail%'
|
||||
on: 'ligado'
|
||||
off: 'desligado'
|
||||
container:
|
||||
player: 'Inventario de %player%'
|
||||
enderchest: 'Bau de Ender de %player%'
|
Reference in New Issue
Block a user