Skip to content

Commit

Permalink
Runtime Configurables API
Browse files Browse the repository at this point in the history
Signed-off-by: Austin L Mayes <[email protected]>

# Conflicts:
#	Atrio/src/main/java/net/avicus/atrio/Present.java
#	Hook/Bukkit/src/main/java/net/avicus/hook/HookPlugin.java
#	Hook/Bukkit/src/main/java/net/avicus/hook/backend/Backend.java
#	Magma/bukkit/src/main/java/net/avicus/magma/Magma.java
#	Magma/bukkit/src/main/java/net/avicus/magma/util/MagmaTranslations.java
#	Magma/core/src/main/java/net/avicus/magma/api/API.java
#	core/src/main/java/net/avicus/atlas/core/Atlas.java
#	core/src/main/java/net/avicus/atlas/core/command/LoadoutCommands.java
#	core/src/main/java/net/avicus/atlas/core/command/RuntimeConfigurableCommands.java
#	core/src/main/java/net/avicus/atlas/core/component/visual/SidebarComponent.java
#	core/src/main/java/net/avicus/atlas/core/component/visual/TabListComponent.java
#	core/src/main/java/net/avicus/atlas/core/event/RefreshUIEvent.java
#	core/src/main/java/net/avicus/atlas/core/match/Match.java
#	core/src/main/java/net/avicus/atlas/core/module/channels/ChannelsModule.java
#	core/src/main/java/net/avicus/atlas/core/module/groups/Group.java
#	core/src/main/java/net/avicus/atlas/core/module/groups/GroupsModule.java
#	core/src/main/java/net/avicus/atlas/core/module/groups/ffa/FFATeam.java
#	core/src/main/java/net/avicus/atlas/core/module/groups/teams/Team.java
#	core/src/main/java/net/avicus/atlas/core/module/objectives/Objective.java
#	core/src/main/java/net/avicus/atlas/core/module/objectives/ObjectivesModule.java
#	core/src/main/java/net/avicus/atlas/core/module/objectives/score/ScoreObjective.java
#	core/src/main/java/net/avicus/atlas/core/module/projectiles/CustomProjectile.java
#	core/src/main/java/net/avicus/atlas/core/module/projectiles/ProjectilesModule.java
#	core/src/main/java/net/avicus/atlas/core/module/spawns/Spawn.java
#	core/src/main/java/net/avicus/atlas/core/module/spawns/SpawnRegion.java
#	core/src/main/java/net/avicus/atlas/core/module/spawns/SpawnsModule.java
#	core/src/main/java/net/avicus/atlas/core/module/zones/Zone.java
#	core/src/main/java/net/avicus/atlas/core/module/zones/ZoneMessage.java
#	core/src/main/java/net/avicus/atlas/core/module/zones/ZoneNode.java
#	core/src/main/java/net/avicus/atlas/core/module/zones/ZonesModule.java
#	core/src/main/java/net/avicus/atlas/core/module/zones/zones/LoadoutApplicationZone.java
#	core/src/main/java/net/avicus/atlas/core/module/zones/zones/TNTCustomizationZone.java
#	core/src/main/java/net/avicus/atlas/core/module/zones/zones/TransportZone.java
#	core/src/main/java/net/avicus/atlas/core/module/zones/zones/VelocityModZone.java
#	core/src/main/java/net/avicus/atlas/core/module/zones/zones/filtered/FilteredInteractionZone.java
#	core/src/main/java/net/avicus/atlas/core/module/zones/zones/filtered/FilteredLiquidZone.java
#	core/src/main/java/net/avicus/atlas/core/module/zones/zones/filtered/FilteredMovementZone.java
#	core/src/main/java/net/avicus/atlas/core/runtimeconfig/ConfigurableWrapper.java
#	core/src/main/java/net/avicus/atlas/core/runtimeconfig/RuntimeConfigurable.java
#	core/src/main/java/net/avicus/atlas/core/runtimeconfig/RuntimeConfigurablesManager.java
#	core/src/main/java/net/avicus/atlas/core/runtimeconfig/fields/AngleProviderField.java
#	core/src/main/java/net/avicus/atlas/core/runtimeconfig/fields/ConfigurableField.java
#	core/src/main/java/net/avicus/atlas/core/runtimeconfig/fields/DurationField.java
#	core/src/main/java/net/avicus/atlas/core/runtimeconfig/fields/EnumField.java
#	core/src/main/java/net/avicus/atlas/core/runtimeconfig/fields/LocalizedXmlField.java
#	core/src/main/java/net/avicus/atlas/core/runtimeconfig/fields/MaterialMatcherField.java
#	core/src/main/java/net/avicus/atlas/core/runtimeconfig/fields/NumberActionField.java
#	core/src/main/java/net/avicus/atlas/core/runtimeconfig/fields/OptionalField.java
#	core/src/main/java/net/avicus/atlas/core/runtimeconfig/fields/RegisteredObjectField.java
#	core/src/main/java/net/avicus/atlas/core/runtimeconfig/fields/SimpleFields.java
#	core/src/main/java/net/avicus/atlas/core/runtimeconfig/fields/VectorField.java
#	core/src/main/java/net/avicus/atlas/core/util/Translations.java
#	sets/competitve-objectives/src/main/java/net/avicus/atlas/sets/competitve/objectives/destroyable/DestroyableObjective.java
#	sets/competitve-objectives/src/main/java/net/avicus/atlas/sets/competitve/objectives/flag/FlagObjective.java
#	sets/competitve-objectives/src/main/java/net/avicus/atlas/sets/competitve/objectives/hill/HillObjective.java
#	sets/competitve-objectives/src/main/java/net/avicus/atlas/sets/competitve/objectives/wool/WoolObjective.java
#	sets/competitve-objectives/src/main/java/net/avicus/atlas/sets/competitve/objectives/zones/ScoreZone.java
#	sets/competitve-objectives/src/main/java/net/avicus/atlas/sets/competitve/objectives/zones/flag/NetZone.java
#	sets/competitve-objectives/src/main/java/net/avicus/atlas/sets/competitve/objectives/zones/flag/PostZone.java
  • Loading branch information
AustinLMayes committed Jan 24, 2022
1 parent 7f75c63 commit f8c7fbc
Show file tree
Hide file tree
Showing 60 changed files with 1,664 additions and 114 deletions.
2 changes: 2 additions & 0 deletions core/src/main/java/net/avicus/atlas/core/Atlas.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.avicus.atlas.core.command.LoadoutCommands.ParentCommand;
import net.avicus.atlas.core.command.ResourcePackCommand;
import net.avicus.atlas.core.command.RotationCommands;
import net.avicus.atlas.core.command.RuntimeConfigurableCommands;
import net.avicus.atlas.core.command.StateCommands;
import net.avicus.atlas.core.command.WorldEditCommands;
import net.avicus.atlas.core.command.exception.CommandMatchException;
Expand Down Expand Up @@ -298,6 +299,7 @@ private void registerCommands(AvicusCommandsRegistration registrar) {
registrar.register(ResourcePackCommand.class);
registrar.register(GroupParentCommand.class);
registrar.register(GenericCommands.class);
registrar.register(RuntimeConfigurableCommands.ParentCommand.class);

// Modular
registrar.register(KitCommands.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package net.avicus.atlas.core.command;

import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.NestedCommand;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Optional;
import java.util.UUID;
import net.avicus.atlas.core.Atlas;
import net.avicus.atlas.core.command.exception.CommandMatchException;
import net.avicus.atlas.core.match.Match;
import net.avicus.atlas.core.match.registry.WeakReference;
import net.avicus.atlas.core.module.loadouts.Loadout;
import net.avicus.atlas.core.module.loadouts.LoadoutsFactory;
import net.avicus.atlas.core.module.projectiles.CustomProjectile;
import net.avicus.atlas.core.module.projectiles.ProjectilesModule;
import net.avicus.atlas.core.runtimeconfig.ConfigurableWrapper;
import net.avicus.compendium.inventory.SingleMaterialMatcher;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.potion.PotionEffect;
import org.joda.time.Duration;

public class RuntimeConfigurableCommands {

@Command(aliases = {"list", "l"}, desc = "List all runtime configurables", max = 0)
@CommandPermissions("atlas.rt.list")
public static void list(CommandContext args, CommandSender sender)
throws CommandException {
Match match = Atlas.getMatch();

if (match == null) {
throw new CommandMatchException();
}

match.getConfigurablesManager().describeAll(sender);
}

@Command(aliases = {"addprod", "ap"}, desc = "Add a default projectile to an item", min = 1)
@CommandPermissions("atlas.rt.list")
public static void add(CommandContext args, CommandSender sender)
throws CommandException {
Match match = Atlas.getMatch();

if (match == null) {
throw new CommandMatchException();
}

Material material = Material.valueOf(args.getJoinedStrings(0).replaceAll(" ", "_").toUpperCase());

CustomProjectile projectile = new CustomProjectile(UUID.randomUUID(), material.name() + " default projectile", true, EntityType.ARROW, 0.0, 1.0, Optional.empty(),
Optional.empty(), false, false, Optional.empty(), new ArrayList<>());
match.getRequiredModule(ProjectilesModule.class).registerProjectile(projectile);
match.getRequiredModule(ProjectilesModule.class).getDefaultProjectiles().put(material, projectile);
match.reRegisterConfigurables();
}

@Command(aliases = {"view", "v"}, desc = "View a configurable by ID", usage = "<id>", min = 1, max = 1)
@CommandPermissions("atlas.rt.view")
public static void view(CommandContext args, CommandSender sender)
throws CommandException {
Match match = Atlas.getMatch();

if (match == null) {
throw new CommandMatchException();
}

ConfigurableWrapper wrapper = match.getConfigurablesManager().getWrapper(args.getString(0));
match.getConfigurablesManager().describe(sender, wrapper, true);
}

@Command(aliases = {"config", "c", "configure"}, desc = "Config a configurable", usage = "<id> <field> <data...>", min = 3)
@CommandPermissions("atlas.rt.modify")
public static void modify(CommandContext args, CommandSender sender)
throws CommandException {
Match match = Atlas.getMatch();

if (match == null) {
throw new CommandMatchException();
}

ConfigurableWrapper wrapper = match.getConfigurablesManager().getWrapper(args.getString(0));
String edited = wrapper.configure(args.getString(1), args.getParsedSlice(2));
sender.sendMessage(ChatColor.GREEN + "Object reconfigured!");
Atlas.get().getMapErrorLogger().info(sender.getName() + ChatColor.RESET + " updated " + edited + ChatColor.RESET + " of " + wrapper.getConfigurable().getDescription(sender));
}

public static class ParentCommand {

@Command(aliases = "rt", usage = "<>", desc = ".", min = 1)
@NestedCommand(RuntimeConfigurableCommands.class)
public static void loadout(CommandContext cmd, CommandSender sender) {
// Never called
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static void registerRegion(CommandContext cmd, CommandSender sender)
CuboidRegion region = new CuboidRegion(min, max);

match.getRegistry().add(new RegisteredObject<>(id, region));
sender.sendMessage("Registered region with ID " + id);
} else {
// TODO: Translate
sender.sendMessage(ChatColor.RED + "You must make a selection first!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Optional;
import java.util.Set;
import lombok.Setter;
import net.avicus.atlas.event.RefreshUIEvent;
import net.avicus.atlas.core.NetworkIdentification;
import net.avicus.atlas.core.component.ListenerComponent;
import net.avicus.atlas.core.event.group.GroupMaxPlayerCountChangeEvent;
Expand Down Expand Up @@ -292,6 +293,11 @@ public void pointEarn(final PointEarnEvent event) {
this.delayedUpdate();
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onRefresh(final RefreshUIEvent event) {
this.delayedUpdate();
}

public void delayedUpdate() {
new AtlasTask() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import lombok.Getter;
import lombok.Setter;
import net.avicus.atlas.core.Atlas;
import net.avicus.atlas.event.RefreshUIEvent;
import net.avicus.atlas.core.component.ListenerComponent;
import net.avicus.atlas.core.event.group.GroupMaxPlayerCountChangeEvent;
import net.avicus.atlas.core.event.group.GroupRenameEvent;
Expand Down Expand Up @@ -131,6 +132,11 @@ public void groupMaxPlayersChange(final GroupMaxPlayerCountChangeEvent event) {
this.update(true);
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onRefresh(final RefreshUIEvent event) {
this.update(true);
}

private Map<Group, TableBox> createTeamBoxes() {
GroupsModule module = this.match.getRequiredModule(GroupsModule.class);

Expand Down
31 changes: 31 additions & 0 deletions core/src/main/java/net/avicus/atlas/core/event/RefreshUIEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.avicus.atlas.event;

import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

public class RefreshUIEvent extends Event {

/**
* Event handlers.
*/
private static final HandlerList handlers = new HandlerList();

/**
* Get the handlers of the event.
*
* @return the handlers of the event
*/
public static HandlerList getHandlerList() {
return handlers;
}

/**
* Get the handlers of the event.
*
* @return the handlers of the event
*/
@Override
public HandlerList getHandlers() {
return handlers;
}
}
15 changes: 15 additions & 0 deletions core/src/main/java/net/avicus/atlas/core/match/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import net.avicus.atlas.core.match.registry.MatchRegistry;
import net.avicus.atlas.core.module.Module;
import net.avicus.atlas.core.module.world.WorldModule;
import net.avicus.atlas.core.runtimeconfig.RuntimeConfigurable;
import net.avicus.atlas.core.runtimeconfig.RuntimeConfigurablesManager;
import net.avicus.atlas.core.util.Events;
import net.avicus.atlas.core.util.Messages;
import net.avicus.atlas.core.util.Version;
Expand All @@ -46,13 +48,16 @@ public class Match {
private String id;
@Getter
private boolean loaded = false;
@Getter
private final RuntimeConfigurablesManager configurablesManager;

public Match(AtlasMap map, MatchFactory factory) {
this.id = UUID.randomUUID().toString().substring(0, 4);
this.map = map;
this.factory = factory;
this.registry = new MatchRegistry(this);
this.modules = new HashSet<>();
this.configurablesManager = new RuntimeConfigurablesManager();
}

public Collection<Player> getPlayers() {
Expand Down Expand Up @@ -151,6 +156,16 @@ public void open() {

MatchOpenEvent event = new MatchOpenEvent(this);
Events.call(event);
reRegisterConfigurables();
}

public void reRegisterConfigurables() {
this.configurablesManager.reset();
for (Module module : getModules()) {
if (module instanceof RuntimeConfigurable) {
this.configurablesManager.registerConfigurable((RuntimeConfigurable) module, null);
}
}
}

public void close() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
import net.avicus.atlas.core.module.groups.Competitor;
import net.avicus.atlas.core.module.groups.Group;
import net.avicus.atlas.core.module.groups.GroupsModule;
import net.avicus.atlas.core.runtimeconfig.RuntimeConfigurable;
import net.avicus.atlas.core.runtimeconfig.fields.ConfigurableField;
import net.avicus.atlas.core.runtimeconfig.fields.SimpleFields;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand All @@ -21,7 +25,7 @@
/**
* This module is responsible for handling team and global chat channels.
*/
public class ChannelsModule implements Module {
public class ChannelsModule implements Module, RuntimeConfigurable {

/**
* Map of players that are currently talking in global chat. If the value is false, they are
Expand All @@ -35,11 +39,11 @@ public class ChannelsModule implements Module {
/**
* If team chat is allowed during this match.
*/
private final boolean allowTeamChat;
private boolean allowTeamChat;
/**
* If global chat is allowed during this match.
*/
private final boolean allowGlobalChat;
private boolean allowGlobalChat;

/**
* Constructor.
Expand Down Expand Up @@ -140,4 +144,17 @@ public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
event.setFormat(format);
}
}

@Override
public ConfigurableField[] getFields() {
return new ConfigurableField[]{
new SimpleFields.BooleanField("Team Chat", () -> this.allowTeamChat, (b) -> this.allowTeamChat = b),
new SimpleFields.BooleanField("Global Chat", () -> this.allowGlobalChat, (b) -> this.allowGlobalChat = b)
};
}

@Override
public String getDescription(CommandSender viewer) {
return "Chat Channels";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@

/**
* Factory that will parse checks in XML anc add them to the match's {@link
* net.avicus.atlas.match.registry.MatchRegistry}
* net.avicus.atlas.core.match.registry.MatchRegistry}
*/
// We build filters first so they can be reference everywhere else.
// We must use WeakReference's here because of this.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

/**
* A wrapper object that contains a block of code that can be executed inside of a {@link
* net.avicus.atlas.match.Match}
* net.avicus.atlas.core.match.Match}
*/
@ToString
public abstract class Executor implements RegisterableObject<Executor> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@

import java.util.Collection;
import net.avicus.atlas.core.command.JoinCommands;
import net.avicus.atlas.event.RefreshUIEvent;
import net.avicus.atlas.core.match.registry.RegisterableObject;
import net.avicus.atlas.core.module.locales.LocalizedXmlString;
import net.avicus.atlas.core.runtimeconfig.RuntimeConfigurable;
import net.avicus.atlas.core.runtimeconfig.fields.ConfigurableField;
import net.avicus.atlas.core.runtimeconfig.fields.LocalizedXmlField;
import net.avicus.atlas.core.runtimeconfig.fields.SimpleFields.IntField;
import net.avicus.atlas.core.util.Events;
import net.avicus.atlas.core.util.color.TeamColor;
import net.avicus.atlas.core.util.distance.PlayerStore;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.DyeColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public interface Group extends RegisterableObject<Group>, PlayerStore {
public interface Group extends RegisterableObject<Group>, PlayerStore, RuntimeConfigurable {

String getId();

Expand Down Expand Up @@ -66,4 +73,23 @@ default boolean isSpectator() {
default double filledPortion() {
return (double) size() / (double) getMaxPlayers();
}

@Override
default String getDescription(CommandSender viewer) {
return getChatColor() + getName().translateDefault() + ChatColor.RESET;
}

@Override
default void onFieldChange(String name) {
Events.call(new RefreshUIEvent());
}

@Override
default ConfigurableField[] getFields() {
return new ConfigurableField[]{
new LocalizedXmlField("Name", this::getName, this::setName),
new IntField("Max Players", this::getMaxPlayers, (v) -> this.setMaxPlayers(v, getMaxOverfill())),
new IntField("Max Overfill", this::getMaxOverfill, (v) -> this.setMaxPlayers(getMaxPlayers(), v))
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.avicus.atlas.core.module.ModuleBridge;
import net.avicus.atlas.core.module.locales.LocalizedXmlString;
import net.avicus.atlas.core.module.spawns.SpawnsModule;
import net.avicus.atlas.core.runtimeconfig.RuntimeConfigurable;
import net.avicus.atlas.core.util.Events;
import net.avicus.atlas.core.util.color.TeamColor;
import org.bukkit.Bukkit;
Expand All @@ -34,7 +35,7 @@

@ToString(exclude = "match")
public abstract class GroupsModule extends BridgeableModule<ModuleBridge<GroupsModule>> implements
Module {
Module, RuntimeConfigurable {

@Getter
private final Match match;
Expand Down Expand Up @@ -412,4 +413,14 @@ public List<Group> search(CommandSender viewer, String query) {
public boolean isSpectator(Player player) {
return getGroup(player).isSpectator();
}

@Override
public String getDescription(CommandSender viewer) {
return "Groups";
}

@Override
public List<RuntimeConfigurable> getChildren() {
return getGroups().stream().map(g -> (RuntimeConfigurable)g).collect(Collectors.toList());
}
}
Loading

0 comments on commit f8c7fbc

Please sign in to comment.