Skip to content

Commit

Permalink
2.0.2 - Fix message
Browse files Browse the repository at this point in the history
- Fix message when chat number
- Add auto update files
  • Loading branch information
VoChiDanh committed Sep 20, 2023
1 parent 914dd31 commit 17079bd
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 55 deletions.
26 changes: 17 additions & 9 deletions README.md
@@ -1,31 +1,39 @@
# Storage [1.8.x - 1.20.x]

>You will have a virtual storage to storage listed blocks in config, when you mine block was listed in config, you'll get block to virtual storage. You can sell it or transfer it to physical item <br>
> You will have a virtual storage to storage listed blocks in config, when you mine block was listed in config, you'll
> get block to virtual storage. You can sell it or transfer it to physical item <br>
> This is recoded version from started so everything will be changed. Please reset all file when update from v1 to
> v2 <br>
>This is recoded version from started so everything will be changed. Please reset all file when update from v1 to v2 <br>
## Commands
>/Storage - Open Gui <br>

>/Storage reload - Reload Files <br>
> /Storage - Open Gui <br>
> /Storage reload - Reload Files <br>
>/Storage max <player> <amount> - Set max item player can storage <br>
> /Storage max <player> <amount> - Set max item player can storage <br>
>/Storage add <material;data> <player> <amount> - Add item to player (data for 1.12.2 and below, if you use 1.13+ use <material>;0 <br>
> /Storage add <material;data> <player> <amount> - Add item to player (data for 1.12.2 and below, if you use 1.13+
> use <material>;0 <br>
>/Storage remove <material;data> <player> <amount> - Remove item to player (data for 1.12.2 and below, if you use 1.13+ use <material>;0 <br>
> /Storage remove <material;data> <player> <amount> - Remove item to player (data for 1.12.2 and below, if you use 1.13+
> use <material>;0 <br>
>/Storage set <material;data> <player> <amount> - Set item to player (data for 1.12.2 and below, if you use 1.13+ use <material>;0 <br>
> /Storage set <material;data> <player> <amount> - Set item to player (data for 1.12.2 and below, if you use 1.13+
> use <material>;0 <br>
## Placeholder

> %storage_storage_(MATERIAL)% -> %Storage_storage_COAL;0% | Show amount item in storage
> %storage_max_storage% | Show max amount item in storage
> %storage_price_(MATERIAL)% -> %Storage_storage_COAL;0% | Show item's price
> %storage_price_(MATERIAL)% -> %Storage_storage_COAL;0% | Show item's price
> %storage_status% | Show status
## Soft Depends

[![placeholderapi](https://img.shields.io/badge/PlaceholderAPI-2.11.3-blue?style=badge)](https://www.spigotmc.org/resources/6245/) <br>
[![worldguard](https://img.shields.io/badge/WorldGuard-v6/v7-blue?style=badge)](https://dev.bukkit.org/projects/worldguard) <br>
11 changes: 6 additions & 5 deletions pom.xml
Expand Up @@ -6,7 +6,7 @@

<groupId>net.danh</groupId>
<artifactId>Storage</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
<packaging>jar</packaging>

<name>Storage</name>
Expand Down Expand Up @@ -158,11 +158,12 @@
<groupId>com.github.DigitalityDev</groupId>
<artifactId>DigitalGUI</artifactId>
<version>1.0.1</version>
</dependency><!-- https://mvnrepository.com/artifact/org.jetbrains/annotations -->
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>24.0.1</version>
<groupId>com.tchristofferson</groupId>
<artifactId>ConfigUpdater</artifactId>
<version>2.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
1 change: 1 addition & 0 deletions src/main/java/net/danh/storage/Listeners/BlockBreak.java
Expand Up @@ -66,6 +66,7 @@ public void onBreak(@NotNull BlockBreakEvent e) {
}
}
}

public boolean isPlacedBlock(Block b) {
List<MetadataValue> metaDataValues = b.getMetadata("PlacedBlock");
for (MetadataValue value : metaDataValues) {
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/net/danh/storage/Listeners/Chat.java
Expand Up @@ -14,6 +14,7 @@
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.Objects;

public class Chat implements Listener {
public static HashMap<Player, String> chat_deposit = new HashMap<>();
Expand All @@ -28,7 +29,8 @@ public void onChat(@NotNull AsyncPlayerChatEvent e) {
if (Number.getInteger(message) > 0) {
new Deposit(p, chat_deposit.get(p), (long) Number.getInteger(message)).doAction();
} else {
p.sendMessage(net.danh.storage.Utils.Chat.colorize(File.getMessage().getString("user.number_so_low")));
p.sendMessage(net.danh.storage.Utils.Chat.colorize(Objects.requireNonNull(File.getMessage().getString("user.unknown_number"))
.replace("<number>", message)));
}
chat_deposit.remove(p);
e.setCancelled(true);
Expand All @@ -37,7 +39,8 @@ public void onChat(@NotNull AsyncPlayerChatEvent e) {
if (Number.getInteger(message) > 0) {
new Withdraw(p, chat_withdraw.get(p), Number.getInteger(message)).doAction();
} else {
p.sendMessage(net.danh.storage.Utils.Chat.colorize(File.getMessage().getString("user.number_so_low")));
p.sendMessage(net.danh.storage.Utils.Chat.colorize(Objects.requireNonNull(File.getMessage().getString("user.unknown_number"))
.replace("<number>", message)));
}
chat_withdraw.remove(p);
e.setCancelled(true);
Expand All @@ -46,7 +49,8 @@ public void onChat(@NotNull AsyncPlayerChatEvent e) {
if (Number.getInteger(message) > 0) {
new Sell(p, chat_sell.get(p), Number.getInteger(message)).doAction();
} else {
p.sendMessage(net.danh.storage.Utils.Chat.colorize(File.getMessage().getString("user.number_so_low")));
p.sendMessage(net.danh.storage.Utils.Chat.colorize(Objects.requireNonNull(File.getMessage().getString("user.unknown_number"))
.replace("<number>", message)));
}
chat_sell.remove(p);
e.setCancelled(true);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/net/danh/storage/Storage.java
Expand Up @@ -53,7 +53,9 @@ public void onEnable() {
SimpleConfigurationManager.register(storage);
File.loadFiles();
File.loadGUI();
if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
File.updateConfig();
File.updateMessage();
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
new PAPI().register();
}
registerEvents(new UpdateChecker(storage), new JoinQuit(), new BlockBreak(), new Chat(), new BlockPlace());
Expand Down
66 changes: 66 additions & 0 deletions src/main/java/net/danh/storage/Utils/File.java
@@ -1,7 +1,17 @@
package net.danh.storage.Utils;

import com.tchristofferson.configupdater.ConfigUpdater;
import net.danh.storage.Storage;
import net.xconfig.bukkit.model.SimpleConfigurationManager;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Objects;
import java.util.logging.Level;

public class File {

Expand Down Expand Up @@ -40,4 +50,60 @@ public static void loadGUI() {
public static void saveFiles() {
getFileSetting().save("config.yml", "message.yml", "GUI/storage.yml", "GUI/items.yml");
}

public static void updateConfig() {
Storage.getStorage().getLogger().log(Level.WARNING, "Your config is updating...");
getFileSetting().save("config.yml");
java.io.File configFile = new java.io.File(Storage.getStorage().getDataFolder(), "config.yml");
FileConfiguration defaultConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(Objects.requireNonNull(Storage.getStorage().getResource("config.yml")), StandardCharsets.UTF_8));
FileConfiguration currentConfig = YamlConfiguration.loadConfiguration(configFile);
List<String> default_admin_help = defaultConfig.getStringList("help.admin");
List<String> default_user_help = defaultConfig.getStringList("help.user");
List<String> current_admin_help = currentConfig.getStringList("help.admin");
List<String> current_user_help = currentConfig.getStringList("help.user");
if (default_admin_help.size() != current_admin_help.size()) {
getConfig().set("help.admin", default_admin_help);
getFileSetting().save("config.yml");
}
if (default_user_help.size() != current_user_help.size()) {
getConfig().set("help.user", default_user_help);
getFileSetting().save("config.yml");
}
try {
ConfigUpdater.update(Storage.getStorage(), "config.yml", configFile);
Storage.getStorage().getLogger().log(Level.WARNING, "Your config have been updated successful");
} catch (IOException e) {
Storage.getStorage().getLogger().log(Level.WARNING, "Can not update config by it self, please backup and rename your config then restart to get newest config!!");
e.printStackTrace();
}
getFileSetting().reload("config.yml");
}

public static void updateMessage() {
Storage.getStorage().getLogger().log(Level.WARNING, "Your message is updating...");
getFileSetting().save("message.yml");
java.io.File configFile = new java.io.File(Storage.getStorage().getDataFolder(), "config.yml");
FileConfiguration defaultConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(Objects.requireNonNull(Storage.getStorage().getResource("message.yml")), StandardCharsets.UTF_8));
FileConfiguration currentConfig = YamlConfiguration.loadConfiguration(configFile);
List<String> default_admin_help = defaultConfig.getStringList("admin.help");
List<String> default_user_help = defaultConfig.getStringList("user.help");
List<String> current_admin_help = currentConfig.getStringList("admin.help");
List<String> current_user_help = currentConfig.getStringList("user.help");
if (default_admin_help.size() != current_admin_help.size()) {
getConfig().set("admin.help", default_admin_help);
getFileSetting().save("message.yml");
}
if (default_user_help.size() != current_user_help.size()) {
getConfig().set("user.help", default_user_help);
getFileSetting().save("message.yml");
}
try {
ConfigUpdater.update(Storage.getStorage(), "message.yml", configFile);
Storage.getStorage().getLogger().log(Level.WARNING, "Your message have been updated successful");
} catch (IOException e) {
Storage.getStorage().getLogger().log(Level.WARNING, "Can not update message by it self, please backup and rename your message then restart to get newest message!!");
e.printStackTrace();
}
getFileSetting().reload("config.yml");
}
}
1 change: 1 addition & 0 deletions src/main/resources/message.yml
Expand Up @@ -18,6 +18,7 @@ user:
set_material_amount: "&c[~] #amount# #material# &7[From #player#]"
number_so_low: "&cYou need a number higher than 0"
not_enough_item: "&cYou haven't enough item"
unknown_number: "&c<number> isn't number"
action:
deposit:
chat_number: "&aHow many item you want to deposit?"
Expand Down
37 changes: 0 additions & 37 deletions src/main/resources/message_vi.yml

This file was deleted.

0 comments on commit 17079bd

Please sign in to comment.