Permalink
Browse files

Use WorldEdit styling and move more of the RegionContainer across.

  • Loading branch information...
me4502 committed Dec 19, 2018
1 parent a194f96 commit 44b3ee0ccfa30ebc02a6fc62e212b365c2fabe75
@@ -17,17 +17,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.sk89q.worldguard.bukkit.commands.region;
package com.sk89q.worldguard.commands.region;

import com.sk89q.squirrelid.cache.ProfileCache;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.RegionGroupFlag;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.bukkit.ChatColor;

import java.util.ArrayList;
import java.util.List;
@@ -69,16 +69,16 @@ private void newLine() {
* Add region name, type, and priority.
*/
public void appendBasics() {
builder.append(ChatColor.BLUE);
builder.append(Style.BLUE);
builder.append("Region: ");
builder.append(ChatColor.YELLOW);
builder.append(Style.YELLOW);
builder.append(region.getId());

builder.append(ChatColor.GRAY);
builder.append(Style.GRAY);
builder.append(" (type=");
builder.append(region.getType().getName());

builder.append(ChatColor.GRAY);
builder.append(Style.GRAY);
builder.append(", priority=");
builder.append(region.getPriority());
builder.append(")");
@@ -90,7 +90,7 @@ public void appendBasics() {
* Add information about flags.
*/
public void appendFlags() {
builder.append(ChatColor.BLUE);
builder.append(Style.BLUE);
builder.append("FlagUtil: ");

appendFlagsList(true);
@@ -118,7 +118,7 @@ public void appendFlagsList(boolean useColors) {
builder.append(", ");
} else {
if (useColors) {
builder.append(ChatColor.YELLOW);
builder.append(Style.YELLOW);
}
}

@@ -129,19 +129,19 @@ public void appendFlagsList(boolean useColors) {

if (group == null) {
builder.append(flag.getName()).append(": ")
.append(ChatColor.stripColor(String.valueOf(val)));
.append(Style.stripColor(String.valueOf(val)));
} else {
builder.append(flag.getName()).append(" -g ")
.append(group).append(": ")
.append(ChatColor.stripColor(String.valueOf(val)));
.append(Style.stripColor(String.valueOf(val)));
}

hasFlags = true;
}

if (!hasFlags) {
if (useColors) {
builder.append(ChatColor.RED);
builder.append(Style.RED);
}
builder.append("(none)");
}
@@ -180,7 +180,7 @@ public void appendParentTree(boolean useColors) {
while (it.hasPrevious()) {
ProtectedRegion cur = it.previous();
if (useColors) {
builder.append(ChatColor.GREEN);
builder.append(Style.GREEN);
}

// Put symbol for child
@@ -197,7 +197,7 @@ public void appendParentTree(boolean useColors) {
// Put (parent)
if (!cur.equals(region)) {
if (useColors) {
builder.append(ChatColor.GRAY);
builder.append(Style.GRAY);
}
builder.append(" (parent, priority=").append(cur.getPriority()).append(")");
}
@@ -211,23 +211,23 @@ public void appendParentTree(boolean useColors) {
* Add information about members.
*/
public void appendDomain() {
builder.append(ChatColor.BLUE);
builder.append(Style.BLUE);
builder.append("Owners: ");
addDomainString(region.getOwners());
newLine();

builder.append(ChatColor.BLUE);
builder.append(Style.BLUE);
builder.append("Members: ");
addDomainString(region.getMembers());
newLine();
}

private void addDomainString(DefaultDomain domain) {
if (domain.size() != 0) {
builder.append(ChatColor.YELLOW);
builder.append(Style.YELLOW);
builder.append(domain.toUserFriendlyString(cache));
} else {
builder.append(ChatColor.RED);
builder.append(Style.RED);
builder.append("(none)");
}
}
@@ -238,17 +238,17 @@ private void addDomainString(DefaultDomain domain) {
public void appendBounds() {
BlockVector3 min = region.getMinimumPoint();
BlockVector3 max = region.getMaximumPoint();
builder.append(ChatColor.BLUE);
builder.append(Style.BLUE);
builder.append("Bounds:");
builder.append(ChatColor.YELLOW);
builder.append(Style.YELLOW);
builder.append(" (").append(min.getBlockX()).append(",").append(min.getBlockY()).append(",").append(min.getBlockZ()).append(")");
builder.append(" -> (").append(max.getBlockX()).append(",").append(max.getBlockY()).append(",").append(max.getBlockZ()).append(")");

newLine();
}

private void appendRegionInformation() {
builder.append(ChatColor.GRAY);
builder.append(Style.GRAY);
builder.append("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
builder.append(" Region Info ");
builder.append("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
@@ -260,7 +260,7 @@ private void appendRegionInformation() {
appendBounds();

if (cache != null) {
builder.append(ChatColor.GRAY).append("Any names suffixed by * are 'last seen names' and may not be up to date.");
builder.append(Style.GRAY).append("Any names suffixed by * are 'last seen names' and may not be up to date.");
newLine();
}
}
@@ -21,6 +21,7 @@

import com.sk89q.worldedit.world.entity.EntityType;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.blacklist.Blacklist;
import com.sk89q.worldedit.util.report.Unreported;

@@ -216,4 +217,20 @@ public String convertLegacyBlock(String legacy) {

return block;
}

public int getMaxRegionCount(LocalPlayer player) {
int max = -1;
for (String group : player.getGroups()) {
if (maxRegionCounts.containsKey(group)) {
int groupMax = maxRegionCounts.get(group);
if (max < groupMax) {
max = groupMax;
}
}
}
if (max <= -1) {
max = maxRegionCountPerPlayer;
}
return max;
}
}
@@ -19,16 +19,24 @@

package com.sk89q.worldguard.protection.regions;

import static com.google.common.base.Preconditions.checkNotNull;

import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.config.ConfigurationManager;
import com.sk89q.worldguard.protection.managers.RegionContainerImpl;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.managers.migration.Migration;
import com.sk89q.worldguard.protection.managers.migration.MigrationException;
import com.sk89q.worldguard.protection.managers.migration.UUIDMigration;
import com.sk89q.worldguard.protection.managers.storage.RegionDriver;

import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;

import javax.annotation.Nullable;

@@ -52,6 +60,20 @@
public void initialize() {
ConfigurationManager config = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
container = new RegionContainerImpl(config.selectedRegionStoreDriver, WorldGuard.getInstance().getFlagRegistry());

loadWorlds();

// Migrate to UUIDs
autoMigrate();
}

/**
* Save data and unload.
*/
public void unload() {
synchronized (lock) {
container.unloadAll();
}
}

/**
@@ -69,7 +91,12 @@ public RegionDriver getDriver() {
* <p>This method may block until the data for all loaded worlds has been
* unloaded and new data has been loaded.</p>
*/
public abstract void reload();
public void reload() {
synchronized (lock) {
unload();
loadWorlds();
}
}

/**
* Get the region manager for a world if one exists.
@@ -116,4 +143,80 @@ public RegionQuery createQuery() {
return new RegionQuery(cache);
}

/**
* Execute a migration and block any loading of region data during
* the migration.
*
* @param migration the migration
* @throws MigrationException thrown by the migration on error
*/
public void migrate(Migration migration) throws MigrationException {
checkNotNull(migration);

synchronized (lock) {
try {
WorldGuard.logger.info("Unloading and saving region data that is currently loaded...");
unload();
migration.migrate();
} finally {
WorldGuard.logger.info("Loading region data for loaded worlds...");
loadWorlds();
}
}
}

/**
* Try loading the region managers for all currently loaded worlds.
*/
protected void loadWorlds() {
synchronized (lock) {
for (World world : WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getWorlds()) {
load(world);
}
}
}

/**
* Unload the region data for a world.
*
* @param world a world
*/
public void unload(World world) {
checkNotNull(world);

synchronized (lock) {
container.unload(world.getName());
}
}

/**
* Execute auto-migration.
*/
protected void autoMigrate() {
ConfigurationManager config = WorldGuard.getInstance().getPlatform().getGlobalStateManager();

if (config.migrateRegionsToUuid) {
RegionDriver driver = getDriver();
UUIDMigration migrator = new UUIDMigration(driver, WorldGuard.getInstance().getProfileService(), WorldGuard.getInstance().getFlagRegistry());
migrator.setKeepUnresolvedNames(config.keepUnresolvedNames);
try {
migrate(migrator);

WorldGuard.logger.info("Regions saved after UUID migration! This won't happen again unless " +
"you change the relevant configuration option in WorldGuard's config.");

config.disableUuidMigration();
} catch (MigrationException e) {
WorldGuard.logger.log(Level.WARNING, "Failed to execute the migration", e);
}
}
}

/**
* Load the region data for a world if it has not been loaded already.
*
* @param world the world
* @return a region manager, either returned from the cache or newly loaded
*/
@Nullable protected abstract RegionManager load(World world);
}
@@ -17,10 +17,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.sk89q.worldguard.bukkit.util.logging;
package com.sk89q.worldguard.util.logging;

import com.sk89q.worldedit.extension.platform.Actor;
import org.bukkit.ChatColor;
import com.sk89q.worldedit.util.formatting.Style;

import java.util.logging.Handler;
import java.util.logging.LogRecord;
@@ -62,7 +62,6 @@ public void flush() {
*/
@Override
public void publish(LogRecord record) {
player.printRaw(ChatColor.GRAY + record.getLevel().getName() + ": "
+ ChatColor.WHITE + record.getMessage());
player.printDebug(record.getLevel().getName() + ": " + Style.WHITE + record.getMessage());
}
}
Oops, something went wrong.

0 comments on commit 44b3ee0

Please sign in to comment.