Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Cleanup the god commands
  • Loading branch information
DarkArc committed Aug 1, 2020
1 parent 83d67f8 commit 014aec0
Showing 1 changed file with 50 additions and 30 deletions.
80 changes: 50 additions & 30 deletions src/main/java/com/sk89q/commandbook/component/god/GodCommands.java
@@ -1,10 +1,31 @@
/*
* CommandBook
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) CommandBook team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.sk89q.commandbook.component.god;

import com.sk89q.commandbook.CommandBook;
import com.sk89q.commandbook.command.argument.MultiPlayerTarget;
import com.sk89q.commandbook.util.ChatUtil;
import com.sk89q.commandbook.util.entity.player.PlayerUtil;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand All @@ -13,22 +34,15 @@
import org.enginehub.piston.annotation.param.Arg;
import org.enginehub.piston.annotation.param.Switch;

@CommandContainer
class GodCommands {
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
public class GodCommands {
private GodComponent component;

public GodCommands(GodComponent component) {
this.component = component;
}

@Command(name = "god", desc = "Enable godmode on a player")
public void godCmd(CommandSender sender,
@Switch (name = 's', desc = "silent") boolean silent,
@Arg(desc = "Player(s) to target", def = "") MultiPlayerTarget targetPlayers)
throws CommandException {

boolean included = false;

private MultiPlayerTarget processTargets(CommandSender sender, MultiPlayerTarget targetPlayers) throws CommandException {
if (targetPlayers == null) {
targetPlayers = new MultiPlayerTarget(PlayerUtil.checkPlayer(sender));
}
Expand All @@ -39,10 +53,25 @@ public void godCmd(CommandSender sender,
CommandBook.inst().checkPermission(sender, "commandbook.god");
} else {
CommandBook.inst().checkPermission(sender, "commandbook.god.other");
break;
}
}

return targetPlayers;
}

@Command(
name = "god",
desc = "Enable godmode on a player"
)
@CommandPermissions({"commandbook.god", "commandbook.god.other"})
public void godCmd(CommandSender sender,
@Switch (name = 's', desc = "silent")
boolean silent,
@Arg(desc = "player(s) to target", def = "")
MultiPlayerTarget targetPlayers) throws CommandException {
targetPlayers = processTargets(sender, targetPlayers);

boolean included = false;
for (Player player : targetPlayers) {
if (!component.hasGodMode(player)) {
component.enableGodMode(player);
Expand Down Expand Up @@ -77,28 +106,19 @@ public void godCmd(CommandSender sender,
}
}

@Command(name = "ungod", desc = "Disable godmode on a player")
@Command(
name = "ungod",
desc = "Disable godmode on a player"
)
@CommandPermissions({"commandbook.god", "commandbook.god.other"})
public void ungodCmd(CommandSender sender,
@Switch (name = 's', desc = "silent") boolean silent,
@Arg(desc = "Player to target", def = "") MultiPlayerTarget targetPlayers)
throws CommandException {
@Switch (name = 's', desc = "silent")
boolean silent,
@Arg(desc = "player(s) to target", def = "")
MultiPlayerTarget targetPlayers) throws CommandException {
targetPlayers = processTargets(sender, targetPlayers);

boolean included = false;

if (targetPlayers == null) {
targetPlayers = new MultiPlayerTarget(PlayerUtil.checkPlayer(sender));
}

// Check permissions!
for (Player player : targetPlayers) {
if (player == sender) {
CommandBook.inst().checkPermission(sender, "commandbook.god");
} else {
CommandBook.inst().checkPermission(sender, "commandbook.god.other");
break;
}
}

for (Player player : targetPlayers) {
if (component.hasGodMode(player)) {
component.disableGodMode(player);
Expand Down

0 comments on commit 014aec0

Please sign in to comment.