Java Code Examples for org.spongepowered.api.world.World#getUniqueId()

The following examples show how to use org.spongepowered.api.world.World#getUniqueId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GDClaimManager.java    From GriefDefender with MIT License 6 votes vote down vote up
public void createWildernessClaim(World world) {
    if (this.theWildernessClaim != null) {
        return;
    }

    final Vector3i lesserCorner = new Vector3i(-30000000, 0, -30000000);
    final Vector3i greaterCorner = new Vector3i(29999999, 255, 29999999);
    // Use world UUID as wilderness claim ID
    GDClaim wilderness = new GDClaim(world, lesserCorner, greaterCorner, world.getUniqueId(), ClaimTypes.WILDERNESS, null, false);
    wilderness.setOwnerUniqueId(GriefDefenderPlugin.WORLD_USER_UUID);
    wilderness.initializeClaimData(null);
    wilderness.claimData.save();
    wilderness.claimStorage.save();
    this.theWildernessClaim = wilderness;
    this.claimUniqueIdMap.put(wilderness.getUniqueId(), wilderness);
}
 
Example 2
Source File: FileStorage.java    From GriefDefender with MIT License 6 votes vote down vote up
public void unloadWorldData(World world) {
    final UUID worldUniqueId = world.getUniqueId();
    GDClaimManager claimWorldManager = this.getClaimWorldManager(worldUniqueId);
    for (Claim claim : claimWorldManager.getWorldClaims()) {
        ((GDClaim) claim).unload();
    }
    // Task must be cancelled before removing the claimWorldManager reference to avoid a memory leak
    Task cleanupTask = cleanupClaimTasks.get(worldUniqueId);
    if (cleanupTask != null) {
       cleanupTask.cancel();
       cleanupClaimTasks.remove(worldUniqueId);
    }

    claimWorldManager.unload();
    this.claimWorldManagers.remove(worldUniqueId);
    BaseStorage.dimensionConfigMap.remove(worldUniqueId);
    BaseStorage.worldConfigMap.remove(worldUniqueId);
}
 
Example 3
Source File: GDClaimManager.java    From GriefDefender with MIT License 4 votes vote down vote up
public GDClaimManager(World world) {
    this.worldUniqueId = world.getUniqueId();
    this.worldName = world.getName();
}
 
Example 4
Source File: FileStorage.java    From GriefDefender with MIT License 4 votes vote down vote up
public GDClaim loadClaim(File claimFile, World world, UUID claimId)
        throws Exception {
    GDClaim claim;

    final GDClaimManager claimManager = this.getClaimWorldManager(world.getUniqueId());
    if (claimManager.getWildernessClaim() != null && claimManager.getWildernessClaim().getUniqueId().equals(claimId)) {
        return null;
    }
    boolean isTown = claimFile.toPath().getParent().endsWith("town");
    boolean writeToStorage = false;
    ClaimStorageData claimStorage = null;
    if (isTown) {
        claimStorage = new TownStorageData(claimFile.toPath(), world.getUniqueId());
    } else {
        claimStorage = new ClaimStorageData(claimFile.toPath(), world.getUniqueId());
    }

    final ClaimType type = claimStorage.getConfig().getType();
    final UUID parent = claimStorage.getConfig().getParent().orElse(null);
    final String fileName = claimFile.getName();
    //final World world = Sponge.getServer().loadWorld(worldProperties).orElse(null);
    //if (world == null) {
    //    throw new Exception("World [Name: " + worldProperties.getWorldName() + "][UUID: " + worldUniqueId.toString() + "] is not loaded.");
    //}

    if (claimFile.getParentFile().getName().equalsIgnoreCase("claimdata")) {
        final Path newPath = claimStorage.filePath.getParent().resolve(type.getName().toLowerCase());
        if (Files.notExists(newPath)) {
            Files.createDirectories(newPath);
        }
        Files.move(claimStorage.filePath, newPath.resolve(fileName));
        claimStorage.filePath = newPath.resolve(fileName);
        claimStorage = new ClaimStorageData(claimStorage.filePath, world.getUniqueId());
    }

    // identify world the claim is in
    UUID claimWorldUniqueId = claimStorage.getConfig().getWorldUniqueId();
    if (!claimWorldUniqueId.equals(world.getUniqueId())) {
        GriefDefenderPlugin.getInstance().getLogger().info("Found mismatch world UUID in " + type.getName().toLowerCase() + " claim file " + claimFile + ". Expected " + world.getUniqueId() + ", found " + claimWorldUniqueId + ". Updating file with correct UUID...");
        claimStorage.getConfig().setWorldUniqueId(world.getUniqueId());
        writeToStorage = true;
    }

    // boundaries
    final boolean cuboid = claimStorage.getConfig().isCuboid();
    Vector3i lesserCorner = claimStorage.getConfig().getLesserBoundaryCornerPos();
    Vector3i greaterCorner = claimStorage.getConfig().getGreaterBoundaryCornerPos();
    if (lesserCorner == null || greaterCorner == null) {
        throw new Exception("Claim file '" + claimFile.getName() + "' has corrupted data and cannot be loaded. Skipping...");
    }

    UUID ownerID = claimStorage.getConfig().getOwnerUniqueId();
    claim = new GDClaim(world, lesserCorner, greaterCorner, claimId, claimStorage.getConfig().getType(), ownerID, cuboid);
    claim.setClaimStorage(claimStorage);
    claim.setClaimData(claimStorage.getConfig());
    GDLoadClaimEvent.Pre preEvent = new GDLoadClaimEvent.Pre(claim);
    GriefDefender.getEventManager().post(preEvent);

    // add parent claim first
    if (parent != null) {
        GDClaim parentClaim = null;
        try {
            parentClaim = (GDClaim) claimManager.getClaimByUUID(parent).orElse(null);
        } catch (Throwable t) {
            t.printStackTrace();
        }
        if (parentClaim == null) {
            throw new Exception("Unable to load claim file '" + claimFile.getAbsolutePath() + "'. Required parent claim '" + parent + "' no longer exists. Skipping...");
        }
        claim.parent = parentClaim;
    }

    claimManager.addClaim(claim, writeToStorage);
    this.claimLoadCount++;
    GDLoadClaimEvent.Post postEvent = new GDLoadClaimEvent.Post(claim);
    GriefDefender.getEventManager().post(postEvent);
    return claim;
}
 
Example 5
Source File: SetHomeCommand.java    From EagleFactions with MIT License 4 votes vote down vote up
@Override
public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException
{
    if(!(source instanceof Player))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.ONLY_IN_GAME_PLAYERS_CAN_USE_THIS_COMMAND));

    final Player player = (Player)source;
    final Optional<Faction> optionalPlayerFaction = getPlugin().getFactionLogic().getFactionByPlayerUUID(player.getUniqueId());

    if (!optionalPlayerFaction.isPresent())
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_IN_FACTION_IN_ORDER_TO_USE_THIS_COMMAND));

    final Faction playerFaction = optionalPlayerFaction.get();
    final World world = player.getWorld();
    final FactionHome newHome = new FactionHome(world.getUniqueId(), new Vector3i(player.getLocation().getBlockPosition()));

    if(super.getPlugin().getPlayerManager().hasAdminMode(player))
    {
        super.getPlugin().getFactionLogic().setHome(playerFaction, newHome);
        source.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GREEN, Messages.FACTION_HOME_HAS_BEEN_SET));
        return CommandResult.success();
    }

    if(playerFaction.getLeader().equals(player.getUniqueId()) || playerFaction.getOfficers().contains(player.getUniqueId()))
    {
        final Optional<Faction> chunkFaction = super.getPlugin().getFactionLogic().getFactionByChunk(world.getUniqueId(), player.getLocation().getChunkPosition());
        if (!chunkFaction.isPresent() && this.factionsConfig.canPlaceHomeOutsideFactionClaim())
        {
            super.getPlugin().getFactionLogic().setHome(playerFaction, newHome);
            source.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GREEN, Messages.FACTION_HOME_HAS_BEEN_SET));
        }
        else if (!chunkFaction.isPresent() && !this.factionsConfig.canPlaceHomeOutsideFactionClaim())
        {
            source.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.FACTION_HOME_MUST_BE_PLACED_INSIDE_FACTION_TERRITORY));
        }
        else if(chunkFaction.isPresent() && chunkFaction.get().getName().equals(playerFaction.getName()))
        {
            super.getPlugin().getFactionLogic().setHome(playerFaction, newHome);
            source.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GREEN, Messages.FACTION_HOME_HAS_BEEN_SET));
        }
        else
        {
            source.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.THIS_LAND_BELONGS_TO_SOMEONE_ELSE));
        }
    }
    else
    {
        source.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_THE_FACTIONS_LEADER_OR_OFFICER_TO_DO_THIS));
    }

    return CommandResult.success();
}
 
Example 6
Source File: WorldDataFile.java    From UltimateCore with MIT License 4 votes vote down vote up
public WorldDataFile(World world) {
    this(world.getUniqueId());
}