本文整理汇总了Java中com.sk89q.worldguard.domains.DefaultDomain类的典型用法代码示例。如果您正苦于以下问题:Java DefaultDomain类的具体用法?Java DefaultDomain怎么用?Java DefaultDomain使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultDomain类属于com.sk89q.worldguard.domains包,在下文中一共展示了DefaultDomain类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addMembers
import com.sk89q.worldguard.domains.DefaultDomain; //导入依赖的package包/类
/**
* Adds a list of members to a region.
*
* @param world World were the region is.
* @param regionName The ID of the region.
* @param playerNames Players to be added.
* @return true on succes, false on failure.
*/
public boolean addMembers(World world, String regionName, String[] playerNames) {
RegionManager rm = wgp.getRegionManager(world);
if (rm == null) {
return false;
}
ProtectedRegion region = rm.getRegion(regionName);
if (region == null) {
return false;
}
DefaultDomain members = region.getMembers();
for (String playerName : playerNames) {
members.addPlayer(playerName);
}
region.setMembers(members);
try {
rm.save();
} catch (ProtectionDatabaseException ex) {
plugin.getLogger().log(Level.SEVERE, "Unexpected failure saving WorldGuard configuration: {0}", ex.toString());
return false;
}
return true;
}
示例2: removeMembers
import com.sk89q.worldguard.domains.DefaultDomain; //导入依赖的package包/类
/**
* Removes a list of members from a region.
*
* @param world World were the region is.
* @param regionName The ID of the region.
* @param playerNames Players to be added.
* @return true on succes, false on failure.
*/
public boolean removeMembers(World world, String regionName, String[] playerNames) {
RegionManager rm = wgp.getRegionManager(world);
if (rm == null) {
return false;
}
ProtectedRegion region = rm.getRegion(regionName);
if (region == null) {
return false;
}
DefaultDomain members = region.getMembers();
for (String playerName : playerNames) {
members.removePlayer(playerName);
}
region.setMembers(members);
try {
rm.save();
} catch (ProtectionDatabaseException ex) {
plugin.getLogger().log(Level.SEVERE, "Unexpected failure saving WorldGuard configuration: {0}", ex.toString());
return false;
}
return true;
}
示例3: getPBregion
import com.sk89q.worldguard.domains.DefaultDomain; //导入依赖的package包/类
/**
* returns a calculated ProtectedCuboidRegion from given params.
*
* @param loc Location of the protection block
* @param length The lenght of the region
* @param height The height of the region
* @param width The width of the reguion
* @param playerName The Owner of the region.
* @return ProtectedCuboidRegion
*/
public ProtectedCuboidRegion getPBregion(Location loc, int length, int height, int width, String playerName) {
BlockVector min = new BlockVector(loc.getBlockX() - ((length - 1) / 2),
0,
loc.getBlockZ() - ((width - 1) / 2));
BlockVector max = new BlockVector(loc.getBlockX() + ((length - 1) / 2),
255,
loc.getBlockZ() + ((width - 1) / 2));
if (height != 0) {
min = min.setY(loc.getBlockY() - ((height - 1) / 2)).toBlockVector();
max = max.setY(loc.getBlockY() + ((height - 1) / 2)).toBlockVector();
}
ProtectedCuboidRegion region = new ProtectedCuboidRegion("ps"
+ loc.getBlockX() + "x"
+ loc.getBlockY() + "y"
+ loc.getBlockZ() + "z", min, max);
DefaultDomain dd = new DefaultDomain();
dd.addPlayer(playerName);
region.setOwners(dd);
return region;
}
示例4: decode
import com.sk89q.worldguard.domains.DefaultDomain; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public DefaultDomain decode(BsonReader reader, DecoderContext decoderContext) {
DefaultDomain domain = new DefaultDomain();
reader.readStartDocument();
while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) {
String name = reader.readName();
if ("players".equals(name)) {
reader.readStartArray();
while (reader.readBsonType() != BsonType.END_OF_DOCUMENT)
domain.addPlayer(UUID.fromString(reader.readString()));
reader.readEndArray();
} else if ("groups".equals(name)) {
reader.readStartArray();
while (reader.readBsonType() != BsonType.END_OF_DOCUMENT)
domain.addGroup(reader.readString());
reader.readEndArray();
} else {
reader.skipValue();
}
}
reader.readEndDocument();
return domain;
}
示例5: encode
import com.sk89q.worldguard.domains.DefaultDomain; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void encode(BsonWriter writer, DefaultDomain value, EncoderContext encoderContext) {
writer.writeStartDocument();
writer.writeName("players");
writer.writeStartArray();
for (UUID uuid : value.getUniqueIds())
writer.writeString(uuid.toString());
writer.writeEndArray();
writer.writeName("groups");
writer.writeStartArray();
for (String group : value.getGroups())
writer.writeString(group);
writer.writeEndArray();
writer.writeEndDocument();
}
示例6: testCodec
import com.sk89q.worldguard.domains.DefaultDomain; //导入依赖的package包/类
@Test
public void testCodec() throws IOException {
Codec<DefaultDomain> codec = DefaultDomainCodec.INSTANCE;
DefaultDomain domain = new DefaultDomain();
domain.addPlayer(UUID.randomUUID());
domain.addGroup("test_group");
DefaultDomain other;
try (StringWriter sw = new StringWriter()) {
codec.encode(new JsonWriter(sw), domain, EncoderContext.builder().build());
other = codec.decode(new JsonReader(sw.toString()), DecoderContext.builder().build());
}
Assert.assertEquals(domain.getPlayers(), other.getPlayers());
Assert.assertEquals(domain.getUniqueIds(), other.getUniqueIds());
Assert.assertEquals(domain.getGroups(), other.getGroups());
}
示例7: buildDomain
import com.sk89q.worldguard.domains.DefaultDomain; //导入依赖的package包/类
/**
* Build a DefaultDomain from a RegionAccessSet.
* @param regionAccessSet RegionAccessSet to read
* @return DefaultDomain containing the entities from the RegionAccessSet
*/
private DefaultDomain buildDomain(RegionAccessSet regionAccessSet) {
DefaultDomain owners = new DefaultDomain();
for(String playerName : regionAccessSet.getPlayerNames()) {
owners.addPlayer(playerName);
}
// Add by name since UUIDs were not yet supported
for(UUID uuid : regionAccessSet.getPlayerUniqueIds()) {
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
if(offlinePlayer != null && offlinePlayer.getName() != null) {
owners.addPlayer(offlinePlayer.getName());
}
}
for(String group : regionAccessSet.getGroupNames()) {
owners.addGroup(group);
}
return owners;
}
示例8: buildDomain
import com.sk89q.worldguard.domains.DefaultDomain; //导入依赖的package包/类
/**
* Build a DefaultDomain from a RegionAccessSet.
* @param regionAccessSet RegionAccessSet to read
* @return DefaultDomain containing the entities from the RegionAccessSet
*/
private DefaultDomain buildDomain(RegionAccessSet regionAccessSet) {
DefaultDomain owners = new DefaultDomain();
for(String playerName : regionAccessSet.getPlayerNames()) {
owners.addPlayer(playerName);
}
for(UUID uuid : regionAccessSet.getPlayerUniqueIds()) {
owners.addPlayer(uuid);
}
for(String group : regionAccessSet.getGroupNames()) {
owners.addGroup(group);
}
return owners;
}
示例9: process
import com.sk89q.worldguard.domains.DefaultDomain; //导入依赖的package包/类
private void process(ProtectedRegion r){
DefaultDomain owners = r.getOwners();
boolean found = false;
for (String s : owners.getPlayers()) {
User u = e.getOfflineUser(s);
if(u != null){
long time = System.currentTimeMillis() - u.getLastLogout();
System.out.println("Milliseconds since last played: " + time);
if (time < WorldRestore.month) {
System.out.println("Found an owner played within last month.");
found = true;
break;
}
}
}
if(!found){
rm.removeRegion(r.getId());
}
}
示例10: addMemberPlayer
import com.sk89q.worldguard.domains.DefaultDomain; //导入依赖的package包/类
public void addMemberPlayer(final ProtectedRegion pr, final String playerName) {
Bukkit.getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
DefaultDomain dd = pr.getMembers();
dd.addPlayer(playerName);
}
});
}
示例11: delMemberPlayer
import com.sk89q.worldguard.domains.DefaultDomain; //导入依赖的package包/类
public boolean delMemberPlayer(ProtectedRegion pr, String playerName) {
boolean result = true;
DefaultDomain dd = pr.getMembers();
if (dd.contains(playerName)) {
dd.removePlayer(playerName);
} else {
result = false;
}
return result;
}
示例12: vaultCreated
import com.sk89q.worldguard.domains.DefaultDomain; //导入依赖的package包/类
@EventHandler
public void vaultCreated(PlayerVaultCreationEvent event) {
// some listener already claimed this event
if (event.isValid()) return;
if (event.getType().equals("region")) {
Player player = event.getCause().getPlayer();
if (!createvault_worldguard.allowed(player)) {
player.sendMessage(LANG.plugin_faction_noVaultPerm);
return;
}
String regionId = event.getCause().getLine(2);
String[] regionComponents = regionId.split("-",1);
WorldGuardAccountHolder owner;
if (regionComponents.length == 1) {
// try to guess the world
owner = getAccountHolder(regionComponents[0]);
} else {
String world = regionComponents[0];
String id = regionComponents[1];
owner = getAccountHolder(world, id);
}
if (owner != null && (owner.region.hasMembersOrOwners() || createvault_admin.allowed(player))) {
DefaultDomain regionOwners = owner.region.getOwners();
if (regionOwners.contains(player.getName())) {
event.setOwner(owner);
event.setValid(true);
}
}
}
}
示例13: removeOwners
import com.sk89q.worldguard.domains.DefaultDomain; //导入依赖的package包/类
public static void removeOwners(DefaultDomain dd, ProtectedRegion r){
DefaultDomain owners = r.getOwners();
owners.removeAll(dd);
r.setOwners(owners);
}
示例14: removeMembers
import com.sk89q.worldguard.domains.DefaultDomain; //导入依赖的package包/类
public static void removeMembers(List<UUID> ids, ProtectedRegion r){
DefaultDomain members = r.getMembers();
DefaultDomain toRemove = new DefaultDomain();
ids.forEach(toRemove::addPlayer);
members.removeAll(toRemove);
r.setMembers(members);
}
示例15: setOwners
import com.sk89q.worldguard.domains.DefaultDomain; //导入依赖的package包/类
@Override
public void setOwners(ProtectedRegion region, RegionAccessSet regionAccessSet) {
DefaultDomain defaultDomain = buildDomain(regionAccessSet);
if(!region.getOwners().toUserFriendlyString().equals(defaultDomain.toUserFriendlyString())) {
region.setOwners(defaultDomain);
}
}