-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca0952e
commit 8d8509f
Showing
3 changed files
with
133 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,61 @@ | ||
package com.laosun.stackone; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonParser; | ||
|
||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
|
||
import static com.laosun.stackone.StackOneMod.LOGGER; | ||
|
||
public class IgnoreItem { | ||
public String item; | ||
|
||
public static ArrayList<String> getIgnoreItems() { | ||
File dir = new File("config/stackone"); | ||
if (!dir.exists()) { | ||
dir.mkdirs(); | ||
} | ||
File file = new File(dir, "ignore_item.json"); | ||
if (!file.isFile()) { | ||
try { | ||
if (!file.createNewFile()) { | ||
LOGGER.error("Fail to create file!"); | ||
} | ||
} catch (IOException e) { | ||
LOGGER.error("Fail to create file!"); | ||
e.printStackTrace(); | ||
} | ||
} | ||
char[] a1 = null; | ||
try { | ||
FileReader fileReader = new FileReader(file); | ||
a1 = new char[(int) file.length()]; | ||
fileReader.read(a1); | ||
} catch (IOException e) { | ||
LOGGER.error("Fail to open file!"); | ||
e.printStackTrace(); | ||
} | ||
Gson gson = new Gson(); | ||
JsonArray jsonArray; | ||
ArrayList<String> ignoreItems = new ArrayList<>(); | ||
try { | ||
if (a1 != null) { | ||
jsonArray = JsonParser.parseString(String.copyValueOf(a1)).getAsJsonArray(); | ||
for (JsonElement user : jsonArray) { | ||
IgnoreItem ignore = gson.fromJson(user, IgnoreItem.class); | ||
ignoreItems.add(ignore.item); | ||
} | ||
} | ||
|
||
} catch (Exception e) { | ||
LOGGER.error("Json has syntax error!"); | ||
e.printStackTrace(); | ||
} | ||
return ignoreItems; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.laosun.stackone; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonParser; | ||
|
||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static com.laosun.stackone.StackOneMod.LOGGER; | ||
|
||
public class Stack { | ||
public String item; | ||
public short max_stack_size; | ||
|
||
public static Map<String, Short> getStackList() { | ||
Map<String, Short> map = new HashMap<>(); | ||
File dir = new File("config/stackone"); | ||
if (!dir.exists()) { | ||
dir.mkdirs(); | ||
} | ||
File file = new File(dir, "max_stack_size.json"); | ||
if (!file.isFile()) { | ||
try { | ||
if (!file.createNewFile()) { | ||
LOGGER.error("Fail to create file!"); | ||
} | ||
} catch (IOException e) { | ||
LOGGER.error("Fail to create file!"); | ||
e.printStackTrace(); | ||
} | ||
} | ||
char[] a1 = null; | ||
try { | ||
FileReader fileReader = new FileReader(file); | ||
a1 = new char[(int) file.length()]; | ||
fileReader.read(a1); | ||
} catch (IOException e) { | ||
LOGGER.error("Fail to open file!"); | ||
e.printStackTrace(); | ||
} | ||
Gson gson = new Gson(); | ||
JsonArray jsonArray; | ||
try { | ||
if (a1 != null) { | ||
jsonArray = JsonParser.parseString(String.copyValueOf(a1)).getAsJsonArray(); | ||
for (JsonElement user : jsonArray) { | ||
Stack ignore = gson.fromJson(user, Stack.class); | ||
map.put(ignore.item, ignore.max_stack_size); | ||
} | ||
} | ||
|
||
} catch (Exception e) { | ||
LOGGER.error("Json has syntax error!"); | ||
e.printStackTrace(); | ||
} | ||
return map; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters