Commit 850ec4a3 authored by Nico Eckes's avatar Nico Eckes

Command overhaul (probably not finished), added suffixes, fixed prefixes

parent f5fe4e2b
Pipeline #754 passed with stage
in 3 minutes and 27 seconds
......@@ -85,6 +85,5 @@ public interface IPermissionHolder {
void unregisterSubHolder(IPermissionHolder holder);
void load(Map<String, Object> map);
Map<String, Object> save();
}
\ No newline at end of file
package com.unitedworldminers.permio.commands;
import com.unitedworldminers.BaseIO.util.CommandNode;
import com.unitedworldminers.permio.commands.general.CmdRemoveinheritance;
import com.unitedworldminers.permio.commands.general.CmdSetinheritance;
import com.unitedworldminers.permio.commands.group.*;
import net.minecraft.command.ICommand;
import org.jetbrains.annotations.NotNull;
......@@ -12,7 +14,7 @@ public class CmdGroup extends CommandNode {
@NotNull
@Override
protected List<ICommand> subCommands() {
return Arrays.asList(new CmdAddinheritance(), new CmdRemoveinheritance(), new CmdRename(), new CmdCreate(), new CmdList(), new CmdRemove());
return Arrays.asList(new CmdRename(), new CmdCreate(), new CmdList(), new CmdRemove());
}
@NotNull
......
......@@ -22,7 +22,7 @@ public class CmdPermission extends CommandNode {
@NotNull
@Override
protected List<ICommand> subCommands() {
return Arrays.asList(new CmdUser(), new CmdGroup(), new CmdReload(), new CmdAddperm(), new CmdRemovePerm(), new CmdPrefix(), new CmdInfo(), new CmdDebug(), new CmdTestPerm());
return Arrays.asList(new CmdSetinheritance(), new CmdRemoveinheritance(), new CmdUser(), new CmdGroup(), new CmdReload(), new CmdAddperm(), new CmdRemovePerm(), new CmdPrefix(), new CmdSuffix(), new CmdInfo(), new CmdDebug(), new CmdTestPerm());
}
@NotNull
......
package com.unitedworldminers.permio.commands;
import com.unitedworldminers.BaseIO.util.CommandNode;
import com.unitedworldminers.permio.commands.player.CmdAddgroup;
import com.unitedworldminers.permio.commands.player.CmdRemovegroup;
import com.unitedworldminers.permio.commands.player.CmdSetgroup;
import net.minecraft.command.ICommand;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class CmdUser extends CommandNode {
@NotNull
@Override
protected List<ICommand> subCommands() {
return Arrays.asList(new CmdAddgroup(), new CmdRemovegroup());
return Collections.singletonList(new CmdSetgroup());
}
@NotNull
......
package com.unitedworldminers.permio.commands.group;
package com.unitedworldminers.permio.commands.general;
import com.unitedworldminers.BaseIO.util.MessageUtils;
import com.unitedworldminers.BaseIO.util.SimpleCommand;
import com.unitedworldminers.permio.api.IGroup;
import com.unitedworldminers.permio.commands.CmdPermission;
import com.unitedworldminers.permio.permissions.Permissions;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.server.MinecraftServer;
import org.jetbrains.annotations.NotNull;
......
package com.unitedworldminers.permio.commands.group;
package com.unitedworldminers.permio.commands.general;
import com.unitedworldminers.BaseIO.util.MessageUtils;
import com.unitedworldminers.BaseIO.util.SimpleCommand;
......@@ -16,15 +16,15 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class CmdAddinheritance extends SimpleCommand {
public class CmdSetinheritance extends SimpleCommand {
@Override
public String commandUsage(ICommandSender sender) {
return "commands.addinheritance.usage";
return "commands.setinheritance.usage";
}
@Override
public List<String> commandNames() {
return Collections.singletonList("addinheritance");
return Collections.singletonList("setinheritance");
}
@Override
......@@ -40,15 +40,15 @@ public class CmdAddinheritance extends SimpleCommand {
try {
group.setInheritance(inherit);
} catch (InheritanceLoopException e) {
MessageUtils.messageToSender(sender, "commands.addinheritance.looperror", inherit.getGroupId(), group.getGroupId());
MessageUtils.messageToSender(sender, "commands.setinheritance.looperror", inherit.getGroupId(), group.getGroupId());
return;
}
MessageUtils.messageToSender(sender, "commands.addinheritance.success", group.getGroupId(), inherit.getGroupId());
MessageUtils.messageToSender(sender, "commands.setinheritance.success", group.getGroupId(), inherit.getGroupId());
}
@Override
public boolean checkPermission(@NotNull MinecraftServer server, @NotNull ICommandSender sender) {
return Permissions.INSTANCE.getPlayer(sender).hasPermission("commands.addinheritance");
return Permissions.INSTANCE.getPlayer(sender).hasPermission("commands.setinheritance");
}
@Override
......
package com.unitedworldminers.permio.commands.player;
package com.unitedworldminers.permio.commands.general;
import com.unitedworldminers.BaseIO.util.MessageUtils;
import com.unitedworldminers.BaseIO.util.SimpleCommand;
import com.unitedworldminers.permio.api.IGroup;
import com.unitedworldminers.permio.api.IPlayer;
import com.unitedworldminers.permio.api.exceptions.InheritanceLoopException;
import com.unitedworldminers.permio.api.IPermissionHolder;
import com.unitedworldminers.permio.commands.CmdPermission;
import com.unitedworldminers.permio.permissions.Permissions;
import net.minecraft.command.ICommandSender;
......@@ -17,38 +16,39 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class CmdRemovegroup extends SimpleCommand {
public class CmdSuffix extends SimpleCommand {
@Override
public String commandUsage(ICommandSender sender) {
return "commands.removegroup.usage";
return "commands.suffix.usage";
}
@Override
public List<String> commandNames() {
return Collections.singletonList("removegroup");
return Collections.singletonList("suffix");
}
@Override
public void run(ICommandSender sender, String[] args, Map<String, String[]> options) {
if (args.length < 2) {
if (args.length == 0) {
MessageUtils.messageToSender(sender, getCommandUsage(sender));
return;
}
IPlayer player = CmdPermission.getPlayer(sender, args[0]);
if (player == null) return;
IGroup group = CmdPermission.getGroup(sender, args[1]);
if (group == null) return;
try {
player.setInheritance(Permissions.INSTANCE.defaultGroup);
} catch (InheritanceLoopException ignored) {
// default group
if (args.length > 1 && args[1].equalsIgnoreCase("set")) {
IPermissionHolder holder = CmdPermission.getHolder(sender, args[0]);
if (holder == null) return;
String suffix = args.length == 2 || args[2].isEmpty() ? null : args[2];
holder.setSuffix(suffix);
MessageUtils.messageToSender(sender, "commands.suffix.set", args[0], String.valueOf(suffix));
} else {
IPermissionHolder holder = CmdPermission.getHolder(sender, args[0]);
if (holder == null) return;
MessageUtils.messageToSender(sender, "commands.suffix.get", args[0], String.valueOf(holder.getSuffix()));
}
MessageUtils.messageToSender(sender, "commands.removegroup.success", group.getGroupId(), args[0]);
}
@Override
public boolean checkPermission(@NotNull MinecraftServer server, @NotNull ICommandSender sender) {
return Permissions.INSTANCE.getPlayer(sender).hasPermission("commands.removegroup");
return Permissions.INSTANCE.getPlayer(sender).hasPermission("commands.suffix");
}
@Override
......@@ -58,6 +58,6 @@ public class CmdRemovegroup extends SimpleCommand {
@Override
protected String tabCompletions() {
return "%p %g";
return "%p|%g set";
}
}
......@@ -17,15 +17,15 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class CmdAddgroup extends SimpleCommand {
public class CmdSetgroup extends SimpleCommand {
@Override
public String commandUsage(ICommandSender sender) {
return "commands.addgroup.usage";
return "commands.setgroup.usage";
}
@Override
public List<String> commandNames() {
return Collections.singletonList("addgroup");
return Collections.singletonList("setgroup");
}
@Override
......@@ -41,15 +41,15 @@ public class CmdAddgroup extends SimpleCommand {
try {
player.setInheritance(group);
} catch (InheritanceLoopException e) {
MessageUtils.messageToSender(sender, "commands.addgroup.inheritanceloop");
MessageUtils.messageToSender(sender, "commands.setgroup.inheritanceloop");
return;
}
MessageUtils.messageToSender(sender, "commands.addgroup.success", group.getGroupId(), args[0]);
MessageUtils.messageToSender(sender, "commands.setgroup.success", group.getGroupId(), args[0]);
}
@Override
public boolean checkPermission(@NotNull MinecraftServer server, @NotNull ICommandSender sender) {
return Permissions.INSTANCE.getPlayer(sender).hasPermission("commands.addgroup");
return Permissions.INSTANCE.getPlayer(sender).hasPermission("commands.setgroup");
}
@Override
......
......@@ -87,8 +87,8 @@ public class PermissionHolder implements IPermissionHolder {
@Override
public void setPrefix(@Nullable String prefix) {
IPermissionHolder.super.setPrefix(prefix);
this.prefix = prefix;
IPermissionHolder.super.setPrefix(prefix);
}
@Nullable
......@@ -99,8 +99,8 @@ public class PermissionHolder implements IPermissionHolder {
@Override
public void setSuffix(@Nullable String suffix) {
IPermissionHolder.super.setSuffix(suffix);
this.suffix = suffix;
IPermissionHolder.super.setSuffix(suffix);
}
@Nullable
......
......@@ -79,6 +79,9 @@ public class Player extends PermissionHolder implements IPlayer {
player.getSuffixes().removeIf(tc-> tc instanceof PermioPrefix);
String suffix = getVisibleSuffix();
if (suffix != null) player.addSuffix(new PermioPrefix(prefix));
player.refreshDisplayName();
player.getPrefixes().forEach(t->System.out.println(t.getFormattedText()));
}
super.updatePlayerLabels();
}
......
commands.addgroup.usage=/perm addperm <group|user> <perm>
commands.addgroup.success=Added group %s to %s.
commands.addinheritance.usage=/perm group addInheritance <group> <inheritance>
commands.addinheritance.looperror=Adding %s to %s would cause a loop of inheritances!
commands.addinheritance.success=Added %s as inheritance for %s.
commands.setgroup.usage=/perm addperm <group|user> <perm>
commands.setgroup.success=Added group %s to %s.
commands.setinheritance.usage=/perm group setinheritance <group> <inheritance>
commands.setinheritance.looperror=Adding %s to %s would cause a loop of inheritances!
commands.setinheritance.success=Added %s as inheritance for %s.
commands.addperm.usage=/perm addperm <group|user> <perm>
commands.addperm.success=Added %s to %s.
commands.create.usage=/perm group create <groupid>
......@@ -22,6 +22,9 @@ commands.holdernotfound=There's no such group or player named '%s'!
commands.prefix.usage=/perm prefix <group|user> [set <newprefix>]
commands.prefix.set=Successfully set the prefix of %s to %s
commands.prefix.get=The prefix of %s is %s.
commands.suffix.usage=/perm suffix <group|user> [set <newsuffix>]
commands.suffix.set=Successfully set the suffix of %s to %s
commands.suffix.get=The suffix of %s is %s.
commands.reload.usage=/perm reload
commands.reload.groups.success=Successfully reloaded the groups.
commands.reload.players.success=Successfully reloaded the players.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment