2014-04-03 01:57:25 +00:00
|
|
|
/*
|
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
|
|
|
*
|
2020-08-25 01:31:47 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
2014-04-03 01:57:25 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2020-08-25 01:31:47 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2014-04-03 01:57:25 +00:00
|
|
|
*
|
2020-08-25 01:31:47 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2014-04-03 01:57:25 +00:00
|
|
|
*/
|
|
|
|
|
2012-10-18 10:34:09 +00:00
|
|
|
package com.sk89q.worldedit;
|
|
|
|
|
2014-04-03 01:57:25 +00:00
|
|
|
import com.sk89q.worldedit.event.extent.EditSessionEvent;
|
2019-09-02 19:22:43 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.Actor;
|
2014-04-04 00:56:21 +00:00
|
|
|
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
2014-04-04 03:48:42 +00:00
|
|
|
import com.sk89q.worldedit.util.eventbus.EventBus;
|
2014-04-05 09:59:38 +00:00
|
|
|
import com.sk89q.worldedit.world.World;
|
2014-04-04 03:48:42 +00:00
|
|
|
|
2020-07-14 02:50:59 +00:00
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
|
|
|
|
2014-04-03 01:57:25 +00:00
|
|
|
/**
|
2014-04-04 03:48:42 +00:00
|
|
|
* Creates new {@link EditSession}s. To get an instance of this factory,
|
|
|
|
* use {@link WorldEdit#getEditSessionFactory()}.
|
2014-07-29 14:57:45 +00:00
|
|
|
*
|
|
|
|
* <p>It is no longer possible to replace the instance of this in WorldEdit
|
2014-04-04 03:48:42 +00:00
|
|
|
* with a custom one. Use {@link EditSessionEvent} to override
|
2014-07-29 14:57:45 +00:00
|
|
|
* the creation of {@link EditSession}s.</p>
|
2014-04-03 01:57:25 +00:00
|
|
|
*/
|
2014-04-04 00:56:21 +00:00
|
|
|
public class EditSessionFactory {
|
2012-11-13 10:07:08 +00:00
|
|
|
|
2012-10-18 10:34:09 +00:00
|
|
|
/**
|
|
|
|
* Construct an edit session with a maximum number of blocks.
|
|
|
|
*
|
2014-04-03 01:57:25 +00:00
|
|
|
* @param world the world
|
|
|
|
* @param maxBlocks the maximum number of blocks that can be changed, or -1 to use no limit
|
2014-07-29 21:23:00 +00:00
|
|
|
* @return an instance
|
2012-10-18 10:34:09 +00:00
|
|
|
*/
|
2014-04-05 09:59:38 +00:00
|
|
|
public EditSession getEditSession(World world, int maxBlocks) {
|
2012-11-13 10:07:08 +00:00
|
|
|
|
2014-07-18 21:46:39 +00:00
|
|
|
// ============ READ ME ============
|
|
|
|
|
|
|
|
// This method is actually implemented if you call WorldEdit.getEditSessionFactory()
|
|
|
|
// as it returns an instance of EditSessionFactoryImpl seen below.
|
|
|
|
|
|
|
|
// Previously, other plugins would create their own EditSessionFactory and extend ours and
|
|
|
|
// then use it to return custom EditSessions so the plugin could log block changes, etc.
|
|
|
|
// However, that method only allows one plugin to hook into WorldEdit at a time,
|
|
|
|
// so now we recommend catching the EditSessionEvent and hooking into our
|
|
|
|
// new(er) Extent framework.
|
|
|
|
|
|
|
|
throw new RuntimeException("Method needs to be implemented");
|
2014-04-05 09:59:38 +00:00
|
|
|
}
|
|
|
|
|
2012-11-13 10:07:08 +00:00
|
|
|
/**
|
|
|
|
* Construct an edit session with a maximum number of blocks.
|
|
|
|
*
|
2014-04-03 01:57:25 +00:00
|
|
|
* @param world the world
|
|
|
|
* @param maxBlocks the maximum number of blocks that can be changed, or -1 to use no limit
|
2019-09-02 19:22:43 +00:00
|
|
|
* @param actor the actor that the {@link EditSession} is for
|
2014-07-29 21:23:00 +00:00
|
|
|
* @return an instance
|
2012-11-13 10:07:08 +00:00
|
|
|
*/
|
2019-09-02 19:22:43 +00:00
|
|
|
public EditSession getEditSession(World world, int maxBlocks, Actor actor) {
|
2012-11-13 10:07:08 +00:00
|
|
|
|
2014-07-18 21:46:39 +00:00
|
|
|
// ============ READ ME ============
|
|
|
|
|
|
|
|
// This method is actually implemented if you call WorldEdit.getEditSessionFactory()
|
|
|
|
// as it returns an instance of EditSessionFactoryImpl seen below.
|
|
|
|
|
|
|
|
// Previously, other plugins would create their own EditSessionFactory and extend ours and
|
|
|
|
// then use it to return custom EditSessions so the plugin could log block changes, etc.
|
|
|
|
// However, that method only allows one plugin to hook into WorldEdit at a time,
|
|
|
|
// so now we recommend catching the EditSessionEvent and hooking into our
|
|
|
|
// new(er) Extent framework.
|
|
|
|
|
|
|
|
throw new RuntimeException("Method needs to be implemented");
|
2014-04-05 09:59:38 +00:00
|
|
|
}
|
|
|
|
|
2012-10-18 10:34:09 +00:00
|
|
|
/**
|
|
|
|
* Construct an edit session with a maximum number of blocks and a block bag.
|
|
|
|
*
|
2014-04-03 01:57:25 +00:00
|
|
|
* @param world the world
|
|
|
|
* @param maxBlocks the maximum number of blocks that can be changed, or -1 to use no limit
|
|
|
|
* @param blockBag an optional {@link BlockBag} to use, otherwise null
|
2014-07-29 21:23:00 +00:00
|
|
|
* @return an instance
|
2012-10-18 10:34:09 +00:00
|
|
|
*/
|
2014-04-05 09:59:38 +00:00
|
|
|
public EditSession getEditSession(World world, int maxBlocks, BlockBag blockBag) {
|
2012-10-18 10:34:09 +00:00
|
|
|
|
2014-07-18 21:46:39 +00:00
|
|
|
// ============ READ ME ============
|
|
|
|
|
|
|
|
// This method is actually implemented if you call WorldEdit.getEditSessionFactory()
|
|
|
|
// as it returns an instance of EditSessionFactoryImpl seen below.
|
|
|
|
|
|
|
|
// Previously, other plugins would create their own EditSessionFactory and extend ours and
|
|
|
|
// then use it to return custom EditSessions so the plugin could log block changes, etc.
|
|
|
|
// However, that method only allows one plugin to hook into WorldEdit at a time,
|
|
|
|
// so now we recommend catching the EditSessionEvent and hooking into our
|
|
|
|
// new(er) Extent framework.
|
|
|
|
|
|
|
|
throw new RuntimeException("Method needs to be implemented");
|
2014-04-05 09:59:38 +00:00
|
|
|
}
|
|
|
|
|
2012-11-13 10:07:08 +00:00
|
|
|
/**
|
|
|
|
* Construct an edit session with a maximum number of blocks and a block bag.
|
|
|
|
*
|
2014-04-03 01:57:25 +00:00
|
|
|
* @param world the world
|
|
|
|
* @param maxBlocks the maximum number of blocks that can be changed, or -1 to use no limit
|
|
|
|
* @param blockBag an optional {@link BlockBag} to use, otherwise null
|
2019-09-02 19:22:43 +00:00
|
|
|
* @param actor the actor that the {@link EditSession} is for
|
2014-07-29 21:23:00 +00:00
|
|
|
* @return an instance
|
2012-11-13 10:07:08 +00:00
|
|
|
*/
|
2019-09-02 19:22:43 +00:00
|
|
|
public EditSession getEditSession(World world, int maxBlocks, BlockBag blockBag, Actor actor) {
|
2014-07-18 21:46:39 +00:00
|
|
|
|
|
|
|
// ============ READ ME ============
|
|
|
|
|
|
|
|
// This method is actually implemented if you call WorldEdit.getEditSessionFactory()
|
|
|
|
// as it returns an instance of EditSessionFactoryImpl seen below.
|
|
|
|
|
|
|
|
// Previously, other plugins would create their own EditSessionFactory and extend ours and
|
|
|
|
// then use it to return custom EditSessions so the plugin could log block changes, etc.
|
|
|
|
// However, that method only allows one plugin to hook into WorldEdit at a time,
|
|
|
|
// so now we recommend catching the EditSessionEvent and hooking into our
|
|
|
|
// new(er) Extent framework.
|
|
|
|
|
|
|
|
throw new RuntimeException("Method needs to be implemented");
|
|
|
|
}
|
|
|
|
|
2014-04-04 03:48:42 +00:00
|
|
|
/**
|
|
|
|
* Internal factory for {@link EditSession}s.
|
|
|
|
*/
|
|
|
|
static final class EditSessionFactoryImpl extends EditSessionFactory {
|
|
|
|
|
|
|
|
private final EventBus eventBus;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new factory.
|
|
|
|
*
|
|
|
|
* @param eventBus the event bus
|
|
|
|
*/
|
2014-07-18 21:46:39 +00:00
|
|
|
EditSessionFactoryImpl(EventBus eventBus) {
|
2014-04-04 03:48:42 +00:00
|
|
|
checkNotNull(eventBus);
|
|
|
|
this.eventBus = eventBus;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-04-05 09:59:38 +00:00
|
|
|
public EditSession getEditSession(World world, int maxBlocks) {
|
2018-10-31 01:39:51 +00:00
|
|
|
return getEditSession(world, maxBlocks, null, null);
|
2014-04-04 03:48:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-09-02 19:22:43 +00:00
|
|
|
public EditSession getEditSession(World world, int maxBlocks, Actor actor) {
|
|
|
|
return getEditSession(world, maxBlocks, null, actor);
|
2014-04-04 03:48:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-04-05 09:59:38 +00:00
|
|
|
public EditSession getEditSession(World world, int maxBlocks, BlockBag blockBag) {
|
2018-10-31 01:39:51 +00:00
|
|
|
return getEditSession(world, maxBlocks, blockBag, null);
|
2014-04-04 03:48:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-09-02 19:22:43 +00:00
|
|
|
public EditSession getEditSession(World world, int maxBlocks, BlockBag blockBag, Actor actor) {
|
2018-10-31 01:39:51 +00:00
|
|
|
if (WorldEdit.getInstance().getConfiguration().traceUnflushedSessions) {
|
2019-09-02 19:22:43 +00:00
|
|
|
return new TracedEditSession(eventBus, world, maxBlocks, blockBag, new EditSessionEvent(world, actor, maxBlocks, null));
|
2018-10-31 01:39:51 +00:00
|
|
|
}
|
2019-09-02 19:22:43 +00:00
|
|
|
return new EditSession(eventBus, world, maxBlocks, blockBag, new EditSessionEvent(world, actor, maxBlocks, null));
|
2014-04-04 03:48:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2012-10-18 10:34:09 +00:00
|
|
|
}
|