Skip to content

Commit

Permalink
2.18.0 - Export command in preparation for the future 3.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
kiranhart committed Dec 18, 2021
1 parent d2f71d0 commit f6ada4c
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ca.tweetzy</groupId>
<artifactId>shops</artifactId>
<version>2.17.1</version>
<version>2.18.0</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ca/tweetzy/shops/Shops.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ public void onPluginEnable() {
new CommandConvert(),
new CommandChangeId(),
new CommandUpload(),
new CommandSellAll()
new CommandSellAll(),
new CommandExport()
);

// Perform the update check
Expand Down
105 changes: 105 additions & 0 deletions src/main/java/ca/tweetzy/shops/commands/CommandExport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package ca.tweetzy.shops.commands;

import ca.tweetzy.core.commands.AbstractCommand;
import ca.tweetzy.core.configuration.Config;
import ca.tweetzy.core.configuration.ConfigFormattingRules;
import ca.tweetzy.shops.Shops;
import ca.tweetzy.shops.api.ShopAPI;
import ca.tweetzy.shops.shop.ShopItem;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.time.Instant;
import java.util.Collections;
import java.util.List;

/**
* The current file has been created by Kiran Hart
* Date Created: December 17 2021
* Time Created: 9:38 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public final class CommandExport extends AbstractCommand {

public CommandExport() {
super(CommandType.PLAYER_ONLY, "export");
}

@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
final Player player = (Player) sender;
final Config data = new Config(Shops.getInstance(), "shops-export.yml");
data.load();


Shops.newChain().async(() -> {
data.set("Shops", null);
data.setHeader(ConfigFormattingRules.CommentStyle.BLOCKED,
"Shops v2 Export",
"You can use this file to import most shop data back into v3 when its released",
"so make sure this file is update to date before upgrading",
"",
"This file was generated by: " + player.getName() + " at " + Instant.now().toString()

);

Shops.getInstance().getShopManager().getShops().forEach(shop -> {
final String node = "Shops." + shop.getId() + ".";
data.set(node + "id", shop.getId());
data.set(node + "display name", shop.getDisplayName());
data.set(node + "desc", shop.getDescription());
data.set(node + "icon", ShopAPI.getInstance().deserializeItem(shop.getDisplayIcon()));
data.set(node + "public", shop.isPublic());
data.set(node + "sell only", shop.isSellOnly());
data.set(node + "buy only", shop.isBuyOnly());
data.set(node + "use sell bonus", shop.isUseSellBonus());
data.set(node + "use buy discount", shop.isUseBuyDiscount());
data.set(node + "use tax", shop.isUseTax());
data.set(node + "needs buy perm", shop.isRequiresPermissionToBuy());
data.set(node + "needs see perm", shop.isRequiresPermissionToSee());
data.set(node + "needs sell perm", shop.isRequiresPermissionToSell());
data.set(node + "sell bonus", shop.getSellBonus());
data.set(node + "buy discount", shop.getBuyDiscount());
data.set(node + "tax", shop.getTax());
data.set(node + "see perm", shop.getSeePermission());
data.set(node + "sell perm", shop.getSellPermission());
data.set(node + "buy perm", shop.getBuyPermission());

int itemIndex = 1;
for (ShopItem shopItem : shop.getShopItems()) {
data.set(node + "items." + itemIndex + ".item", ShopAPI.getInstance().deserializeItem(shopItem.getItem()));
data.set(node + "items." + itemIndex + ".sell price", shopItem.getSellPrice());
data.set(node + "items." + itemIndex + ".buy price", shopItem.getBuyPrice());
data.set(node + "items." + itemIndex + ".buy discount", shopItem.getBuyDiscount());
data.set(node + "items." + itemIndex + ".buy only", shopItem.isBuyOnly());
data.set(node + "items." + itemIndex + ".sell only", shopItem.isSellOnly());
itemIndex++;
}
});
data.save();
Shops.getInstance().getLocale().newMessage("&aExported Shop data to &2shops-export.yml").sendPrefixedMessage(player);
}).execute();

return ReturnType.SUCCESS;
}

@Override
protected List<String> onTab(CommandSender sender, String... args) {
return null;
}

@Override
public String getPermissionNode() {
return "shops.cmd.export";
}

@Override
public String getSyntax() {
return "export";
}

@Override
public String getDescription() {
return "Used to export shop v2 data";
}
}
3 changes: 2 additions & 1 deletion src/main/java/ca/tweetzy/shops/managers/StorageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public AbstractCommand.ReturnType removeShop(Player player, String shopId) {
}
});
} else {
if (!ShopAPI.getInstance().exists(shopId)) {
Shop shop = Shops.getInstance().getShopManager().getShop(shopId);
if (shop == null) {
Shops.getInstance().getLocale().getMessage("shop.does_not_exists").processPlaceholder("shop_id", shopId).sendPrefixedMessage(player);
return AbstractCommand.ReturnType.FAILURE;
}
Expand Down

0 comments on commit f6ada4c

Please sign in to comment.