From 250bc95e96c52fc3fb9da7aca77686d8b7a1ee94 Mon Sep 17 00:00:00 2001
From: cwisniew <craig.wisniewski@gmail.com>
Date: Sun, 1 Oct 2023 00:50:45 +0930
Subject: [PATCH] fix for statsheet error when renaming property type

---
 .../ui/campaignproperties/CampaignPropertiesDialog.java     | 1 -
 .../campaignproperties/TokenPropertiesManagementPanel.java  | 2 +-
 .../java/net/rptools/maptool/model/CampaignProperties.java  | 6 +++++-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/main/java/net/rptools/maptool/client/ui/campaignproperties/CampaignPropertiesDialog.java b/src/main/java/net/rptools/maptool/client/ui/campaignproperties/CampaignPropertiesDialog.java
index 890669fdd9..f968d99e4a 100644
--- a/src/main/java/net/rptools/maptool/client/ui/campaignproperties/CampaignPropertiesDialog.java
+++ b/src/main/java/net/rptools/maptool/client/ui/campaignproperties/CampaignPropertiesDialog.java
@@ -203,7 +203,6 @@ private void accept() {
           .forEach(
               (o, n) -> {
                 campaign.renameTokenTypes(o, n);
-                System.out.println("Renaming " + o + " to " + n);
               });
       MapTool.getFrame().hideGlassPane();
       copyUIToCampaign();
diff --git a/src/main/java/net/rptools/maptool/client/ui/campaignproperties/TokenPropertiesManagementPanel.java b/src/main/java/net/rptools/maptool/client/ui/campaignproperties/TokenPropertiesManagementPanel.java
index e3a873ae52..c2e744b88b 100644
--- a/src/main/java/net/rptools/maptool/client/ui/campaignproperties/TokenPropertiesManagementPanel.java
+++ b/src/main/java/net/rptools/maptool/client/ui/campaignproperties/TokenPropertiesManagementPanel.java
@@ -182,7 +182,6 @@ public void initTypeDeleteButton() {
           var type = (String) getTokenTypeList().getSelectedValue();
           if (type != null) {
             JPanel renameToPanel = new JPanel();
-            // renameToPanel.setLayout(new BoxLayout(renameToPanel, BoxLayout.PAGE_AXIS));
             JComboBox<String> types =
                 new JComboBox<>(
                     tokenTypeMap.keySet().stream()
@@ -332,6 +331,7 @@ public void initTokenTypeName() {
             var oldName = (String) ttList.getSelectedValue();
             var newName = field.getText();
             tokenTypeMap.put(newName, tokenTypeMap.remove(oldName));
+            tokenTypeStatSheetMap.put(newName, tokenTypeStatSheetMap.remove(oldName));
             ttList.setSelectedValue(newName, true);
             updateExistingTokenTypes(oldName, newName);
           }
diff --git a/src/main/java/net/rptools/maptool/model/CampaignProperties.java b/src/main/java/net/rptools/maptool/model/CampaignProperties.java
index 18e1707555..fc7dbe7fbb 100644
--- a/src/main/java/net/rptools/maptool/model/CampaignProperties.java
+++ b/src/main/java/net/rptools/maptool/model/CampaignProperties.java
@@ -190,7 +190,11 @@ public StatSheetProperties getTokenTypeDefaultStatSheet(String propertyType) {
    */
   public void setTokenTypeDefaultStatSheet(
       String propertyType, StatSheetProperties statSheetProperties) {
-    tokenTypeStatSheetMap.put(propertyType, statSheetProperties);
+    if (statSheetProperties == null) {
+      tokenTypeStatSheetMap.remove(propertyType);
+    } else {
+      tokenTypeStatSheetMap.put(propertyType, statSheetProperties);
+    }
   }
 
   public Map<String, SightType> getSightTypeMap() {