diff --git a/forge-game/src/main/java/forge/game/Game.java b/forge-game/src/main/java/forge/game/Game.java index b597e0d8316..32e38e51fa8 100644 --- a/forge-game/src/main/java/forge/game/Game.java +++ b/forge-game/src/main/java/forge/game/Game.java @@ -17,12 +17,7 @@ */ package forge.game; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.HashBasedTable; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Multimap; -import com.google.common.collect.Table; +import com.google.common.collect.*; import com.google.common.eventbus.EventBus; import forge.GameCommand; import forge.card.CardRarity; @@ -49,7 +44,10 @@ import forge.game.zone.Zone; import forge.game.zone.ZoneType; import forge.trackable.Tracker; -import forge.util.*; +import forge.util.Aggregates; +import forge.util.IterableUtil; +import forge.util.MyRandom; +import forge.util.Visitor; import forge.util.collect.FCollection; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.tuple.Pair; @@ -593,7 +591,7 @@ public synchronized void setGameOver(GameEndReason reason) { } public Zone getZoneOf(final Card card) { - return card.getLastKnownZone(); + return card == null ? null : card.getLastKnownZone(); } public synchronized CardCollectionView getCardsIn(final ZoneType zone) { diff --git a/forge-gui-desktop/src/main/java/forge/gui/framework/SRearrangingUtil.java b/forge-gui-desktop/src/main/java/forge/gui/framework/SRearrangingUtil.java index 02f634a7447..5b0e806c079 100644 --- a/forge-gui-desktop/src/main/java/forge/gui/framework/SRearrangingUtil.java +++ b/forge-gui-desktop/src/main/java/forge/gui/framework/SRearrangingUtil.java @@ -1,16 +1,5 @@ package forge.gui.framework; -import java.awt.Container; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionAdapter; -import java.awt.event.MouseMotionListener; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.JPanel; - import forge.gui.MouseUtil; import forge.localinstance.skin.FSkinProp; import forge.toolbox.FSkin; @@ -18,6 +7,12 @@ import forge.toolbox.FSkin.SkinnedLayeredPane; import forge.view.FView; +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.util.ArrayList; +import java.util.List; + /** * Package-private utilities for rearranging drag behavior using * the draggable panels registered in FView. @@ -291,7 +286,7 @@ private static void endRearrange() { } // Remove old cell if necessary, or, enforce rough bounds on new cell. - if (cellSrc.getDocs().size() == 0) { + if (cellSrc.getDocs().isEmpty()) { fillGap(); FView.SINGLETON_INSTANCE.removeDragCell(cellSrc); } diff --git a/forge-gui-desktop/src/main/java/forge/screens/deckeditor/CDeckEditorUI.java b/forge-gui-desktop/src/main/java/forge/screens/deckeditor/CDeckEditorUI.java index c1069f04bd4..825ed21029c 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/deckeditor/CDeckEditorUI.java +++ b/forge-gui-desktop/src/main/java/forge/screens/deckeditor/CDeckEditorUI.java @@ -17,13 +17,6 @@ */ package forge.screens.deckeditor; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.util.HashMap; -import java.util.Map.Entry; - -import javax.swing.SwingUtilities; - import forge.Singletons; import forge.deck.DeckBase; import forge.deck.DeckProxy; @@ -34,16 +27,17 @@ import forge.gui.framework.ICDoc; import forge.item.InventoryItem; import forge.itemmanager.ItemManager; -import forge.screens.deckeditor.controllers.ACEditorBase; -import forge.screens.deckeditor.controllers.CEditorConstructed; -import forge.screens.deckeditor.controllers.CEditorQuestCardShop; -import forge.screens.deckeditor.controllers.CProbabilities; -import forge.screens.deckeditor.controllers.CStatistics; -import forge.screens.deckeditor.controllers.DeckController; +import forge.screens.deckeditor.controllers.*; import forge.screens.deckeditor.views.*; import forge.screens.match.controllers.CDetailPicture; import forge.util.ItemPool; +import javax.swing.*; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.util.HashMap; +import java.util.Map.Entry; + /** * Constructs instance of deck editor UI controller, used as a single point of * top-level control for child UIs. Tasks targeting the view of individual @@ -184,6 +178,10 @@ private void moveSelectedItems(final ItemManager it @SuppressWarnings("unchecked") public void addSelectedCards(final boolean toAlternate, final int number) { + if (childController == null || childController.getCatalogManager() == null) { + return; + } + moveSelectedItems(childController.getCatalogManager(), new _MoveAction() { @Override public void move(final Iterable> items) { ((ACEditorBase)childController).addItems(items, toAlternate); diff --git a/forge-gui-desktop/src/main/java/forge/screens/match/controllers/CCombat.java b/forge-gui-desktop/src/main/java/forge/screens/match/controllers/CCombat.java index c73013de090..eeca61f43a3 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/match/controllers/CCombat.java +++ b/forge-gui-desktop/src/main/java/forge/screens/match/controllers/CCombat.java @@ -1,8 +1,6 @@ package forge.screens.match.controllers; import com.google.common.collect.Iterables; -import org.apache.commons.lang3.StringUtils; - import forge.game.GameEntityView; import forge.game.card.CardView; import forge.game.card.CardView.CardStateView; @@ -12,6 +10,7 @@ import forge.screens.match.views.VCombat; import forge.util.Lang; import forge.util.collect.FCollection; +import org.apache.commons.lang3.StringUtils; /** * Controls the combat panel in the match UI. @@ -79,13 +78,14 @@ private static String getCombatDescription(final CombatView localCombat, final G display.append("\n"); if (defender instanceof CardView) { PlayerView controller = ((CardView) defender).getController(); - if (controller == null) + if (controller == null) { //shouldn't be null but display card's + controller ie Black Knight's controller display.append(Lang.getInstance().getPossesive(defender.getName())).append(" controller"); - else + } else { display.append(Lang.getInstance().getPossesive(controller.getName())).append(" "); + } } - display.append(defender).append(" is attacked by:\n"); + display.append(defender).append(" is attacked by:\n`"); // Associate Bands, Attackers Blockers boolean previousBand = false; diff --git a/forge-gui-desktop/src/main/java/forge/screens/match/views/VCombat.java b/forge-gui-desktop/src/main/java/forge/screens/match/views/VCombat.java index bc4c911ec47..952d23ee7c2 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/match/views/VCombat.java +++ b/forge-gui-desktop/src/main/java/forge/screens/match/views/VCombat.java @@ -104,10 +104,9 @@ public CCombat getLayoutControl() { //========= Observer update methods - /** @param s0   {@link java.lang.String} */ public void updateCombat(final int cntAttackers, final String desc) { // No need to update this unless it's showing - if (!this.equals(parentCell.getSelected())) { return; } + if (parentCell == null || !this.equals(parentCell.getSelected())) { return; } tab.setText(cntAttackers > 0 ? (Localizer.getInstance().getMessage("lblCombatTab") + " : " + cntAttackers) : Localizer.getInstance().getMessage("lblCombatTab")); tar.setText(desc); diff --git a/forge-gui-desktop/src/main/java/forge/screens/match/views/VLog.java b/forge-gui-desktop/src/main/java/forge/screens/match/views/VLog.java index f5c74f11102..d8703888230 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/match/views/VLog.java +++ b/forge-gui-desktop/src/main/java/forge/screens/match/views/VLog.java @@ -17,13 +17,7 @@ */ package forge.screens.match.views; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.JPanel; - import com.google.common.collect.Lists; - import forge.game.GameLogEntry; import forge.game.GameLogEntryType; import forge.game.GameView; @@ -40,6 +34,10 @@ import forge.util.Localizer; import net.miginfocom.swing.MigLayout; +import javax.swing.*; +import java.util.ArrayList; +import java.util.List; + /** * Assembles Swing components of game log report. * @@ -135,7 +133,7 @@ public void updateConsole() { } private boolean isGameLogConsoleVisible() { - return parentCell.getSelected().equals(this); + return parentCell != null && parentCell.getSelected().equals(this); } private void resetDisplayIfNewGame(final GameView model) { diff --git a/forge-gui-desktop/src/main/java/forge/screens/match/views/VStack.java b/forge-gui-desktop/src/main/java/forge/screens/match/views/VStack.java index 1375f7196a3..2c870fe13c5 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/match/views/VStack.java +++ b/forge-gui-desktop/src/main/java/forge/screens/match/views/VStack.java @@ -17,21 +17,6 @@ */ package forge.screens.match.views; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Point; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.image.BufferedImage; - -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JPopupMenu; -import javax.swing.ScrollPaneConstants; -import javax.swing.SwingUtilities; -import javax.swing.border.EmptyBorder; - import forge.CachedCardImage; import forge.game.GameView; import forge.game.card.CardView.CardStateView; @@ -52,6 +37,13 @@ import forge.util.collect.FCollectionView; import net.miginfocom.swing.MigLayout; +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.image.BufferedImage; + /** * Assembles Swing components of stack report. * @@ -123,7 +115,7 @@ public void updateStack() { tab.setText(Localizer.getInstance().getMessage("lblStack") + " : " + items.size()); // No need to update the rest unless it's showing - if (!parentCell.getSelected().equals(this)) { return; } + if (parentCell == null || !parentCell.getSelected().equals(this)) { return; } hoveredItem = null; scroller.removeAll(); diff --git a/forge-gui-desktop/src/main/java/forge/view/arcane/CardPanelContainer.java b/forge-gui-desktop/src/main/java/forge/view/arcane/CardPanelContainer.java index 5519126c920..4155dc38ff9 100644 --- a/forge-gui-desktop/src/main/java/forge/view/arcane/CardPanelContainer.java +++ b/forge-gui-desktop/src/main/java/forge/view/arcane/CardPanelContainer.java @@ -17,16 +17,6 @@ */ package forge.view.arcane; -import java.awt.Dimension; -import java.awt.Rectangle; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseMotionListener; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.SwingUtilities; - import forge.game.card.CardView; import forge.gui.FThreads; import forge.screens.match.CMatchUI; @@ -35,6 +25,14 @@ import forge.toolbox.special.CardZoomer; import forge.view.arcane.util.CardPanelMouseListener; +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionListener; +import java.util.ArrayList; +import java.util.List; + /** * Manages mouse events and common functionality for CardPanel containing * components. @@ -278,7 +276,7 @@ public CardPanel addCard(final CardView card) { public final CardPanel getCardPanel(final int gameCardID) { for (final CardPanel panel : this.getCardPanels()) { - if (panel.getCard().getId() == gameCardID) { + if (panel.getCard() != null && panel.getCard().getId() == gameCardID) { return panel; } }