mirror of
https://github.com/garbagemule/MobArena.git
synced 2024-11-26 12:36:00 +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.
|
||||
- Food levels no longer deplete for players in the lobby and spectator area.
|
||||
- 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
|
||||
- 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;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PotionEffectParser
|
||||
{
|
||||
private static final int TICKS_PER_SECOND = 20;
|
||||
private static final int DEFAULT_POTION_AMPLIFIER = 0;
|
||||
private static final int DEFAULT_POTION_DURATION = Integer.MAX_VALUE;
|
||||
|
||||
public static List<PotionEffect> parsePotionEffects(String s) {
|
||||
if (s == null || s.isEmpty())
|
||||
return null;
|
||||
|
||||
List<PotionEffect> potions = new ArrayList<>();
|
||||
for (String potion : s.split(",")) {
|
||||
PotionEffect eff = parsePotionEffect(potion.trim());
|
||||
if (eff != null) {
|
||||
potions.add(eff);
|
||||
}
|
||||
}
|
||||
|
||||
return potions;
|
||||
}
|
||||
|
||||
public static PotionEffect parsePotionEffect(String p) {
|
||||
return parsePotionEffect(p, true);
|
||||
}
|
||||
|
||||
public static PotionEffect parsePotionEffect(String p, boolean logFailure) {
|
||||
if (p == null || p.isEmpty())
|
||||
return null;
|
||||
|
||||
String[] parts = p.split(":");
|
||||
PotionEffect result = null;
|
||||
|
||||
switch (parts.length) {
|
||||
case 1:
|
||||
result = parseSingle(parts[0]);
|
||||
break;
|
||||
case 2:
|
||||
result = withAmplifier(parts[0], parts[1]);
|
||||
break;
|
||||
case 3:
|
||||
result = withAmplifierAndDuration(parts[0], parts[1], parts[2]);
|
||||
break;
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
if (logFailure) {
|
||||
Bukkit.getLogger().warning("[MobArena] Failed to parse potion effect: " + p);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static PotionEffect parseSingle(String type) {
|
||||
PotionEffectType effect = getType(type);
|
||||
|
||||
if (effect == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new PotionEffect(effect, DEFAULT_POTION_DURATION, DEFAULT_POTION_AMPLIFIER);
|
||||
}
|
||||
}
|
||||
|
||||
private static PotionEffect withAmplifier(String type, String amplifier) {
|
||||
PotionEffectType effect = getType(type);
|
||||
int amp = getAmplification(amplifier);
|
||||
|
||||
if (effect == null || amp == -1) {
|
||||
return null;
|
||||
} else {
|
||||
return new PotionEffect(effect, DEFAULT_POTION_DURATION, amp);
|
||||
}
|
||||
}
|
||||
|
||||
private static PotionEffect withAmplifierAndDuration(String type, String amplifier, String duration) {
|
||||
PotionEffectType effect = getType(type);
|
||||
int amp = getAmplification(amplifier);
|
||||
int dur = getDuration(duration);
|
||||
|
||||
if (effect == null || dur == -1 || amp == -1) {
|
||||
return null;
|
||||
} else {
|
||||
return new PotionEffect(effect, dur * TICKS_PER_SECOND, amp);
|
||||
}
|
||||
}
|
||||
|
||||
private static PotionEffectType getType(String type) {
|
||||
PotionEffectType effect = null;
|
||||
|
||||
if (type.matches("[0-9]+")) {
|
||||
effect = PotionEffectType.getById(Integer.parseInt(type));
|
||||
} else {
|
||||
effect = PotionEffectType.getByName(type.toUpperCase());
|
||||
}
|
||||
|
||||
return effect;
|
||||
}
|
||||
|
||||
private static int getDuration(String duration) {
|
||||
int dur = -1;
|
||||
|
||||
if (duration.matches("[0-9]+")) {
|
||||
dur = Integer.parseInt(duration);
|
||||
}
|
||||
|
||||
return dur;
|
||||
}
|
||||
|
||||
private static int getAmplification(String amplifier) {
|
||||
int amp = -1;
|
||||
|
||||
if (amplifier.matches("[0-9]+")) {
|
||||
amp = Integer.parseInt(amplifier);
|
||||
}
|
||||
|
||||
return amp;
|
||||
}
|
||||
}
|
||||
package com.garbagemule.MobArena.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PotionEffectParser
|
||||
{
|
||||
private static final int TICKS_PER_SECOND = 20;
|
||||
private static final int DEFAULT_POTION_AMPLIFIER = 0;
|
||||
private static final int DEFAULT_POTION_DURATION = Integer.MAX_VALUE;
|
||||
|
||||
public static List<PotionEffect> parsePotionEffects(String s) {
|
||||
if (s == null || s.isEmpty())
|
||||
return null;
|
||||
|
||||
List<PotionEffect> potions = new ArrayList<>();
|
||||
for (String potion : s.split(",")) {
|
||||
PotionEffect eff = parsePotionEffect(potion.trim());
|
||||
if (eff != null) {
|
||||
potions.add(eff);
|
||||
}
|
||||
}
|
||||
|
||||
return potions;
|
||||
}
|
||||
|
||||
public static PotionEffect parsePotionEffect(String p) {
|
||||
return parsePotionEffect(p, true);
|
||||
}
|
||||
|
||||
public static PotionEffect parsePotionEffect(String p, boolean logFailure) {
|
||||
if (p == null || p.isEmpty())
|
||||
return null;
|
||||
|
||||
String[] parts = p.split(":");
|
||||
PotionEffect result = null;
|
||||
|
||||
switch (parts.length) {
|
||||
case 1:
|
||||
result = parseSingle(parts[0]);
|
||||
break;
|
||||
case 2:
|
||||
result = withAmplifier(parts[0], parts[1]);
|
||||
break;
|
||||
case 3:
|
||||
result = withAmplifierAndDuration(parts[0], parts[1], parts[2]);
|
||||
break;
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
if (logFailure) {
|
||||
Bukkit.getLogger().warning("[MobArena] Failed to parse potion effect: " + p);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static PotionEffect parseSingle(String type) {
|
||||
PotionEffectType effect = PotionEffectType.getByName(type);
|
||||
|
||||
if (effect == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new PotionEffect(effect, DEFAULT_POTION_DURATION, DEFAULT_POTION_AMPLIFIER);
|
||||
}
|
||||
}
|
||||
|
||||
private static PotionEffect withAmplifier(String type, String amplifier) {
|
||||
PotionEffectType effect = PotionEffectType.getByName(type);
|
||||
int amp = getAmplification(amplifier);
|
||||
|
||||
if (effect == null || amp == -1) {
|
||||
return null;
|
||||
} else {
|
||||
return new PotionEffect(effect, DEFAULT_POTION_DURATION, amp);
|
||||
}
|
||||
}
|
||||
|
||||
private static PotionEffect withAmplifierAndDuration(String type, String amplifier, String duration) {
|
||||
PotionEffectType effect = PotionEffectType.getByName(type);
|
||||
int amp = getAmplification(amplifier);
|
||||
int dur = getDuration(duration);
|
||||
|
||||
if (effect == null || dur == -1 || amp == -1) {
|
||||
return null;
|
||||
} else {
|
||||
return new PotionEffect(effect, dur * TICKS_PER_SECOND, amp);
|
||||
}
|
||||
}
|
||||
|
||||
private static int getDuration(String duration) {
|
||||
int dur = -1;
|
||||
|
||||
if (duration.matches("[0-9]+")) {
|
||||
dur = Integer.parseInt(duration);
|
||||
}
|
||||
|
||||
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