remove serialization header from data.yml
This commit is contained in:
parent
b4e326b0ec
commit
df457f2be2
@ -1,18 +1,28 @@
|
|||||||
package de.Linus122.TelegramChat;
|
package de.Linus122.TelegramChat;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
public class Data {
|
public class Data {
|
||||||
private String token = "";
|
private String token = "";
|
||||||
|
|
||||||
// Player name // ChatID
|
// Player name // ChatID
|
||||||
private HashMap<Integer, UUID> linkedChats = new HashMap<Integer, UUID>();
|
private HashMap<Integer, UUID> linkedChats = new HashMap<Integer, UUID>();
|
||||||
|
|
||||||
// Player name // RandomInt
|
// Player name // RandomInt
|
||||||
private HashMap<String, UUID> linkCodes = new HashMap<String, UUID>();
|
private HashMap<String, UUID> linkCodes = new HashMap<String, UUID>();
|
||||||
|
|
||||||
public List<Integer> ids = new ArrayList<Integer>();
|
public List<Integer> ids = new ArrayList<Integer>();
|
||||||
|
|
||||||
private boolean firstUse = true;
|
private boolean firstUse = true;
|
||||||
|
|
||||||
|
|
||||||
public String getToken() {
|
public String getToken() {
|
||||||
return token;
|
return token;
|
||||||
|
@ -2,14 +2,15 @@ package de.Linus122.TelegramChat;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@ -25,8 +26,8 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
import de.Linus122.Metrics.Metrics;
|
import de.Linus122.Metrics.Metrics;
|
||||||
import de.Linus122.TelegramComponents.ChatMessageToTelegram;
|
|
||||||
import de.Linus122.TelegramComponents.ChatMessageToMc;
|
import de.Linus122.TelegramComponents.ChatMessageToMc;
|
||||||
|
import de.Linus122.TelegramComponents.ChatMessageToTelegram;
|
||||||
|
|
||||||
public class Main extends JavaPlugin implements Listener {
|
public class Main extends JavaPlugin implements Listener {
|
||||||
private static File datad = new File("plugins/TelegramChat/data.json");
|
private static File datad = new File("plugins/TelegramChat/data.json");
|
||||||
@ -49,16 +50,32 @@ public class Main extends JavaPlugin implements Listener {
|
|||||||
dir.mkdir();
|
dir.mkdir();
|
||||||
data = new Data();
|
data = new Data();
|
||||||
if (datad.exists()) {
|
if (datad.exists()) {
|
||||||
|
Gson gson = new Gson();
|
||||||
try {
|
try {
|
||||||
FileInputStream fin = new FileInputStream(datad);
|
FileReader fileReader = new FileReader(datad);
|
||||||
ObjectInputStream ois = new ObjectInputStream(fin);
|
StringBuilder sb = new StringBuilder();
|
||||||
Gson gson = new Gson();
|
int c;
|
||||||
data = (Data) gson.fromJson((String) ois.readObject(), Data.class);
|
while((c = fileReader.read()) !=-1) {
|
||||||
ois.close();
|
sb.append((char) c);
|
||||||
fin.close();
|
}
|
||||||
|
|
||||||
|
data = (Data) gson.fromJson(sb.toString(), Data.class);
|
||||||
|
|
||||||
|
fileReader.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// old method for loading the data.yml file
|
||||||
e.printStackTrace();
|
try {
|
||||||
|
FileInputStream fin = new FileInputStream(datad);
|
||||||
|
ObjectInputStream ois = new ObjectInputStream(fin);
|
||||||
|
|
||||||
|
data = (Data) gson.fromJson((String) ois.readObject(), Data.class);
|
||||||
|
ois.close();
|
||||||
|
fin.close();
|
||||||
|
} catch (Exception e2) {
|
||||||
|
e2.printStackTrace();
|
||||||
|
}
|
||||||
|
this.getLogger().log(Level.INFO, "Converted old data.yml");
|
||||||
|
save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,12 +106,10 @@ public class Main extends JavaPlugin implements Listener {
|
|||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FileOutputStream fout = new FileOutputStream(datad);
|
FileWriter fileWriter = new FileWriter(datad);
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(fout);
|
fileWriter.write(gson.toJson(data));
|
||||||
|
|
||||||
oos.writeObject(gson.toJson(data));
|
fileWriter.close();
|
||||||
fout.close();
|
|
||||||
oos.close();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
Loading…
Reference in New Issue
Block a user