Skip to content

Commit

Permalink
remove parameters in #load (wtf was i thinking when adding them)
Browse files Browse the repository at this point in the history
  • Loading branch information
efekos committed Feb 24, 2024
1 parent f8e66be commit fcf9e63
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/main/java/me/efekos/simpler/config/ListDataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package me.efekos.simpler.config;

import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -151,10 +152,8 @@ public void save(){

/**
* Loads all the data from the save before. You don't have to check if file exists, because method does it.
* @param clazz Accessing a class object of a type parameter is impossible, so you need to give it. Just do
* {@code <T>[].class} here, replacing {@code <T>} with name of your type. That type must be same with {@link T}.
*/
public void load(Class<T[]> clazz){
public void load(){
Gson gson = new Gson();
String absPath = plugin.getDataFolder().getAbsolutePath()+path;
File file = new File(absPath);
Expand All @@ -163,7 +162,8 @@ public void load(Class<T[]> clazz){
try {
Reader reader = new FileReader(file);

T[] n = gson.fromJson(reader,clazz);

T[] n = gson.fromJson(reader, new TypeToken<List<T>>(){}.getType());

for (T t : n) {
datas.add(t);
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/me/efekos/simpler/config/MapDataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@

package me.efekos.simpler.config;

import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;
import java.io.*;
import java.security.InvalidParameterException;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
* A basic database class made using {@link Gson}. You can store a {@link java.util.Map<K,V>} in this data. Use {@link #save()}
Expand Down Expand Up @@ -131,10 +135,8 @@ public void save(){

/**
* Loads all the data from the save before. You don't have to check if file exists, because method does it.
* @param clazz Accessing a class object of a type parameter is impossible, so you need to give it. Just do
* {@code Map<K,V>[].class} here, replacing {@code <K>} and {@code <V>} with the name of your type. That type must be same with {@link K} and {@link V}.
*/
public void load(Class<Map<K,V>> clazz){
public void load(){
Gson gson = new Gson();
String absPath = plugin.getDataFolder().getAbsolutePath()+"\\"+path;
File file = new File(absPath);
Expand All @@ -143,7 +145,10 @@ public void load(Class<Map<K,V>> clazz){
try {
Reader reader = new FileReader(file);

Map<K,V> n = gson.fromJson(reader,clazz);
TypeToken<Map<K, V>> token = new TypeToken<>() {
};

Map<K,V> n = (Map<K, V>) gson.fromJson(reader,token.getRawType());

data = n;

Expand Down

0 comments on commit fcf9e63

Please sign in to comment.