mirror of
https://github.com/garbagemule/MobArena.git
synced 2024-11-29 22:23:54 +01:00
Drop support for getting potion effect types by magic number IDs.
getById() is deprecated, and while this does break existing functionality, it is a good kind of breakage because it forces people over to the name-based IDs, which they will eventually be happier with. Partial fix for #406
This commit is contained in:
parent
0009e6363a
commit
fa2016acb5
@ -17,6 +17,7 @@ These changes will (most likely) be included in the next version.
|
|||||||
- MobArena no longer crashes when players try to join with items that lower their max health below the default of 20. Players with lower max health will notice missing health in the lobby, but it will quickly regenerate to full.
|
- MobArena no longer crashes when players try to join with items that lower their max health below the default of 20. Players with lower max health will notice missing health in the lobby, but it will quickly regenerate to full.
|
||||||
- Food levels no longer deplete for players in the lobby and spectator area.
|
- Food levels no longer deplete for players in the lobby and spectator area.
|
||||||
- Wither skeletons now correctly spawn with stone swords.
|
- Wither skeletons now correctly spawn with stone swords.
|
||||||
|
- Support for denoting potion effects by magic number IDs has been dropped. This means that if your config-file has any such magic numbers in it, MobArena will no longer successfully parse them and will throw an error on startup.
|
||||||
|
|
||||||
## [0.103.2] - 2019-04-23
|
## [0.103.2] - 2019-04-23
|
||||||
- MobArena no longer touches the `flySpeed` player attribute when players join an arena. This should fix issues where a crash would result in players being "locked in the air" when trying to fly outside of the arena. It also introduces compatibility with plugins that use flight to augment player abilities.
|
- MobArena no longer touches the `flySpeed` player attribute when players join an arena. This should fix issues where a crash would result in players being "locked in the air" when trying to fly outside of the arena. It also introduces compatibility with plugins that use flight to augment player abilities.
|
||||||
|
@ -1,128 +1,116 @@
|
|||||||
package com.garbagemule.MobArena.util;
|
package com.garbagemule.MobArena.util;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PotionEffectParser
|
public class PotionEffectParser
|
||||||
{
|
{
|
||||||
private static final int TICKS_PER_SECOND = 20;
|
private static final int TICKS_PER_SECOND = 20;
|
||||||
private static final int DEFAULT_POTION_AMPLIFIER = 0;
|
private static final int DEFAULT_POTION_AMPLIFIER = 0;
|
||||||
private static final int DEFAULT_POTION_DURATION = Integer.MAX_VALUE;
|
private static final int DEFAULT_POTION_DURATION = Integer.MAX_VALUE;
|
||||||
|
|
||||||
public static List<PotionEffect> parsePotionEffects(String s) {
|
public static List<PotionEffect> parsePotionEffects(String s) {
|
||||||
if (s == null || s.isEmpty())
|
if (s == null || s.isEmpty())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
List<PotionEffect> potions = new ArrayList<>();
|
List<PotionEffect> potions = new ArrayList<>();
|
||||||
for (String potion : s.split(",")) {
|
for (String potion : s.split(",")) {
|
||||||
PotionEffect eff = parsePotionEffect(potion.trim());
|
PotionEffect eff = parsePotionEffect(potion.trim());
|
||||||
if (eff != null) {
|
if (eff != null) {
|
||||||
potions.add(eff);
|
potions.add(eff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return potions;
|
return potions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PotionEffect parsePotionEffect(String p) {
|
public static PotionEffect parsePotionEffect(String p) {
|
||||||
return parsePotionEffect(p, true);
|
return parsePotionEffect(p, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PotionEffect parsePotionEffect(String p, boolean logFailure) {
|
public static PotionEffect parsePotionEffect(String p, boolean logFailure) {
|
||||||
if (p == null || p.isEmpty())
|
if (p == null || p.isEmpty())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
String[] parts = p.split(":");
|
String[] parts = p.split(":");
|
||||||
PotionEffect result = null;
|
PotionEffect result = null;
|
||||||
|
|
||||||
switch (parts.length) {
|
switch (parts.length) {
|
||||||
case 1:
|
case 1:
|
||||||
result = parseSingle(parts[0]);
|
result = parseSingle(parts[0]);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
result = withAmplifier(parts[0], parts[1]);
|
result = withAmplifier(parts[0], parts[1]);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
result = withAmplifierAndDuration(parts[0], parts[1], parts[2]);
|
result = withAmplifierAndDuration(parts[0], parts[1], parts[2]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
if (logFailure) {
|
if (logFailure) {
|
||||||
Bukkit.getLogger().warning("[MobArena] Failed to parse potion effect: " + p);
|
Bukkit.getLogger().warning("[MobArena] Failed to parse potion effect: " + p);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PotionEffect parseSingle(String type) {
|
private static PotionEffect parseSingle(String type) {
|
||||||
PotionEffectType effect = getType(type);
|
PotionEffectType effect = PotionEffectType.getByName(type);
|
||||||
|
|
||||||
if (effect == null) {
|
if (effect == null) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return new PotionEffect(effect, DEFAULT_POTION_DURATION, DEFAULT_POTION_AMPLIFIER);
|
return new PotionEffect(effect, DEFAULT_POTION_DURATION, DEFAULT_POTION_AMPLIFIER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PotionEffect withAmplifier(String type, String amplifier) {
|
private static PotionEffect withAmplifier(String type, String amplifier) {
|
||||||
PotionEffectType effect = getType(type);
|
PotionEffectType effect = PotionEffectType.getByName(type);
|
||||||
int amp = getAmplification(amplifier);
|
int amp = getAmplification(amplifier);
|
||||||
|
|
||||||
if (effect == null || amp == -1) {
|
if (effect == null || amp == -1) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return new PotionEffect(effect, DEFAULT_POTION_DURATION, amp);
|
return new PotionEffect(effect, DEFAULT_POTION_DURATION, amp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PotionEffect withAmplifierAndDuration(String type, String amplifier, String duration) {
|
private static PotionEffect withAmplifierAndDuration(String type, String amplifier, String duration) {
|
||||||
PotionEffectType effect = getType(type);
|
PotionEffectType effect = PotionEffectType.getByName(type);
|
||||||
int amp = getAmplification(amplifier);
|
int amp = getAmplification(amplifier);
|
||||||
int dur = getDuration(duration);
|
int dur = getDuration(duration);
|
||||||
|
|
||||||
if (effect == null || dur == -1 || amp == -1) {
|
if (effect == null || dur == -1 || amp == -1) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return new PotionEffect(effect, dur * TICKS_PER_SECOND, amp);
|
return new PotionEffect(effect, dur * TICKS_PER_SECOND, amp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PotionEffectType getType(String type) {
|
private static int getDuration(String duration) {
|
||||||
PotionEffectType effect = null;
|
int dur = -1;
|
||||||
|
|
||||||
if (type.matches("[0-9]+")) {
|
if (duration.matches("[0-9]+")) {
|
||||||
effect = PotionEffectType.getById(Integer.parseInt(type));
|
dur = Integer.parseInt(duration);
|
||||||
} else {
|
}
|
||||||
effect = PotionEffectType.getByName(type.toUpperCase());
|
|
||||||
}
|
return dur;
|
||||||
|
}
|
||||||
return effect;
|
|
||||||
}
|
private static int getAmplification(String amplifier) {
|
||||||
|
int amp = -1;
|
||||||
private static int getDuration(String duration) {
|
|
||||||
int dur = -1;
|
if (amplifier.matches("[0-9]+")) {
|
||||||
|
amp = Integer.parseInt(amplifier);
|
||||||
if (duration.matches("[0-9]+")) {
|
}
|
||||||
dur = Integer.parseInt(duration);
|
|
||||||
}
|
return amp;
|
||||||
|
}
|
||||||
return dur;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static int getAmplification(String amplifier) {
|
|
||||||
int amp = -1;
|
|
||||||
|
|
||||||
if (amplifier.matches("[0-9]+")) {
|
|
||||||
amp = Integer.parseInt(amplifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
return amp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user