So my code is boolean Success = BlockLocation.setBlockType(BlockTypes.BEDROCK);
But Success will somtimes = false and sometimes be true I am attempting too create a rollback plugin it will always do it on the same exact cords that it did not work on before. Am I missing something why does setBlockType fail?
It could be for many many reasons…
1,it’s not a valid pos, for example the axis Y is biger than 256 or less then 0.
2, The block in that position is the same as the block you want to set.
here is some common reason, and you’d better import and setup sponges and mixins to debug
I destroy the block everytime before I update it too a new block type. the Cords are correct but it still fails too roll the block back
Mind showing your code?
private void RollBack(Player player,String PlayerName) {
PlayerBlockLog UserLog = main.getPlayerBlockLog(PlayerName);
ArrayList<BlockLog> UserBlockLog = UserLog.BlockLogs;
for(int i = 0; i < UserBlockLog.size(); i++) {
BlockLog CurrentBlockLog = UserBlockLog.get(i);
String RecentID = CurrentBlockLog.getRecentID();
int XCord = CurrentBlockLog.getXCord();
int YCord = CurrentBlockLog.getYCord();
int ZCord = CurrentBlockLog.getZCord();
Location<World> BlockLocation = new Location<World>(Sponge.getServer().getWorld("world").get() , XCord, YCord, ZCord);
BlockType NewBlockType = Sponge.getGame().getRegistry().getType(BlockType.class, RecentID).get();
//This checks if it is a placed block if it is a place block remove that placed block
if(RecentID.contentEquals("minecraft:air") == true) {
boolean Success = false;
Success = BlockLocation.removeBlock();
if(Success == false) player.sendMessage(Text.of("ERROR FAILED TOO REMOVE BLOCK ID: " + BlockLocation.getBlockType().getId()));
if(Success == false) player.sendMessage(Text.of("XCord: " + XCord + " YCord: " + YCord + " ZCord: " + ZCord));
i++;
continue;
}
//This is if a block was removed
boolean Success = false;
BlockLocation.removeBlock();
Success = BlockLocation.setBlockType(NewBlockType);
if(Success == false) player.sendMessage(Text.of("ERROR FAILED TOO ROLLBACK BLOCK ID: " + BlockLocation.getBlockType().getId()));
if(Success == false) player.sendMessage(Text.of("XCord: " + XCord + " YCord: " + YCord + " ZCord: " + ZCord));
i++;
}
}
Because you are removing the block and then setting the block within the same tick, its likely that it would return false.
I have figured out the solution too this issue. It seems I was accessing the wrong userdatalogs for block place and break history so that explains it.(Something completely not apart of the Sponge API my own project I am working on.)
for(int i = 0; i < UserBlockLog.size(); i++) { This is suppose too be this
for(int i = 0; i < UserBlockLog.size(); ) {