Add clone commands

This commit is contained in:
Luck 2016-09-29 18:07:41 +01:00
parent cb89a92ba9
commit 41744f9416
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
8 changed files with 153 additions and 2 deletions

View File

@ -63,6 +63,7 @@ public class GroupMainCommand extends MainCommand<Group> {
.add(new GroupBulkChange())
.add(new GroupClear())
.add(new GroupRename())
.add(new GroupClone())
.build()
);
}

View File

@ -0,0 +1,73 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* 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 me.lucko.luckperms.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.*;
import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.data.LogEntry;
import me.lucko.luckperms.groups.Group;
import me.lucko.luckperms.utils.ArgumentChecker;
import java.util.List;
public class GroupClone extends SubCommand<Group> {
public GroupClone() {
super("clone", "Clone the group", Permission.GROUP_CLONE, Predicate.not(1),
Arg.list(Arg.create("name", true, "the name of the clone"))
);
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
String newGroupName = args.get(0).toLowerCase();
if (ArgumentChecker.checkName(newGroupName)) {
Message.GROUP_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (plugin.getDatastore().loadGroup(newGroupName)) {
Message.GROUP_ALREADY_EXISTS.send(sender);
return CommandResult.INVALID_ARGS;
}
if (!plugin.getDatastore().createAndLoadGroup(newGroupName)) {
Message.CREATE_GROUP_ERROR.send(sender);
return CommandResult.FAILURE;
}
Group newGroup = plugin.getGroupManager().get(newGroupName);
if (newGroup == null) {
Message.GROUP_LOAD_ERROR.send(sender);
return CommandResult.LOADING_ERROR;
}
plugin.getGroupManager().copy(group, newGroup);
Message.CLONE_SUCCESS.send(sender, group.getName(), newGroup.getName());
LogEntry.build().actor(sender).acted(group).action("clone " + newGroup.getName()).build().submit(plugin, sender);
save(newGroup, sender, plugin);
return CommandResult.SUCCESS;
}
}

View File

@ -34,7 +34,7 @@ import java.util.List;
public class GroupRename extends SubCommand<Group> {
public GroupRename() {
super("rename", "Rename the group", Permission.TRACK_APPEND, Predicate.not(1),
super("rename", "Rename the group", Permission.GROUP_RENAME, Predicate.not(1),
Arg.list(Arg.create("name", true, "the new name"))
);
}

View File

@ -43,6 +43,7 @@ public class TrackMainCommand extends MainCommand<Track> {
.add(new TrackRemove())
.add(new TrackClear())
.add(new TrackRename())
.add(new TrackClone())
.build()
);
}

View File

@ -0,0 +1,73 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* 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 me.lucko.luckperms.commands.track.subcommands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.*;
import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.data.LogEntry;
import me.lucko.luckperms.tracks.Track;
import me.lucko.luckperms.utils.ArgumentChecker;
import java.util.List;
public class TrackClone extends SubCommand<Track> {
public TrackClone() {
super("clone", "Clone the track", Permission.TRACK_CLONE, Predicate.not(1),
Arg.list(Arg.create("name", true, "the name of the clone"))
);
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
String newTrackName = args.get(0).toLowerCase();
if (ArgumentChecker.checkName(newTrackName)) {
Message.TRACK_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (plugin.getDatastore().loadTrack(newTrackName)) {
Message.TRACK_ALREADY_EXISTS.send(sender);
return CommandResult.INVALID_ARGS;
}
if (!plugin.getDatastore().createAndLoadTrack(newTrackName)) {
Message.CREATE_TRACK_ERROR.send(sender);
return CommandResult.FAILURE;
}
Track newTrack = plugin.getTrackManager().get(newTrackName);
if (newTrack == null) {
Message.TRACK_LOAD_ERROR.send(sender);
return CommandResult.LOADING_ERROR;
}
plugin.getTrackManager().copy(track, newTrack);
Message.CLONE_SUCCESS.send(sender, track.getName(), newTrack.getName());
LogEntry.build().actor(sender).acted(track).action("clone " + newTrack.getName()).build().submit(plugin, sender);
save(newTrack, sender, plugin);
return CommandResult.SUCCESS;
}
}

View File

@ -34,7 +34,7 @@ import java.util.List;
public class TrackRename extends SubCommand<Track> {
public TrackRename() {
super("rename", "Rename the track", Permission.TRACK_APPEND, Predicate.not(1),
super("rename", "Rename the track", Permission.TRACK_RENAME, Predicate.not(1),
Arg.list(Arg.create("name", true, "the new name"))
);
}

View File

@ -93,6 +93,7 @@ public enum Message {
CREATE_SUCCESS("&b{0}&a was successfully created.", true),
DELETE_SUCCESS("&b{0}&a was successfully deleted.", true),
RENAME_SUCCESS("&b{0}&a was successfully renamed to &b{1}&a.", true),
CLONE_SUCCESS("&b{0}&a was successfully cloned to &b{1}&a.", true),
USER_ALREADY_MEMBER_OF("{0} is already a member of '{1}'.", true),
USER_NOT_MEMBER_OF("{0} is not a member of '{1}'.", true),

View File

@ -101,6 +101,7 @@ public enum Permission {
GROUP_BULKCHANGE("bulkchange", "group"),
GROUP_CLEAR("clear", "group"),
GROUP_RENAME("rename", "group"),
GROUP_CLONE("clone", "group"),
TRACK_INFO("info", "track"),
TRACK_APPEND("append", "track"),
@ -108,6 +109,7 @@ public enum Permission {
TRACK_REMOVE("remove", "track"),
TRACK_CLEAR("clear", "track"),
TRACK_RENAME("rename", "track"),
TRACK_CLONE("clone", "track"),
LOG_RECENT("recent", "log"),
LOG_USER_HISTORY("userhistory", "log"),