Skip to content

Commit

Permalink
Remove Java 8 Optionals (woops\!)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverdunk committed Mar 12, 2016
1 parent 28d3ac3 commit 7fcd3e1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.bukkit.entity.Player;

import java.util.HashMap;
import java.util.Optional;

@AllArgsConstructor
public class JukeboxCommand implements CommandExecutor {
Expand Down Expand Up @@ -93,7 +92,7 @@ private boolean play(CommandSender sender, String[] args){
if(playFor == null){
HashMap<String, String> findAndReplace = new HashMap<String, String>();
findAndReplace.put("user", args[1]);
MessageUtils.sendMessage(sender, "command.notOnline", Optional.of(findAndReplace));
MessageUtils.sendMessage(sender, "command.notOnline", findAndReplace);
return true;
}
if(args[0].equalsIgnoreCase("music")) JukeboxAPI.play(playFor, args[2], ResourceType.MUSIC);
Expand All @@ -106,7 +105,7 @@ private boolean stop(CommandSender sender, String[] args){
if(playFor == null){
HashMap<String, String> findAndReplace = new HashMap<String, String>();
findAndReplace.put("user", args[1]);
MessageUtils.sendMessage(sender, "command.notOnline", Optional.of(findAndReplace));
MessageUtils.sendMessage(sender, "command.notOnline", findAndReplace);
return true;
}
JukeboxAPI.stopMusic(playFor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.json.JSONObject;

import java.io.*;
import java.util.Optional;

public class LangUtils {

Expand Down
10 changes: 4 additions & 6 deletions src/main/java/com/oliverdunk/jukeboxapi/utils/MessageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.bukkit.command.CommandSender;

import java.util.HashMap;
import java.util.Optional;

public class MessageUtils {

Expand All @@ -18,7 +17,7 @@ public class MessageUtils {
* @param key Key which should be used to lookup the message
*/
public static void sendMessage(CommandSender player, String key){
sendMessage(player, key, Optional.<HashMap<String,String>>empty());
sendMessage(player, key, null);
}

/**
Expand All @@ -28,14 +27,13 @@ public static void sendMessage(CommandSender player, String key){
* @param key Key which should be used to lookup the message
* @param findAndReplace Optional list of keys which should be replaced with the corresponding values
*/
public static void sendMessage(CommandSender player, String key, Optional<HashMap<String, String>> findAndReplace){
public static void sendMessage(CommandSender player, String key, HashMap<String, String> findAndReplace){
String message = langUtils.get(key);

//Replace any values in the find and replace HashMap, if it is present
message = ChatColor.translateAlternateColorCodes('&', message);
if (findAndReplace.isPresent()) {
HashMap<String, String> findReplace = findAndReplace.get();
for (String find : findReplace.keySet()) message = message.replace("[" + find + "]", findReplace.get(find));
if (findAndReplace != null) {
for (String find : findAndReplace.keySet()) message = message.replace("[" + find + "]", findAndReplace.get(find));
}

player.sendMessage(message);
Expand Down

0 comments on commit 7fcd3e1

Please sign in to comment.