mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 22:45:09 +00:00
Full Imports and Code Format Optimization
This commit is contained in:
1 parent
250edf099c
commit
6815f579a7
1192 files changed
+60344
-62167
No files matched your search
@@ -22,16 +22,16 @@ import static noppes.npcs.util.CustomNPCsThreader.customNPCThread;
|
||||
|
||||
public class Market {
|
||||
|
||||
private static final CacheHashMap<String, MarketCachedObject> marketCache = new CacheHashMap<>(5 * 60 * 1000, 1 * 60 * 1000);
|
||||
private static final CacheHashMap<String, MarketCachedObject> marketCache = new CacheHashMap<>(5 * 60 * 1000, 60 * 1000);
|
||||
|
||||
public static void save(RoleTrader r, String name) {
|
||||
if(name.isEmpty())
|
||||
if (name.isEmpty())
|
||||
return;
|
||||
|
||||
NBTTagCompound roleCompound = r.writeNBT(new NBTTagCompound());
|
||||
roleCompound.setString("SaveName", name);
|
||||
putMarketCache(name, roleCompound);
|
||||
if(r.recordHistory)
|
||||
if (r.recordHistory)
|
||||
return;
|
||||
|
||||
saveFile(roleCompound);
|
||||
@@ -43,12 +43,12 @@ public class Market {
|
||||
File file1 = getFile(name);
|
||||
customNPCThread.execute(() -> {
|
||||
try {
|
||||
if(ConfigMain.MarketDatFormat){
|
||||
if (ConfigMain.MarketDatFormat) {
|
||||
CompressedStreamTools.writeCompressed(compound, new FileOutputStream(file));
|
||||
} else {
|
||||
NBTJsonUtil.SaveFile(file, compound);
|
||||
}
|
||||
if(file1.exists()){
|
||||
if (file1.exists()) {
|
||||
file1.delete();
|
||||
}
|
||||
file.renameTo(file1);
|
||||
@@ -58,9 +58,9 @@ public class Market {
|
||||
});
|
||||
}
|
||||
|
||||
public static void getMarket(RoleTrader role, String name){
|
||||
public static void getMarket(RoleTrader role, String name) {
|
||||
NBTTagCompound data = getMarketCache(name);
|
||||
if(data != null){
|
||||
if (data != null) {
|
||||
role.readNBT(data);
|
||||
return;
|
||||
}
|
||||
@@ -84,56 +84,53 @@ public class Market {
|
||||
}
|
||||
|
||||
|
||||
static public void load(RoleTrader role, String name){
|
||||
if(role.npc.worldObj.isRemote)
|
||||
static public void load(RoleTrader role, String name) {
|
||||
if (role.npc.worldObj.isRemote)
|
||||
return;
|
||||
File file = getFile(name);
|
||||
if(!file.exists())
|
||||
if (!file.exists())
|
||||
return;
|
||||
|
||||
try {
|
||||
if(ConfigMain.MarketDatFormat){
|
||||
if (ConfigMain.MarketDatFormat) {
|
||||
NBTTagCompound compound = NBTJsonUtil.loadNBTData(file);
|
||||
role.readNBT(compound);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
role.readNBT(NBTJsonUtil.LoadFile(file));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static File getMarketDir(){
|
||||
try{
|
||||
File file = new File(CustomNpcs.getWorldSaveDirectory(),"markets");
|
||||
if(!file.exists())
|
||||
public static File getMarketDir() {
|
||||
try {
|
||||
File file = new File(CustomNpcs.getWorldSaveDirectory(), "markets");
|
||||
if (!file.exists())
|
||||
file.mkdir();
|
||||
return file;
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static File getNewMarketDir(){
|
||||
try{
|
||||
File file = new File(CustomNpcs.getWorldSaveDirectory(),"markets_new");
|
||||
if(file.exists()){
|
||||
public static File getNewMarketDir() {
|
||||
try {
|
||||
File file = new File(CustomNpcs.getWorldSaveDirectory(), "markets_new");
|
||||
if (file.exists()) {
|
||||
return null;
|
||||
}
|
||||
file.mkdir();
|
||||
return file;
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static File getFile(String name){
|
||||
private static File getFile(String name) {
|
||||
String filename = name.toLowerCase();
|
||||
if(ConfigMain.MarketDatFormat){
|
||||
if (ConfigMain.MarketDatFormat) {
|
||||
filename += ".dat";
|
||||
} else {
|
||||
filename += ".json";
|
||||
@@ -143,27 +140,26 @@ public class Market {
|
||||
}
|
||||
|
||||
static public void setMarket(EntityNPCInterface npc, String marketName) {
|
||||
if(marketName.isEmpty())
|
||||
if (marketName.isEmpty())
|
||||
return;
|
||||
if(!getFile(marketName).exists())
|
||||
if (!getFile(marketName).exists())
|
||||
Market.save((RoleTrader) npc.roleInterface, marketName);
|
||||
|
||||
Market.getMarket((RoleTrader) npc.roleInterface, marketName);
|
||||
}
|
||||
|
||||
|
||||
public static void convertMarketFiles(final EntityPlayerMP sender, final boolean type){
|
||||
public static void convertMarketFiles(final EntityPlayerMP sender, final boolean type) {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
executor.execute(() -> {
|
||||
String fileType;
|
||||
if(type){
|
||||
if (type) {
|
||||
fileType = ".dat";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
fileType = ".json";
|
||||
}
|
||||
|
||||
if(sender != null){
|
||||
if (sender != null) {
|
||||
LogWriter.info("Market Conversion queued by " + sender.getCommandSenderName());
|
||||
sender.addChatMessage(new ChatComponentText("Market Conversion to " + fileType + " format"));
|
||||
}
|
||||
@@ -171,58 +167,58 @@ public class Market {
|
||||
File dir = getMarketDir();
|
||||
LogWriter.info("Converting Market to " + fileType + " format");
|
||||
File[] files = dir.listFiles(); // Get an array of all files in the directory
|
||||
if(files != null){
|
||||
if (files != null) {
|
||||
int length = files.length;
|
||||
if(length != 0){
|
||||
if(length > 100){
|
||||
if (length != 0) {
|
||||
if (length > 100) {
|
||||
LogWriter.info("Found " + length + " Market files... This may take a few minutes");
|
||||
}
|
||||
int tenPercent = (int) ((double) length * 0.1);
|
||||
int progress = 0;
|
||||
File saveDir = getNewMarketDir();
|
||||
if(saveDir == null){
|
||||
if(sender != null){
|
||||
if (saveDir == null) {
|
||||
if (sender != null) {
|
||||
sender.addChatMessage(new ChatComponentText("markets_new folder already exists please delete it or rename it"));
|
||||
}
|
||||
LogWriter.error("markets_new folder already exists please delete it or rename it");
|
||||
return;
|
||||
}
|
||||
// Load the files in parallel using a stream
|
||||
for(int i = 0; i < length; i++){
|
||||
for (int i = 0; i < length; i++) {
|
||||
File file = files[i];
|
||||
if(file.isDirectory() || (!file.getName().endsWith(".json") && !file.getName().endsWith(".dat")))
|
||||
if (file.isDirectory() || (!file.getName().endsWith(".json") && !file.getName().endsWith(".dat")))
|
||||
continue;
|
||||
try {
|
||||
String filename = "error";
|
||||
boolean valid = false;
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
if(type){
|
||||
if(file.getName().endsWith(".json")){
|
||||
if (type) {
|
||||
if (file.getName().endsWith(".json")) {
|
||||
compound = NBTJsonUtil.LoadFile(file);
|
||||
if(compound.hasKey("PlayerName")) {
|
||||
if (compound.hasKey("PlayerName")) {
|
||||
filename = file.getName().substring(0, file.getName().length() - 5);
|
||||
valid = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(file.getName().endsWith(".dat")){
|
||||
if (file.getName().endsWith(".dat")) {
|
||||
compound = NBTJsonUtil.loadNBTData(file);
|
||||
if(compound.hasKey("PlayerName")){
|
||||
if (compound.hasKey("PlayerName")) {
|
||||
filename = file.getName().substring(0, file.getName().length() - 4);
|
||||
valid = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(valid){
|
||||
if (valid) {
|
||||
try {
|
||||
File newFile = new File(saveDir, filename + "_new" + fileType);
|
||||
File oldFile = new File(saveDir, filename + fileType);
|
||||
if(type){
|
||||
if (type) {
|
||||
CompressedStreamTools.writeCompressed(compound, new FileOutputStream(newFile));
|
||||
} else {
|
||||
NBTJsonUtil.SaveFile(newFile, compound);
|
||||
}
|
||||
if(oldFile.exists()){
|
||||
if (oldFile.exists()) {
|
||||
oldFile.delete();
|
||||
}
|
||||
newFile.renameTo(oldFile);
|
||||
@@ -233,8 +229,8 @@ public class Market {
|
||||
} catch (Exception e) {
|
||||
LogWriter.error("Error loading: " + file.getAbsolutePath(), e);
|
||||
}
|
||||
if(tenPercent != 0 ){
|
||||
if(progress != 100){
|
||||
if (tenPercent != 0) {
|
||||
if (progress != 100) {
|
||||
if (i % tenPercent == 0) {
|
||||
progress += 10;
|
||||
LogWriter.info("Converting Market: Progress: " + progress + "%");
|
||||
@@ -244,7 +240,7 @@ public class Market {
|
||||
}
|
||||
}
|
||||
}
|
||||
if(sender != null){
|
||||
if (sender != null) {
|
||||
sender.addChatMessage(new ChatComponentText("Market Conversion complete"));
|
||||
}
|
||||
LogWriter.info("Market Converted - Please rename the markets_new folder to markets and restart");
|
||||
|
||||
Reference in new issue
Block a user