mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-16 22:15:06 +00:00
Revert lots of multithreading for better threaded saving and data synchronization
This commit is contained in:
1 parent
6f1914c002
commit
49fab85291
6 files changed
+19
-20
No files matched your search
@@ -13,7 +13,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.village.MerchantRecipeList;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.util.CustomNPCsScheduler;
|
||||
import noppes.npcs.util.CustomNPCsThreader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@@ -26,7 +26,7 @@ public class Server {
|
||||
}
|
||||
|
||||
public static void sendDataDelayed(final EntityPlayerMP player, final EnumPacketClient type, int delay, final Object... obs) {
|
||||
CustomNPCsScheduler.runTack(() -> {
|
||||
CustomNPCsThreader.runTack(() -> {
|
||||
PacketBuffer buffer = new PacketBuffer(Unpooled.buffer());
|
||||
try {
|
||||
if (!fillBuffer(buffer, type, obs))
|
||||
@@ -51,7 +51,7 @@ public class Server {
|
||||
}
|
||||
|
||||
public static void sendAssociatedData(final Entity entity, final EnumPacketClient enu, final Object... obs) {
|
||||
CustomNPCsScheduler.runTack(() -> {
|
||||
CustomNPCsThreader.runTack(() -> {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
try {
|
||||
if(!fillBuffer(buffer, enu, obs))
|
||||
|
||||
@@ -7,11 +7,9 @@ package noppes.npcs.containers;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
@@ -19,7 +17,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 noppes.npcs.util.CustomNPCsThreader;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
@@ -135,7 +133,7 @@ public class ContainerCustomGui extends Container {
|
||||
}
|
||||
|
||||
EntityPlayerMP p = (EntityPlayerMP) player;
|
||||
CustomNPCsScheduler.runTack(() -> {p.sendContainerToPlayer(this);}, 10);
|
||||
p.sendContainerToPlayer(this);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,21 +9,20 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.controllers.data.*;
|
||||
import noppes.npcs.util.CustomNPCsScheduler;
|
||||
import noppes.npcs.util.CustomNPCsThreader;
|
||||
import noppes.npcs.util.NBTJsonUtil;
|
||||
import org.lwjgl.Sys;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import static noppes.npcs.util.CustomNPCsThreader.playerDataThread;
|
||||
|
||||
public class PlayerDataController {
|
||||
public static PlayerDataController instance;
|
||||
public HashMap<String, String> nameUUIDs;
|
||||
@@ -169,7 +168,7 @@ public class PlayerDataController {
|
||||
}
|
||||
|
||||
public synchronized void savePlayerDataMap(){
|
||||
CustomNPCsScheduler.runTack(() -> {
|
||||
playerDataThread.execute(() -> {
|
||||
try {
|
||||
File saveDir = getSaveDir();
|
||||
File file = new File(saveDir, "___playermap.dat_new");
|
||||
|
||||
@@ -15,7 +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 noppes.npcs.util.CustomNPCsThreader;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -100,7 +100,7 @@ public class BankData {
|
||||
NoppesUtilServer.sendOpenGui(player, EnumGuiType.PlayerBankSmall, npc, slot, bank.id, 0);
|
||||
}
|
||||
final ItemStack item = currency;
|
||||
CustomNPCsScheduler.runTack(() -> {
|
||||
CustomNPCsThreader.runTack(() -> {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setInteger("MaxSlots", bank.getMaxSlots());
|
||||
compound.setInteger("UnlockedSlots", unlockedSlots);
|
||||
|
||||
@@ -19,12 +19,14 @@ import noppes.npcs.entity.data.DataSkinOverlays;
|
||||
import noppes.npcs.entity.data.DataTimers;
|
||||
import noppes.npcs.roles.RoleCompanion;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.util.CustomNPCsScheduler;
|
||||
import noppes.npcs.util.CustomNPCsThreader;
|
||||
import noppes.npcs.util.NBTJsonUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import static noppes.npcs.util.CustomNPCsThreader.playerDataThread;
|
||||
|
||||
public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
public PlayerDialogData dialogData = new PlayerDialogData(this);
|
||||
public PlayerBankData bankData = new PlayerBankData(this);
|
||||
@@ -302,8 +304,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
public synchronized void save() {
|
||||
final NBTTagCompound compound = getNBT();
|
||||
final String filename = uuid + ".json";
|
||||
|
||||
CustomNPCsScheduler.runTack(() -> {
|
||||
playerDataThread.execute(() -> {
|
||||
try {
|
||||
File saveDir = PlayerDataController.instance.getSaveDir();
|
||||
File file = new File(saveDir, filename + "_new");
|
||||
@@ -316,8 +317,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
} catch (Exception e) {
|
||||
LogWriter.except(e);
|
||||
}
|
||||
|
||||
PlayerDataController.instance.putPlayerMap(playername, uuid);
|
||||
});
|
||||
PlayerDataController.instance.putPlayerMap(playername, uuid);
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -1,11 +1,13 @@
|
||||
package noppes.npcs.util;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class CustomNPCsScheduler {
|
||||
public class CustomNPCsThreader {
|
||||
private final static ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
|
||||
public static final Executor playerDataThread = Executors.newSingleThreadExecutor();
|
||||
|
||||
public static void runTack(Runnable task, int delay){
|
||||
executor.schedule(task, delay, TimeUnit.MILLISECONDS);
|
||||
Reference in new issue
Block a user