PistonGlitch Fixes

Ticket #147
This commit is contained in:
Jascha Starke 2013-09-19 17:17:05 +02:00
parent 9a6d57f2e2
commit 2bb077f94f
2 changed files with 19 additions and 2 deletions

View file

@ -124,7 +124,7 @@ public class BlockListener implements Listener {
if (mod.isDebug()) if (mod.isDebug())
mod.getLog().debug("PistionExtend moves "+sblock.getType()+"-Block from "+sblock.getLocation()+" to "+dest.getLocation()); 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(); mod.getQueries().getDB().endTransaction();
} }
@ -148,8 +148,12 @@ public class BlockListener implements Listener {
try { try {
if (mod.isDebug()) if (mod.isDebug())
mod.getLog().debug("PistionRetract moves "+source.getType()+"-Block from "+source.getLocation()+" to "+dest.getLocation()); 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) { } catch (SQLException e) {
try {
mod.getQueries().getDB().revertTransaction();
} catch (SQLException e1) {
}
mod.getLog().warn("DB-Error while onBlockMove (retract): "+e.getMessage()); mod.getLog().warn("DB-Error while onBlockMove (retract): "+e.getMessage());
//event.setCancelled(true); //event.setCancelled(true);
} }

View file

@ -23,6 +23,19 @@ public class DBModel {
this.q = mod.getQueries(); 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 { public void removeState(BlockState state) throws SQLException {
//removeMetaBlock(state.getLocation().getBlock()); //removeMetaBlock(state.getLocation().getBlock());
setMetaBlock(state.getLocation().getBlock(), null); setMetaBlock(state.getLocation().getBlock(), null);