Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/main/java/me/kodysimpson/simpapi/colors/ColorTranslator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.TextComponent;
import org.jetbrains.annotations.NotNull;

Expand All @@ -11,16 +10,15 @@

public class ColorTranslator {

private static final Pattern HEX_PATTERN = Pattern.compile("(&#[0-9a-fA-F]{6})");

@Deprecated
public static final String WITH_DELIMITER = "((?<=%1$s)|(?=%1$s))";
private static final Pattern HEX_PATTERN = Pattern.compile("(&#[0-9a-fA-F]{6})");

/**
* @param text The string of text to apply color/effects to
* @return Returns a string of text with color/effects applied
*/
public static String translateColorCodes(@NotNull String text){
public static String translateColorCodes(@NotNull String text) {
//good thing we're stuck on java 8, which means we can't use this (:
// String hexColored = HEX_PATTERN.matcher(text)
// .replaceAll(match -> "" + ChatColor.of(match.group(1)));
Expand All @@ -41,7 +39,7 @@ public static String translateColorCodes(@NotNull String text){
* @param text The text with color codes that you want to turn into a TextComponent
* @return the TextComponent with hex colors and regular colors
*/
public static TextComponent translateColorCodesToTextComponent(@NotNull String text){
public static TextComponent translateColorCodesToTextComponent(@NotNull String text) {
//This is done solely to ensure hex color codes are in the format
//fromLegacyText expects:
//&#FF0000 -> &x&f&f&0&0&0&0
Expand All @@ -50,7 +48,7 @@ public static TextComponent translateColorCodesToTextComponent(@NotNull String t
TextComponent base = new TextComponent();
BaseComponent[] converted = TextComponent.fromLegacyText(colored);

for(BaseComponent comp : converted) {
for (BaseComponent comp : converted) {
base.addExtra(comp);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public interface CommandList {

/**
* @param sender The thing that ran the command
* @param sender The thing that ran the command
* @param subCommandList A list of all the subcommands you can display
*/
void displayCommandList(CommandSender sender, List<SubCommand> subCommandList);
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/me/kodysimpson/simpapi/command/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
public class CommandManager {

/**
* @param plugin An instance of your plugin that is using this API. If called within plugin main class, provide this keyword
* @param commandName The name of the command
* @param plugin An instance of your plugin that is using this API. If called within plugin main class, provide this keyword
* @param commandName The name of the command
* @param commandDescription Description of command as would put it in plugin.yml
* @param commandUsage Usage of command as would put it in plugin.yml
* @param aliases A String list of aliases(or nothing for overloaded method)
* @param subcommands Class reference to each SubCommand you create for this core command
* @param commandUsage Usage of command as would put it in plugin.yml
* @param aliases A String list of aliases(or nothing for overloaded method)
* @param subcommands Class reference to each SubCommand you create for this core command
*/
@SafeVarargs
public static void createCoreCommand(JavaPlugin plugin, String commandName,
Expand All @@ -36,7 +36,7 @@ public static void createCoreCommand(JavaPlugin plugin, String commandName,
ArrayList<SubCommand> commands = new ArrayList<>();

Arrays.stream(subcommands).map(subcommand -> {
try{
try {
Constructor<? extends SubCommand> constructor = subcommand.getConstructor();
return constructor.newInstance();
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
Expand All @@ -54,11 +54,11 @@ public static void createCoreCommand(JavaPlugin plugin, String commandName,


/**
* @param plugin An instance of your plugin that is using this API. If called within plugin main class, provide this keyword
* @param commandName The name of the command
* @param plugin An instance of your plugin that is using this API. If called within plugin main class, provide this keyword
* @param commandName The name of the command
* @param commandDescription Description of command as would put it in plugin.yml
* @param commandUsage Usage of command as would put it in plugin.yml
* @param subcommands Class reference to each SubCommand you create for this core command
* @param commandUsage Usage of command as would put it in plugin.yml
* @param subcommands Class reference to each SubCommand you create for this core command
*/
@SafeVarargs
public static void createCoreCommand(JavaPlugin plugin, String commandName,
Expand Down
29 changes: 14 additions & 15 deletions src/main/java/me/kodysimpson/simpapi/command/CoreCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.kodysimpson.simpapi.command;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand All @@ -18,34 +17,34 @@ class CoreCommand extends Command {
private final ArrayList<SubCommand> subcommands;
private final CommandList commandList;

public CoreCommand(String name, String description, String usageMessage, CommandList commandList, List<String> aliases, ArrayList<SubCommand> subCommands){
public CoreCommand(String name, String description, String usageMessage, CommandList commandList, List<String> aliases, ArrayList<SubCommand> subCommands) {
super(name, description, usageMessage, aliases);
//Get the subcommands so we can access them in the command manager class(here)
this.subcommands = subCommands;
this.commandList = commandList;
}

public ArrayList<SubCommand> getSubCommands(){
public ArrayList<SubCommand> getSubCommands() {
return subcommands;
}

@Override
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, String[] args) {

if (args.length > 0){
for (int i = 0; i < getSubCommands().size(); i++){
if (args[0].equalsIgnoreCase(getSubCommands().get(i).getName()) || (getSubCommands().get(i).getAliases() != null && getSubCommands().get(i).getAliases().contains(args[0]))){
if (args.length > 0) {
for (int i = 0; i < getSubCommands().size(); i++) {
if (args[0].equalsIgnoreCase(getSubCommands().get(i).getName()) || (getSubCommands().get(i).getAliases() != null && getSubCommands().get(i).getAliases().contains(args[0]))) {
getSubCommands().get(i).perform(sender, args);
}
}
}else {
if (commandList == null){
} else {
if (commandList == null) {
sender.sendMessage("--------------------------------");
for (SubCommand subcommand : subcommands) {
sender.sendMessage(subcommand.getSyntax() + " - " + subcommand.getDescription());
}
sender.sendMessage("--------------------------------");
}else{
} else {
commandList.displayCommandList(sender, subcommands);
}
}
Expand All @@ -55,23 +54,23 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String commandLab

@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, String[] args) throws IllegalArgumentException {
if (args.length == 1){ //prank <subcommand> <args>
if (args.length == 1) { //prank <subcommand> <args>
ArrayList<String> subcommandsArguments = new ArrayList<>();

//Does the subcommand autocomplete
for (int i = 0; i < getSubCommands().size(); i++){
for (int i = 0; i < getSubCommands().size(); i++) {
subcommandsArguments.add(getSubCommands().get(i).getName());
}
return subcommandsArguments;
}else if(args.length >= 2){
for (int i = 0; i < getSubCommands().size(); i++){
if (args[0].equalsIgnoreCase(getSubCommands().get(i).getName())){
} else if (args.length >= 2) {
for (int i = 0; i < getSubCommands().size(); i++) {
if (args[0].equalsIgnoreCase(getSubCommands().get(i).getName())) {
List<String> subCommandArgs = getSubCommands().get(i).getSubcommandArguments(
(Player) sender, args
);

//getSubcommandArguments will have returned null if no implementation was provided.
if(subCommandArgs != null)
if (subCommandArgs != null)
return subCommandArgs;

return Collections.emptyList();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/kodysimpson/simpapi/command/SubCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public abstract class SubCommand {

/**
* @param sender The thing that ran the command
* @param args The args passed into the command when run
* @param args The args passed into the command when run
*/
public abstract void perform(CommandSender sender, String[] args);

/**
* @param player The player who ran the command
* @param args The args passed into the command when run
* @param args The args passed into the command when run
* @return A list of arguments to be suggested for autocomplete
*/
public abstract List<String> getSubcommandArguments(Player player, String[] args);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/me/kodysimpson/simpapi/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
@Target(ElementType.TYPE)
public @interface Config {
String fileName();

ConfigManager.FileType fileType();
}
32 changes: 16 additions & 16 deletions src/main/java/me/kodysimpson/simpapi/config/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@

public class ConfigManager {

private PrettyPrinter prettyPrinter = null;

public enum FileType{
JSON, YAML
}
private final PrettyPrinter prettyPrinter = null;

/**
* @param plugin An instance of your plugin
* @param plugin An instance of your plugin
* @param configClass A class reference to a Java class annotated with @Config containing your config values
* @param <T> The generic type of the Config class
* @param <T> The generic type of the Config class
* @return A new instance of the Config class to be used throughout your plugin
*/
public static <T> T loadConfig(JavaPlugin plugin, Class<T> configClass) {
Expand All @@ -37,15 +33,15 @@ public static <T> T loadConfig(JavaPlugin plugin, Class<T> configClass) {
if (configAnnotation == null) {
plugin.getLogger().severe("The provided Configuration Java class was not annotated properly with @Config from SimpAPI. Therefore the config could not be loaded.");
plugin.getPluginLoader().disablePlugin(plugin);
}else{
} else {

String fileName = configAnnotation.fileName();
FileType fileType = configAnnotation.fileType();

File messagesConfigFile = getConfigFile(plugin, fileName, fileType);
ObjectMapper mapper = getObjectMapper(fileType);

if (!messagesConfigFile.exists()){
if (!messagesConfigFile.exists()) {
try {
config = configClass.getConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
Expand All @@ -57,7 +53,7 @@ public static <T> T loadConfig(JavaPlugin plugin, Class<T> configClass) {
} catch (IOException e) {
e.printStackTrace();
}
}else{
} else {
//since it exists already, load the values into the object
try {
plugin.getLogger().info("Attempting to read " + fileName + " config file.");
Expand All @@ -75,16 +71,16 @@ public static <T> T loadConfig(JavaPlugin plugin, Class<T> configClass) {
}

/**
* @param plugin Your plugin class
* @param plugin Your plugin class
* @param configObject An instance of your Config class to use to save the contents of it to file
*/
public static void saveConfig(JavaPlugin plugin, Object configObject) {

Config configAnnotation = configObject.getClass().getAnnotation(Config.class);
if (configAnnotation == null){
if (configAnnotation == null) {
plugin.getLogger().severe("The provided Configuration Java class was not annotated properly with @Config from SimpAPI. Therefore the config could not be saved.");
plugin.getPluginLoader().disablePlugin(plugin);
}else{
} else {

String fileName = configAnnotation.fileName();
FileType fileType = configAnnotation.fileType();
Expand All @@ -103,7 +99,7 @@ public static void saveConfig(JavaPlugin plugin, Object configObject) {

}

private static File getConfigFile(JavaPlugin plugin, String fileName, FileType fileType){
private static File getConfigFile(JavaPlugin plugin, String fileName, FileType fileType) {
switch (fileType) {
case YAML:
return new File(plugin.getDataFolder(), fileName + ".yml");
Expand All @@ -115,11 +111,15 @@ private static File getConfigFile(JavaPlugin plugin, String fileName, FileType f
}

private static ObjectMapper getObjectMapper(FileType fileType) {
if (fileType == FileType.YAML){
if (fileType == FileType.YAML) {
return new ObjectMapper(new YAMLFactory()).configure(JsonGenerator.Feature.IGNORE_UNKNOWN, true).configure(JsonParser.Feature.IGNORE_UNDEFINED, true).configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}else{
} else {
return new ObjectMapper(new JsonFactory()).configure(JsonGenerator.Feature.IGNORE_UNKNOWN, true).configure(JsonParser.Feature.IGNORE_UNDEFINED, true).configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).setDefaultPrettyPrinter(new DefaultPrettyPrinter());
}
}

public enum FileType {
JSON, YAML
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* Wraps {@link ConversationFactory} to make building conversations with players
* significantly less tedious and boiler-plate prone.
*
* @see ConversationOptions
* @author muunitnocQ
* @see ConversationOptions
*/
public final class ConversationStarter {

Expand Down Expand Up @@ -83,12 +83,12 @@ public final static class ConversationOptions {
* @see ColorTranslator#translateColorCodes(String)
*/
public final ConversationPrefix prefix;
private final String rawPrefix;
public final boolean localEcho;
public final boolean modal;
public final int timeOut;
public final boolean escapeWordsCaseSensitive;
public final String[] escapeWords;
private final String rawPrefix;

/**
* Describes all options a conversation can have.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ final class PrefixedAbandonedListener implements ConversationAbandonedListener {
this.prefix = prefix;
}

private static String tl(String msg) {
return ColorTranslator.translateColorCodes(msg);
}

@Override
public void conversationAbandoned(ConversationAbandonedEvent abandonedEvent) {
if (abandonedEvent.gracefulExit()) return;
Expand Down Expand Up @@ -54,8 +58,4 @@ public void conversationAbandoned(ConversationAbandonedEvent abandonedEvent) {
player.sendMessage(tl(prefix + "&9Conversation cancelled by &#FF00FFcosmic energy&9."));
}

private static String tl(String msg) {
return ColorTranslator.translateColorCodes(msg);
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package me.kodysimpson.simpapi.exceptions;


public class MenuManagerException extends Exception{

public class MenuManagerException extends Exception {


}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.kodysimpson.simpapi.exceptions;

public class MenuManagerNotSetupException extends Exception{
public class MenuManagerNotSetupException extends Exception {
}
Loading