Implement PlayerDomain (add/remove player/groups from member/owners)

This commit is contained in:
Gabriele C 2018-11-22 15:29:34 +01:00
parent 19ef34bd0f
commit ee8a7c806a
3 changed files with 88 additions and 9 deletions

View File

@ -0,0 +1,20 @@
package org.codemc.worldguardwrapper.region;
import java.util.Set;
import java.util.UUID;
public interface PlayerDomain {
Set<UUID> getPlayers();
void addPlayer(UUID uuid);
void removePlayer(UUID uuid);
Set<String> getGroups();
void addGroup(String name);
void removeGroup(String name);
}

View File

@ -5,8 +5,6 @@ import org.codemc.worldguardwrapper.selection.Selection;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
public interface WrappedRegion {
@ -20,9 +18,9 @@ public interface WrappedRegion {
int getPriority();
Set<UUID> getOwners();
PlayerDomain getOwners();
Set<UUID> getMembers();
PlayerDomain getMembers();
boolean contains(Location location);

View File

@ -23,10 +23,11 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.codemc.worldguardwrapper.flags.AbstractWrappedFlag;
import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
import org.codemc.worldguardwrapper.region.PlayerDomain;
import org.codemc.worldguardwrapper.region.WrappedRegion;
import org.codemc.worldguardwrapper.selection.CuboidSelection;
import org.codemc.worldguardwrapper.selection.PolygonalSelection;
import org.codemc.worldguardwrapper.selection.Selection;
import org.codemc.worldguardwrapper.region.WrappedRegion;
import java.util.*;
import java.util.stream.Collectors;
@ -141,15 +142,75 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
}
@Override
public Set<UUID> getOwners() {
public PlayerDomain getOwners() {
return new PlayerDomain() {
@Override
public Set<UUID> getPlayers() {
return region.getOwners().getUniqueIds();
}
@Override
public Set<UUID> getMembers() {
public void addPlayer(UUID uuid) {
region.getOwners().addPlayer(uuid);
}
@Override
public void removePlayer(UUID uuid) {
region.getOwners().removePlayer(uuid);
}
@Override
public Set<String> getGroups() {
return region.getOwners().getGroups();
}
@Override
public void addGroup(String name) {
region.getOwners().addGroup(name);
}
@Override
public void removeGroup(String name) {
region.getOwners().removeGroup(name);
}
};
}
@Override
public PlayerDomain getMembers() {
return new PlayerDomain() {
@Override
public Set<UUID> getPlayers() {
return region.getMembers().getUniqueIds();
}
@Override
public void addPlayer(UUID uuid) {
region.getMembers().addPlayer(uuid);
}
@Override
public void removePlayer(UUID uuid) {
region.getMembers().removePlayer(uuid);
}
@Override
public Set<String> getGroups() {
return region.getMembers().getGroups();
}
@Override
public void addGroup(String name) {
region.getMembers().addGroup(name);
}
@Override
public void removeGroup(String name) {
region.getMembers().removeGroup(name);
}
};
}
@Override
public boolean contains(Location location) {
return region.contains(toBlockVector(location));