-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add per-series knockback customization (#39)
* Add per-series knockback customization * Remove verbose * Move setupKnockback to its own KnockbackManager * Make KnockbackManager listen to BoltMatchStatusChangeEvent * Run formatter
- Loading branch information
Showing
5 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
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
112 changes: 112 additions & 0 deletions
112
src/main/java/rip/bolt/ingame/api/definitions/BoltKnockback.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,112 @@ | ||
package rip.bolt.ingame.api.definitions; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import org.github.paperspigot.PaperSpigotConfig; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class BoltKnockback { | ||
private double friction; | ||
private double horizontal; | ||
private double vertical; | ||
private double verticalLimit; | ||
private double extraHorizontal; | ||
private double extraVertical; | ||
|
||
public BoltKnockback() {} | ||
|
||
public BoltKnockback( | ||
double friction, | ||
double horizontal, | ||
double vertical, | ||
double verticalLimit, | ||
double extraHorizontal, | ||
double extraVertical) { | ||
this.friction = friction; | ||
this.horizontal = horizontal; | ||
this.vertical = vertical; | ||
this.verticalLimit = verticalLimit; | ||
this.extraHorizontal = extraHorizontal; | ||
this.extraVertical = extraVertical; | ||
} | ||
|
||
public double getFriction() { | ||
return friction; | ||
} | ||
|
||
public void setFriction(double friction) { | ||
this.friction = friction; | ||
} | ||
|
||
public double getHorizontal() { | ||
return horizontal; | ||
} | ||
|
||
public void setHorizontal(double horizontal) { | ||
this.horizontal = horizontal; | ||
} | ||
|
||
public double getVertical() { | ||
return vertical; | ||
} | ||
|
||
public void setVertical(double vertical) { | ||
this.vertical = vertical; | ||
} | ||
|
||
public double getVerticalLimit() { | ||
return verticalLimit; | ||
} | ||
|
||
public void setVerticalLimit(double verticalLimit) { | ||
this.verticalLimit = verticalLimit; | ||
} | ||
|
||
public double getExtraHorizontal() { | ||
return extraHorizontal; | ||
} | ||
|
||
public void setExtraHorizontal(double extraHorizontal) { | ||
this.extraHorizontal = extraHorizontal; | ||
} | ||
|
||
public double getExtraVertical() { | ||
return extraVertical; | ||
} | ||
|
||
public void setExtraVertical(double extraVertical) { | ||
this.extraVertical = extraVertical; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "BoltKnockback{" | ||
+ "friction=" | ||
+ friction | ||
+ ", horizontal=" | ||
+ horizontal | ||
+ ", vertical=" | ||
+ vertical | ||
+ ", verticalLimit=" | ||
+ verticalLimit | ||
+ ", extraHorizontal=" | ||
+ extraHorizontal | ||
+ ", extraVertical=" | ||
+ extraVertical | ||
+ '}'; | ||
} | ||
|
||
public static BoltKnockback defaults() { | ||
double friction = PaperSpigotConfig.config.getDouble("paper.knockback.friction", 2.0D); | ||
double horizontal = PaperSpigotConfig.config.getDouble("paper.knockback.horizontal", 0.4D); | ||
double vertical = PaperSpigotConfig.config.getDouble("paper.knockback.vertical", 0.4D); | ||
double verticalLimit = | ||
PaperSpigotConfig.config.getDouble("paper.knockback.vertical-limit", 0.4D); | ||
double extraHorizontal = | ||
PaperSpigotConfig.config.getDouble("paper.knockback.extra-horizontal", 0.5D); | ||
double extraVertical = | ||
PaperSpigotConfig.config.getDouble("paper.knockback.extra-vertical", 0.1D); | ||
|
||
return new BoltKnockback( | ||
friction, horizontal, vertical, verticalLimit, extraHorizontal, extraVertical); | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
src/main/java/rip/bolt/ingame/ranked/KnockbackManager.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,32 @@ | ||
package rip.bolt.ingame.ranked; | ||
|
||
import java.util.Objects; | ||
import javax.annotation.Nullable; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.github.paperspigot.PaperSpigotConfig; | ||
import rip.bolt.ingame.api.definitions.BoltKnockback; | ||
import rip.bolt.ingame.events.BoltMatchStatusChangeEvent; | ||
|
||
public class KnockbackManager implements Listener { | ||
public KnockbackManager() {} | ||
|
||
@EventHandler(priority = EventPriority.MONITOR) | ||
public void onBoltMatchStateChange(BoltMatchStatusChangeEvent event) { | ||
if (Objects.equals(event.getNewStatus(), MatchStatus.CREATED)) { | ||
setupKnockback(event.getBoltMatch().getSeries().getKnockback()); | ||
} | ||
} | ||
|
||
public void setupKnockback(@Nullable BoltKnockback knockback) { | ||
if (knockback == null) knockback = BoltKnockback.defaults(); | ||
|
||
PaperSpigotConfig.knockbackFriction = knockback.getFriction(); | ||
PaperSpigotConfig.knockbackHorizontal = knockback.getHorizontal(); | ||
PaperSpigotConfig.knockbackVertical = knockback.getVertical(); | ||
PaperSpigotConfig.knockbackVerticalLimit = knockback.getVerticalLimit(); | ||
PaperSpigotConfig.knockbackExtraHorizontal = knockback.getExtraHorizontal(); | ||
PaperSpigotConfig.knockbackExtraVertical = knockback.getExtraVertical(); | ||
} | ||
} |
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