Skip to content

Commit

Permalink
Version check on /is and /usb
Browse files Browse the repository at this point in the history
  • Loading branch information
rlf committed Dec 26, 2014
1 parent c9ed96a commit fdfb9b9
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class DevCommand implements CommandExecutor, TabCompleter {
private Map<String, Command> commandMap = new HashMap<>();

public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] split) {
if (!uSkyBlock.getInstance().isRequirementsMet(sender, true)) {
return true;
}
final Player player;
if (split.length == 0) {
if (sender.hasPermission("usb.mod.protect") || sender.hasPermission("usb.mod.protectall") || sender.hasPermission("usb.mod.topten") || sender.hasPermission("usb.mod.orphan") || sender.hasPermission("usb.admin.delete") || sender.hasPermission("usb.admin.remove") || sender.hasPermission("usb.admin.register")) {
Expand Down Expand Up @@ -117,7 +120,7 @@ public boolean onCommand(final CommandSender sender, final Command command, fina
sender.sendMessage(ChatColor.YELLOW + "Marking all islands inactive for more than " + split[1] + " days.");
uSkyBlock.getInstance().getServer().getScheduler().runTaskAsynchronously(uSkyBlock.getInstance(), new Runnable() {
@SuppressWarnings("deprecation")
@Override
@Override
public void run() {
final File directoryPlayers = new File(uSkyBlock.getInstance().getDataFolder() + File.separator + "players");
long offlineTime = 0L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ public IslandCommand() {
}

public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] split) {
uSkyBlock sky = uSkyBlock.getInstance();
if (!sky.isRequirementsMet(sender, false)) {
sender.sendMessage(ChatColor.RED + "/is is currently disabled, contact a server-administrator");
return true;
}
if (!(sender instanceof Player)) {
return handleConsoleCommand(sender, command, label, split);
}
final Player player = (Player) sender;
uSkyBlock sky = uSkyBlock.getInstance();
final PlayerInfo pi = sky.getPlayerInfo(player);
if (pi == null) {
player.sendMessage(ChatColor.RED + "Error: Couldn't read your player data!");
Expand Down
37 changes: 36 additions & 1 deletion src/main/java/us/talabrek/ultimateskyblock/uSkyBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import us.talabrek.ultimateskyblock.admin.DevCommand;
Expand All @@ -30,7 +31,10 @@
import us.talabrek.ultimateskyblock.event.MobEvents;
import us.talabrek.ultimateskyblock.event.PlayerEvents;
import us.talabrek.ultimateskyblock.imports.impl.PlayerImporterImpl;
import us.talabrek.ultimateskyblock.island.*;
import us.talabrek.ultimateskyblock.island.IslandCommand;
import us.talabrek.ultimateskyblock.island.IslandInfo;
import us.talabrek.ultimateskyblock.island.IslandLogic;
import us.talabrek.ultimateskyblock.island.LevelLogic;
import us.talabrek.ultimateskyblock.player.PlayerInfo;
import us.talabrek.ultimateskyblock.player.PlayerNotifier;

Expand All @@ -43,6 +47,12 @@
import java.util.logging.Level;

public class uSkyBlock extends JavaPlugin {
private static final String[][] depends = new String[][]{
new String[]{"Vault", "1.5"},
new String[]{"WorldEdit", "6.0"},
new String[]{"WorldGuard", "6.0"},
};
private static String missingRequirements = null;
private final Map<String, FileConfiguration> configFiles = new ConcurrentHashMap<>();

private SkyBlockMenu menu;
Expand Down Expand Up @@ -151,6 +161,7 @@ public FileConfiguration getConfig() {
}

public void onEnable() {
missingRequirements = null;
instance = this;
configFiles.clear();
activePlayers.clear();
Expand Down Expand Up @@ -211,6 +222,30 @@ public void run() {
}, 0L);
}

public synchronized boolean isRequirementsMet(CommandSender sender, boolean isDev) {
if (missingRequirements == null) {
PluginManager pluginManager = getServer().getPluginManager();
missingRequirements = "";
for (String[] pluginReq : depends) {
if (pluginManager.isPluginEnabled(pluginReq[0])) {
PluginDescriptionFile desc = pluginManager.getPlugin(pluginReq[0]).getDescription();
if (pluginReq[1].compareTo(desc.getVersion()) > 0) {
missingRequirements += "\u00a7buSkyBlock\u00a7e depends on \u00a79" + pluginReq[0] + "\u00a7e >= \u00a7av" + pluginReq[1] + "\u00a7e but only \u00a7cv" + desc.getVersion() + "\u00a7e was found!\n";
}
} else {
missingRequirements += "\u00a7buSkyBlock\u00a7e depends on \u00a79" + pluginReq[0] + "\u00a7e >= \u00a7av" + pluginReq[1];
}
}
}
if (missingRequirements.isEmpty()) {
return true;
} else if (isDev || sender.isOp()) {
sender.sendMessage(missingRequirements.split("\n"));
return false;
}
return false;
}

private void createFolders() {
if (!getDataFolder().exists()) {
getDataFolder().mkdirs();
Expand Down

0 comments on commit fdfb9b9

Please sign in to comment.