Coloured Text

Discussion in 'Plugin Development' started by Joshua Neicho, Mar 18, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Joshua Neicho

    hi i was wondering how i would use a .txt document for applying colour to text in the .txt
    this is the code i use =]
    Application.java

    Code:
    package com.JWNJWN.Application;
    
    import java.io.File;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Application extends JavaPlugin {
        static String maindirectory = "plugins/Application/";
    
        public void onEnable() {
            new File(maindirectory).mkdirs();
    
            LoadSettings.loadMain();
    
            PluginDescriptionFile pdfFile = getDescription();
            System.out.println(pdfFile.getName() + " version "
                    + pdfFile.getVersion() + " is Enabled!");
        }
    
        public boolean onCommand(CommandSender sender, Command cmd,
                String commandLabel, String[] args) {
            if (cmd.getName().compareToIgnoreCase("apply") == 0) {
    
                sender.sendMessage(LoadSettings.ApplyLine1Colour + "Applyone");
                sender.sendMessage(LoadSettings.ApplyLine2Colour + "ApplyTwo");
                sender.sendMessage(LoadSettings.ApplyLine3Colour + "ApplyThree");
                sender.sendMessage(LoadSettings.ApplyLine4Colour + "ApplyFour");
                sender.sendMessage(LoadSettings.ApplyLine5Colour + "ApplyFive");
                sender.sendMessage(LoadSettings.ApplyLine6Colour + "ApplySix");
            }
            return true;
        }
    
        public void onDisable() {
            PluginDescriptionFile pdfFile = getDescription();
            System.out.println(pdfFile.getName() + " version "
                    + pdfFile.getVersion() + " is Disabled!");
        }
    
        {
    
        }
    }

    LoadSetting.java

    Code:
    package com.JWNJWN.Application;
    
    import org.bukkit.ChatColor;
    
    public class LoadSettings {
        static ChatColor Red;
        static String ApplyLine1Colour;
        static String ApplyLine2Colour;
        static String ApplyLine3Colour;
        static String ApplyLine4Colour;
        static String ApplyLine5Colour;
        static String ApplyLine6Colour;
        static String ApplyOne;
        static String ApplyTwo;
        static String ApplyThree;
        static String ApplyFour;
        static String ApplyFive;
        static String ApplySix;
        static String TeamOne;
    
        public static void loadMain() {
            String propertiesFile = Application.maindirectory
                    + "Application.properties";
            PluginProperties properties = new PluginProperties(propertiesFile);
            properties.load();
    
            Red = ChatColor.RED;
    
            ApplyLine1Colour = properties.getString("Apply Line 1 Colour",
                    "Write Line 1 Colour Here");
            ApplyLine1Colour = properties.getString("Apply Line 2 Colour",
                    "Write Line 2 Colour Here");
            ApplyLine1Colour = properties.getString("Apply Line 3 Colour",
                    "Write Line 3 Colour Here");
            ApplyLine1Colour = properties.getString("Apply Line 4 Colour",
                    "Write Line 4 Colour Here");
            ApplyLine1Colour = properties.getString("Apply Line 5 Colour",
                    "Write Line 5 Colour Here");
            ApplyLine1Colour = properties.getString("Apply Line 6 Colour",
                    "Write Line 6 Colour Here");
            ApplyOne = properties
                    .getString("Apply Line One", "Write Line One Here");
            ApplyTwo = properties
                    .getString("Apply Line Two", "Write Line Two Here");
            ApplyThree = properties.getString("Apply Line Three",
                    "Write Line Three Here");
            ApplyFour = properties.getString("Apply Line Four",
                    "Write Line Four Here");
            ApplyFive = properties.getString("Apply Line Five",
                    "Write Line Five Here");
            ApplySix = properties
                    .getString("Apply Line Six", "Write Line Six Here");
            properties.save("===Application & Teams Configuration===");
    
        }
    
    }
    
    PluginProperties.java
    Code:
    package com.JWNJWN.Application;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Properties;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    
    public class PluginProperties extends Properties {
        static final long serialVersionUID = 0L;
        static final Logger log = Logger.getLogger("minecraft");
        private String fileName;
    
        public PluginProperties(String file) {
            this.fileName = file;
        }
    
        public void load() {
            File file = new File(this.fileName);
            if (file.exists()) {
                try {
                    load(new FileInputStream(this.fileName));
                } catch (IOException ex) {
                    log.log(Level.SEVERE, "Unable to load " + this.fileName, ex);
                }
            }
        }
    
        public void save(String start) {
            try {
                store(new FileOutputStream(this.fileName), start);
            } catch (IOException ex) {
                log.log(Level.SEVERE, "Unable to save " + this.fileName, ex);
            }
        }
    
        public int getInteger(String key, int value) {
            if (containsKey(key)) {
                return Integer.parseInt(getProperty(key));
            }
    
            put(key, String.valueOf(value));
            return value;
        }
    
        public double getDouble(String key, double value) {
            if (containsKey(key)) {
                return Double.parseDouble(getProperty(key));
            }
    
            put(key, String.valueOf(value));
            return value;
        }
    
        public String getString(String key, String value) {
            if (containsKey(key)) {
                return getProperty(key);
            }
    
            put(key, value);
            return value;
        }
    
        public boolean getBoolean(String key, boolean value) {
            if (containsKey(key)) {
                String boolString = getProperty(key);
                return (boolString.length() > 0)
                        && (boolString.toLowerCase().charAt(0) == 't');
            }
            put(key, value ? "true" : "false");
            return value;
        }
    
    }
    And the only colour i have set up is Red in case you are wondering

    bump?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 12, 2016
  2. Offline

    Plague

    What exactly are you trying to do and where seems to be the problem?
     
  3. Offline

    Joshua Neicho

    well i am trying to make this line
    sender.sendMessage(LoadSettings.ApplyLine1Colour + "ApplyOne");
    use ApplyLine1Colour be the colour of ApplyOne ect and when someone uses /aply it uses them
     
  4. Offline

    Plague

    And the problem?
     
  5. Offline

    Joshua Neicho

    well it doesn't use the colour and it doesn't print the message stated under the ApplyOne string when im trying to use the colour with it please help
     
  6. Offline

    Plague

    And how does the settings file look like?
     
Thread Status:
Not open for further replies.

Share This Page