Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More a reminder that a solution was found #5

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
.idea/
.gradle/
build/
*.class
.vscode
bin
10 changes: 6 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = "com.iridium"
version = "1.0.7"
version = "1.0.8"
description = "IridiumChunkBusters"

repositories {
Expand All @@ -14,17 +14,19 @@ repositories {
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
maven("https://ci.ender.zone/plugin/repository/everything/")
maven("https://jitpack.io")
maven("https://nexus.iridiumdevelopment.net/repository/maven-releases/")
maven("https://papermc.io/repo/repository/maven-public/")
maven("https://repo.rosewooddev.io/repository/public/")
maven("https://hub.jeff-media.com/nexus/repository/jeff-media-public/")
maven("https://moyskleytech.com/debian/m2/")
mavenLocal()
mavenCentral()
maven("https://nexus.iridiumdevelopment.net/repository/maven-releases/")
}

dependencies {
// Dependencies that we want to shade in
implementation("org.jetbrains:annotations:22.0.0")
implementation("com.iridium:IridiumCore:1.5.3")
implementation("com.iridium:IridiumCore:1.6.7")
implementation("org.bstats:bstats-bukkit:3.0.0")
implementation("com.j256.ormlite:ormlite-core:6.1")
implementation("com.j256.ormlite:ormlite-jdbc:6.1")
Expand All @@ -34,7 +36,7 @@ dependencies {
compileOnly("org.projectlombok:lombok:1.18.22")
compileOnly("org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT")
compileOnly("net.prosavage:FactionsX:1.2")
compileOnly("com.massivecraft.massivesuper:MassiveSuper:2.14.0")
compileOnly("com.massivecraft.massivesuper:MassiveCore:2.14")
compileOnly("com.massivecraft.massivesuper:Factions:2.14.0")
compileOnly("com.massivecraft:Factions:1.6.9.5-U0.6.8") {
exclude("com.darkblade12")
Expand Down
90 changes: 87 additions & 3 deletions src/main/java/com/iridium/chunkbusters/database/BlockData.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import lombok.NoArgsConstructor;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;

import java.io.StringReader;
import java.util.Base64;

@Getter
Expand Down Expand Up @@ -45,7 +47,7 @@ public class BlockData {
private String blocks;

public ChunkLayer getBlocks() {
return IridiumChunkBusters.getInstance().getPersist().load(ChunkLayer.class, new String(Base64.getDecoder().decode(blocks)));
return alternateDeserializer(blocks);
}

public Chunk getChunk() {
Expand All @@ -58,6 +60,88 @@ public BlockData(@NotNull ChunkBuster chunkBuster, @NotNull String world, int x,
this.x = x;
this.y = y;
this.z = z;
this.blocks = new String(Base64.getEncoder().encode(IridiumChunkBusters.getInstance().getPersist().toString(blocks).getBytes()));
this.blocks = new String(Base64.getEncoder().encode(alternateSerialize(blocks).getBytes()));
}
}
private ChunkLayer alternateDeserializer(String base64)
{
String ymlString = new String(Base64.getDecoder().decode(base64));
//System.out.println(ymlString);
ChunkLayer cl = new ChunkLayer();
//ChunkLayer cl = IridiumChunkBusters.getInstance().getPersist().load(ChunkLayer.class, );
String[] lines = ymlString.split("\n");
boolean isReadingBlocks = false,isReadingData=false;
int index1=0,index2=0;

for (String line : lines) {
if(line.contains("blocks:"))
{
isReadingBlocks=true;
index1=-1;
index2=0;
continue;
}
if(line.contains("data:"))
{
isReadingBlocks=false;
isReadingData=true;
index1=0;
continue;
}
if(isReadingBlocks)
{
if(line.contains("- - "))
{
index1++;
index2=0;
}
//System.out.println("Line {"+line+"} Reading, i1="+index1+",i2="+index2);
String substringed = line.substring(4);
Material matched = Material.getMaterial(substringed);
//System.out.println("Line {"+substringed+"} matched as "+matched);

cl.blocks[index1][index2++]= matched;
}
if(isReadingData)
{
if(line.startsWith(" "))
cl.data[index1++] = Base64.getDecoder().decode(line.substring(2));
}
}

return cl;
}
private String alternateSerialize(ChunkLayer cl)
{
//return IridiumChunkBusters.getInstance().getPersist().toString(cl);
StringBuilder sb = new StringBuilder("---\n");
sb.append("blocks:\n");

for(Material[] row:cl.blocks)
{
boolean first=true;

for(Material mat:row)
{
sb.append(first?"- ":" ");
sb.append("- ");
if(mat!=null)
sb.append(mat.name());
else
sb.append("null");
sb.append("\n");
first=false;
}
}

sb.append("data:\n");
for(byte[] row:cl.data)
{
sb.append("- !!binary |-\n");
sb.append(" ");
sb.append(new String(Base64.getEncoder().encode(row)));
sb.append("\n");
}

return sb.toString();
}
}
17 changes: 12 additions & 5 deletions src/main/java/com/iridium/chunkbusters/database/ChunkBuster.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -114,11 +115,12 @@ private void deleteChunks(final List<Chunk> chunks, int minHeight) {
for (int x = cx; x < cx + 16; x++) {
for (int z = cz; z < cz + 16; z++) {
Location location = new Location(world, x, y, z);
BlockState blockState = location.getBlock().getState();
Block block = location.getBlock();
BlockState blockState = block.getState();
if (IridiumChunkBusters.getInstance().getConfiguration().blacklist.contains(XMaterial.matchXMaterial(blockState.getType())) || !IridiumChunkBusters.getInstance().getSupport().canDelete(player, location) || blockState.getType().equals(Material.AIR) || chunkBusters.contains(location)) {
continue;
}
chunkLayer.blocks[x - cx][z - cz] = blockState.getType();
chunkLayer.blocks[x - cx][z - cz] = block.getType();
chunkLayer.data[x - cx][z - cz] = blockState.getRawData();
IridiumChunkBusters.getInstance().getNms().deleteBlockFast(location);
}
Expand Down Expand Up @@ -149,11 +151,16 @@ public void undo() {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
if (chunkLayer.blocks[x][z] == null) continue;
BlockState blockState = chunk.getBlock(x, y, z).getState();
if (IridiumChunkBusters.getInstance().getConfiguration().onlyRestoreWhenBlockIsAir && !blockState.getType().equals(Material.AIR))
Block block=chunk.getBlock(x, y, z);

if (IridiumChunkBusters.getInstance().getConfiguration().onlyRestoreWhenBlockIsAir && !block.getType().equals(Material.AIR))
continue;

block.setType(chunkLayer.blocks[x][z],false);
BlockState blockState = block.getState();
blockState.setType(chunkLayer.blocks[x][z]);
blockState.setRawData(chunkLayer.data[x][z]);
blockState.getData().setData(chunkLayer.data[x][z]);
//blockState.setRawData(chunkLayer.data[x][z]);
blockState.update(true, false);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: IridiumChunkBusters
version: 1.0.3
version: 1.0.8
description: A plugin for removing chunks
main: com.iridium.chunkbusters.IridiumChunkBusters
api-version: '1.13'
Expand Down