Skip to content

Commit ccdf866

Browse files
authored
Merge pull request #29 from muunitnocQ/code-cleanup
Ran IntelliJ formatter on entire project
2 parents df158a3 + be9b0f3 commit ccdf866

17 files changed

Lines changed: 98 additions & 104 deletions

src/main/java/me/kodysimpson/simpapi/colors/ColorTranslator.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import net.md_5.bungee.api.ChatColor;
44
import net.md_5.bungee.api.chat.BaseComponent;
5-
import net.md_5.bungee.api.chat.ComponentBuilder;
65
import net.md_5.bungee.api.chat.TextComponent;
76
import org.jetbrains.annotations.NotNull;
87

@@ -11,16 +10,15 @@
1110

1211
public class ColorTranslator {
1312

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

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

53-
for(BaseComponent comp : converted) {
51+
for (BaseComponent comp : converted) {
5452
base.addExtra(comp);
5553
}
5654

src/main/java/me/kodysimpson/simpapi/command/CommandList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
public interface CommandList {
1212

1313
/**
14-
* @param sender The thing that ran the command
14+
* @param sender The thing that ran the command
1515
* @param subCommandList A list of all the subcommands you can display
1616
*/
1717
void displayCommandList(CommandSender sender, List<SubCommand> subCommandList);

src/main/java/me/kodysimpson/simpapi/command/CommandManager.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
public class CommandManager {
1919

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

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

5555

5656
/**
57-
* @param plugin An instance of your plugin that is using this API. If called within plugin main class, provide this keyword
58-
* @param commandName The name of the command
57+
* @param plugin An instance of your plugin that is using this API. If called within plugin main class, provide this keyword
58+
* @param commandName The name of the command
5959
* @param commandDescription Description of command as would put it in plugin.yml
60-
* @param commandUsage Usage of command as would put it in plugin.yml
61-
* @param subcommands Class reference to each SubCommand you create for this core command
60+
* @param commandUsage Usage of command as would put it in plugin.yml
61+
* @param subcommands Class reference to each SubCommand you create for this core command
6262
*/
6363
@SafeVarargs
6464
public static void createCoreCommand(JavaPlugin plugin, String commandName,

src/main/java/me/kodysimpson/simpapi/command/CoreCommand.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package me.kodysimpson.simpapi.command;
22

3-
import org.bukkit.Bukkit;
43
import org.bukkit.command.Command;
54
import org.bukkit.command.CommandSender;
65
import org.bukkit.entity.Player;
@@ -18,34 +17,34 @@ class CoreCommand extends Command {
1817
private final ArrayList<SubCommand> subcommands;
1918
private final CommandList commandList;
2019

21-
public CoreCommand(String name, String description, String usageMessage, CommandList commandList, List<String> aliases, ArrayList<SubCommand> subCommands){
20+
public CoreCommand(String name, String description, String usageMessage, CommandList commandList, List<String> aliases, ArrayList<SubCommand> subCommands) {
2221
super(name, description, usageMessage, aliases);
2322
//Get the subcommands so we can access them in the command manager class(here)
2423
this.subcommands = subCommands;
2524
this.commandList = commandList;
2625
}
2726

28-
public ArrayList<SubCommand> getSubCommands(){
27+
public ArrayList<SubCommand> getSubCommands() {
2928
return subcommands;
3029
}
3130

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

35-
if (args.length > 0){
36-
for (int i = 0; i < getSubCommands().size(); i++){
37-
if (args[0].equalsIgnoreCase(getSubCommands().get(i).getName()) || (getSubCommands().get(i).getAliases() != null && getSubCommands().get(i).getAliases().contains(args[0]))){
34+
if (args.length > 0) {
35+
for (int i = 0; i < getSubCommands().size(); i++) {
36+
if (args[0].equalsIgnoreCase(getSubCommands().get(i).getName()) || (getSubCommands().get(i).getAliases() != null && getSubCommands().get(i).getAliases().contains(args[0]))) {
3837
getSubCommands().get(i).perform(sender, args);
3938
}
4039
}
41-
}else {
42-
if (commandList == null){
40+
} else {
41+
if (commandList == null) {
4342
sender.sendMessage("--------------------------------");
4443
for (SubCommand subcommand : subcommands) {
4544
sender.sendMessage(subcommand.getSyntax() + " - " + subcommand.getDescription());
4645
}
4746
sender.sendMessage("--------------------------------");
48-
}else{
47+
} else {
4948
commandList.displayCommandList(sender, subcommands);
5049
}
5150
}
@@ -55,23 +54,23 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String commandLab
5554

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

6160
//Does the subcommand autocomplete
62-
for (int i = 0; i < getSubCommands().size(); i++){
61+
for (int i = 0; i < getSubCommands().size(); i++) {
6362
subcommandsArguments.add(getSubCommands().get(i).getName());
6463
}
6564
return subcommandsArguments;
66-
}else if(args.length >= 2){
67-
for (int i = 0; i < getSubCommands().size(); i++){
68-
if (args[0].equalsIgnoreCase(getSubCommands().get(i).getName())){
65+
} else if (args.length >= 2) {
66+
for (int i = 0; i < getSubCommands().size(); i++) {
67+
if (args[0].equalsIgnoreCase(getSubCommands().get(i).getName())) {
6968
List<String> subCommandArgs = getSubCommands().get(i).getSubcommandArguments(
7069
(Player) sender, args
7170
);
7271

7372
//getSubcommandArguments will have returned null if no implementation was provided.
74-
if(subCommandArgs != null)
73+
if (subCommandArgs != null)
7574
return subCommandArgs;
7675

7776
return Collections.emptyList();

src/main/java/me/kodysimpson/simpapi/command/SubCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ public abstract class SubCommand {
3333

3434
/**
3535
* @param sender The thing that ran the command
36-
* @param args The args passed into the command when run
36+
* @param args The args passed into the command when run
3737
*/
3838
public abstract void perform(CommandSender sender, String[] args);
3939

4040
/**
4141
* @param player The player who ran the command
42-
* @param args The args passed into the command when run
42+
* @param args The args passed into the command when run
4343
* @return A list of arguments to be suggested for autocomplete
4444
*/
4545
public abstract List<String> getSubcommandArguments(Player player, String[] args);

src/main/java/me/kodysimpson/simpapi/config/Config.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
@Target(ElementType.TYPE)
1010
public @interface Config {
1111
String fileName();
12+
1213
ConfigManager.FileType fileType();
1314
}

src/main/java/me/kodysimpson/simpapi/config/ConfigManager.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,12 @@
1616

1717
public class ConfigManager {
1818

19-
private PrettyPrinter prettyPrinter = null;
20-
21-
public enum FileType{
22-
JSON, YAML
23-
}
19+
private final PrettyPrinter prettyPrinter = null;
2420

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

4238
String fileName = configAnnotation.fileName();
4339
FileType fileType = configAnnotation.fileType();
4440

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

48-
if (!messagesConfigFile.exists()){
44+
if (!messagesConfigFile.exists()) {
4945
try {
5046
config = configClass.getConstructor().newInstance();
5147
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
@@ -57,7 +53,7 @@ public static <T> T loadConfig(JavaPlugin plugin, Class<T> configClass) {
5753
} catch (IOException e) {
5854
e.printStackTrace();
5955
}
60-
}else{
56+
} else {
6157
//since it exists already, load the values into the object
6258
try {
6359
plugin.getLogger().info("Attempting to read " + fileName + " config file.");
@@ -75,16 +71,16 @@ public static <T> T loadConfig(JavaPlugin plugin, Class<T> configClass) {
7571
}
7672

7773
/**
78-
* @param plugin Your plugin class
74+
* @param plugin Your plugin class
7975
* @param configObject An instance of your Config class to use to save the contents of it to file
8076
*/
8177
public static void saveConfig(JavaPlugin plugin, Object configObject) {
8278

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

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

104100
}
105101

106-
private static File getConfigFile(JavaPlugin plugin, String fileName, FileType fileType){
102+
private static File getConfigFile(JavaPlugin plugin, String fileName, FileType fileType) {
107103
switch (fileType) {
108104
case YAML:
109105
return new File(plugin.getDataFolder(), fileName + ".yml");
@@ -115,11 +111,15 @@ private static File getConfigFile(JavaPlugin plugin, String fileName, FileType f
115111
}
116112

117113
private static ObjectMapper getObjectMapper(FileType fileType) {
118-
if (fileType == FileType.YAML){
114+
if (fileType == FileType.YAML) {
119115
return new ObjectMapper(new YAMLFactory()).configure(JsonGenerator.Feature.IGNORE_UNKNOWN, true).configure(JsonParser.Feature.IGNORE_UNDEFINED, true).configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
120-
}else{
116+
} else {
121117
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());
122118
}
123119
}
124120

121+
public enum FileType {
122+
JSON, YAML
123+
}
124+
125125
}

src/main/java/me/kodysimpson/simpapi/conversations/ConversationStarter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* Wraps {@link ConversationFactory} to make building conversations with players
1717
* significantly less tedious and boiler-plate prone.
1818
*
19-
* @see ConversationOptions
2019
* @author muunitnocQ
20+
* @see ConversationOptions
2121
*/
2222
public final class ConversationStarter {
2323

@@ -83,12 +83,12 @@ public final static class ConversationOptions {
8383
* @see ColorTranslator#translateColorCodes(String)
8484
*/
8585
public final ConversationPrefix prefix;
86-
private final String rawPrefix;
8786
public final boolean localEcho;
8887
public final boolean modal;
8988
public final int timeOut;
9089
public final boolean escapeWordsCaseSensitive;
9190
public final String[] escapeWords;
91+
private final String rawPrefix;
9292

9393
/**
9494
* Describes all options a conversation can have.

src/main/java/me/kodysimpson/simpapi/conversations/PrefixedAbandonedListener.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ final class PrefixedAbandonedListener implements ConversationAbandonedListener {
2323
this.prefix = prefix;
2424
}
2525

26+
private static String tl(String msg) {
27+
return ColorTranslator.translateColorCodes(msg);
28+
}
29+
2630
@Override
2731
public void conversationAbandoned(ConversationAbandonedEvent abandonedEvent) {
2832
if (abandonedEvent.gracefulExit()) return;
@@ -54,8 +58,4 @@ public void conversationAbandoned(ConversationAbandonedEvent abandonedEvent) {
5458
player.sendMessage(tl(prefix + "&9Conversation cancelled by &#FF00FFcosmic energy&9."));
5559
}
5660

57-
private static String tl(String msg) {
58-
return ColorTranslator.translateColorCodes(msg);
59-
}
60-
6161
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package me.kodysimpson.simpapi.exceptions;
22

33

4-
public class MenuManagerException extends Exception{
5-
4+
public class MenuManagerException extends Exception {
65

76

87
}

0 commit comments

Comments
 (0)