forked from alkarinv/BattleArena
-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update potion effect format and add give-item action
- Loading branch information
Showing
15 changed files
with
192 additions
and
64 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
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
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
63 changes: 63 additions & 0 deletions
63
plugin/src/main/java/org/battleplugins/arena/config/PotionEffectParser.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,63 @@ | ||
package org.battleplugins.arena.config; | ||
|
||
import org.bukkit.NamespacedKey; | ||
import org.bukkit.potion.PotionEffect; | ||
import org.bukkit.potion.PotionEffectType; | ||
|
||
public class PotionEffectParser implements ArenaConfigParser.Parser<PotionEffect> { | ||
|
||
@Override | ||
public PotionEffect parse(Object object) throws ParseException { | ||
if (object instanceof String contents) { | ||
return deserializeSingular(contents); | ||
} | ||
|
||
throw new ParseException("Invalid PotionEffect for object: " + object) | ||
.cause(ParseException.Cause.INVALID_TYPE) | ||
.type(PotionEffectParser.class) | ||
.userError(); | ||
} | ||
|
||
public static PotionEffect deserializeSingular(String contents) throws ParseException { | ||
SingularValueParser.ArgumentBuffer buffer = SingularValueParser.parseNamed(contents, SingularValueParser.BraceStyle.CURLY, ';'); | ||
if (!buffer.hasNext()) { | ||
throw new ParseException("No data found for PotionEffect") | ||
.cause(ParseException.Cause.INVALID_TYPE) | ||
.type(PotionEffectParser.class) | ||
.userError(); | ||
} | ||
|
||
PotionEffectType type; | ||
int duration = 20; | ||
int amplifier = 1; | ||
boolean ambient = true; | ||
boolean particles = true; | ||
|
||
SingularValueParser.Argument root = buffer.pop(); | ||
if (root.key().equals("root")) { | ||
type = PotionEffectType.getByKey(NamespacedKey.fromString(root.value())); | ||
if (type == null) { | ||
throw new ParseException("Invalid potion effect type " + root.value()) | ||
.cause(ParseException.Cause.INVALID_VALUE) | ||
.type(PotionEffectParser.class) | ||
.userError(); | ||
} | ||
} else { | ||
throw new ParseException("Invalid PotionEffect root tag " + root.key()) | ||
.cause(ParseException.Cause.INTERNAL_ERROR) | ||
.type(PotionEffectParser.class); | ||
} | ||
|
||
while (buffer.hasNext()) { | ||
SingularValueParser.Argument effectArgument = buffer.pop(); | ||
switch (effectArgument.key()) { | ||
case "duration" -> duration = Integer.parseInt(effectArgument.value()) * 20; | ||
case "amplifier" -> amplifier = Integer.parseInt(effectArgument.value()) - 1; | ||
case "ambient" -> ambient = Boolean.parseBoolean(effectArgument.value()); | ||
case "particles" -> particles = Boolean.parseBoolean(effectArgument.value()); | ||
} | ||
} | ||
|
||
return new PotionEffect(type, duration, amplifier, ambient, particles); | ||
} | ||
} |
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
Oops, something went wrong.