Skip to content

Commit

Permalink
Merge branch 'release-4.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Stealth2800 committed May 4, 2015
2 parents 464a4f2 + 0565228 commit 53c447c
Show file tree
Hide file tree
Showing 14 changed files with 563 additions and 32 deletions.
2 changes: 1 addition & 1 deletion FlexCore.iml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<orderEntry type="library" name="Maven: net.jodah:expiringmap:0.3.1" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.3" level="project" />
<orderEntry type="library" name="Maven: com.gamingmesh:jobs:2.12.0" level="project" />
<orderEntry type="library" name="Maven: com.stealthyone.mcb:mcml:1.5.2-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.stealthyone.mcb:mcml:1.5.3-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.comphenix.packetwrapper:PacketWrapper:1.8-R0.1" level="project" />
<orderEntry type="library" name="Maven: com.comphenix.protocol:ProtocolLib:3.6.3-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: cglib:cglib-nodep:2.2.2" level="project" />
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.st28.flexseries</groupId>
<artifactId>flexcore</artifactId>
<version>4.0.0</version>
<version>4.1.0</version>
<name>FlexCore</name>
<description>Powerful library for Bukkit plugins</description>
<url>http://stealthyone.com/</url>
Expand Down Expand Up @@ -118,7 +118,7 @@
<dependency>
<groupId>com.stealthyone.mcb</groupId>
<artifactId>mcml</artifactId>
<version>1.5.2-SNAPSHOT</version>
<version>1.5.3-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>mkremins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import me.st28.flexseries.flexcore.message.MessageReference;
import me.st28.flexseries.flexcore.message.ReplacementMap;
import me.st28.flexseries.flexcore.permission.PermissionNode;
import me.st28.flexseries.flexcore.player.uuid_tracker.PlayerUuidTracker;
import me.st28.flexseries.flexcore.plugin.FlexPlugin;
import me.st28.flexseries.flexcore.util.QuickMap;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -168,4 +171,65 @@ public static Player getTargetPlayer(CommandSender sender, String name, boolean
return player;
}

/**
* Gets a player's UUID based on name.
*
* @param sender The sender of the command.
* @param name The name entered by the sender.
* @param notSender True to make sure the target is not the sender.
* @return The UUID of the matched player.<br />
* Null if no matching player was found.
*/
public static UUID getPlayerUuid(CommandSender sender, String name, boolean notSender, boolean isOnline, boolean silent) {
UUID found = null;

PlayerUuidTracker uuidTracker = FlexPlugin.getRegisteredModule(PlayerUuidTracker.class);

// 1) Try getting by exact name
Player online = Bukkit.getPlayerExact(name);
if (online != null) {
found = online.getUniqueId();
}

if (found == null) {
// 2) Try getting by matching name
List<String> matchedNames = new ArrayList<>();

for (String curName : uuidTracker.getNamesToUuids().keySet()) {
if (name.equalsIgnoreCase(curName)) {
// Exact match
matchedNames.add(name);
break;
}

if (curName.toLowerCase().contains(name.toLowerCase())) {
// Partial match
matchedNames.add(curName);
}
}

if (matchedNames.size() == 1) {
found = uuidTracker.getUuid(matchedNames.get(0));
name = uuidTracker.getName(found);
}
}

if (found != null && notSender && sender instanceof Player && ((Player) sender).getUniqueId().equals(found)) {
if (!silent) {
throw new CommandInterruptedException(MessageReference.create(FlexCore.class, "general.errors.players_cannot_be_self"));
}
return null;
} else if (found != null && isOnline && Bukkit.getPlayer(found) == null) {
if (!silent) {
throw new CommandInterruptedException(MessageReference.create(FlexCore.class, "general.errors.players_matched_offline", new QuickMap<>("{NAME}", name).getMap()));
}
return null;
} else if (found == null) {
if (!silent) {
throw new CommandInterruptedException(MessageReference.create(FlexCore.class, "general.errors.players_matched_none_offline", new QuickMap<>("{NAME}", name).getMap()));
}
}
return found;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ public abstract class FlexCommand<T extends FlexPlugin> {
*/
private final List<String> labels = new ArrayList<>();

/**
* Label aliases that execute subcommands directly.
*/
private final Map<String, FlexSubcommand<T>> subcommandLabels = new HashMap<>();

/**
* The command that this command exists under.
*/
Expand All @@ -69,7 +64,7 @@ public abstract class FlexCommand<T extends FlexPlugin> {
/**
* Subcommands under this command.
*/
private final Map<String, FlexSubcommand<T>> subcommands = new HashMap<>();
private final Map<String, FlexSubcommand<T>> subcommands = new LinkedHashMap<>();

/**
* The settings for this command.
Expand All @@ -90,6 +85,7 @@ public FlexCommand(T plugin, String label, List<CommandArgument> arguments, Flex

this.plugin = plugin;
this.labels.add(label.toLowerCase());
this.labels.addAll(pluginCommand.getAliases());
this.parent = null;
if (arguments != null) {
Validate.noNullElements(arguments, "Arguments list cannot contain any null arguments.");
Expand Down Expand Up @@ -139,7 +135,7 @@ public final T getPlugin() {
}

/**
* @return a list containing the label(s) for this command. Element 0 is the main label.
* @return an unmodifiable list containing the label(s) for this command. Element 0 is the main label.
*/
public final List<String> getLabels() {
return Collections.unmodifiableList(labels);
Expand Down Expand Up @@ -174,7 +170,7 @@ public final List<FlexCommand<T>> getParents() {
public final PermissionNode getPermission() {
PermissionNode permission = settings.getPermission();
if (permission == null && settings.shouldInheritPermission()) {
return getParent().getPermission();
return getParent() == null ? null : getParent().getPermission();
}
return permission;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import me.st28.flexseries.flexcore.plugin.FlexPlugin;
import org.apache.commons.lang.Validate;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -54,7 +55,7 @@ public final class FlexCommandSettings<T extends FlexPlugin> {
/**
* Label aliases that execute subcommands directly.
*/
private final Map<String, FlexCommand<T>> subcommandAliases = new HashMap<>();
private final Map<String, String> subcommandAliases = new HashMap<>();

/**
* If true, will use the default subcommand, regardless of argument count.
Expand Down Expand Up @@ -152,6 +153,44 @@ public final String getDefaultSubcommand() {
return defaultSubcommand;
}

/**
* @return the aliases for labels that should execute subcommands directly.
*/
public final Map<String, String> getSubcommandAliases() {
return Collections.unmodifiableMap(subcommandAliases);
}

/**
* Sets a subcommand alias.
*
* @param alias The main label alias.
* @param subcommand The subcommand that should be executed directly for the given alias.
* @return The settings instance, for chaining.
*/
public final FlexCommandSettings<T> subcommandAlias(String alias, FlexCommand<T> subcommand) {
Validate.notNull(alias, "Alias cannot be null.");
Validate.notNull(subcommand, "Subcommand cannot be null.");
checkState();

return subcommandAlias(alias, subcommand.getLabels().get(0));
}

/**
* Sets a subcommand alias.
*
* @param alias The main label alias.
* @param subcommand The subcommand that should be executed directly for the given alias.
* @return The settings instance, for chaining.
*/
public final FlexCommandSettings<T> subcommandAlias(String alias, String subcommand) {
Validate.notNull(alias, "Alias cannot be null.");
Validate.notNull(subcommand, "Subcommand cannot be null.");
checkState();

subcommandAliases.put(alias, subcommand);
return this;
}

/**
* Makes this command a dummy command, meaning that it will use the default subcommand, regardless of argument count.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ public static <T extends FlexPlugin> void registerCommand(FlexPlugin plugin, Fle

if (/*!command.getSubcommands().isEmpty() && */!command.getSubcommands().containsKey("help")) {
command.registerSubcommand(new FlexHelpCommand<>(command));
if (command.getSettings().isDummyCommand()) {
if (command.getSettings().isDummyCommand() && command.getSettings().getDefaultSubcommand() == null) {
command.getSettings().defaultSubcommand("help");
}
}

for (FlexSubcommand<T> subcommand : command.getSubcommands().values()) {
if (/*!subcommand.getSubcommands().isEmpty() && */!subcommand.getSubcommands().containsKey("help")) {
subcommand.registerSubcommand(new FlexHelpCommand<>(subcommand));
if (subcommand.getSettings().isDummyCommand()) {
if (subcommand.getSettings().isDummyCommand() && subcommand.getSettings().getDefaultSubcommand() == null) {
subcommand.getSettings().defaultSubcommand("help");
}
}
Expand All @@ -105,7 +105,11 @@ public final boolean onCommand(CommandSender sender, Command command, String lab
String cookieUserId = null;

args = CommandUtils.fixArguments(args);
FlexCommand<?> currentCommand = this.command.getSubcommands().get(label.toLowerCase());;
FlexCommand<?> currentCommand = this.command.getSubcommands().get(((FlexCommandSettings<?>) this.command.getSettings()).getSubcommandAliases().get(label.toLowerCase()));

if (currentCommand == null) {
currentCommand = this.command.getSubcommands().get(label.toLowerCase());
}

// Set the cookie for this command label
if (cookieManager != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public FlexHelpCommand(FlexCommand<T> parent) {
PermissionNode parentPerm = parent.getPermission();
if (parentPerm != null) {
String helpPerm = parentPerm.getNode() + ".help";
Bukkit.getPluginManager().addPermission(new Permission(helpPerm, PermissionDefault.TRUE));
try {
Bukkit.getPluginManager().addPermission(new Permission(helpPerm, PermissionDefault.TRUE));
} catch (IllegalArgumentException ex) {}

getSettings().permission(new SimplePermissionNode(helpPerm));
}
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/me/st28/flexseries/flexcore/logging/LogHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,52 +46,104 @@ public static void debug(Class<? extends JavaPlugin> pluginClass, String message
LogHelper.debug(JavaPlugin.getPlugin(pluginClass), message);
}

public static void debug(Class<? extends JavaPlugin> pluginClass, String message, Throwable throwable) {
LogHelper.debug(JavaPlugin.getPlugin(pluginClass), message, throwable);
}

public static void debug(JavaPlugin plugin, String message) {
if (plugin.getConfig().getBoolean("debug")) {
Bukkit.getLogger().log(Level.INFO, String.format("[%s DEBUG] %s", plugin.getName(), message));
}
}

public static void debug(JavaPlugin plugin, String message, Throwable throwable) {
if (plugin.getConfig().getBoolean("debug")) {
Bukkit.getLogger().log(Level.INFO, String.format("[%s DEBUG] %s", plugin.getName(), message), throwable);
}
}

public static void debug(FlexModule module, String message) {
if (module.getPlugin().getConfig().getBoolean("debug")) {
Bukkit.getLogger().log(Level.INFO, String.format("[%s/%s DEBUG] %s", module.getPlugin().getName(), module.getIdentifier(), message));
}
}

public static void debug(FlexModule module, String message, Throwable throwable) {
if (module.getPlugin().getConfig().getBoolean("debug")) {
Bukkit.getLogger().log(Level.INFO, String.format("[%s/%s DEBUG] %s", module.getPlugin().getName(), module.getIdentifier(), message), throwable);
}
}

public static void info(Class<? extends JavaPlugin> pluginClass, String message) {
LogHelper.info(JavaPlugin.getPlugin(pluginClass), message);
}

public static void info(Class<? extends JavaPlugin> pluginClass, String message, Throwable throwable) {
LogHelper.info(JavaPlugin.getPlugin(pluginClass), message, throwable);
}

public static void info(JavaPlugin plugin, String message) {
Bukkit.getLogger().log(Level.INFO, String.format("[%s] %s", plugin.getName(), message));
}

public static void info(JavaPlugin plugin, String message, Throwable throwable) {
Bukkit.getLogger().log(Level.INFO, String.format("[%s] %s", plugin.getName(), message), throwable);
}

public static void info(FlexModule module, String message) {
Bukkit.getLogger().log(Level.INFO, String.format("[%s/%s] %s", module.getPlugin().getName(), module.getIdentifier(), message));
}

public static void info(FlexModule module, String message, Throwable throwable) {
Bukkit.getLogger().log(Level.INFO, String.format("[%s/%s] %s", module.getPlugin().getName(), module.getIdentifier(), message), throwable);
}

public static void warning(Class<? extends JavaPlugin> pluginClass, String message) {
LogHelper.warning(JavaPlugin.getPlugin(pluginClass), message);
}

public static void warning(Class<? extends JavaPlugin> pluginClass, String message, Throwable throwable) {
LogHelper.warning(JavaPlugin.getPlugin(pluginClass), message, throwable);
}

public static void warning(JavaPlugin plugin, String message) {
Bukkit.getLogger().log(Level.WARNING, String.format("[%s] %s", plugin.getName(), message));
}

public static void warning(JavaPlugin plugin, String message, Throwable throwable) {
Bukkit.getLogger().log(Level.WARNING, String.format("[%s] %s", plugin.getName(), message), throwable);
}

public static void warning(FlexModule module, String message) {
Bukkit.getLogger().log(Level.WARNING, String.format("[%s/%s] %s", module.getPlugin().getName(), module.getIdentifier(), message));
}

public static void warning(FlexModule module, String message, Throwable throwable) {
Bukkit.getLogger().log(Level.WARNING, String.format("[%s/%s] %s", module.getPlugin().getName(), module.getIdentifier(), message), throwable);
}

public static void severe(Class<? extends JavaPlugin> pluginClass, String message) {
LogHelper.severe(JavaPlugin.getPlugin(pluginClass), message);
}

public static void severe(Class<? extends JavaPlugin> pluginClass, String message, Throwable throwable) {
LogHelper.severe(JavaPlugin.getPlugin(pluginClass), message, throwable);
}

public static void severe(JavaPlugin plugin, String message) {
Bukkit.getLogger().log(Level.SEVERE, String.format("[%s] %s", plugin.getName(), message));
}

public static void severe(JavaPlugin plugin, String message, Throwable throwable) {
Bukkit.getLogger().log(Level.SEVERE, String.format("[%s] %s", plugin.getName(), message), throwable);
}

public static void severe(FlexModule module, String message) {
Bukkit.getLogger().log(Level.SEVERE, String.format("[%s/%s] %s", module.getPlugin().getName(), module.getIdentifier(), message));
}

public static void severe(FlexModule module, String message, Throwable throwable) {
Bukkit.getLogger().log(Level.SEVERE, String.format("[%s/%s] %s", module.getPlugin().getName(), module.getIdentifier(), message), throwable);
}

}
Loading

0 comments on commit 53c447c

Please sign in to comment.