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

Fix time command throwing exceptions when used in console #3622

Merged
merged 1 commit into from
Sep 9, 2020
Merged
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
30 changes: 19 additions & 11 deletions Essentials/src/com/earth2me/essentials/commands/Commandtime.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package com.earth2me.essentials.commands;

import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.DescParseTickFormat;
import com.earth2me.essentials.utils.NumberUtil;
import com.google.common.collect.Lists;
import org.bukkit.Server;
import org.bukkit.World;

import java.util.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.StringJoiner;
import java.util.TreeSet;

import static com.earth2me.essentials.I18n.tl;

Expand Down Expand Up @@ -63,14 +71,14 @@ public void run(final Server server, final CommandSource sender, final String co
}

// Start updating world times, we have what we need
User user = ess.getUser(sender.getPlayer());
if (!user.isAuthorized("essentials.time.set")) {
if (!sender.isAuthorized("essentials.time.set", ess)) {
throw new Exception(tl("timeSetPermission"));
}

for (World world : worlds) {
if (!canUpdateWorld(user, world)) {
throw new Exception(tl("timeSetWorldPermission", user.getWorld().getName()));
if (!canUpdateWorld(sender, world)) {
//We can ensure that this is User as the console has all permissions (for essentials commands).
throw new Exception(tl("timeSetWorldPermission", sender.getUser(ess).getBase().getWorld().getName()));
}
}

Expand Down Expand Up @@ -127,13 +135,13 @@ private Set<World> getWorlds(final Server server, final CommandSource sender, fi
return worlds;
}

private boolean canUpdateAll(User user) {
return !ess.getSettings().isWorldTimePermissions() // First check if per world permissions are enabled, if not, return true.
|| user == null || user.isAuthorized("essentials.time.world.all");
private boolean canUpdateAll(CommandSource sender) {
return !ess.getSettings().isWorldTimePermissions() // First check if per world permissions are enabled, if not, return true.
|| sender.isAuthorized("essentials.time.world.all", ess);
}

private boolean canUpdateWorld(User user, World world) {
return canUpdateAll(user) || user.isAuthorized("essentials.time.world." + normalizeWorldName(world));
private boolean canUpdateWorld(CommandSource sender, World world) {
return canUpdateAll(sender) || sender.isAuthorized("essentials.time.world." + normalizeWorldName(world), ess);
}

private String normalizeWorldName(World world) {
Expand Down