Resolve arenas by name using slugs.

This commit is a minor refactor of how arenas are resolved by name,
similar to the previous arena class resolution refactoring.

The difference this time around is that there is an ArenaMaster method
that does most of the work for a lot of different areas of the plugin,
`getArenaWithName(String)`. This method is called from well over 30
different places in the code base, making it a cornerstone of all arena
resolution. Luckily, it is called primarily from places that shouldn't
care _how_ an arena is resolved.

Affected by this commit are all commands that resolve arenas by name,
including all those not listed in the diff, because of the change to
`getArenaWithName(String)` on ArenaMaster.

Commands that can tab complete arena name arguments now complete slugs
instead of config names.
This commit is contained in:
Andreas Troelsen 2020-11-01 15:05:38 +01:00
parent fdb84dfaf4
commit 0f93d8ac05
11 changed files with 22 additions and 20 deletions

View File

@ -24,7 +24,7 @@ These changes will (most likely) be included in the next version.
- New command `/ma addreward <player> <thing>` can be used to add a reward to an arena player's reward list. This can be useful for hooking into the rewards system from scripts or other plugins. - New command `/ma addreward <player> <thing>` can be used to add a reward to an arena player's reward list. This can be useful for hooking into the rewards system from scripts or other plugins.
- The Root Target ability now uses potion effects (slowness, slow falling, and negative jump boost) instead of repeated teleports. This should make for a smoother root experience. - The Root Target ability now uses potion effects (slowness, slow falling, and negative jump boost) instead of repeated teleports. This should make for a smoother root experience.
- Permissions for arenas and classes are now based on "slugs". It is now possible to configure permissions for arenas and classes with multi-word names (including "My Items"). Check the Permissions page on the wiki for details. - Permissions for arenas and classes are now based on "slugs". It is now possible to configure permissions for arenas and classes with multi-word names (including "My Items"). Check the Permissions page on the wiki for details.
- Commands that resolve class names now consistently resolve and tab complete "slugs" instead of arbitrarily "squashed" names. This greatly improves support for multi-word names. - Commands that resolve arena and/or class names now consistently resolve and tab complete "slugs" instead of arbitrarily "squashed" names. This greatly improves support for multi-word names.
- The class signs generated by the `/ma autogenerate` command now use class names from the config-file instead of arbitrarily "squashed" names. - The class signs generated by the `/ma autogenerate` command now use class names from the config-file instead of arbitrarily "squashed" names.
- Leaderboards now use arena names from the config-file instead of arbitrarily "prettified" names. - Leaderboards now use arena names from the config-file instead of arbitrarily "prettified" names.
- Using `spectate-on-death: true` no longer forces players out to their join location/exit warp before moving them to the spectator area. This should prevent "jumpy" behavior in multi-world setups. - Using `spectate-on-death: true` no longer forces players out to their join location/exit warp before moving them to the spectator area. This should prevent "jumpy" behavior in multi-world setups.

View File

@ -8,6 +8,7 @@ import com.garbagemule.MobArena.framework.ArenaMaster;
import com.garbagemule.MobArena.things.InvalidThingInputString; import com.garbagemule.MobArena.things.InvalidThingInputString;
import com.garbagemule.MobArena.things.Thing; import com.garbagemule.MobArena.things.Thing;
import com.garbagemule.MobArena.util.JoinInterruptTimer; import com.garbagemule.MobArena.util.JoinInterruptTimer;
import com.garbagemule.MobArena.util.Slugs;
import com.garbagemule.MobArena.util.config.ConfigUtils; import com.garbagemule.MobArena.util.config.ConfigUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@ -232,8 +233,9 @@ public class ArenaMasterImpl implements ArenaMaster
} }
public Arena getArenaWithName(Collection<Arena> arenas, String configName) { public Arena getArenaWithName(Collection<Arena> arenas, String configName) {
String slug = Slugs.create(configName);
for (Arena arena : arenas) for (Arena arena : arenas)
if (arena.configName().equalsIgnoreCase(configName)) if (arena.getSlug().equalsIgnoreCase(slug))
return arena; return arena;
return null; return null;
} }

View File

@ -67,8 +67,8 @@ public class DisableCommand implements Command
List<Arena> arenas = am.getArenas(); List<Arena> arenas = am.getArenas();
return arenas.stream() return arenas.stream()
.filter(arena -> arena.configName().toLowerCase().startsWith(prefix)) .filter(arena -> arena.getSlug().startsWith(prefix))
.map(Arena::configName) .map(Arena::getSlug)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
} }

View File

@ -67,8 +67,8 @@ public class EnableCommand implements Command
List<Arena> arenas = am.getArenas(); List<Arena> arenas = am.getArenas();
return arenas.stream() return arenas.stream()
.filter(arena -> arena.configName().toLowerCase().startsWith(prefix)) .filter(arena -> arena.getSlug().startsWith(prefix))
.map(Arena::configName) .map(Arena::getSlug)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
} }

View File

@ -117,9 +117,9 @@ public class ForceCommand implements Command
List<Arena> arenas = am.getArenas(); List<Arena> arenas = am.getArenas();
return arenas.stream() return arenas.stream()
.filter(arena -> arena.configName().toLowerCase().startsWith(prefix)) .filter(arena -> arena.getSlug().startsWith(prefix))
.filter(arena -> start != arena.isRunning()) .filter(arena -> start != arena.isRunning())
.map(Arena::configName) .map(Arena::getSlug)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
} }

View File

@ -69,8 +69,8 @@ public class EditArenaCommand implements Command
List<Arena> arenas = am.getArenas(); List<Arena> arenas = am.getArenas();
return arenas.stream() return arenas.stream()
.filter(arena -> arena.configName().toLowerCase().startsWith(prefix)) .filter(arena -> arena.getSlug().startsWith(prefix))
.map(Arena::configName) .map(Arena::getSlug)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
} }

View File

@ -51,8 +51,8 @@ public class RemoveArenaCommand implements Command
List<Arena> arenas = am.getArenas(); List<Arena> arenas = am.getArenas();
return arenas.stream() return arenas.stream()
.filter(arena -> arena.configName().toLowerCase().startsWith(prefix)) .filter(arena -> arena.getSlug().startsWith(prefix))
.map(Arena::configName) .map(Arena::getSlug)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
} }

View File

@ -120,9 +120,9 @@ public class SettingCommand implements Command {
String prefix = args[0].toLowerCase(); String prefix = args[0].toLowerCase();
return arenas.stream() return arenas.stream()
.filter(arena -> arena.configName().toLowerCase().startsWith(prefix)) .filter(arena -> arena.getSlug().startsWith(prefix))
.filter(arena -> !arena.isRunning()) .filter(arena -> !arena.isRunning())
.map(Arena::configName) .map(Arena::getSlug)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }

View File

@ -101,8 +101,8 @@ public class SetupCommand implements Command, Listener {
List<Arena> arenas = am.getArenas(); List<Arena> arenas = am.getArenas();
return arenas.stream() return arenas.stream()
.filter(arena -> arena.configName().toLowerCase().startsWith(prefix)) .filter(arena -> arena.getSlug().startsWith(prefix))
.map(Arena::configName) .map(Arena::getSlug)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }

View File

@ -94,9 +94,9 @@ public class JoinCommand implements Command
return arenas.stream() return arenas.stream()
.filter(Arena::isEnabled) .filter(Arena::isEnabled)
.filter(arena -> arena.configName().toLowerCase().startsWith(prefix)) .filter(arena -> arena.getSlug().startsWith(prefix))
.filter(arena -> arena.getRegion().isSetup()) .filter(arena -> arena.getRegion().isSetup())
.map(Arena::configName) .map(Arena::getSlug)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
} }

View File

@ -88,9 +88,9 @@ public class SpecCommand implements Command
return arenas.stream() return arenas.stream()
.filter(Arena::isEnabled) .filter(Arena::isEnabled)
.filter(arena -> arena.configName().toLowerCase().startsWith(prefix)) .filter(arena -> arena.getSlug().startsWith(prefix))
.filter(arena -> arena.getRegion().isSetup()) .filter(arena -> arena.getRegion().isSetup())
.map(Arena::configName) .map(Arena::getSlug)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
} }