|
| 1 | +/* |
| 2 | + * This file is part of SpongeAPI, licensed under the MIT License (MIT). |
| 3 | + * |
| 4 | + * Copyright (c) SpongePowered <https://www.spongepowered.org> |
| 5 | + * Copyright (c) contributors |
| 6 | + * |
| 7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | + * of this software and associated documentation files (the "Software"), to deal |
| 9 | + * in the Software without restriction, including without limitation the rights |
| 10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | + * copies of the Software, and to permit persons to whom the Software is |
| 12 | + * furnished to do so, subject to the following conditions: |
| 13 | + * |
| 14 | + * The above copyright notice and this permission notice shall be included in |
| 15 | + * all copies or substantial portions of the Software. |
| 16 | + * |
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 | + * THE SOFTWARE. |
| 24 | + */ |
| 25 | +package org.spongepowered.api.event.cause.entity.damage; |
| 26 | + |
| 27 | +import org.spongepowered.api.Sponge; |
| 28 | +import org.spongepowered.api.event.entity.DamageCalculationEvent; |
| 29 | + |
| 30 | +import java.util.List; |
| 31 | +import java.util.Optional; |
| 32 | + |
| 33 | +/** |
| 34 | + * Represents the mutable equivalent of a {@link DamageStep}. |
| 35 | + * This allows plugins to add and remove modifiers during the {@link DamageCalculationEvent.Pre}. |
| 36 | + */ |
| 37 | +public interface DamageStepSpec { |
| 38 | + |
| 39 | + /** |
| 40 | + * Gets a mutable list of all children steps that applies just before this step. |
| 41 | + * Adding a step to this list will raise an error if the step is already the child of another step. |
| 42 | + * |
| 43 | + * @return The list of children steps |
| 44 | + */ |
| 45 | + List<DamageStepSpec.Child> childrenBefore(); |
| 46 | + |
| 47 | + /** |
| 48 | + * Gets a mutable list of all children steps that applies just after this step. |
| 49 | + * Adding a step to this list will raise an error if the step is already the child of another step. |
| 50 | + * |
| 51 | + * @return The list of children steps |
| 52 | + */ |
| 53 | + List<DamageStepSpec.Child> childrenAfter(); |
| 54 | + |
| 55 | + /** |
| 56 | + * Represents a step made by the platform (vanilla and mods). |
| 57 | + */ |
| 58 | + interface Root extends DamageStepSpec { |
| 59 | + |
| 60 | + /** |
| 61 | + * Gets the {@link DamageStepType} for this step. |
| 62 | + * |
| 63 | + * @return The damage step type |
| 64 | + */ |
| 65 | + DamageStepType type(); |
| 66 | + |
| 67 | + static DamageStepSpec.Root of(DamageStepType type) { |
| 68 | + return Sponge.game().factoryProvider().provide(Factory.class).of(type); |
| 69 | + } |
| 70 | + |
| 71 | + interface Factory { |
| 72 | + DamageStepSpec.Root of(DamageStepType type); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * Represents a step made by a plugin (a modifier). |
| 78 | + */ |
| 79 | + interface Child extends DamageStepSpec { |
| 80 | + |
| 81 | + /** |
| 82 | + * Gets the parent of this step. |
| 83 | + * |
| 84 | + * @return The parent of this step |
| 85 | + */ |
| 86 | + Optional<DamageStepSpec> parent(); |
| 87 | + |
| 88 | + /** |
| 89 | + * The {@link DamageModifier} function of this step. |
| 90 | + * |
| 91 | + * @return The damage modifier |
| 92 | + */ |
| 93 | + DamageModifier modifier(); |
| 94 | + |
| 95 | + /** |
| 96 | + * Creates a new {@link DamageStepSpec.Child} from the given damage modifier. |
| 97 | + * |
| 98 | + * @param modifier The damage modifier |
| 99 | + * @return The child step |
| 100 | + */ |
| 101 | + static DamageStepSpec.Child of(DamageModifier modifier) { |
| 102 | + return DamageStepSpec.Child.builder().modifier(modifier).build(); |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * Creates a new {@link Builder} to create {@link DamageStepSpec.Child}s. |
| 107 | + * |
| 108 | + * @return The new builder |
| 109 | + */ |
| 110 | + static Builder builder() { |
| 111 | + return Sponge.game().builderProvider().provide(Builder.class); |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * A builder to create {@link DamageStepSpec.Child}s. |
| 116 | + */ |
| 117 | + interface Builder extends org.spongepowered.api.util.Builder<DamageStepSpec.Child, Builder> { |
| 118 | + |
| 119 | + /** |
| 120 | + * Sets the {@link DamageModifier} function for this step. |
| 121 | + * |
| 122 | + * @param modifier The damage modifier |
| 123 | + * @return this builder for chaining |
| 124 | + */ |
| 125 | + Builder modifier(DamageModifier modifier); |
| 126 | + } |
| 127 | + } |
| 128 | +} |
0 commit comments