pull/6/head
parent
d77cb08f53
commit
2711fae9c7
8 changed files with 174 additions and 21 deletions
@ -0,0 +1,66 @@ |
||||
package xyz.soukup.ecoCraftCore.utilities; |
||||
|
||||
import net.kyori.adventure.text.Component; |
||||
import net.kyori.adventure.text.minimessage.MiniMessage; |
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; |
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; |
||||
import org.bukkit.command.CommandSender; |
||||
import org.bukkit.configuration.file.FileConfiguration; |
||||
import org.bukkit.configuration.file.YamlConfiguration; |
||||
import org.bukkit.entity.Player; |
||||
|
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.util.HashMap; |
||||
import java.util.Objects; |
||||
|
||||
import static xyz.soukup.ecoCraftCore.EcoCraftCore.plugin; |
||||
|
||||
public class Messages { |
||||
private static File messagesFile; |
||||
private static YamlConfiguration messages; |
||||
|
||||
public static void init() throws IOException { |
||||
messagesFile = new File(plugin.getDataFolder(), "messages.yml"); |
||||
|
||||
plugin.saveResource("messages.yml", true); |
||||
|
||||
if (!messagesFile.exists()){ |
||||
plugin.saveResource("messages.yml", false); |
||||
} |
||||
|
||||
messages = YamlConfiguration.loadConfiguration(messagesFile); |
||||
|
||||
messages.save(messagesFile); |
||||
|
||||
} |
||||
|
||||
public static Component get(String key) { |
||||
String string = messages.getString(key); |
||||
if (string == null){ |
||||
return Component.text(key); |
||||
} |
||||
return MiniMessage.miniMessage().deserialize(string); |
||||
} |
||||
|
||||
public static Component get(String key, HashMap<String, String> placeholders){ |
||||
String string = messages.getString(key); |
||||
if (string == null){ |
||||
return Component.text(key); |
||||
} |
||||
|
||||
TagResolver.Builder resolverBuilder = TagResolver.builder(); |
||||
placeholders.forEach((k, value) -> resolverBuilder.resolver(Placeholder.unparsed(k, value))); |
||||
|
||||
|
||||
return MiniMessage.miniMessage().deserialize(string, resolverBuilder.build()); |
||||
} |
||||
|
||||
public static void send(CommandSender sender, String key){ |
||||
sender.sendMessage(get(key)); |
||||
} |
||||
|
||||
public static void send(CommandSender sender, String key, HashMap<String, String> placeholders){ |
||||
sender.sendMessage(get(key, placeholders)); |
||||
} |
||||
} |
||||
@ -0,0 +1,48 @@ |
||||
package xyz.soukup.ecoCraftCore.utilities; |
||||
|
||||
|
||||
import org.bukkit.Location; |
||||
import xyz.soukup.ecoCraftCore.objects.Account; |
||||
import xyz.soukup.ecoCraftCore.objects.Transaction; |
||||
|
||||
import java.util.HashMap; |
||||
|
||||
public class PHHM { |
||||
public static HashMap<String, String> get(Location location){ |
||||
HashMap<String, String> hashMap = new HashMap<>(); |
||||
|
||||
hashMap.put("x", Integer.toString(location.getBlockX())); |
||||
hashMap.put("y", Integer.toString(location.getBlockY())); |
||||
hashMap.put("z", Integer.toString(location.getBlockZ())); |
||||
hashMap.put("world", location.getWorld().getName()); |
||||
|
||||
return hashMap; |
||||
} |
||||
|
||||
public static HashMap<String, String> get(Transaction transaction){ |
||||
HashMap<String, String> hashMap = new HashMap<>(); |
||||
|
||||
hashMap.put("transaction-id", String.format("%bd", transaction.getId())); |
||||
hashMap.put("amount", String.format("%.2f", transaction.getAmount())); |
||||
hashMap.put("sender", transaction.getSender()); |
||||
hashMap.put("sender-type", transaction.getSenderType()); |
||||
hashMap.put("receiver", transaction.getReceiver()); |
||||
hashMap.put("receiver-type", transaction.getReceiverType()); |
||||
hashMap.put("type", transaction.getType()); |
||||
hashMap.put("primary-info", transaction.getPrimaryInfo()); |
||||
hashMap.put("secondary-info", transaction.getSecondaryInfo()); |
||||
|
||||
return hashMap; |
||||
|
||||
} |
||||
|
||||
public static HashMap<String, String> get(Account account){ |
||||
HashMap<String, String> hashMap = new HashMap<>(); |
||||
|
||||
hashMap.put("balance", String.format("%.2f", account.getBalance())); |
||||
hashMap.put("owner", account.getOwner()); |
||||
hashMap.put("type", account.getType()); |
||||
|
||||
return hashMap; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue