001package net.tnemc.item.component.helper.effect;
002/*
003 * The New Item Library
004 * Copyright (C) 2022 - 2025 Daniel "creatorfromhell" Vidmar
005 *
006 * This program is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public License
017 * along with this program; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019 */
020
021import net.tnemc.item.JSONHelper;
022import org.json.simple.JSONArray;
023import org.json.simple.JSONObject;
024
025import java.util.ArrayList;
026import java.util.List;
027import java.util.Objects;
028
029/**
030 * RemoveEffectsReviveEffect
031 *
032 * @author creatorfromhell
033 * @since 0.2.0.0
034 */
035public class RemoveEffectsComponentEffect extends ComponentEffect {
036
037  private final List<String> effectIds = new ArrayList<>();
038
039  @Override
040  public String getType() {
041    return "remove_effects";
042  }
043
044  @Override
045  public JSONObject toJSON() {
046    final JSONObject json = new JSONObject();
047    json.put("type", getType());
048    json.put("probability", probability);
049
050    final JSONArray effectsArray = new JSONArray();
051    effectsArray.addAll(effectIds);
052    json.put("effects", effectsArray);
053
054    return json;
055  }
056
057  @Override
058  public void readJSON(final JSONHelper json) {
059    probability = json.getFloat("probability");
060
061    effectIds.clear();
062    if(json.has("effects")) {
063      effectIds.addAll(json.getStringList("effects"));
064    }
065  }
066
067  public List<String> getEffectIds() {
068    return effectIds;
069  }
070
071  @Override
072  public boolean equals(final Object obj) {
073    if(!(obj instanceof final RemoveEffectsComponentEffect other)) return false;
074
075    return super.equals(obj) && Objects.equals(this.effectIds, other.effectIds);
076  }
077
078  @Override
079  public int hashCode() {
080    return Objects.hash(super.hashCode(), effectIds);
081  }
082
083  @Override
084  public RemoveEffectsComponentEffect clone() {
085    final RemoveEffectsComponentEffect copy = new RemoveEffectsComponentEffect();
086    copy.probability(this.probability);
087    copy.getEffectIds().addAll(this.effectIds);
088    return copy;
089  }
090}