Skip to content

Commit

Permalink
Merge pull request #66 from TheNextLvl-net/area-creator-fix
Browse files Browse the repository at this point in the history
Area creator mutability fix
  • Loading branch information
NonSwag authored Nov 2, 2024
2 parents e50ff63 + dab3b9f commit 892e5ac
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ public interface AreaCreator<T extends Region> {
*/
AreaCreator<T> flags(Map<Flag<?>, @Nullable Object> flags);

/**
* Sets the members for the area being created.
*
* @param members a set of UUIDs representing the members to be associated with the area
* @return the AreaCreator instance with the specified members set
*/
AreaCreator<T> members(Set<UUID> members);

/**
* Sets the name for the area being created.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,52 @@ public class CraftAreaCreator<T extends Region> implements AreaCreator<T> {
private Set<UUID> members = new HashSet<>();
private int priority = 0;

@SuppressWarnings("unchecked")
public CraftAreaCreator(ProtectPlugin plugin, String name, World world, T region, @Nullable String parent,
@Nullable UUID owner, Map<Flag<?>, @Nullable Object> flags, Set<UUID> members, int priority) {
this.plugin = plugin;
this.name = name;
this.world = world;
this.region = region;
this.region = (T) region.clone();
this.parent = parent;
this.owner = owner;
this.flags = flags;
this.members = members;
this.flags = new HashMap<>(flags);
this.members = new HashSet<>(members);
this.priority = priority;
}

@SuppressWarnings("unchecked")
public CraftAreaCreator(ProtectPlugin plugin, String name, World world, T region) {
this.plugin = plugin;
this.name = name;
this.world = world;
this.region = region;
this.region = (T) region.clone();
}

@Override
public AreaCreator<T> copy() {
return new CraftAreaCreator<>(plugin, name, world, region, parent, owner, flags, members, priority);
}

@Override
@SuppressWarnings("unchecked")
public AreaCreator<T> region(T region) {
this.region = (T) region.clone();
return this;
}

@Override
public AreaCreator<T> flags(Map<Flag<?>, @Nullable Object> flags) {
this.flags = new HashMap<>(flags);
return this;
}

@Override
public AreaCreator<T> members(Set<UUID> members) {
this.members = new HashSet<>(members);
return this;
}

@Override
public AreaCreator<T> parent(@Nullable String parent) {
this.parent = parent;
Expand Down

0 comments on commit 892e5ac

Please sign in to comment.