mirror of
https://github.com/SimplexDevelopment/FreedomNetworkSuite.git
synced 2025-07-05 23:06:41 +00:00
Documentation, Add BouncyPads
This commit is contained in:
@ -5,20 +5,40 @@ import me.totalfreedom.config.Configuration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A registry for all the configurations.
|
||||
*/
|
||||
public class ConfigRegistry
|
||||
{
|
||||
/**
|
||||
* A map of all the configurations.
|
||||
*/
|
||||
private final Map<String, Configuration> configurationList = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Registers a configuration.
|
||||
* @param name The name of the configuration.
|
||||
* @param configuration The configuration.
|
||||
*/
|
||||
public void register(final String name, final Configuration configuration)
|
||||
{
|
||||
configurationList.put(name, configuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a configuration.
|
||||
* @param name The name of the configuration.
|
||||
*/
|
||||
public void unregister(final String name)
|
||||
{
|
||||
configurationList.remove(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a configuration.
|
||||
* @param name The name of the configuration.
|
||||
* @return The configuration.
|
||||
*/
|
||||
public Configuration getConfiguration(final String name)
|
||||
{
|
||||
return configurationList.get(name);
|
||||
|
@ -6,25 +6,49 @@ import me.totalfreedom.provider.EventProvider;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A registry for {@link FEvent}s.
|
||||
*/
|
||||
public class EventRegistry
|
||||
{
|
||||
/**
|
||||
* The list of events.
|
||||
*/
|
||||
private final List<FEvent> events;
|
||||
|
||||
/**
|
||||
* Creates a new event registry.
|
||||
*/
|
||||
public EventRegistry()
|
||||
{
|
||||
this.events = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an event.
|
||||
* @param event The event to register.
|
||||
*/
|
||||
public void register(final FEvent event)
|
||||
{
|
||||
this.events.add(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters an event.
|
||||
* @param event The event to unregister.
|
||||
*/
|
||||
public void unregister(final FEvent event)
|
||||
{
|
||||
this.events.remove(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an {@link EventProvider} for the specified event class which contains the actual {@link FEvent} instance.
|
||||
*
|
||||
* @param clazz The event class.
|
||||
* @return The event provider.
|
||||
* @param <T> The event type.
|
||||
*/
|
||||
public <T extends FEvent> EventProvider<T> getEvent(final Class<T> clazz)
|
||||
{
|
||||
for (final FEvent event : this.events)
|
||||
|
@ -6,25 +6,49 @@ import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A registry for {@link Group}s.
|
||||
*/
|
||||
public class GroupRegistry
|
||||
{
|
||||
/**
|
||||
* The list of groups.
|
||||
*/
|
||||
private final List<Group> groups;
|
||||
|
||||
/**
|
||||
* Creates a new group registry.
|
||||
*/
|
||||
public GroupRegistry()
|
||||
{
|
||||
this.groups = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a group.
|
||||
* @param group The group to register.
|
||||
* @return {@code true} if the group was registered, {@code false} otherwise.
|
||||
*/
|
||||
public boolean registerGroup(final Group group)
|
||||
{
|
||||
return groups.add(group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a group.
|
||||
* @param group The group to unregister.
|
||||
* @return {@code true} if the group was unregistered, {@code false} otherwise.
|
||||
*/
|
||||
public boolean unregisterGroup(final Group group)
|
||||
{
|
||||
return groups.remove(group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a group by name.
|
||||
* @param name The name of the group.
|
||||
* @return The group, or {@code null} if no group was found.
|
||||
*/
|
||||
public Group getGroup(final String name)
|
||||
{
|
||||
final PlainTextComponentSerializer s = PlainTextComponentSerializer.plainText();
|
||||
@ -39,6 +63,9 @@ public class GroupRegistry
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The list of groups.
|
||||
*/
|
||||
public List<Group> getGroups()
|
||||
{
|
||||
return groups;
|
||||
|
@ -6,15 +6,29 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A registry for modules.
|
||||
*/
|
||||
public class ModuleRegistry
|
||||
{
|
||||
/**
|
||||
* The list of modules.
|
||||
*/
|
||||
private final List<JavaPlugin> plugins;
|
||||
|
||||
/**
|
||||
* Creates a new module registry.
|
||||
*/
|
||||
public ModuleRegistry()
|
||||
{
|
||||
this.plugins = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a module to the registry.
|
||||
*
|
||||
* @param plugin The module to add.
|
||||
*/
|
||||
public void addModule(final JavaPlugin plugin)
|
||||
{
|
||||
if (this.plugins.contains(plugin))
|
||||
@ -24,19 +38,30 @@ public class ModuleRegistry
|
||||
this.plugins.add(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a module from the registry.
|
||||
*
|
||||
* @param plugin The module to remove.
|
||||
*/
|
||||
public void removeModule(final JavaPlugin plugin)
|
||||
{
|
||||
this.plugins.remove(plugin);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends JavaPlugin> ModuleProvider<T> getModule(final Class<T> clazz)
|
||||
/**
|
||||
* Gets a module from the registry wrapped in a {@link ModuleProvider}.
|
||||
*
|
||||
* @param clazz The class of the module.
|
||||
* @param <T> The type of the module.
|
||||
* @return The module.
|
||||
*/
|
||||
public <T extends JavaPlugin> ModuleProvider<T> getProvider(final Class<T> clazz)
|
||||
{
|
||||
for (final JavaPlugin plugin : plugins)
|
||||
{
|
||||
if (clazz.isInstance(plugin))
|
||||
{
|
||||
return () -> (T) plugin;
|
||||
return () -> clazz.cast(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,39 +7,91 @@ import org.bukkit.entity.Player;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A registry for {@link UserData} objects.
|
||||
*/
|
||||
public class UserRegistry
|
||||
{
|
||||
/**
|
||||
* A map of {@link User} objects to {@link UserData} objects.
|
||||
*/
|
||||
private final Map<User, UserData> userDataMap;
|
||||
|
||||
/**
|
||||
* Creates a new {@link UserRegistry}.
|
||||
*/
|
||||
public UserRegistry()
|
||||
{
|
||||
this.userDataMap = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link UserData} object for the given {@link User}.
|
||||
*
|
||||
* @param user The {@link User} to get the {@link UserData} for.
|
||||
* @return The {@link UserData} object for the given {@link User}.
|
||||
*/
|
||||
public UserData getUserData(final User user)
|
||||
{
|
||||
return userDataMap.get(user);
|
||||
}
|
||||
|
||||
public UserData fromPlayer(final Player player) {
|
||||
/**
|
||||
* Gets the {@link UserData} object for the given {@link Player}.
|
||||
*/
|
||||
public UserData fromPlayer(final Player player)
|
||||
{
|
||||
return userDataMap.entrySet()
|
||||
.stream()
|
||||
.filter(entry -> entry.getKey().getUniqueId().equals(player.getUniqueId()))
|
||||
.filter(entry -> entry.getKey()
|
||||
.getUniqueId()
|
||||
.equals(player.getUniqueId()))
|
||||
.findFirst()
|
||||
.map(Map.Entry::getValue)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link User} object for the given {@link Player}.
|
||||
*
|
||||
* @param player The {@link Player} to get the {@link User} for.
|
||||
* @return The {@link User} object for the given {@link Player}.
|
||||
*/
|
||||
public User getUser(final Player player)
|
||||
{
|
||||
return userDataMap.entrySet()
|
||||
.stream()
|
||||
.filter(entry -> entry.getKey()
|
||||
.getUniqueId()
|
||||
.equals(player.getUniqueId()))
|
||||
.findFirst()
|
||||
.map(Map.Entry::getKey)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the given {@link User} and {@link UserData} objects.
|
||||
* @param user The {@link User} to register.
|
||||
* @param userData The {@link UserData} to register.
|
||||
*/
|
||||
public void registerUserData(final User user, final UserData userData)
|
||||
{
|
||||
userDataMap.put(user, userData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters the given {@link User} and {@link UserData} objects.
|
||||
* @param user The {@link User} to unregister.
|
||||
*/
|
||||
public void unregisterUserData(final User user)
|
||||
{
|
||||
userDataMap.remove(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the map of {@link User} objects to {@link UserData} objects.
|
||||
* @return The map of {@link User} objects to {@link UserData} objects.
|
||||
*/
|
||||
public Map<User, UserData> getUserDataMap()
|
||||
{
|
||||
return userDataMap;
|
||||
|
Reference in New Issue
Block a user