Skip to content
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
14 changes: 14 additions & 0 deletions Essentials/src/main/java/com/earth2me/essentials/ISettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,22 @@ public interface ISettings extends IConf {

Set getMultipleHomes();

Set<String> getHomesPerWorld();

Set<String> getHomesPerWorldGroup();

int getHomeLimit(String set);

int getWorldHomeLimit(String set);

int getWorldGroupHomeLimit(String set);

Set<String> getWorldGroupHomeList(String set);

boolean isHomeLimitPerWorldEnabled();

boolean isHomeLimitPerWorldGroupEnabled();

int getHomeLimit(User user);

int getSpawnMobLimit();
Expand Down
87 changes: 84 additions & 3 deletions Essentials/src/main/java/com/earth2me/essentials/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Objects;
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import java.util.stream.Collectors;

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

Expand Down Expand Up @@ -198,13 +200,28 @@ public Set<String> getMultipleHomes() {
return section == null ? null : ConfigurateUtil.getKeys(section);
}

@Override
public Set<String> getHomesPerWorld() {
final CommentedConfigurationNode section = config.getSection("homes-per-world");
return section == null ? null : ConfigurateUtil.getKeys(section);
}

@Override
public Set<String> getHomesPerWorldGroup() {
final CommentedConfigurationNode section = config.getSection("homes-per-world-group");
return section == null ? null : ConfigurateUtil.getKeys(section);
}

@Override
public int getHomeLimit(final User user) {
int limit = 1;
if (user.isAuthorized("essentials.sethome.multiple")) {
limit = getHomeLimit("default");
final boolean hasMultipleHomeAuthorization = user.isAuthorized("essentials.sethome.multiple");
if (!hasMultipleHomeAuthorization) {
return limit;
}

limit = getHomeLimit("default");

final Set<String> homeList = getMultipleHomes();
if (homeList != null) {
for (final String set : homeList) {
Expand All @@ -213,14 +230,78 @@ public int getHomeLimit(final User user) {
}
}
}

final boolean homesPerWorldEnabled = isHomeLimitPerWorldEnabled();
final boolean homesPerWorldGroupEnabled = isHomeLimitPerWorldGroupEnabled();

if(!homesPerWorldEnabled)
return limit;

if(homesPerWorldGroupEnabled) {
final Set<String> homesPerWorldGroup = getHomesPerWorldGroup();
if (homesPerWorldGroup != null) {
for (final String set : homesPerWorldGroup) {
if (limit < getWorldGroupHomeLimit(set) && isUserInWorldGroup(user, set)) {
limit = getWorldGroupHomeLimit(set);
}
}
}
}else{
final Set<String> homesPerWorld = getHomesPerWorld();
if (homesPerWorld != null) {
for (final String set : homesPerWorld) {
if (limit < getWorldHomeLimit(set) && isUserInWorld(user, set)) {
limit = getWorldHomeLimit(set);
}
}
}
}

return limit;
}

public boolean isUserInWorld(User user, String worldName) {
return Objects.requireNonNull(user.getWorld()).getName().equalsIgnoreCase(worldName);
}

public boolean isUserInWorldGroup(User user, String worldGroup) {
return getWorldGroupHomeList(worldGroup).stream().anyMatch(worldName -> isUserInWorld(user, worldName));
}

@Override
public int getHomeLimit(final String set) {
return config.getInt("sethome-multiple." + set, config.getInt("sethome-multiple.default", 3));
}

@Override
public int getWorldHomeLimit(String set) {
return config.getInt("homes-per-world." + set, config.getInt("sethome-multiple.default", 3));
}

@Override
public int getWorldGroupHomeLimit(String set) {
return config.getInt("homes-per-world-group." + set + ".home-limit", config.getInt("sethome-multiple.default", 3));
}

@Override
public Set<String> getWorldGroupHomeList(String set) {
final String worlds = config.getString("homes-per-world-group." + set + ".worlds", null);
if(worlds == null) {
return new HashSet<>();
}
return Arrays.stream(worlds.split(",")).collect(Collectors.toSet());
}

@Override
public boolean isHomeLimitPerWorldEnabled() {
return config.getBoolean("home-limit-per-world", false);
}

@Override
public boolean isHomeLimitPerWorldGroupEnabled() {
return config.getBoolean("home-limit-per-world-group", false);
}

private int _getChatRadius() {
return config.getInt("chat.radius", config.getInt("chat-radius", 0));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.UUID;
import java.util.logging.Level;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public abstract class UserData extends PlayerExtension implements IConf {
protected final transient Essentials ess;
Expand Down Expand Up @@ -178,6 +179,12 @@ public List<String> getHomes() {
return new ArrayList<>(holder.homes().keySet());
}

public List<String> getHomesPerWorld(String worldName) {
return holder.homes().entrySet().stream()
.filter(homeLocation -> homeLocation.getValue().worldName().equalsIgnoreCase(worldName))
.map(Map.Entry::getKey).collect(Collectors.toList());
}

public void setHome(String name, final Location loc) {
//Invalid names will corrupt the yaml
name = StringUtil.safeString(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
import org.bukkit.Server;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;

import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.Collections;
import java.util.concurrent.CompletableFuture;

public class Commandhome extends EssentialsCommand {
Expand Down Expand Up @@ -120,8 +122,8 @@ private String getHomeLimit(final User player) {
return Integer.toString(ess.getSettings().getHomeLimit(player));
}

private void goHome(final User user, final User player, final String home, final Trade charge, final CompletableFuture<Boolean> future) throws Exception {
if (home.length() < 1) {
public void goHome(final User user, final User player, final String home, final Trade charge, final CompletableFuture<Boolean> future) throws Exception {
if (home.isEmpty()) {
throw new NotEnoughArgumentsException();
}
final Location loc = player.getHome(home);
Expand All @@ -131,6 +133,9 @@ private void goHome(final User user, final User player, final String home, final
if (user.getWorld() != loc.getWorld() && ess.getSettings().isWorldHomePermissions() && !user.isAuthorized("essentials.worlds." + loc.getWorld().getName())) {
throw new TranslatableException("noPerm", "essentials.worlds." + loc.getWorld().getName());
}
if(!isUserHomeInWorldOrWorldGroupWorld(user.getWorld().getName(), Objects.requireNonNull(loc.getWorld()).getName())) {
throw new Exception(tl("teleportNotPossible"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets use TranslatableException here:

throw new TranslatableException("teleportNotPossible");

}
final UserTeleportHomeEvent event = new UserTeleportHomeEvent(user, home, loc, UserTeleportHomeEvent.HomeType.HOME);
user.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
Expand All @@ -143,6 +148,27 @@ private void goHome(final User user, final User player, final String home, final
}
}

public boolean isUserHomeInWorldOrWorldGroupWorld(String worldFrom, String worldTo) {
final boolean isHomeLimitPerWorldEnabled = ess.getSettings().isHomeLimitPerWorldEnabled();
final boolean isHomeLimitPerWorldGroupEnabled = ess.getSettings().isHomeLimitPerWorldGroupEnabled();
if(!isHomeLimitPerWorldEnabled) {
return true;
}
if(isHomeLimitPerWorldGroupEnabled) {
final Set<String> worldGroups = ess.getSettings().getHomesPerWorldGroup();

for (String wGroup : worldGroups) {
final Set<String> worldsPerWG = ess.getSettings().getWorldGroupHomeList(wGroup);

if (worldsPerWG.contains(worldFrom) && worldsPerWG.contains(worldTo))
return true;
}
}else{
return worldFrom.equalsIgnoreCase(worldTo);
}
return false;
}

@Override
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
final boolean canVisitOthers = user.isAuthorized("essentials.home.others");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

public class Commandsethome extends EssentialsCommand {
Expand Down Expand Up @@ -89,7 +90,10 @@ public void run(final Server server, final User user, final String commandLabel,
private boolean checkHomeLimit(final User user, final User usersHome, final String name) throws Exception {
if (!user.isAuthorized("essentials.sethome.multiple.unlimited")) {
final int limit = ess.getSettings().getHomeLimit(user);
if (usersHome.getHomes().size() >= limit) {
final List<String> homes = usersHome.isReachable() ?
usersHome.getHomesPerWorld(Objects.requireNonNull(usersHome.getLocation().getWorld()).getName())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we get the limit for user not usersHome`?

: usersHome.getHomes();
if (homes.size() >= limit) {
if (usersHome.getHomes().contains(name)) {
return false;
}
Expand Down
32 changes: 32 additions & 0 deletions Essentials/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,38 @@ spawn-if-no-home: true
# Should players be asked to provide confirmation for homes they attempt to overwrite?
confirm-home-overwrite: false

# This setting enables to have for each world limit of homes
# e.g. when enabled, user can have 3 homes in world, 3 in world_nether and 3 in world_the_end.
home-limit-per-world: false

# When home-limit-per-world is enabled, with configuration sethome-multiple whichever setting has a number higher,
# it then will be used
# e.g. if sethome-multiple.vip is 5 and user has permission for this, and user is in world named world_the_end which
# limit for home is 2, then user will have limit of higher number, therefore 5 homes in that world.
# To not follow this logic, please remove user permission for that 'home rank'.
# If world is not present in this configuration, configuration sethome-multiple.default
# will be used as a home limit for that world.
homes-per-world:
world: 5
world_the_end: 2

# For this configuration, previous configuration home-limit-per-world needs to be enabled.
# This allows you to create 'world groups' which can consist of how many worlds you want
# and set limit for these worlds, then they will act as one world with their limit.
# e.g. 'world group' named player-worlds which has worlds 'world' and 'world_nether'
# which home limit is set to 4. User will have maximum of 4 homes in these worlds total.
# If world is not present in this configuration, configuration sethome-multiple.default
# will be used as a home limit for that world.
home-limit-per-world-group: false

# Name of the world group can be any english letter with spaces that are -
# Worlds are split by a colon without spaces, as shown in the example: world,world_nether .
# Worlds in a 'world group' act as one world.
homes-per-world-group:
player-worlds:
worlds: world,world_nether
home-limit: 4
Comment on lines +833 to +859
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think these config options should instead be:

home-limit-per-world: false

sethome-world-multiple:
  default:
    world: 5
    world_the_nether: 10
  vip:
    world: 10
    world_the_nether: 20

this way we can minimize confusion and let people configure it all under one setting, people who don't want to do by group can just use default


############################################################
# +------------------------------------------------------+ #
# | Economy | #
Expand Down
1 change: 1 addition & 0 deletions Essentials/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,7 @@ teleportDisabled=<secondary>{0} <dark_red>has teleportation disabled.
teleportHereRequest=<secondary>{0}<primary> has requested that you teleport to them.
teleportHome=<primary>Teleporting to <secondary>{0}<primary>.
teleporting=<primary>Teleporting...
teleportNotPossible=\<secondary>Teleportation to that location is not possible from this world
teleportInvalidLocation=Value of coordinates cannot be over 30000000
teleportNewPlayerError=<dark_red>Failed to teleport new player\!
teleportNoAcceptPermission=<secondary>{0} <dark_red>does not have permission to accept teleport requests.
Expand Down
Loading
Loading