-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2.18.0 - Export command in preparation for the future 3.0 release
- Loading branch information
Showing
4 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/main/java/ca/tweetzy/shops/commands/CommandExport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters