mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
remove warnings, use FileUtil to read text files
This commit is contained in:
@@ -22,8 +22,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
import forge.Card;
|
||||
|
||||
import forge.Command;
|
||||
|
||||
@@ -805,7 +805,7 @@ public class ComputerUtilAttack {
|
||||
for (int i = 0; i < attackersLeft.size(); i++) {
|
||||
final Card attacker = attackersLeft.get(i);
|
||||
if (this.aiAggression < 5 && !attacker.hasFirstStrike() && !attacker.hasDoubleStrike()
|
||||
&& CombatUtil.getTotalFirstStrikeBlockPower(attacker, AllZone.getHumanPlayer())
|
||||
&& CombatUtil.getTotalFirstStrikeBlockPower(attacker, ai.getOpponent())
|
||||
>= attacker.getKillDamage()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -957,7 +957,7 @@ public class MagicStack extends MyObservable {
|
||||
AllZone.getInputControl().setInput(target);
|
||||
} else {
|
||||
// AI choosing what to haunt
|
||||
final List<Card> oppCreats = CardLists.filterControlledBy(creats, AllZone.getHumanPlayer());
|
||||
final List<Card> oppCreats = CardLists.filterControlledBy(creats, source.getController().getOpponent());
|
||||
if (oppCreats.size() != 0) {
|
||||
haunterDiesWork.setTargetCard(CardFactoryUtil.getWorstCreatureAI(oppCreats));
|
||||
} else {
|
||||
|
||||
@@ -17,27 +17,24 @@
|
||||
*/
|
||||
package forge.properties;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
|
||||
import forge.Constant;
|
||||
import forge.Constant.Preferences;
|
||||
import forge.gui.home.EMenuItem;
|
||||
import forge.gui.match.VMatchUI;
|
||||
import forge.gui.match.nonsingleton.VField;
|
||||
import forge.gui.match.views.VDev;
|
||||
import forge.util.FileUtil;
|
||||
|
||||
/**
|
||||
* Holds default preference values in an enum.
|
||||
@@ -165,25 +162,16 @@ public class ForgePreferences {
|
||||
// This code is here temporarily to facilitate this transfer.
|
||||
// After a while, this can be deleted. Doublestrike 21-5-12
|
||||
final File oldFile = new File("forge.preferences");
|
||||
|
||||
if (oldFile.exists()) {
|
||||
final File newFile = new File(NewConstants.PREFS_GLOBAL_FILE);
|
||||
final InputStream in = new FileInputStream(oldFile);
|
||||
final OutputStream out = new FileOutputStream(newFile);
|
||||
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
in.close();
|
||||
out.close();
|
||||
|
||||
Files.copy(oldFile, newFile);
|
||||
oldFile.delete();
|
||||
} // END TEMPORARY CONSOLIDATION FACILITATION
|
||||
|
||||
final BufferedReader input = new BufferedReader(new FileReader(NewConstants.PREFS_GLOBAL_FILE));
|
||||
String line = null;
|
||||
while ((line = input.readLine()) != null) {
|
||||
List<String> lines = FileUtil.readFile(NewConstants.PREFS_GLOBAL_FILE);
|
||||
for( String line :lines ) {
|
||||
|
||||
if (line.startsWith("#") || (line.length() == 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -17,18 +17,18 @@
|
||||
*/
|
||||
package forge.quest.data;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants.Quest;
|
||||
import forge.util.FileUtil;
|
||||
|
||||
/**
|
||||
* Holds default preference values in an enum. Loads preferred values when
|
||||
@@ -226,10 +226,10 @@ public class QuestPreferences implements Serializable {
|
||||
/** Instantiates a QuestPreferences object. */
|
||||
public QuestPreferences() {
|
||||
this.preferenceValues = new HashMap<QPref, String>();
|
||||
try {
|
||||
final BufferedReader input = new BufferedReader(new FileReader(ForgeProps.getFile(Quest.PREFS)));
|
||||
String line = null;
|
||||
while ((line = input.readLine()) != null) {
|
||||
|
||||
List<String> lines = FileUtil.readFile(ForgeProps.getFile(Quest.PREFS));
|
||||
|
||||
for (String line : lines ) {
|
||||
if (line.startsWith("#") || (line.length() == 0)) {
|
||||
continue;
|
||||
}
|
||||
@@ -240,11 +240,6 @@ public class QuestPreferences implements Serializable {
|
||||
this.setPreference(split[0], split[1]);
|
||||
}
|
||||
}
|
||||
} catch (final FileNotFoundException ex) {
|
||||
// ex.printStackTrace();
|
||||
} catch (final IOException ex) {
|
||||
// ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/** Saves prefs map to file. */
|
||||
|
||||
@@ -17,18 +17,17 @@
|
||||
*/
|
||||
package forge.quest.io;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import com.esotericsoftware.minlog.Log;
|
||||
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
import forge.util.FileUtil;
|
||||
import forge.util.MyRandom;
|
||||
|
||||
/**
|
||||
@@ -76,17 +75,16 @@ public class ReadPriceList {
|
||||
* @return a {@link java.util.HashMap} object.
|
||||
*/
|
||||
private HashMap<String, Integer> readFile(final File file) {
|
||||
BufferedReader in;
|
||||
final HashMap<String, Integer> map = new HashMap<String, Integer>();
|
||||
final Random r = MyRandom.getRandom();
|
||||
try {
|
||||
|
||||
in = new BufferedReader(new FileReader(file));
|
||||
String line = in.readLine();
|
||||
List<String> lines = FileUtil.readFile(file);
|
||||
for (String line : lines) {
|
||||
if ( line.trim().length() == 0 ) break;
|
||||
|
||||
if (line.startsWith(ReadPriceList.COMMENT))
|
||||
continue;
|
||||
|
||||
// stop reading if end of file or blank line is read
|
||||
while ((line != null) && (line.trim().length() != 0)) {
|
||||
if (!line.startsWith(ReadPriceList.COMMENT)) {
|
||||
final String[] s = line.split("=");
|
||||
final String name = s[0].trim();
|
||||
final String price = s[1].trim();
|
||||
@@ -123,14 +121,6 @@ public class ReadPriceList {
|
||||
Log.warn("NumberFormatException: " + nfe.getMessage());
|
||||
}
|
||||
}
|
||||
line = in.readLine();
|
||||
} // if
|
||||
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("ReadPriceList : readFile error, " + ex);
|
||||
}
|
||||
|
||||
return map;
|
||||
} // readFile()
|
||||
|
||||
|
||||
@@ -108,6 +108,7 @@ public class HttpUtil {
|
||||
httpOut.write(bufferBytesRead);
|
||||
httpOut.flush();
|
||||
}
|
||||
uploadFileReader.close();
|
||||
} catch (final IOException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user