ago1024 / WurmServerModLauncher

Wurm Unlimited Mod Launcher
59 stars 21 forks source link

No update for christmasmod #74

Closed revelation343 closed 10 months ago

revelation343 commented 10 months ago

To the best of my review, christmasmod only configures up to the year 2020 due to the variables within the christmasmod.java class. I attempted to add 2023 and have it read from the christmasmod.config however, it would not compile with modlauncher 0.45 due to super.action not being available in the OpenPresentActionPerformer.java

I removed the super. from the code and it was able to compile from there.

I will likely work on fixing this for myself, but figured I would mention it since it is a popular mod.

# Award the spyglass
# You can use item ids or names from ItemList
#present2015=spyglass
#present2016=spyglass
#present2017=spyglass
#present2018=spyglass
#present2019=spyglass
#present2020=489
#present2021=489
#present2022=665
present2023=664

I set the variable to the default in the code int present2023 = 972 and added the following:

this.present2023 = Integer.parseInt(properties.getProperty("present2023", String.valueOf(this.present2023)));

I still received a farwalker amulet despite the .config edit. Then the server crashed due to the following: I believe it would also be required to add:

            case 14:
                return new OpenPresentActionPerformer.GiftData(this.present2023);

For it to work and not crash the server. However, the holidays are a busy time so I will manually handle gifts. Maybe an update to the code would help out people who do not/cannot figure out java, Maybe adding the next 5-10 years as a proactive approach would be positive. Also someway to remove setflag(62, true) across all players in a command as I've had mixed luck with update players set reimbursed=0; in players.db which was the suggested method so players could receive gifts again, I'm not sure if there has been a way to automatically reset this flag looking at source. Thanks!

Tyoda commented 10 months ago

You forgot to paste the crash message. Also I think for 2023 you'd want case 16:.

I have not tested this code but I think a simple dynamic way of parsing and storing them is the the easiest, really:

[...]

private final Map<String, Integer> presentMap = new HashMap<>();

@Override
public void configure(Properties properties) {
  for(String key : properties.stringPropertyNames()) {
    if (key.startsWith("present")) {
      Integer present = Integer.valueOf(properties.getProperty(key));
      presentMap.put(key, present);
      LOGGER.log(Level.INFO, key + ": " + present);
    }
  }
}

[...]

private GiftData createGiftData(byte auxdata) {
  String presentString = "present" + (2007+auxdata);
  if(presentMap.containsKey(presentString)) {
    return new GiftData(presentMap.get(presentString));
  } else {
    return OpenPresentActionPerformer.getDefaultPresentData(auxdata);
  }
}

[...]
revelation343 commented 10 months ago
case 14:
                return new OpenPresentActionPerformer.GiftData(this.present2023);

Ah sorry Tyoda, I meant to state that I did not add this line of code which is why it didn't work^

I was in a bit of a hurry and didn't catch the actual error as it was spamming the console until the server shut down gracefully. So I just replaced it with the old .jar for now. However, what you have suggested looks like a good way to handle future years without having to intialize variable per year and also not having to add the code to the action performer. I think you've nailed it on the head!

ago1024 commented 10 months ago

The upper limit is now 2134 (2007+127)