Introduce slugs in arenas and classes.
Whitespace and punctuation in identifiers is a fairly big source of issues in areas like permissions and commands where whitespace isn't directly supported (or at least makes things needlessly difficult). This commit introduces the concept of a "slug" in arenas and classes, giving them a _consistent_ `kebab-case` name for use in such places, but it does not implement their use anywhere. Slugs are expected to be the solution to problems like the one posed in issue #647. At the time of writing, we're only concerned with simple stuff like removing periods, commas, parentheses and replacing underscores and spaces with dashes. If it turns out that people have unanticipatedly problematic arena and class names, we may have to expand the slug definition rules or allow for custom slugs.
This commit is contained in:
@@ -3,6 +3,7 @@ package com.garbagemule.MobArena;
|
||||
import com.garbagemule.MobArena.framework.Arena;
|
||||
import com.garbagemule.MobArena.framework.ArenaMaster;
|
||||
import com.garbagemule.MobArena.things.Thing;
|
||||
import com.garbagemule.MobArena.util.Slugs;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -16,6 +17,7 @@ import java.util.stream.IntStream;
|
||||
public class ArenaClass
|
||||
{
|
||||
private String configName, lowercaseName;
|
||||
private String slug;
|
||||
private Thing helmet, chestplate, leggings, boots, offhand;
|
||||
private List<Thing> armor;
|
||||
private List<Thing> items;
|
||||
@@ -32,6 +34,7 @@ public class ArenaClass
|
||||
*/
|
||||
public ArenaClass(String name, Thing price, boolean unbreakableWeapons, boolean unbreakableArmor) {
|
||||
this.configName = name;
|
||||
this.slug = Slugs.create(name);
|
||||
this.lowercaseName = name.toLowerCase().replace(" ", "");
|
||||
|
||||
this.items = new ArrayList<>();
|
||||
@@ -54,6 +57,14 @@ public class ArenaClass
|
||||
return configName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the slug version of the arena class name.
|
||||
* @return the slugified class name
|
||||
*/
|
||||
public String getSlug() {
|
||||
return slug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the lowercase class name.
|
||||
* @return the lowercase class name
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.garbagemule.MobArena.things.InvalidThingInputString;
|
||||
import com.garbagemule.MobArena.things.Thing;
|
||||
import com.garbagemule.MobArena.things.ThingPicker;
|
||||
import com.garbagemule.MobArena.util.ClassChests;
|
||||
import com.garbagemule.MobArena.util.Slugs;
|
||||
import com.garbagemule.MobArena.util.inventory.InventoryManager;
|
||||
import com.garbagemule.MobArena.util.timer.AutoStartTimer;
|
||||
import com.garbagemule.MobArena.util.timer.StartDelayTimer;
|
||||
@@ -77,6 +78,7 @@ public class ArenaImpl implements Arena
|
||||
// General stuff
|
||||
private MobArena plugin;
|
||||
private String name;
|
||||
private String slug;
|
||||
private World world;
|
||||
private Messenger messenger;
|
||||
private Announcer announcer;
|
||||
@@ -155,6 +157,7 @@ public class ArenaImpl implements Arena
|
||||
throw new NullPointerException("[MobArena] ERROR! World for arena '" + name + "' does not exist!");
|
||||
|
||||
this.name = name;
|
||||
this.slug = Slugs.create(name);
|
||||
this.world = world;
|
||||
this.plugin = plugin;
|
||||
this.settings = makeSection(section, "settings");
|
||||
@@ -1448,6 +1451,11 @@ public class ArenaImpl implements Arena
|
||||
return MAUtils.nameConfigToArena(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSlug() {
|
||||
return slug;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobArena getPlugin()
|
||||
{
|
||||
|
||||
@@ -223,6 +223,8 @@ public interface Arena
|
||||
|
||||
String arenaName();
|
||||
|
||||
String getSlug();
|
||||
|
||||
MobArena getPlugin();
|
||||
|
||||
Map<String,ArenaClass> getClasses();
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.garbagemule.MobArena.util;
|
||||
|
||||
public final class Slugs {
|
||||
|
||||
/**
|
||||
* Create a slug version
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public static String create(String input) {
|
||||
return input
|
||||
.toLowerCase()
|
||||
.replaceAll("[.,:;'\"]", "")
|
||||
.replaceAll("[<>(){}\\[\\]]", "")
|
||||
.replaceAll("[ _']", "-");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user