Advertisement
GamesofFreak

First Java Code

Jul 15th, 2024
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.42 KB | Gaming | 0 0
  1. package api.sparklearts.astralinfusion.soul;
  2.  
  3. import java.util.List;
  4. import java.util.ArrayList;
  5.  
  6. public class SoulType {
  7.     private static final List<SoulType> SOUL_TYPES = new ArrayList<>();
  8.  
  9.     private final String id;
  10.     private final String displayName;
  11.     private final SoulTypeRarities rarity;
  12.     private final double corruption;
  13.     private double strength;
  14.  
  15.     private SoulType(String id, String displayName, SoulTypeRarities rarity, double corruption, double strength) {
  16.         this.id = id;
  17.         this.displayName = displayName;
  18.         this.rarity = rarity;
  19.         this.corruption = corruption;
  20.         this.strength = strength;
  21.     }
  22.  
  23.     public static List<SoulType> getSoulTypes() { // Neue Getter-Methode
  24.         return SOUL_TYPES;
  25.     }
  26.  
  27.     public String getId() {
  28.         return id;
  29.     }
  30.  
  31.     public String getDisplayName() {
  32.         return displayName;
  33.     }
  34.  
  35.     public SoulTypeRarities getRarity() {
  36.         return rarity;
  37.     }
  38.  
  39.     public Double getCorruption() {
  40.         return corruption;
  41.     }
  42.  
  43.     public Double getStrength() {
  44.         return strength;
  45.     }
  46.  
  47.     public void setStrength(double newStrength) {
  48.         this.strength = newStrength;
  49.     }
  50.  
  51.     public void addStrength(double addStrength) {
  52.         this.strength += addStrength;
  53.     }
  54.  
  55.     public static SoulType register(String id, String displayName, SoulTypeRarities rarity, double corruption, double strength) throws IllegalArgumentException {
  56.         double minCorruption = 0;
  57.         double maxCorruption = 2;
  58.         double minStrength = 0;
  59.         double maxStrength = 5;
  60.         if (corruption < minCorruption || corruption > maxCorruption) {
  61.             throw new IllegalArgumentException("Corruption must be between " + minCorruption + " and " + maxCorruption + " .");
  62.         }
  63.         if (strength < minStrength || strength > maxStrength) {
  64.             throw new IllegalArgumentException("Strength must be between " + minStrength + " and " + maxStrength + " .");
  65.         }
  66.         SoulType newType = new SoulType(id, displayName, rarity, corruption, strength);
  67.         SOUL_TYPES.add(newType);
  68.         for (SoulType soulType : SOUL_TYPES) {
  69.             if (soulType.getId().equals(id)) {
  70.                 throw new IllegalArgumentException("SoulType with id '" + id + "' already exists.");
  71.             }
  72.         }
  73.         return newType;
  74.     }
  75.  
  76.     public static SoulType fromId(String id) {
  77.         for (SoulType soulType : SOUL_TYPES) {
  78.             if (soulType.getId().equals(id)) {
  79.                 return soulType;
  80.             }
  81.         }
  82.         throw new IllegalArgumentException("SoulType with id '" + id + "' not found.");
  83.     }
  84. }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement