diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockListener.java index 831fe5f..3dfdd5e 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockListener.java @@ -124,7 +124,7 @@ public class BlockListener implements Listener { if (mod.isDebug()) mod.getLog().debug("PistionExtend moves "+sblock.getType()+"-Block from "+sblock.getLocation()+" to "+dest.getLocation()); - mod.getQueries().move(sblock.getLocation(), dest.getLocation()); + mod.getModel().moveState(sblock, dest); } mod.getQueries().getDB().endTransaction(); } @@ -148,8 +148,12 @@ public class BlockListener implements Listener { try { if (mod.isDebug()) mod.getLog().debug("PistionRetract moves "+source.getType()+"-Block from "+source.getLocation()+" to "+dest.getLocation()); - mod.getQueries().move(source.getLocation(), source.getRelative(event.getDirection().getOppositeFace()).getLocation()); + mod.getModel().moveState(source, source.getRelative(event.getDirection().getOppositeFace())); } catch (SQLException e) { + try { + mod.getQueries().getDB().revertTransaction(); + } catch (SQLException e1) { + } mod.getLog().warn("DB-Error while onBlockMove (retract): "+e.getMessage()); //event.setCancelled(true); } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/DBModel.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/DBModel.java index 3f504fb..758c60f 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/DBModel.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/DBModel.java @@ -23,6 +23,19 @@ public class DBModel { this.q = mod.getQueries(); } + public void moveState(Block from, Block to) throws SQLException { + q.delete(to.getLocation()); + q.move(from.getLocation(), to.getLocation()); + HasBlockState metaBlock = getMetaBlock(from); + if (metaBlock.set) { + BlockState state = metaBlock.state; + state.setLocation(to.getLocation()); + setMetaBlock(to, getMetaBlock(from).state); + } else { + removeMetaBlock(to); + } + setMetaBlock(from, null); + } public void removeState(BlockState state) throws SQLException { //removeMetaBlock(state.getLocation().getBlock()); setMetaBlock(state.getLocation().getBlock(), null);