String list help !!

Status
This thread has been locked.

Declyn.

Banned
Feedback score
0
Posts
18
Reactions
1
Resources
0
Hey all!

I need some help, I'm trying to make my code a little bit more clean.

Instead of having to do:

public static String test = "";
public static String test1 = "";
public static String test2 = "";

Is there something like, uhhh... this I can do?

public static String {
test = "";
test1 = "";
test2 = "";
}
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Declyn.

Banned
Feedback score
0
Posts
18
Reactions
1
Resources
0
What do you want to do exactly?
I want to make my configuration a lot more simple, use one class and then get the config from their.

Why don't you try compiling the code and see what happens
That code doesn't work, I'm looking for something similar to the example I provided that works.
 
Banned forever. Reason: Ban Evading (declynXD)

Norska

Java Developer (https://norska.dev)
Supreme
Feedback score
68
Posts
901
Reactions
1,407
Resources
14
Do you want to get a string list from a configuration file? I assume you'd want to send it as a message to someone etc.?

EDIT:
Code:
for (String message : getConfig().getStringList("message")) {
p.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
}

In your config you'd just do something like:
Code:
message:
- '&cLine 1'
- '&c&lLine 2 etc.'
 
Last edited:

BrianGrug

Full time failure
Supreme
Feedback score
56
Posts
1,473
Reactions
995
Resources
5
I don't really understand what you mean but try using a for-loop
 

Blood

Deactivated
Feedback score
23
Posts
497
Reactions
287
Resources
0
What are you trying to do? Is a List<String> what you're looking for?
 

Declyn.

Banned
Feedback score
0
Posts
18
Reactions
1
Resources
0
Do you want to get a string list from a configuration file? I assume you'd want to send it as a message to someone etc.?
No no no, what I'm going to do is in the class I want a config message for is do:

Config."INSERT MESSAGE I WANT"

from one singular class file, and then inside the class file will be Rank.getInstance().getConfig.getString("");[DOUBLEPOST=1550967108][/DOUBLEPOST]public static String Bold = ChatColor.BOLD.toString();
public static String Strike = ChatColor.STRIKETHROUGH.toString();
public static String Line = ChatColor.UNDERLINE.toString();
public static String Italics = ChatColor.ITALIC.toString();
public static String Reset = ChatColor.WHITE.toString();
public static String Aqua = ChatColor.AQUA.toString();
public static String Black = ChatColor.BLACK.toString();
public static String Blue = ChatColor.BLUE.toString();
public static String DAqua = ChatColor.DARK_AQUA.toString();
public static String DBlue = ChatColor.DARK_BLUE.toString();
public static String DGray = ChatColor.DARK_GRAY.toString();
public static String DGreen = ChatColor.DARK_GREEN.toString();
public static String DPurple = ChatColor.DARK_PURPLE.toString();
public static String DRed = ChatColor.DARK_RED.toString();
public static String Gold = ChatColor.GOLD.toString();
public static String Gray = ChatColor.GRAY.toString();
public static String Green = ChatColor.GREEN.toString();
public static String Purple = ChatColor.LIGHT_PURPLE.toString();
public static String Red = ChatColor.RED.toString();
public static String ChatColor.WHITE = ChatColor.WHITE.toString();
public static String Yellow = ChatColor.WHITE.toString();
public static String Split = "\u00a7";

public static String strip(String Text) {
return ChatColor.stripColor((String) Text);
}

instead of doing this, I want to do something like

public static String {

Bold = ChatColor.BOLD.toString();
Red = ChatColor.RED.toString();
}
 
Last edited:
Banned forever. Reason: Ban Evading (declynXD)

Blood

Deactivated
Feedback score
23
Posts
497
Reactions
287
Resources
0
No no no, what I'm going to do is in the class I want a config message for is do:

Config."INSERT MESSAGE I WANT"

from one singular class file, and then inside the class file will be Rank.getInstance().getConfig.getString("");
Maybe an enum would work for that.
Something like
Code:
public enum ConfigMessages {
    MESSAGE1("path.here")

    private String path;
    ConfigMessages(String path) { this.path = path; }
    @Override
    public String toString() { return getConfig().getString(path); }
}
 
Last edited:

Tabuu

Developer
Supreme
Feedback score
3
Posts
39
Reactions
19
Resources
0
You mean like this:

Code:
public static String
        StringA = "A",
        StringB = "B",
        StringC = "B";
 

LamerGamerYT

Discord Bots - Discord Setups
Premium
Feedback score
24
Posts
329
Reactions
84
Resources
0
This is what you can do:
Code:
HashMap<String, String> colorCodes = new HashMap<>();
colorCodes.put("bold", ChatColor.BOLD.toString());
colorCodes.put("strike", ChatColor.STRIKETHROUGH.toString());
and so on...

Then, to get a specific color, you can do:
Code:
colorCodes.get("bold");
colorCodes.get("strike");
 

Killstreak702

Premium
Feedback score
1
Posts
227
Reactions
105
Resources
0
These replies oml.

You can use the method: Arrays#asList - it uses a diamond type "T" and returns a List<T> and takes an array of objects that extend the diamond type

Example usage:
List<String> myStrings = Arrays.asList(
"Some",
"cool",
"strings"
);

Same goes for anything else, like integers:
List<Integer> myInts = Arrays.asList(
1,
2,
4,
6,
8,
10,
12 // and so on...
);

You can also do something similar with arrays.

String[] myStringArray = {"Some", "cool", "strings"};
 
Status
This thread has been locked.
Top