fuck me components are ugly
This commit is contained in:
@ -4,13 +4,17 @@ import cc.fascinated.Aetheria;
|
||||
import cc.fascinated.playercolor.PlayerColor;
|
||||
import lombok.Getter;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.UUID;
|
||||
@Getter
|
||||
@Getter @Log4j2
|
||||
public class Account {
|
||||
|
||||
/**
|
||||
@ -44,6 +48,7 @@ public class Account {
|
||||
private final PlayerColor playerColorProfile;
|
||||
|
||||
public Account(UUID uuid) {
|
||||
log.info("Loading account for " + uuid);
|
||||
boolean newAccount = false;
|
||||
|
||||
this.uuid = uuid;
|
||||
@ -64,15 +69,17 @@ public class Account {
|
||||
if (newAccount) {
|
||||
this.firstJoin = System.currentTimeMillis();
|
||||
this.lastLogin = System.currentTimeMillis();
|
||||
save(false); // Save default values
|
||||
this.save(false); // Save default values
|
||||
log.info("Created new account for " + this.uuid);
|
||||
}
|
||||
|
||||
this.firstJoin = config.getLong("firstJoin");
|
||||
this.lastLogin = config.getLong("lastLogin");
|
||||
|
||||
// Load profiles
|
||||
this.playerColorProfile = config.contains("playerColor") ?
|
||||
new PlayerColor(this, config.getConfigurationSection("playerColor")) : new PlayerColor(this);
|
||||
this.playerColorProfile = new PlayerColor(this, this.getProfileSection("playerColor"));
|
||||
|
||||
log.info("Loaded account for " + this.uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,7 +88,7 @@ public class Account {
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return getPlayer().getName();
|
||||
return this.getPlayer().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,7 +97,7 @@ public class Account {
|
||||
* @return the player
|
||||
*/
|
||||
public Player getPlayer() {
|
||||
return org.bukkit.Bukkit.getPlayer(uuid);
|
||||
return Bukkit.getPlayer(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -102,6 +109,15 @@ public class Account {
|
||||
getPlayer().sendPlainMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the player.
|
||||
*
|
||||
* @param component the message to send
|
||||
*/
|
||||
public void sendMessage(Component component) {
|
||||
getPlayer().sendMessage(component);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a profile to the configuration.
|
||||
*
|
||||
@ -109,10 +125,18 @@ public class Account {
|
||||
* @param key the key to save the profile under
|
||||
*/
|
||||
private void saveProfile(Profile profile, String key) {
|
||||
key += "Profile"; // append "Profile" to the key to signify it's a profile
|
||||
key = this.getProfileId(key); // append "Profile" to the key to signify it's a profile
|
||||
profile.save(config.getConfigurationSection(key) == null ? config.createSection(key) : config.getConfigurationSection(key));
|
||||
}
|
||||
|
||||
private ConfigurationSection getProfileSection(String key) {
|
||||
return this.config.getConfigurationSection(this.getProfileId(key));
|
||||
}
|
||||
|
||||
private String getProfileId(String key) {
|
||||
return key + "Profile"; // append "Profile" to the key to signify it's a profile
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void save(boolean saveProfiles) {
|
||||
this.config.set("firstJoin", this.firstJoin);
|
||||
|
@ -22,15 +22,6 @@ public abstract class Profile extends Manager {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is used for creating a new profile.
|
||||
*
|
||||
* @param account the account to create the profile for
|
||||
*/
|
||||
public Profile(Account account) {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves this profile to file.
|
||||
*
|
||||
|
@ -16,16 +16,14 @@ public class PlayerColor extends Profile {
|
||||
*/
|
||||
private NamedTextColor color;
|
||||
|
||||
public PlayerColor(Account account) {
|
||||
super(account);
|
||||
|
||||
this.color = PlayerColorManager.getRandomColor();
|
||||
}
|
||||
|
||||
public PlayerColor(Account account, ConfigurationSection section) {
|
||||
super(account, section);
|
||||
|
||||
this.color = NamedTextColor.namedColor(section.getInt("color"));
|
||||
if (section == null) {
|
||||
this.color = PlayerColorManager.getRandomColor();
|
||||
} else {
|
||||
this.color = NamedTextColor.namedColor(section.getInt("color"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,6 +4,7 @@ import cc.fascinated.account.Account;
|
||||
import cc.fascinated.command.Command;
|
||||
import cc.fascinated.playercolor.PlayerColor;
|
||||
import cc.fascinated.playercolor.PlayerColorManager;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.util.List;
|
||||
@ -16,13 +17,20 @@ public class PlayerColorCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void execute(Account account, String[] args) {
|
||||
List<NamedTextColor> validColors = PlayerColorManager.getValidColors();
|
||||
PlayerColor playerColorProfile = account.getPlayerColorProfile();
|
||||
|
||||
if (args.length == 0) {
|
||||
account.sendMessage("§b§lPLAYERCOLOR §7» §fYour current color is: " + playerColorProfile.getColor() + "§f.");
|
||||
account.sendMessage(Component.text("§b§lPLAYERCOLOR §7» §fYour current color is: ").append(Component.text(playerColorProfile.getColor().toString()).color(playerColorProfile.getColor())));
|
||||
Component validColorsComponent = Component.text("§fValid colors: ");
|
||||
for (NamedTextColor validColor : validColors) {
|
||||
validColorsComponent = validColorsComponent.append(Component.text(validColor.toString() + ", ").color(validColor));
|
||||
}
|
||||
validColorsComponent = validColorsComponent.append(Component.text("random.").color(NamedTextColor.WHITE));
|
||||
account.sendMessage(validColorsComponent);
|
||||
return;
|
||||
}
|
||||
|
||||
List<NamedTextColor> validColors = PlayerColorManager.getValidColors();
|
||||
if (args[0].equalsIgnoreCase("random")) {
|
||||
playerColorProfile.setColor(validColors.get((int) (Math.random() * validColors.size())));
|
||||
account.sendMessage("§b§lPLAYERCOLOR §7» §fYour color has been set to: " + playerColorProfile.getColor() + "§f.");
|
||||
@ -32,16 +40,10 @@ public class PlayerColorCommand extends Command {
|
||||
NamedTextColor color = PlayerColorManager.getColor(args[0]);
|
||||
if (color == null) {
|
||||
account.sendMessage("§b§lPLAYERCOLOR §7» §cInvalid color.");
|
||||
|
||||
StringBuilder builder = new StringBuilder("§fValid colors: ");
|
||||
for (NamedTextColor validColor : validColors) {
|
||||
builder.append(validColor).append(", ");
|
||||
}
|
||||
account.sendMessage(builder.substring(0, builder.length() - 2) + ".");
|
||||
return;
|
||||
}
|
||||
|
||||
playerColorProfile.setColor(color);
|
||||
account.sendMessage("§b§lPLAYERCOLOR §7» §fYour color has been set to: " + playerColorProfile.getColor() + "§f.");
|
||||
account.sendMessage(Component.text("§b§lPLAYERCOLOR §7» §fYour color has been set to: ").append(Component.text(playerColorProfile.getColor().toString()).color(playerColorProfile.getColor())));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user