mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-16 17:44:46 +00:00
Final & Synchronized Data sending with slight delays to heavily improve server performance
This commit is contained in:
1 parent
ee33a57323
commit
cf82314181
8 files changed
+47
-36
No files matched your search
@@ -242,8 +242,8 @@ public class NoppesUtilServer {
|
||||
EnumGuiType gui, EntityNPCInterface npc) {
|
||||
sendOpenGui(player, gui, npc, 0, 0, 0);
|
||||
}
|
||||
public static void sendOpenGui(EntityPlayer player,
|
||||
EnumGuiType gui, EntityNPCInterface npc, int i, int j, int k) {
|
||||
public static void sendOpenGui(final EntityPlayer player,
|
||||
final EnumGuiType gui, final EntityNPCInterface npc, final int i, final int j, final int k) {
|
||||
if(!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.Map;
|
||||
|
||||
public class Server {
|
||||
|
||||
public static boolean sendData(EntityPlayerMP player, EnumPacketClient enu, Object... obs) {
|
||||
public static boolean sendData(final EntityPlayerMP player, final EnumPacketClient enu, final Object... obs) {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
try {
|
||||
if(!fillBuffer(buffer, enu, obs))
|
||||
@@ -58,7 +58,7 @@ public class Server {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void sendAssociatedData(Entity entity, EnumPacketClient enu, Object... obs) {
|
||||
public static void sendAssociatedData(final Entity entity, final EnumPacketClient enu, final Object... obs) {
|
||||
CustomNPCsScheduler.runTack(() -> {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
try {
|
||||
|
||||
@@ -3,14 +3,17 @@ package noppes.npcs.client;
|
||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import noppes.npcs.AnimationData;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.client.gui.OverlayQuestTracking;
|
||||
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
|
||||
import noppes.npcs.client.renderer.customitem.ImageData;
|
||||
import noppes.npcs.constants.EnumPacketServer;
|
||||
import noppes.npcs.controllers.data.SkinOverlay;
|
||||
import noppes.npcs.util.CustomNPCsScheduler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
@@ -23,15 +26,17 @@ public class Client {
|
||||
public static HashMap<UUID, AnimationData> playerAnimations = new HashMap<>();
|
||||
private static HashMap<String, ImageData> imageDataCache = new HashMap<>();
|
||||
|
||||
public static void sendData(EnumPacketServer enu, Object... obs) {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
try {
|
||||
if(!Server.fillBuffer(buffer, enu, obs))
|
||||
return;
|
||||
CustomNpcs.Channel.sendToServer(new FMLProxyPacket(buffer, "CustomNPCs"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public static void sendData(final EnumPacketServer enu, final Object... obs) {
|
||||
CustomNPCsScheduler.runTack(() -> {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
try {
|
||||
if(!Server.fillBuffer(buffer, enu, obs))
|
||||
return;
|
||||
CustomNpcs.Channel.sendToServer(new FMLProxyPacket(buffer, "CustomNPCs"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static ImageData getImageData(String directory) {
|
||||
|
||||
@@ -19,6 +19,7 @@ import noppes.npcs.api.gui.IItemSlot;
|
||||
import noppes.npcs.client.gui.custom.components.CustomGuiSlot;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.gui.ScriptGui;
|
||||
import noppes.npcs.util.CustomNPCsScheduler;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
@@ -134,8 +135,7 @@ public class ContainerCustomGui extends Container {
|
||||
}
|
||||
|
||||
EntityPlayerMP p = (EntityPlayerMP) player;
|
||||
p.sendContainerToPlayer(this);
|
||||
|
||||
CustomNPCsScheduler.runTack(() -> {p.sendContainerToPlayer(this);}, 10);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,10 @@ public class ContainerNPCBankInterface extends ContainerNpcInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
public synchronized void setCurrency(ItemStack item){
|
||||
currency.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int i)
|
||||
{
|
||||
|
||||
@@ -257,9 +257,9 @@ public class PlayerDataController {
|
||||
return new NBTTagCompound();
|
||||
}
|
||||
|
||||
public synchronized void savePlayerData(PlayerData data){
|
||||
NBTTagCompound compound = data.getNBT();
|
||||
String filename = data.uuid + ".json";
|
||||
public synchronized void savePlayerData(final PlayerData data){
|
||||
final NBTTagCompound compound = data.getNBT();
|
||||
final String filename = data.uuid + ".json";
|
||||
|
||||
CustomNPCsScheduler.runTack(() -> {
|
||||
try {
|
||||
|
||||
@@ -15,6 +15,7 @@ import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.containers.ContainerNPCBankInterface;
|
||||
import noppes.npcs.controllers.BankController;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.util.CustomNPCsScheduler;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -74,10 +75,8 @@ public class BankData {
|
||||
return bank.canBeUpgraded(slot) && upgradedSlots.get(slot);
|
||||
}
|
||||
|
||||
public void openBankGui(EntityPlayer player, EntityNPCInterface npc, int bankId, int slot) {
|
||||
Bank bank = BankController.getInstance().banks.get(bankId);
|
||||
if(bank == null)
|
||||
bank = BankController.getInstance().banks.values().iterator().next();
|
||||
public void openBankGui(final EntityPlayer player, EntityNPCInterface npc, int bankId, int slot) {
|
||||
final Bank bank = BankController.getInstance().getBank(bankId);
|
||||
|
||||
if(bank.getMaxSlots() <= slot)
|
||||
return;
|
||||
@@ -100,17 +99,19 @@ public class BankData {
|
||||
else{
|
||||
NoppesUtilServer.sendOpenGui(player, EnumGuiType.PlayerBankSmall, npc, slot, bank.id, 0);
|
||||
}
|
||||
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setInteger("MaxSlots", bank.getMaxSlots());
|
||||
compound.setInteger("UnlockedSlots", unlockedSlots);
|
||||
if(currency != null){
|
||||
compound.setTag("Currency", NoppesUtilServer.writeItem(currency, new NBTTagCompound()));
|
||||
ContainerNPCBankInterface container = getContainer(player);
|
||||
container.currency.item = currency;
|
||||
}
|
||||
|
||||
Server.sendData((EntityPlayerMP)player, EnumPacketClient.GUI_DATA,compound);
|
||||
final ItemStack item = currency;
|
||||
CustomNPCsScheduler.runTack(() -> {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setInteger("MaxSlots", bank.getMaxSlots());
|
||||
compound.setInteger("UnlockedSlots", unlockedSlots);
|
||||
if (item != null) {
|
||||
compound.setTag("Currency", NoppesUtilServer.writeItem(item, new NBTTagCompound()));
|
||||
ContainerNPCBankInterface container = getContainer(player);
|
||||
if (container != null)
|
||||
container.setCurrency(item);
|
||||
}
|
||||
Server.sendDataChecked((EntityPlayerMP) player, EnumPacketClient.GUI_DATA, compound);
|
||||
}, 300);
|
||||
}
|
||||
private ContainerNPCBankInterface getContainer(EntityPlayer player){
|
||||
Container con = player.openContainer;
|
||||
|
||||
@@ -18,6 +18,7 @@ import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.constants.EnumGuiType;
|
||||
import noppes.npcs.entity.EntityCustomNpc;
|
||||
import noppes.npcs.util.CustomNPCsScheduler;
|
||||
|
||||
public class ItemNpcWand extends Item{
|
||||
|
||||
@@ -35,7 +36,7 @@ public class ItemNpcWand extends Item{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer player, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
|
||||
public boolean onItemUse(ItemStack par1ItemStack, final EntityPlayer player, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
|
||||
{
|
||||
if(par3World.isRemote)
|
||||
return true;
|
||||
@@ -50,8 +51,8 @@ public class ItemNpcWand extends Item{
|
||||
|
||||
par3World.spawnEntityInWorld(npc);
|
||||
npc.setHealth(npc.getMaxHealth());
|
||||
|
||||
NoppesUtilServer.sendOpenGui(player,EnumGuiType.MainMenuDisplay,npc);
|
||||
|
||||
CustomNPCsScheduler.runTack(() -> NoppesUtilServer.sendOpenGui(player, EnumGuiType.MainMenuDisplay,npc), 100);
|
||||
}
|
||||
else
|
||||
player.addChatMessage(new ChatComponentTranslation("availability.permission"));
|
||||
|
||||
Reference in new issue
Block a user