WorldEdit 6.0
This commit is contained in:
parent
acb0717644
commit
87cde8e182
9 changed files with 114 additions and 553 deletions
15
pom.xml
15
pom.xml
|
@ -9,7 +9,7 @@
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<plib.version>1.4-SNAPSHOT</plib.version>
|
<plib.version>1.4-SNAPSHOT</plib.version>
|
||||||
<bukkit.version>1.8-R0.1-SNAPSHOT</bukkit.version>
|
<bukkit.version>1.8.3-R0.1-SNAPSHOT</bukkit.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<scm>
|
<scm>
|
||||||
|
@ -41,9 +41,9 @@
|
||||||
<url>http://repo.ja-s.de/mvn</url>
|
<url>http://repo.ja-s.de/mvn</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
<!-- Official (Craft-)Bukkit repository -->
|
<!-- (Craft-)Bukkit repository -->
|
||||||
<repository>
|
<repository>
|
||||||
<id>bukkit-repo</id>
|
<id>spigot-repo</id>
|
||||||
<url>http://repo.bukkit.org/content/groups/public</url>
|
<url>http://repo.bukkit.org/content/groups/public</url>
|
||||||
</repository>
|
</repository>
|
||||||
<!-- Official WorldGuard and WorldEdit repository -->
|
<!-- Official WorldGuard and WorldEdit repository -->
|
||||||
|
@ -91,6 +91,12 @@
|
||||||
<artifactId>worldguard</artifactId>
|
<artifactId>worldguard</artifactId>
|
||||||
<version>6.0.0-SNAPSHOT</version>
|
<version>6.0.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<!-- http://dev.bukkit.org/server-mods/worldedit/ -->
|
||||||
|
<groupId>com.sk89q</groupId>
|
||||||
|
<artifactId>worldedit</artifactId>
|
||||||
|
<version>6.0.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<!-- http://dev.bukkit.org/server-mods/authme-reloaded/ -->
|
<!-- http://dev.bukkit.org/server-mods/authme-reloaded/ -->
|
||||||
<groupId>uk.org.whoami</groupId>
|
<groupId>uk.org.whoami</groupId>
|
||||||
|
@ -158,9 +164,6 @@
|
||||||
<!-- Needed to fetch DocComments from Source -->
|
<!-- Needed to fetch DocComments from Source -->
|
||||||
<annotationProcessor>de.jaschastarke.maven.AnnotationProcessor</annotationProcessor>
|
<annotationProcessor>de.jaschastarke.maven.AnnotationProcessor</annotationProcessor>
|
||||||
</annotationProcessors>
|
</annotationProcessors>
|
||||||
<excludes>
|
|
||||||
<exclude>**/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/*</exclude>
|
|
||||||
</excludes>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package de.jaschastarke.minecraft.limitedcreative;
|
package de.jaschastarke.minecraft.limitedcreative;
|
||||||
|
|
||||||
|
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
|
|
||||||
import de.jaschastarke.bukkit.lib.CoreModule;
|
import de.jaschastarke.bukkit.lib.CoreModule;
|
||||||
import de.jaschastarke.bukkit.lib.commands.AliasHelpedCommand;
|
import de.jaschastarke.bukkit.lib.commands.AliasHelpedCommand;
|
||||||
import de.jaschastarke.bukkit.lib.modules.AdditionalBlockBreaks;
|
import de.jaschastarke.bukkit.lib.modules.AdditionalBlockBreaks;
|
||||||
|
@ -12,12 +15,11 @@ import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockListener;
|
||||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateCommand;
|
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateCommand;
|
||||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateConfig;
|
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateConfig;
|
||||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel;
|
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel;
|
||||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DependencyListener;
|
|
||||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.HangingListener;
|
import de.jaschastarke.minecraft.limitedcreative.blockstate.HangingListener;
|
||||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.PlayerListener;
|
import de.jaschastarke.minecraft.limitedcreative.blockstate.PlayerListener;
|
||||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.SyncronizedModel;
|
import de.jaschastarke.minecraft.limitedcreative.blockstate.SyncronizedModel;
|
||||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.ThreadedModel;
|
import de.jaschastarke.minecraft.limitedcreative.blockstate.ThreadedModel;
|
||||||
//import de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.LCEditSessionFactory;
|
import de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.EditSessionListener;
|
||||||
import de.jaschastarke.modularize.IModule;
|
import de.jaschastarke.modularize.IModule;
|
||||||
import de.jaschastarke.modularize.ModuleEntry;
|
import de.jaschastarke.modularize.ModuleEntry;
|
||||||
|
|
||||||
|
@ -50,7 +52,6 @@ public class ModBlockStates extends CoreModule<LimitedCreative> {
|
||||||
listeners.addListener(new BlockListener(this));
|
listeners.addListener(new BlockListener(this));
|
||||||
listeners.addListener(new HangingListener(this));
|
listeners.addListener(new HangingListener(this));
|
||||||
listeners.addListener(new PlayerListener(this));
|
listeners.addListener(new PlayerListener(this));
|
||||||
listeners.addListener(new DependencyListener(this));
|
|
||||||
|
|
||||||
command = new BlockStateCommand(this);
|
command = new BlockStateCommand(this);
|
||||||
}
|
}
|
||||||
|
@ -77,12 +78,11 @@ public class ModBlockStates extends CoreModule<LimitedCreative> {
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
getLog().warn("WorldEdit Integration is not Supported in this Version! Lookout for updates!");
|
try {
|
||||||
/*try {
|
WorldEdit.getInstance().getEventBus().register(new EditSessionListener(ModBlockStates.this));
|
||||||
LCEditSessionFactory.initFactory(ModBlockStates.this);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
getLog().warn(plugin.getLocale().trans("block_state.warning.worldedit_sessionfactory_failed", e.getMessage()));
|
getLog().warn(plugin.getLocale().trans("block_state.warning.worldedit_sessionfactory_failed", e.getMessage()));
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
}.runTaskLater(plugin, 1L);
|
}.runTaskLater(plugin, 1L);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
package de.jaschastarke.minecraft.limitedcreative.blockstate;
|
|
||||||
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.server.PluginEnableEvent;
|
|
||||||
|
|
||||||
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
|
|
||||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.LCEditSessionFactory;
|
|
||||||
|
|
||||||
public class DependencyListener implements Listener {
|
|
||||||
private ModBlockStates mod;
|
|
||||||
|
|
||||||
public DependencyListener(ModBlockStates mod) {
|
|
||||||
this.mod = mod;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPluginLoaded(PluginEnableEvent event) {
|
|
||||||
if (event.getPlugin().getName().equals("LogBlock") || event.getPlugin().getName().equals("WorldEdit")) {
|
|
||||||
try {
|
|
||||||
if (mod.getPlugin().getServer().getPluginManager().isPluginEnabled("WorldEdit"))
|
|
||||||
LCEditSessionFactory.initFactory(mod);
|
|
||||||
} catch (Exception e) {
|
|
||||||
mod.getLog().warn(mod.getPlugin().getLocale().trans("block_state.warning.worldedit_sessionfactory_failed", e.getMessage()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
package de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.Vector;
|
||||||
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||||
|
import com.sk89q.worldedit.extent.Extent;
|
||||||
|
import com.sk89q.worldedit.extent.logging.AbstractLoggingExtent;
|
||||||
|
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState;
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState.Source;
|
||||||
|
|
||||||
|
public class EditSessionExtent extends AbstractLoggingExtent {
|
||||||
|
private ModBlockStates mod;
|
||||||
|
private Player player = null;
|
||||||
|
private World world;
|
||||||
|
|
||||||
|
public EditSessionExtent(Extent extent, ModBlockStates mod, Player player, World world) {
|
||||||
|
super(extent);
|
||||||
|
this.mod = mod;
|
||||||
|
this.player = player;
|
||||||
|
this.world = world;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a block is being changed.
|
||||||
|
*
|
||||||
|
* @param position the position
|
||||||
|
* @param newBlock the new block to replace the old one
|
||||||
|
*/
|
||||||
|
protected void onBlockChange(Vector pt, BaseBlock newBlock) {
|
||||||
|
if (mod.isDebug())
|
||||||
|
mod.getLog().debug("WorldEdit-Integration: BlockChange: "+pt.toString()+" BB: " + newBlock.toString());
|
||||||
|
Location loc = new Location(world, pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||||
|
if (newBlock.getType() == 0) {
|
||||||
|
mod.getModel().removeState(loc.getBlock());
|
||||||
|
} else {
|
||||||
|
BlockState s = mod.getModel().getState(loc.getBlock());
|
||||||
|
if (s == null) {
|
||||||
|
s = new BlockState();
|
||||||
|
s.setLocation(loc);
|
||||||
|
}
|
||||||
|
s.setGameMode(null);
|
||||||
|
s.setPlayerName(player.getName());
|
||||||
|
s.setDate(new Date());
|
||||||
|
s.setSource(Source.EDIT);
|
||||||
|
if (mod.isDebug())
|
||||||
|
mod.getLog().debug("WorldEdit-Integration: Saving BlockState: " + s.toString());
|
||||||
|
|
||||||
|
mod.getModel().setState(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.EditSession.Stage;
|
||||||
|
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||||
|
import com.sk89q.worldedit.event.extent.EditSessionEvent;
|
||||||
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
|
import com.sk89q.worldedit.util.eventbus.Subscribe;
|
||||||
|
import com.sk89q.worldedit.world.World;
|
||||||
|
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
|
||||||
|
|
||||||
|
public class EditSessionListener {
|
||||||
|
private ModBlockStates mod;
|
||||||
|
|
||||||
|
public EditSessionListener(ModBlockStates mod) {
|
||||||
|
this.mod = mod;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onEditSession(EditSessionEvent event) {
|
||||||
|
if (mod.getConfig().getWorldeditIntegration()) {
|
||||||
|
if (event.getStage() == Stage.BEFORE_CHANGE) {
|
||||||
|
if (mod.isDebug())
|
||||||
|
mod.getLog().debug("WorldEdit-Integration: New EditSession: "+event.getActor().getName()+" in World "+event.getWorld().getName()); // + " (" + event.getStage() + ")");
|
||||||
|
Actor actor = event.getActor();
|
||||||
|
World world = event.getWorld();
|
||||||
|
if (actor != null && actor.isPlayer() && world != null && world instanceof BukkitWorld) {
|
||||||
|
Player player = Bukkit.getPlayer(actor.getUniqueId());
|
||||||
|
event.setExtent(new EditSessionExtent(event.getExtent(), mod, player, ((BukkitWorld) event.getWorld()).getWorld()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,97 +0,0 @@
|
||||||
package de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit;
|
|
||||||
|
|
||||||
import com.sk89q.worldedit.EditSession;
|
|
||||||
import com.sk89q.worldedit.LocalPlayer;
|
|
||||||
import com.sk89q.worldedit.LocalWorld;
|
|
||||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
|
||||||
import com.sk89q.worldedit.Vector;
|
|
||||||
import com.sk89q.worldedit.bags.BlockBag;
|
|
||||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
|
||||||
import com.sk89q.worldedit.patterns.Pattern;
|
|
||||||
import com.sk89q.worldedit.regions.Region;
|
|
||||||
|
|
||||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.DBTransaction;
|
|
||||||
|
|
||||||
public class LCEditSession extends EditSession {
|
|
||||||
private LCEditSessionFactory factory;
|
|
||||||
private LocalPlayer player;
|
|
||||||
|
|
||||||
public LCEditSession(LCEditSessionFactory factory, LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) {
|
|
||||||
super(world, maxBlocks, blockBag);
|
|
||||||
this.factory = factory;
|
|
||||||
this.player = player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LCEditSession(LCEditSessionFactory factory, LocalWorld world, int maxBlocks, LocalPlayer player) {
|
|
||||||
super(world, maxBlocks);
|
|
||||||
this.factory = factory;
|
|
||||||
this.player = player;
|
|
||||||
}
|
|
||||||
|
|
||||||
private DBTransaction transaction;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void flushQueue() {
|
|
||||||
transaction = factory.getModel().groupUpdate();
|
|
||||||
super.flushQueue();
|
|
||||||
if (transaction != null) {
|
|
||||||
transaction.finish();
|
|
||||||
transaction = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int setBlocks(Region region, BaseBlock block) throws MaxChangedBlocksException {
|
|
||||||
boolean useTransaction = false;
|
|
||||||
if (transaction == null) {
|
|
||||||
transaction = factory.getModel().groupUpdate();
|
|
||||||
useTransaction = true;
|
|
||||||
}
|
|
||||||
int ret;
|
|
||||||
try {
|
|
||||||
ret = super.setBlocks(region, block);
|
|
||||||
} catch (MaxChangedBlocksException e) {
|
|
||||||
transaction = null;
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
if (transaction != null && useTransaction) {
|
|
||||||
transaction.finish();
|
|
||||||
transaction = null;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException {
|
|
||||||
boolean useTransaction = false;
|
|
||||||
if (transaction == null) {
|
|
||||||
transaction = factory.getModel().groupUpdate();
|
|
||||||
useTransaction = true;
|
|
||||||
}
|
|
||||||
int ret;
|
|
||||||
try {
|
|
||||||
ret = super.setBlocks(region, pattern);
|
|
||||||
} catch (MaxChangedBlocksException e) {
|
|
||||||
transaction = null;
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
if (transaction != null && useTransaction) {
|
|
||||||
transaction.finish();
|
|
||||||
transaction = null;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean rawSetBlock(Vector pt, BaseBlock block) {
|
|
||||||
boolean success = super.rawSetBlock(pt, block);
|
|
||||||
if (success) {
|
|
||||||
if (transaction != null) {
|
|
||||||
factory.onTransactionBlockEdit(transaction, player, pt, block);
|
|
||||||
} else {
|
|
||||||
factory.onBlockEdit(player, pt, block);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,216 +0,0 @@
|
||||||
package de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit;
|
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import org.bukkit.Location;
|
|
||||||
|
|
||||||
import com.sk89q.worldedit.EditSession;
|
|
||||||
import com.sk89q.worldedit.EditSessionFactory;
|
|
||||||
import com.sk89q.worldedit.LocalPlayer;
|
|
||||||
import com.sk89q.worldedit.LocalWorld;
|
|
||||||
import com.sk89q.worldedit.Vector;
|
|
||||||
import com.sk89q.worldedit.WorldEdit;
|
|
||||||
import com.sk89q.worldedit.bags.BlockBag;
|
|
||||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
|
||||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
|
||||||
|
|
||||||
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
|
|
||||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState;
|
|
||||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState.Source;
|
|
||||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel;
|
|
||||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.DBTransaction;
|
|
||||||
|
|
||||||
public class LCEditSessionFactory extends EditSessionFactory {
|
|
||||||
private ModBlockStates mod;
|
|
||||||
private EditSessionParent parent;
|
|
||||||
|
|
||||||
static enum EditSessionParent {
|
|
||||||
WORLDEDIT,
|
|
||||||
LOGBLOCK("de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.LCEditSession_LogBlock"),
|
|
||||||
COREPROTECT("de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.LCEditSession_CoreProtect");
|
|
||||||
|
|
||||||
private String cls = null;
|
|
||||||
EditSessionParent() {
|
|
||||||
}
|
|
||||||
EditSessionParent(String cls) {
|
|
||||||
this.cls = cls;
|
|
||||||
}
|
|
||||||
public EditSession createInstance(LCEditSessionFactory factory, LocalWorld world, int maxBlocks, LocalPlayer player) {
|
|
||||||
if (this.cls != null) {
|
|
||||||
try {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Class<EditSession> sessClass = (Class<EditSession>) Class.forName(cls);
|
|
||||||
return sessClass.getConstructor(LCEditSessionFactory.class, LocalWorld.class, int.class, LocalPlayer.class)
|
|
||||||
.newInstance(factory, world, maxBlocks, player);
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (InstantiationException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (SecurityException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new LCEditSession(factory, world, maxBlocks, player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public EditSession createInstance(LCEditSessionFactory factory, LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) {
|
|
||||||
if (this.cls != null) {
|
|
||||||
try {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Class<EditSession> sessClass = (Class<EditSession>) Class.forName(cls);
|
|
||||||
return sessClass.getConstructor(LCEditSessionFactory.class, LocalWorld.class, int.class, LocalPlayer.class)
|
|
||||||
.newInstance(factory, world, maxBlocks, player);
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (InstantiationException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (SecurityException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new LCEditSession(factory, world, maxBlocks, player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ModBlockStates getLimitedCreativeModule() {
|
|
||||||
return mod;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LCEditSessionFactory(ModBlockStates mod, EditSessionParent parent) {
|
|
||||||
this.mod = mod;
|
|
||||||
this.parent = parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EditSession getEditSession(LocalWorld world, int maxBlocks, LocalPlayer player) {
|
|
||||||
return parent.createInstance(this, world, maxBlocks, player);
|
|
||||||
/*switch (parent) {
|
|
||||||
case LOGBLOCK:
|
|
||||||
return new LCEditSession_LogBlock(this, world, maxBlocks, player);
|
|
||||||
default:
|
|
||||||
return new LCEditSession(this, world, maxBlocks, player);
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|
||||||
// Without Player, the world isn't know, so we can't opporate
|
|
||||||
/*@Override
|
|
||||||
public EditSession getEditSession(LocalWorld world, int maxBlocks) {
|
|
||||||
return new LCEditSession(this, world, maxBlocks, null);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EditSession getEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) {
|
|
||||||
return parent.createInstance(this, world, maxBlocks, blockBag, player);
|
|
||||||
/*switch (parent) {
|
|
||||||
case LOGBLOCK:
|
|
||||||
return new LCEditSession_LogBlock(this, world, maxBlocks, blockBag, player);
|
|
||||||
default:
|
|
||||||
return new LCEditSession(this, world, maxBlocks, blockBag, player);
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|
||||||
/*@Override
|
|
||||||
public EditSession getEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag) {
|
|
||||||
return new LCEditSession(this, world, maxBlocks, blockBag, null);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
public static void initFactory(ModBlockStates mod) throws Exception {
|
|
||||||
EditSessionFactory currentEditSessionFactory = WorldEdit.getInstance().getEditSessionFactory();
|
|
||||||
if (currentEditSessionFactory instanceof LCEditSessionFactory) {
|
|
||||||
if (mod.isDebug())
|
|
||||||
mod.getLog().debug("WorlEdit-SessionFactory is already hooked");
|
|
||||||
} else if (currentEditSessionFactory.getClass().equals(EditSessionFactory.class)) { // not overridden
|
|
||||||
if (mod.isDebug())
|
|
||||||
mod.getLog().debug("Replacing WorldEdits SessionFactory");
|
|
||||||
WorldEdit.getInstance().setEditSessionFactory(new LCEditSessionFactory(mod, EditSessionParent.WORLDEDIT));
|
|
||||||
} else if (currentEditSessionFactory.getClass().getName().equals("de.diddiz.worldedit.LogBlockEditSessionFactory")) {
|
|
||||||
if (mod.isDebug())
|
|
||||||
mod.getLog().debug("Replacing LogBlocks WorldEdit-SessionFactory");
|
|
||||||
WorldEdit.getInstance().setEditSessionFactory(new LCEditSessionFactory(mod, EditSessionParent.LOGBLOCK));
|
|
||||||
} else if (currentEditSessionFactory.getClass().getName().equals("net.coreprotect.worldedit.CoreProtectEditSessionFactory")) {
|
|
||||||
if (mod.isDebug())
|
|
||||||
mod.getLog().debug("Replacing CoreProtects WorldEdit-SessionFactory");
|
|
||||||
WorldEdit.getInstance().setEditSessionFactory(new LCEditSessionFactory(mod, EditSessionParent.COREPROTECT));
|
|
||||||
} else {
|
|
||||||
throw new Exception("WorldEdit-SessionFactory is hooked by an unknown another Plugin (" + currentEditSessionFactory.getClass().getName() + ").");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*public void onBlockEdit(Vector pt, BaseBlock block) {
|
|
||||||
this.onBlockEdit(null, pt, block);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
public DBModel getModel() {
|
|
||||||
return mod.getModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean onBlockEdit(LocalPlayer player, Vector pt, BaseBlock block) {
|
|
||||||
if (player != null) {
|
|
||||||
Location loc = new Location(((BukkitWorld) player.getWorld()).getWorld(), pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
|
||||||
if (block.getType() == 0) {
|
|
||||||
mod.getModel().removeState(loc.getBlock());
|
|
||||||
} else {
|
|
||||||
BlockState s = mod.getModel().getState(loc.getBlock());
|
|
||||||
if (s == null) {
|
|
||||||
s = new BlockState();
|
|
||||||
s.setLocation(loc);
|
|
||||||
}
|
|
||||||
s.setGameMode(null);
|
|
||||||
s.setPlayerName(player.getName());
|
|
||||||
s.setDate(new Date());
|
|
||||||
s.setSource(Source.EDIT);
|
|
||||||
if (mod.isDebug())
|
|
||||||
mod.getLog().debug("Saving BlockState: " + s.toString());
|
|
||||||
|
|
||||||
mod.getModel().setState(s);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean onTransactionBlockEdit(DBTransaction transaction, LocalPlayer player, Vector pt, BaseBlock block) {
|
|
||||||
if (player != null) {
|
|
||||||
Location loc = new Location(((BukkitWorld) player.getWorld()).getWorld(), pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
|
||||||
if (block.getType() == 0) {
|
|
||||||
transaction.removeState(loc.getBlock());
|
|
||||||
} else {
|
|
||||||
BlockState s = mod.getModel().getState(loc.getBlock());
|
|
||||||
if (s == null) {
|
|
||||||
s = new BlockState();
|
|
||||||
s.setLocation(loc);
|
|
||||||
}
|
|
||||||
s.setGameMode(null);
|
|
||||||
s.setPlayerName(player.getName());
|
|
||||||
s.setDate(new Date());
|
|
||||||
s.setSource(Source.EDIT);
|
|
||||||
if (mod.isDebug())
|
|
||||||
mod.getLog().debug("Saving BlockState: " + s.toString());
|
|
||||||
|
|
||||||
transaction.setState(s);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,99 +0,0 @@
|
||||||
package de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit;
|
|
||||||
|
|
||||||
import net.coreprotect.CoreProtect;
|
|
||||||
import net.coreprotect.worldedit.CoreProtectEditSession;
|
|
||||||
|
|
||||||
import com.sk89q.worldedit.LocalPlayer;
|
|
||||||
import com.sk89q.worldedit.LocalWorld;
|
|
||||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
|
||||||
import com.sk89q.worldedit.Vector;
|
|
||||||
import com.sk89q.worldedit.bags.BlockBag;
|
|
||||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
|
||||||
import com.sk89q.worldedit.patterns.Pattern;
|
|
||||||
import com.sk89q.worldedit.regions.Region;
|
|
||||||
|
|
||||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.DBTransaction;
|
|
||||||
|
|
||||||
public class LCEditSession_CoreProtect extends CoreProtectEditSession {
|
|
||||||
private LCEditSessionFactory factory;
|
|
||||||
private LocalPlayer player;
|
|
||||||
|
|
||||||
public LCEditSession_CoreProtect(LCEditSessionFactory factory, LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) {
|
|
||||||
super(world, maxBlocks, blockBag, player, CoreProtect.getInstance());
|
|
||||||
this.factory = factory;
|
|
||||||
this.player = player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LCEditSession_CoreProtect(LCEditSessionFactory factory, LocalWorld world, int maxBlocks, LocalPlayer player) {
|
|
||||||
super(world, maxBlocks, player, CoreProtect.getInstance());
|
|
||||||
this.factory = factory;
|
|
||||||
this.player = player;
|
|
||||||
}
|
|
||||||
|
|
||||||
private DBTransaction transaction;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void flushQueue() {
|
|
||||||
transaction = factory.getModel().groupUpdate();
|
|
||||||
super.flushQueue();
|
|
||||||
if (transaction != null) {
|
|
||||||
transaction.finish();
|
|
||||||
transaction = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int setBlocks(Region region, BaseBlock block) throws MaxChangedBlocksException {
|
|
||||||
boolean useTransaction = false;
|
|
||||||
if (transaction == null) {
|
|
||||||
transaction = factory.getModel().groupUpdate();
|
|
||||||
useTransaction = true;
|
|
||||||
}
|
|
||||||
int ret;
|
|
||||||
try {
|
|
||||||
ret = super.setBlocks(region, block);
|
|
||||||
} catch (MaxChangedBlocksException e) {
|
|
||||||
transaction = null;
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
if (transaction != null && useTransaction) {
|
|
||||||
transaction.finish();
|
|
||||||
transaction = null;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException {
|
|
||||||
boolean useTransaction = false;
|
|
||||||
if (transaction == null) {
|
|
||||||
transaction = factory.getModel().groupUpdate();
|
|
||||||
useTransaction = true;
|
|
||||||
}
|
|
||||||
int ret;
|
|
||||||
try {
|
|
||||||
ret = super.setBlocks(region, pattern);
|
|
||||||
} catch (MaxChangedBlocksException e) {
|
|
||||||
transaction = null;
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
if (transaction != null && useTransaction) {
|
|
||||||
transaction.finish();
|
|
||||||
transaction = null;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean rawSetBlock(Vector pt, BaseBlock block) {
|
|
||||||
boolean success = super.rawSetBlock(pt, block);
|
|
||||||
if (success) {
|
|
||||||
if (transaction != null) {
|
|
||||||
factory.onTransactionBlockEdit(transaction, player, pt, block);
|
|
||||||
} else {
|
|
||||||
factory.onBlockEdit(player, pt, block);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,98 +0,0 @@
|
||||||
package de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit;
|
|
||||||
|
|
||||||
import com.sk89q.worldedit.LocalPlayer;
|
|
||||||
import com.sk89q.worldedit.LocalWorld;
|
|
||||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
|
||||||
import com.sk89q.worldedit.Vector;
|
|
||||||
import com.sk89q.worldedit.bags.BlockBag;
|
|
||||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
|
||||||
import com.sk89q.worldedit.patterns.Pattern;
|
|
||||||
import com.sk89q.worldedit.regions.Region;
|
|
||||||
|
|
||||||
import de.diddiz.LogBlock.LogBlock;
|
|
||||||
import de.diddiz.worldedit.LogBlockEditSession;
|
|
||||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.DBTransaction;
|
|
||||||
|
|
||||||
public class LCEditSession_LogBlock extends LogBlockEditSession {
|
|
||||||
private LCEditSessionFactory factory;
|
|
||||||
private LocalPlayer player;
|
|
||||||
|
|
||||||
public LCEditSession_LogBlock(LCEditSessionFactory factory, LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) {
|
|
||||||
super(world, maxBlocks, blockBag, player, LogBlock.getInstance());
|
|
||||||
this.factory = factory;
|
|
||||||
this.player = player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LCEditSession_LogBlock(LCEditSessionFactory factory, LocalWorld world, int maxBlocks, LocalPlayer player) {
|
|
||||||
super(world, maxBlocks, player, LogBlock.getInstance());
|
|
||||||
this.factory = factory;
|
|
||||||
this.player = player;
|
|
||||||
}
|
|
||||||
|
|
||||||
private DBTransaction transaction;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void flushQueue() {
|
|
||||||
transaction = factory.getModel().groupUpdate();
|
|
||||||
super.flushQueue();
|
|
||||||
if (transaction != null) {
|
|
||||||
transaction.finish();
|
|
||||||
transaction = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int setBlocks(Region region, BaseBlock block) throws MaxChangedBlocksException {
|
|
||||||
boolean useTransaction = false;
|
|
||||||
if (transaction == null) {
|
|
||||||
transaction = factory.getModel().groupUpdate();
|
|
||||||
useTransaction = true;
|
|
||||||
}
|
|
||||||
int ret;
|
|
||||||
try {
|
|
||||||
ret = super.setBlocks(region, block);
|
|
||||||
} catch (MaxChangedBlocksException e) {
|
|
||||||
transaction = null;
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
if (transaction != null && useTransaction) {
|
|
||||||
transaction.finish();
|
|
||||||
transaction = null;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException {
|
|
||||||
boolean useTransaction = false;
|
|
||||||
if (transaction == null) {
|
|
||||||
transaction = factory.getModel().groupUpdate();
|
|
||||||
useTransaction = true;
|
|
||||||
}
|
|
||||||
int ret;
|
|
||||||
try {
|
|
||||||
ret = super.setBlocks(region, pattern);
|
|
||||||
} catch (MaxChangedBlocksException e) {
|
|
||||||
transaction = null;
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
if (transaction != null && useTransaction) {
|
|
||||||
transaction.finish();
|
|
||||||
transaction = null;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean rawSetBlock(Vector pt, BaseBlock block) {
|
|
||||||
boolean success = super.rawSetBlock(pt, block);
|
|
||||||
if (success) {
|
|
||||||
if (transaction != null) {
|
|
||||||
factory.onTransactionBlockEdit(transaction, player, pt, block);
|
|
||||||
} else {
|
|
||||||
factory.onBlockEdit(player, pt, block);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue