App-minecraft
view release on metacpan or search on metacpan
NAME
App::minecraft - Backup and restore your Minecraft. Install mods.
USAGE
$ minecraft.pl backup
$ minecraft.pl install Shelf.zip
$ minecraft.pl install --jar /usr/local/bin/jar Shelf.zip
$ minecraft.pl restore --verbose
DESCRIPTION
As it stands this script is very limited. However, I did manage to
successfully backup my Minecraft folder, install the Shelf mod in the
sample directory and restore my Minecraft without any problems. Remember
to always perform a backup using the 'backup' parameter before
installing any mod, because this script can, and probably will, corrupt
your main jar file. So use it at your own peril!
In the future I'd like it to properly check the contents of each zip
before doing anything. Some mods have different formats, and
App::minecraft needs to be smart enough to handle those and know what to
do with them.
AUTHOR
Brad Haywood <brad@perlpowered.com>
lib/App/minecraft.pm view on Meta::CPAN
package App::minecraft;
our $VERSION = '0.001';
=head1 NAME
App::minecraft - Backup and restore your Minecraft. Install mods.
=head1 USAGE
$ minecraft.pl backup
$ minecraft.pl install Shelf.zip
$ minecraft.pl install --jar /usr/local/bin/jar Shelf.zip
$ minecraft.pl restore --verbose
=head1 DESCRIPTION
As it stands this script is very limited. However, I did manage to successfully backup my Minecraft folder, install the Shelf mod in the sample directory and restore my Minecraft without any problems.
Remember to always perform a backup using the 'backup' parameter before installing any mod, because this script can, and probably will, corrupt your main jar file. So use it at your own peril!
In the future I'd like it to properly check the contents of each zip before doing anything. Some mods have different formats, and App::minecraft needs to be smart enough to handle those and know what to do with them.
=head1 AUTHOR
Brad Haywood <brad@perlpowered.com>
=head1 LICENSE
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
script/minecraft.pl view on Meta::CPAN
use 5.010;
use Cwd qw(getcwd abs_path);
use Archive::Zip qw(:ERROR_CODES);
use File::Path qw(rmtree);
use File::Copy::Recursive qw(fcopy dircopy);
my $jar_bin;
my $mod;
my $verbose = 0;
my $backup = 0;
my $restore = 0;
my $home = $ENV{HOME}
or die "Could not get home from \$ENV\n";
my $app_dir = "${home}/.minecraft-app";
my $last = $ARGV[ scalar(@ARGV) -1 ];
sub _show_usage {
print STDERR "Minecraft App\n\n";
print STDERR "Options:\n";
print STDERR " backup - Backups Minecraft directory\n";
print STDERR " restore - Restores Minecraft directory from backup\n";
print STDERR " install <zip> - Installs a mod (Requres zip format)\n\n";
print STDERR "Flags:\n";
print STDERR " -h - This menu\n";
print STDERR " -v|--verbose - More warnings\n";
print STDERR " -j|--jar - Override location of jar binary\n";
exit(0);
}
while(my $arg = shift @ARGV) {
for ($arg) {
if (/^backup$/) { $backup = 1; }
elsif (/^restore$/) { $restore = 1; }
elsif (/^install$/) { $mod = 1; }
elsif (/^-v$|^--verbose$/) { $verbose = 1; }
elsif (/^-j$|^--jar$/) { $jar_bin = shift @ARGV; }
elsif (/^-h$|^--help$/) { _show_usage(); }
}
}
$mod = $last
if $mod;
_show_usage()
if not $mod and not $backup and not $restore;
sub _create_config {
open my $cfg, '>', "${app_dir}/config.yml" or
return (0, "Could not write to ${app_dir}/config.yml");
print $cfg "Minecraft:\n";
print $cfg " bin: ${app_dir}/minecraft.jar\n";
close $cfg;
return 1;
}
script/minecraft.pl view on Meta::CPAN
say "Found in ${jar_bin}" if $verbose;
}
else {
say "Failed" if $verbose;
die "[error] Could not find the 'jar' binary in your paths or config\n";
}
}
}
}
if ($backup and $restore) {
die "[stupidity] Why are you trying to backup and restore at the same time?\n";
}
sub _run_backup {
if (my $num_files_and_dirs = dircopy("${home}/.minecraft", "${app_dir}/minecraft")) {
say "[info] Successfully backed up ${num_files_and_dirs} files and directories";
exit(0);
}
else {
die "[error] Backup failed\n";
}
}
sub _run_restore {
script/minecraft.pl view on Meta::CPAN
}
else {
die "[error] Can't find mod ${mod}\n";
}
}
else {
die "[error] No mod was chosen to be installed\n";
}
}
_run_backup() if $backup;
_run_restore() if $restore;
_run_install() if $mod;
( run in 0.641 second using v1.01-cache-2.11-cpan-49f99fa48dc )