Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
Added migration command and bumped version
Browse files Browse the repository at this point in the history
  • Loading branch information
Flibio committed Apr 3, 2016
1 parent 106f72c commit a55d252
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sourceCompatibility = '1.8'
targetCompatibility = '1.8'

group 'io.github.flibio'
version '2.0.0'
version '2.0.1'

defaultTasks 'licenseFormat', 'clean', 'build'

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/github/flibio/economylite/EconomyLite.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import io.github.flibio.economylite.api.CurrencyEconService;
import io.github.flibio.economylite.api.PlayerEconService;
import io.github.flibio.economylite.api.VirtualEconService;
import io.github.flibio.economylite.commands.MigrateCommand;
import io.github.flibio.economylite.commands.PayCommand;
import io.github.flibio.economylite.commands.admin.AddCommand;
import io.github.flibio.economylite.commands.admin.EconCommand;
Expand Down Expand Up @@ -136,7 +137,8 @@ public void onServerInitialize(GameInitializationEvent event) {
new PayCommand(),
new BalTopCommand(),
new VirtualBalanceCommand(),
new VirtualSetCommand()
new VirtualSetCommand(),
new MigrateCommand()
);
// Register currency registry
game.getRegistry().registerModule(Currency.class, new CurrencyRegistryModule());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* This file is part of EconomyLite, licensed under the MIT License (MIT).
*
* Copyright (c) 2015 - 2016 Flibio
* Copyright (c) Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.github.flibio.economylite.commands;

import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
import ninja.leaping.configurate.loader.ConfigurationLoader;

import org.slf4j.Logger;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.command.args.GenericArguments;
import org.spongepowered.api.command.spec.CommandSpec;
import org.spongepowered.api.command.spec.CommandSpec.Builder;
import org.spongepowered.api.text.Text;

import io.github.flibio.economylite.EconomyLite;
import io.github.flibio.economylite.api.PlayerEconService;
import io.github.flibio.economylite.api.VirtualEconService;
import io.github.flibio.utils.commands.AsyncCommand;
import io.github.flibio.utils.commands.BaseCommandExecutor;
import io.github.flibio.utils.commands.Command;
import io.github.flibio.utils.message.MessageStorage;

import java.io.File;
import java.math.BigDecimal;
import java.util.UUID;

@AsyncCommand
@Command(aliases = {"migrate"}, permission = "economylite.admin.migrate")
public class MigrateCommand extends BaseCommandExecutor<CommandSource> {

private MessageStorage messageStorage = EconomyLite.getMessageStorage();
private PlayerEconService playerService = EconomyLite.getPlayerService();
private VirtualEconService virtualService = EconomyLite.getVirtualService();
private Logger logger = EconomyLite.getInstance().getLogger();

@Override
public Builder getCommandSpecBuilder() {
return CommandSpec.builder()
.executor(this)
.arguments(GenericArguments.optional(GenericArguments.bool(Text.of("confirm"))));
}

@Override
public void run(CommandSource src, CommandContext args) {
if (args.getOne("confirm").isPresent()) {
File file = new File("config/economylite/data.conf");
File bFile = new File("config/economylite/businesses.conf");
try {
if (file.exists()) {
ConfigurationLoader<?> manager = HoconConfigurationLoader.builder().setFile(file).build();
ConfigurationNode root = manager.load();
root.getChildrenMap().keySet().forEach(raw -> {
if (raw instanceof String) {
UUID uuid = UUID.fromString((String) raw);
if (root.getNode(uuid.toString()).getNode("balance") != null) {
int balance = root.getNode(uuid.toString()).getNode("balance").getInt();
playerService.setBalance(uuid, BigDecimal.valueOf(balance), EconomyLite.getEconomyService().getDefaultCurrency());
}
}
});
}
if (bFile.exists()) {
ConfigurationLoader<?> manager = HoconConfigurationLoader.builder().setFile(bFile).build();
ConfigurationNode root = manager.load();
root.getChildrenMap().keySet().forEach(raw -> {
if (raw instanceof String) {
String name = (String) raw;
if (root.getNode(name).getNode("balance") != null) {
int balance = root.getNode(name).getNode("balance").getInt();
virtualService.setBalance(name, BigDecimal.valueOf(balance), EconomyLite.getEconomyService().getDefaultCurrency());
}
}
});
}
src.sendMessage(messageStorage.getMessage("command.migrate.completed"));
} catch (Exception e) {
logger.error(e.getMessage());
src.sendMessage(messageStorage.getMessage("command.migrate.fail"));
}
} else {
src.sendMessage(messageStorage.getMessage("command.migrate.confirm"));
}
}

}
4 changes: 4 additions & 0 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ command.econ.removesuccess=&aSuccessfully removed currency from the balance of &
command.econ.setfail=&cFailed to set the balance of {name}!
command.econ.setsuccess=&aSuccessfully set the balance of &6{name}!

command.migrate.completed=&aMigration completed!
command.migrate.confirm=&cMigrating will override any existing balances. &6Run &a/migrate yes &6to confirm the migration!
command.migrate.fail=&cMigration failed!

command.pay.notyou=&cYou can not pay yourself!
command.pay.failed=&cThe payment to {target} failed!
command.pay.success=&aSuccessfully payed &6{target}!

0 comments on commit a55d252

Please sign in to comment.