-
-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
371 additions
and
192 deletions.
There are no files selected for viewing
Submodule SpongeAPI
updated
8 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
src/main/java/org/spongepowered/common/event/cause/entity/damage/SpongeDamageModifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* This file is part of Sponge, licensed under the MIT License (MIT). | ||
* | ||
* Copyright (c) SpongePowered <https://www.spongepowered.org> | ||
* Copyright (c) contributors | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package org.spongepowered.common.event.cause.entity.damage; | ||
|
||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
import org.spongepowered.api.event.Cause; | ||
import org.spongepowered.api.event.cause.entity.damage.DamageModifier; | ||
import org.spongepowered.api.event.cause.entity.damage.DamageStepType; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
public class SpongeDamageModifier implements DamageModifier { | ||
protected final DamageStepType type; | ||
protected final Cause cause; | ||
protected final @Nullable Function function; | ||
|
||
public SpongeDamageModifier(final DamageStepType type, final Cause cause, final @Nullable Function function) { | ||
this.type = type; | ||
this.cause = cause; | ||
this.function = function; | ||
} | ||
|
||
@Override | ||
public final DamageStepType type() { | ||
return this.type; | ||
} | ||
|
||
@Override | ||
public final Cause cause() { | ||
return this.cause; | ||
} | ||
|
||
@Override | ||
public final Optional<Function> function() { | ||
return Optional.ofNullable(this.function); | ||
} | ||
|
||
public static class Builder implements DamageModifier.Builder { | ||
private @Nullable DamageStepType type; | ||
private @Nullable Cause cause; | ||
private Function function; | ||
|
||
public Builder() { | ||
this.reset(); | ||
} | ||
|
||
@Override | ||
public DamageModifier.Builder reset() { | ||
this.type = null; | ||
this.cause = null; | ||
this.function = (step, damage) -> damage; | ||
return this; | ||
} | ||
|
||
@Override | ||
public DamageModifier.Builder type(DamageStepType type) { | ||
this.type = Objects.requireNonNull(type, "type"); | ||
return this; | ||
} | ||
|
||
@Override | ||
public DamageModifier.Builder cause(Cause cause) { | ||
this.cause = Objects.requireNonNull(cause, "cause"); | ||
return this; | ||
} | ||
|
||
@Override | ||
public DamageModifier.Builder function(Function function) { | ||
this.function = Objects.requireNonNull(function, "function"); | ||
return this; | ||
} | ||
|
||
@Override | ||
public DamageModifier build() { | ||
if (this.type == null) { | ||
throw new IllegalStateException("type must be set"); | ||
} | ||
if (this.cause == null) { | ||
throw new IllegalStateException("cause must be set"); | ||
} | ||
return new SpongeDamageModifier(this.type, this.cause, this.function); | ||
} | ||
} | ||
} |
Oops, something went wrong.