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