Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command plugin compatability into GeneralCommands #2041

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class BukkitConfigurationManager extends YamlConfigurationManager {

private boolean hasCommandBookGodMode;
boolean extraStats;
private boolean hasEssentialsGodMode;

/**
* Construct the object.
Expand Down Expand Up @@ -124,4 +125,12 @@ public void updateCommandBookGodMode() {
public boolean hasCommandBookGodMode() {
return hasCommandBookGodMode;
}

public void updateEssentialsGodMode() {
hasEssentialsGodMode = plugin.getServer().getPluginManager().isPluginEnabled("Essentials");
}

public boolean hasEssentialsGodMode() {
return hasEssentialsGodMode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import com.sk89q.worldguard.bukkit.util.Entities;
import com.sk89q.worldguard.bukkit.util.Events;
import com.sk89q.worldguard.commands.GeneralCommands;
import com.sk89q.worldguard.commands.GeneralCompatibleCommands;
import com.sk89q.worldguard.commands.ProtectionCommands;
import com.sk89q.worldguard.commands.ToggleCommands;
import com.sk89q.worldguard.domains.registry.SimpleDomainRegistry;
Expand Down Expand Up @@ -160,8 +161,13 @@ public void onEnable() {
reg.register(ToggleCommands.class);
reg.register(ProtectionCommands.class);

if (!platform.getGlobalStateManager().hasCommandBookGodMode()) {
platform.getGlobalStateManager().updateCommandBookGodMode();
platform.getGlobalStateManager().updateEssentialsGodMode();

if (!platform.getGlobalStateManager().hasCommandBookGodMode() && !platform.getGlobalStateManager().hasEssentialsGodMode()) {
reg.register(GeneralCommands.class);
}else{
reg.register(GeneralCompatibleCommands.class);
}

getServer().getScheduler().scheduleSyncRepeatingTask(this, sessionManager, BukkitSessionManager.RUN_DELAY, BukkitSessionManager.RUN_DELAY);
Expand Down Expand Up @@ -192,8 +198,6 @@ public void onEnable() {
(new DebuggingListener(this, WorldGuard.logger)).registerEvents();
}

platform.getGlobalStateManager().updateCommandBookGodMode();

if (getServer().getPluginManager().isPluginEnabled("CommandBook")) {
getServer().getPluginManager().registerEvents(new WorldGuardCommandBookListener(this), this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,20 @@ public void onPluginEnable(PluginEnableEvent event) {
if (event.getPlugin().getDescription().getName().equalsIgnoreCase("CommandBook")) {
getConfig().updateCommandBookGodMode();
}

if(event.getPlugin().getDescription().getName().equalsIgnoreCase("Essentials")){
getConfig().updateEssentialsGodMode();
}
}

@EventHandler
public void onPluginDisable(PluginDisableEvent event) {
if (event.getPlugin().getDescription().getName().equalsIgnoreCase("CommandBook")) {
getConfig().updateCommandBookGodMode();
}

if(event.getPlugin().getDescription().getName().equalsIgnoreCase("Essentials")){
getConfig().updateEssentialsGodMode();
}
}
}
2 changes: 1 addition & 1 deletion worldguard-bukkit/src/main/resources/defaults/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# - If you want to check the format of this file before putting it
# into WorldGuard, paste it into http://yaml-online-parser.appspot.com/
# and see if it gives "ERROR:".
# - Lines starting with # are commentsand so they are ignored.
# - Lines starting with # are comments and so they are ignored.
#
# WARNING:
# Remember to check the compatibility spreadsheet for WorldGuard to see
Expand Down
2 changes: 1 addition & 1 deletion worldguard-bukkit/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ name: WorldGuard
main: com.sk89q.worldguard.bukkit.WorldGuardPlugin
version: "${internalVersion}"
depend: [WorldEdit]
softdepend: [CommandBook]
softdepend: [CommandBook, Essentials]
api-version: "1.20"
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public GeneralCommands(WorldGuard worldGuard) {
this.worldGuard = worldGuard;
}

@Command(aliases = {"god"}, usage = "[player]",
@Command(aliases = {"god", "wggod"}, usage = "[player]",
desc = "Enable godmode on a player", flags = "s", max = 1)
public void god(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
Iterable<? extends LocalPlayer> targets = null;
Expand Down Expand Up @@ -84,7 +84,7 @@ public void god(CommandContext args, Actor sender) throws CommandException, Auth
}
}

@Command(aliases = {"ungod"}, usage = "[player]",
@Command(aliases = {"ungod", "wgungod"}, usage = "[player]",
desc = "Disable godmode on a player", flags = "s", max = 1)
public void ungod(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
Iterable<? extends LocalPlayer> targets;
Expand Down Expand Up @@ -127,7 +127,7 @@ public void ungod(CommandContext args, Actor sender) throws CommandException, Au
}
}

@Command(aliases = {"heal"}, usage = "[player]", desc = "Heal a player", flags = "s", max = 1)
@Command(aliases = {"heal", "wgheal"}, usage = "[player]", desc = "Heal a player", flags = "s", max = 1)
public void heal(CommandContext args, Actor sender) throws CommandException, AuthorizationException {

Iterable<? extends LocalPlayer> targets = null;
Expand Down Expand Up @@ -171,7 +171,7 @@ public void heal(CommandContext args, Actor sender) throws CommandException, Aut
}
}

@Command(aliases = {"slay"}, usage = "[player]", desc = "Slay a player", flags = "s", max = 1)
@Command(aliases = {"slay", "wgslay"}, usage = "[player]", desc = "Slay a player", flags = "s", max = 1)
public void slay(CommandContext args, Actor sender) throws CommandException, AuthorizationException {

Iterable<? extends LocalPlayer> targets = Lists.newArrayList();
Expand Down Expand Up @@ -212,7 +212,7 @@ public void slay(CommandContext args, Actor sender) throws CommandException, Aut
}
}

@Command(aliases = {"locate"}, usage = "[player]", desc = "Locate a player", max = 1)
@Command(aliases = {"locate", "locate"}, usage = "[player]", desc = "Locate a player", max = 1)
@CommandPermissions({"worldguard.locate"})
public void locate(CommandContext args, Actor sender) throws CommandException {
LocalPlayer player = worldGuard.checkPlayer(sender);
Expand All @@ -229,7 +229,7 @@ public void locate(CommandContext args, Actor sender) throws CommandException {
}
}

@Command(aliases = {"stack", ";"}, usage = "", desc = "Stack items", max = 0)
@Command(aliases = {"stack", "wgstack", ";"}, usage = "", desc = "Stack items", max = 0)
@CommandPermissions({"worldguard.stack"})
public void stack(CommandContext args, Actor sender) throws CommandException {
LocalPlayer player = worldGuard.checkPlayer(sender);
Expand All @@ -238,4 +238,6 @@ public void stack(CommandContext args, Actor sender) throws CommandException {

player.print("Items compacted into stacks!");
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard 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.worldguard.commands;

import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.util.auth.AuthorizationException;
import com.sk89q.worldguard.WorldGuard;

public class GeneralCompatibleCommands {
private final GeneralCommands generalCommands;

public GeneralCompatibleCommands(WorldGuard worldGuard) {
this.generalCommands = new GeneralCommands(worldGuard);
}

@Command(aliases = {"wggod"}, usage = "[player]",
desc = "Enable godmode on a player", flags = "s", max = 1)
public void god(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
generalCommands.god(args, sender);
}

@Command(aliases = {"wgungod"}, usage = "[player]",
desc = "Disable godmode on a player", flags = "s", max = 1)
public void ungod(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
generalCommands.ungod(args, sender);
}

@Command(aliases = {"wgheal"}, usage = "[player]", desc = "Heal a player", flags = "s", max = 1)
public void heal(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
generalCommands.heal(args, sender);
}

@Command(aliases = {"wgslay"}, usage = "[player]", desc = "Slay a player", flags = "s", max = 1)
public void slay(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
generalCommands.slay(args, sender);
}

@Command(aliases = {"wglocate"}, usage = "[player]", desc = "Locate a player", max = 1)
@CommandPermissions({"worldguard.locate"})
public void locate(CommandContext args, Actor sender) throws CommandException {
generalCommands.locate(args, sender);
}

@Command(aliases = {"wgstack", ";"}, usage = "", desc = "Stack items", max = 0)
@CommandPermissions({"worldguard.stack"})
public void stack(CommandContext args, Actor sender) throws CommandException {
generalCommands.stack(args, sender);
}
}