diff --git a/src/main/java/forge/quest/io/QuestDataIO.java b/src/main/java/forge/quest/io/QuestDataIO.java index d1fb7d1ccf6..dfb5315b680 100644 --- a/src/main/java/forge/quest/io/QuestDataIO.java +++ b/src/main/java/forge/quest/io/QuestDataIO.java @@ -431,10 +431,10 @@ public class QuestDataIO { } GameFormatQuest res = new GameFormatQuest(name, allowedSets, bannedCards); try { - if ( StringUtils.isNotEmpty(unlocksUsed)) { + if (StringUtils.isNotEmpty(unlocksUsed)) { setFinalField(GameFormatQuest.class, "unlocksUsed", res, Integer.parseInt(unlocksUsed)); } - setFinalField(GameFormatQuest.class, "allowUnlocks", res, canUnlock); + setFinalField(GameFormatQuest.class, "allowUnlocks", res, canUnlock); } catch (NumberFormatException e) { e.printStackTrace(); } catch (IllegalAccessException e) { @@ -442,7 +442,7 @@ public class QuestDataIO { } catch (NoSuchFieldException e) { e.printStackTrace(); } - + return res; } } @@ -462,7 +462,7 @@ public class QuestDataIO { @Override public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { final String value = reader.getValue(); - return GameType.smartValueOf(value, GameType.Quest); + return GameType.smartValueOf(value, GameType.Quest); } } diff --git a/src/main/java/forge/quest/io/ReadPriceList.java b/src/main/java/forge/quest/io/ReadPriceList.java index b810ccb11f3..c44e180fb71 100644 --- a/src/main/java/forge/quest/io/ReadPriceList.java +++ b/src/main/java/forge/quest/io/ReadPriceList.java @@ -77,14 +77,17 @@ public class ReadPriceList { private HashMap readFile(final File file) { final HashMap map = new HashMap(); final Random r = MyRandom.getRandom(); - + List lines = FileUtil.readFile(file); for (String line : lines) { - if ( line.trim().length() == 0 ) break; - - if (line.startsWith(ReadPriceList.COMMENT)) - continue; - + if (line.trim().length() == 0) { + break; + } + + if (line.startsWith(ReadPriceList.COMMENT)) { + continue; + } + final String[] s = line.split("="); final String name = s[0].trim(); final String price = s[1].trim(); @@ -120,7 +123,7 @@ public class ReadPriceList { } catch (final NumberFormatException nfe) { Log.warn("NumberFormatException: " + nfe.getMessage()); } - } + } return map; } // readFile() diff --git a/src/main/java/forge/sound/AudioClip.java b/src/main/java/forge/sound/AudioClip.java index 67436e79cdb..a00e2d62a76 100644 --- a/src/main/java/forge/sound/AudioClip.java +++ b/src/main/java/forge/sound/AudioClip.java @@ -39,22 +39,23 @@ import javax.sound.sampled.UnsupportedAudioFileException; * * @author Agetian */ -public class AudioClip implements IAudioClip{ +public class AudioClip implements IAudioClip { private final Clip clip; private final int SOUND_SYSTEM_DELAY = 30; - private final static String PathToSound = "res/sound"; - - public static boolean fileExists(String fileName) { + private static final String PathToSound = "res/sound"; + + public static boolean fileExists(String fileName) { File fSound = new File(PathToSound, fileName); return fSound.exists(); } - + public AudioClip(final String filename) { File fSound = new File(PathToSound, filename); - if ( !fSound.exists() ) + if (!fSound.exists()) { throw new IllegalArgumentException("Sound file " + fSound.toString() + " does not exist, cannot make a clip of it"); - + } + try { AudioInputStream stream = AudioSystem.getAudioInputStream(fSound); AudioFormat format = stream.getFormat(); @@ -74,8 +75,9 @@ public class AudioClip implements IAudioClip{ } public final void play() { - if (null == clip) + if (null == clip) { return; + } clip.setMicrosecondPosition(0); try { Thread.sleep(SOUND_SYSTEM_DELAY); @@ -86,8 +88,9 @@ public class AudioClip implements IAudioClip{ } public final void loop() { - if (null == clip) + if (null == clip) { return; + } clip.setMicrosecondPosition(0); try { Thread.sleep(SOUND_SYSTEM_DELAY); @@ -98,14 +101,16 @@ public class AudioClip implements IAudioClip{ } public final void stop() { - if (null == clip) + if (null == clip) { return; + } clip.stop(); } public final boolean isDone() { - if (null == clip) + if (null == clip) { return false; + } return !clip.isRunning(); } } diff --git a/src/main/java/forge/sound/EventVisualizer.java b/src/main/java/forge/sound/EventVisualizer.java index 551bb1d9bd2..db711098ab3 100644 --- a/src/main/java/forge/sound/EventVisualizer.java +++ b/src/main/java/forge/sound/EventVisualizer.java @@ -30,14 +30,14 @@ import forge.game.event.SpellResolvedEvent; import forge.game.event.TokenCreatedEvent; /** - * This class is in charge of converting any forge.game.event.Event to a SoundEffectType + * This class is in charge of converting any forge.game.event.Event to a SoundEffectType. * */ public class EventVisualizer { - final static Map, SoundEffectType> matchTable = new HashMap, SoundEffectType>(); - - public EventVisualizer() { + static final Map, SoundEffectType> matchTable = new HashMap, SoundEffectType>(); + + public EventVisualizer() { matchTable.put(CounterAddedEvent.class, SoundEffectType.AddCounter); matchTable.put(BlockerAssignedEvent.class, SoundEffectType.Block); matchTable.put(CardDamagedEvent.class, SoundEffectType.Damage); @@ -55,8 +55,8 @@ public class EventVisualizer { matchTable.put(ShuffleEvent.class, SoundEffectType.Shuffle); matchTable.put(TokenCreatedEvent.class, SoundEffectType.Token); } - - + + public final SoundEffectType getSoundForEvent(Event evt) { SoundEffectType fromMap = matchTable.get(evt.getClass()); @@ -86,7 +86,7 @@ public class EventVisualizer { return fromMap; } - + /** * Plays the sound corresponding to the outcome of the duel. * @@ -113,7 +113,9 @@ public class EventVisualizer { // if there's a specific effect for this particular card, play it and // we're done. SoundEffectType specialEffect = getSpecificCardEffect(source); - if( specialEffect != null ) return specialEffect; + if (specialEffect != null) { + return specialEffect; + } if (source.isCreature() && source.isArtifact()) { return SoundEffectType.ArtifactCreature; @@ -145,7 +147,7 @@ public class EventVisualizer { public static SoundEffectType getSoundEffectForTapState(boolean tapped_state) { return tapped_state ? SoundEffectType.Tap : SoundEffectType.Untap; } - + /** * Plays the sound corresponding to the land type when the land is played. * @@ -160,7 +162,9 @@ public class EventVisualizer { // if there's a specific effect for this particular card, play it and // we're done. SoundEffectType specialEffect = getSpecificCardEffect(land); - if( specialEffect != null ) return specialEffect; + if (specialEffect != null) { + return specialEffect; + } final List manaProduced = land.getManaAbility(); @@ -209,6 +213,6 @@ public class EventVisualizer { public boolean isSyncSound(SoundEffectType effect) { return effect.getIsSynced(); - } + } } diff --git a/src/main/java/forge/sound/IAudioClip.java b/src/main/java/forge/sound/IAudioClip.java index b8343358ce7..050f354082b 100644 --- a/src/main/java/forge/sound/IAudioClip.java +++ b/src/main/java/forge/sound/IAudioClip.java @@ -1,8 +1,8 @@ package forge.sound; -public interface IAudioClip { +public interface IAudioClip { public void play(); public boolean isDone(); public void stop(); public void loop(); -} \ No newline at end of file +} diff --git a/src/main/java/forge/sound/NoSoundClip.java b/src/main/java/forge/sound/NoSoundClip.java index 0db6985d48d..ec4a17a2834 100644 --- a/src/main/java/forge/sound/NoSoundClip.java +++ b/src/main/java/forge/sound/NoSoundClip.java @@ -4,15 +4,15 @@ package forge.sound; public class NoSoundClip implements IAudioClip { @Override - public void play() {} + public void play() { } @Override public boolean isDone() { return false; } @Override - public void stop() {} + public void stop() { } @Override - public void loop() {} - -} \ No newline at end of file + public void loop() { } + +} diff --git a/src/main/java/forge/sound/SoundEffectType.java b/src/main/java/forge/sound/SoundEffectType.java index a7ae9089a34..3b71d08651c 100644 --- a/src/main/java/forge/sound/SoundEffectType.java +++ b/src/main/java/forge/sound/SoundEffectType.java @@ -43,11 +43,11 @@ public enum SoundEffectType { Block("block.wav", false), BlueLand("blue_land.wav", false), Creature("creature.wav", false), - Damage("damage.wav", true), + Damage("damage.wav", true), Destroy("destroy.wav", true), Discard("discard.wav", false), Draw("draw.wav", false), - Enchantment("enchant.wav", false), + Enchantment("enchant.wav", false), EndOfTurn("end_of_turn.wav", false), Equip("equip.wav", false), FlipCoin("flip_coin.wav", false), @@ -71,7 +71,7 @@ public enum SoundEffectType { WhiteLand("white_land.wav", false), WinDuel("win_duel.wav", false); - + private final String resourceFileName; private final boolean isSynced; @@ -82,7 +82,7 @@ public enum SoundEffectType { return resourceFileName; } /** - * @param filename + * @param filename * name of the sound file associated with the entry. * @param isSoundSynced * determines if only one instance of the sound can be played diff --git a/src/main/java/forge/sound/SoundSystem.java b/src/main/java/forge/sound/SoundSystem.java index 6292f604eaf..ba018929b5e 100644 --- a/src/main/java/forge/sound/SoundSystem.java +++ b/src/main/java/forge/sound/SoundSystem.java @@ -15,26 +15,27 @@ import forge.properties.ForgePreferences.FPref; */ public class SoundSystem { - private final static IAudioClip emptySound = new NoSoundClip(); - private final static Map loadedClips = new EnumMap(SoundEffectType.class); - + private static final IAudioClip emptySound = new NoSoundClip(); + private static final Map loadedClips = new EnumMap(SoundEffectType.class); + private final EventVisualizer visualizer = new EventVisualizer(); - + protected IAudioClip fetchResource(SoundEffectType type) { - if (!Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_ENABLE_SOUNDS)) + if (!Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_ENABLE_SOUNDS)) { return emptySound; + } IAudioClip clip = loadedClips.get(type); - if ( null == clip ) { // cache miss + if (null == clip) { // cache miss String resource = type.getResourceFileName(); clip = AudioClip.fileExists(resource) ? new AudioClip(resource) : emptySound; loadedClips.put(type, clip); } return clip; } - - + + /** * Play the sound associated with the Sounds enumeration element. */ @@ -67,16 +68,19 @@ public class SoundSystem { public void stop(SoundEffectType type) { fetchResource(type).stop(); } - + @Subscribe public void receiveEvent(Event evt) { SoundEffectType effect = visualizer.getSoundForEvent(evt); - if ( null == effect ) return; + if (null == effect) { + return; + } boolean isSync = visualizer.isSyncSound(effect); - if ( isSync ) + if (isSync) { playSync(effect); - else + } else { play(effect); + } } }