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.JSONObject;
023
024import java.util.Objects;
025
026/**
027 * PlaySoundReviveEffect
028 *
029 * @author creatorfromhell
030 * @since 0.2.0.0
031 */
032public class PlaySoundComponentEffect extends ComponentEffect {
033
034  private String sound;
035
036  @Override
037  public String getType() {
038    return "play_sound";
039  }
040
041  @Override
042  public JSONObject toJSON() {
043    final JSONObject json = new JSONObject();
044    json.put("type", getType());
045    json.put("probability", probability);
046    json.put("sound", sound);
047
048    return json;
049  }
050
051  @Override
052  public void readJSON(final JSONHelper json) {
053    probability = json.getFloat("probability");
054    sound = json.getString("sound");
055  }
056
057  public String sound() {
058
059    return sound;
060  }
061
062  public void sound(final String sound) {
063
064    this.sound = sound;
065  }
066
067  @Override
068  public boolean equals(final Object obj) {
069    if(!(obj instanceof final PlaySoundComponentEffect other)) return false;
070
071    return super.equals(obj) && Objects.equals(this.sound, other.sound);
072  }
073
074  @Override
075  public int hashCode() {
076    return Objects.hash(super.hashCode(), sound);
077  }
078
079  @Override
080  public PlaySoundComponentEffect clone() {
081
082    final PlaySoundComponentEffect copy = new PlaySoundComponentEffect();
083    copy.sound(this.sound);
084    copy.probability(this.probability);
085    return copy;
086  }
087}