Skip to content

Commit

Permalink
Rename APalettedContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurelien30000 committed Jul 12, 2022
1 parent c927557 commit f6d2ce0
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
6 changes: 3 additions & 3 deletions src/main/java/com/plotsquared/plothider/PacketHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.plothider.storage.BlockStorage;
import com.plotsquared.plothider.storage.palette.APalettedContainer;
import com.plotsquared.plothider.storage.palette.PalettedContainer;
import com.plotsquared.plothider.storage.palette.PalettedContainerType;
import org.bukkit.entity.Player;

Expand Down Expand Up @@ -340,8 +340,8 @@ public void onPacketSending(PacketEvent event) {
== plot3) || (current == plot4)) {
for (BlockStorage section1 : array) {
for (int y = 0; y < 16; y++) {
if (section1.getBlock(x, y, z) != APalettedContainer.AIR) {
section1.setBlock(x, y, z, APalettedContainer.AIR);
if (section1.getBlock(x, y, z) != PalettedContainer.AIR) {
section1.setBlock(x, y, z, PalettedContainer.AIR);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
package com.plotsquared.plothider.storage;

import com.plotsquared.plothider.storage.palette.APalettedContainer;
import com.plotsquared.plothider.storage.palette.PalettedContainer;
import com.plotsquared.plothider.storage.palette.PalettedContainerType;

import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -73,7 +73,7 @@ public void read(ByteArrayInputStream buffer, PalettedContainerType palettedCont
// Read the actual (compressed) block data.
long[] data = BlockStorage.readLongs(buffer, dataArrayLength);

APalettedContainer palettedContainer = APalettedContainer.build(palettedContainerType, bitsPerEntry, states, data);
PalettedContainer palettedContainer = PalettedContainer.build(palettedContainerType, bitsPerEntry, states, data);
if (palettedContainerType == PalettedContainerType.BLOCKS) {
storage.setBlocksPalletedContainer(palettedContainer);
} else {
Expand All @@ -85,18 +85,18 @@ public void read(ByteArrayInputStream buffer, PalettedContainerType palettedCont
}

public int getBlock(int x, int y, int z) {
APalettedContainer palettedContainer = this.storage.getBlocksPalletedContainer();
PalettedContainer palettedContainer = this.storage.getBlocksPalletedContainer();

int id = palettedContainer.get(index(x, y, z));
return palettedContainer.getBitsPerEntry() <= 8 ?
(id >= 0 && id < palettedContainer.getStates().size()
? palettedContainer.getStates().get(id)
: APalettedContainer.AIR) :
: PalettedContainer.AIR) :
id;
}

public void setBlock(int x, int y, int z, int state) {
APalettedContainer palettedContainer = this.storage.getBlocksPalletedContainer();
PalettedContainer palettedContainer = this.storage.getBlocksPalletedContainer();
byte bitsPerEntry = palettedContainer.getBitsPerEntry();

int id = bitsPerEntry <= 8
Expand All @@ -113,7 +113,7 @@ public void setBlock(int x, int y, int z, int state) {
if (bitsPerEntry > 8) {
oldStates = new ArrayList<>(palettedContainer.getStates());
palettedContainer.getStates().clear();
bitsPerEntry = APalettedContainer.DIRECT_PALETTE_SIZE;
bitsPerEntry = PalettedContainer.DIRECT_PALETTE_SIZE;
}
FlexibleStorage oldStorage = this.storage;
this.storage = new FlexibleStorage(bitsPerEntry, palettedContainer.getStates(),
Expand All @@ -136,7 +136,7 @@ public void setBlock(int x, int y, int z, int state) {
// Make the changes.
palettedContainer.set(index(x, y, z), id);

if (state == APalettedContainer.AIR)
if (state == PalettedContainer.AIR)
blockCount--;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
package com.plotsquared.plothider.storage;

import com.plotsquared.plothider.storage.palette.APalettedContainer;
import com.plotsquared.plothider.storage.palette.PalettedContainer;
import com.plotsquared.plothider.storage.palette.PalettedContainerType;

import java.io.ByteArrayOutputStream;
Expand All @@ -32,37 +32,37 @@

public class FlexibleStorage {

private APalettedContainer blocksPalletedContainer;
private APalettedContainer biomesPalletedContainer;
private PalettedContainer blocksPalletedContainer;
private PalettedContainer biomesPalletedContainer;

public FlexibleStorage() {
this.blocksPalletedContainer = null;
this.biomesPalletedContainer = null;
}

public FlexibleStorage(byte bitsPerEntry, List<Integer> states, int bytes) {
this(bitsPerEntry, states, new long[(bytes + ((char) (64 / APalettedContainer.getRealUsedBits(bitsPerEntry))) - 1)
/ ((char) (64 / APalettedContainer.getRealUsedBits(bitsPerEntry)))]);
this(bitsPerEntry, states, new long[(bytes + ((char) (64 / PalettedContainer.getRealUsedBits(bitsPerEntry))) - 1)
/ ((char) (64 / PalettedContainer.getRealUsedBits(bitsPerEntry)))]);
}

public FlexibleStorage(byte bitsPerEntry, List<Integer> states, long[] data) {
this.blocksPalletedContainer = APalettedContainer.build(PalettedContainerType.BLOCKS, bitsPerEntry, states, data);
this.blocksPalletedContainer = PalettedContainer.build(PalettedContainerType.BLOCKS, bitsPerEntry, states, data);
this.biomesPalletedContainer = null;
}

public APalettedContainer getBlocksPalletedContainer() {
public PalettedContainer getBlocksPalletedContainer() {
return blocksPalletedContainer;
}

public APalettedContainer getBiomesPalletedContainer() {
public PalettedContainer getBiomesPalletedContainer() {
return biomesPalletedContainer;
}

public void setBlocksPalletedContainer(APalettedContainer blocksPalletedContainer) {
public void setBlocksPalletedContainer(PalettedContainer blocksPalletedContainer) {
this.blocksPalletedContainer = blocksPalletedContainer;
}

public void setBiomesPalletedContainer(APalettedContainer biomesPalletedContainer) {
public void setBiomesPalletedContainer(PalettedContainer biomesPalletedContainer) {
this.biomesPalletedContainer = biomesPalletedContainer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* @since TODO
*/
public class PaddedPalettedContainer extends APalettedContainer {
public class PaddedPalettedContainer extends PalettedContainer {

private static final int[] MAGIC = new int[]{-1, -1, 0, Integer.MIN_VALUE, 0, 0, 1431655765, 1431655765, 0, Integer.MIN_VALUE, 0, 1, 858993459, 858993459, 0, 715827882, 715827882, 0, 613566756, 613566756, 0, Integer.MIN_VALUE, 0, 2, 477218588, 477218588, 0, 429496729, 429496729, 0, 390451572, 390451572, 0, 357913941, 357913941, 0, 330382099, 330382099, 0, 306783378, 306783378, 0, 286331153, 286331153, 0, Integer.MIN_VALUE, 0, 3, 252645135, 252645135, 0, 238609294, 238609294, 0, 226050910, 226050910, 0, 214748364, 214748364, 0, 204522252, 204522252, 0, 195225786, 195225786, 0, 186737708, 186737708, 0, 178956970, 178956970, 0, 171798691, 171798691, 0, 165191049, 165191049, 0, 159072862, 159072862, 0, 153391689, 153391689, 0, 148102320, 148102320, 0, 143165576, 143165576, 0, 138547332, 138547332, 0, Integer.MIN_VALUE, 0, 4, 130150524, 130150524, 0, 126322567, 126322567, 0, 122713351, 122713351, 0, 119304647, 119304647, 0, 116080197, 116080197, 0, 113025455, 113025455, 0, 110127366, 110127366, 0, 107374182, 107374182, 0, 104755299, 104755299, 0, 102261126, 102261126, 0, 99882960, 99882960, 0, 97612893, 97612893, 0, 95443717, 95443717, 0, 93368854, 93368854, 0, 91382282, 91382282, 0, 89478485, 89478485, 0, 87652393, 87652393, 0, 85899345, 85899345, 0, 84215045, 84215045, 0, 82595524, 82595524, 0, 81037118, 81037118, 0, 79536431, 79536431, 0, 78090314, 78090314, 0, 76695844, 76695844, 0, 75350303, 75350303, 0, 74051160, 74051160, 0, 72796055, 72796055, 0, 71582788, 71582788, 0, 70409299, 70409299, 0, 69273666, 69273666, 0, 68174084, 68174084, 0, Integer.MIN_VALUE, 0, 5};
private final int valuesPerLong;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*
* @since TODO
*/
public abstract class APalettedContainer {
public abstract class PalettedContainer {

public static final int CHUNK_SECTION_SIZE = 16 * 16 * 16;
public static final int BIOME_SECTION_SIZE = 4 * 4 * 4;
Expand All @@ -51,7 +51,7 @@ public abstract class APalettedContainer {
protected int size;
protected final long maxEntryValue;

public APalettedContainer(PalettedContainerType palettedContainerType, byte bitsPerEntry, List<Integer> states, long[] data) {
public PalettedContainer(PalettedContainerType palettedContainerType, byte bitsPerEntry, List<Integer> states, long[] data) {
// Yes, bitsPerEntry may be equal to 0. https://wiki.vg/Chunk_Format#Data_structure
if ((bitsPerEntry < 0)) {
throw new IllegalArgumentException(
Expand All @@ -63,8 +63,8 @@ public APalettedContainer(PalettedContainerType palettedContainerType, byte bits
this.data = data;

this.size = palettedContainerType == PalettedContainerType.BLOCKS
? APalettedContainer.CHUNK_SECTION_SIZE
: APalettedContainer.BIOME_SECTION_SIZE;
? PalettedContainer.CHUNK_SECTION_SIZE
: PalettedContainer.BIOME_SECTION_SIZE;
this.maxEntryValue = ((1L << this.bitsPerEntry) - 1);
}

Expand Down Expand Up @@ -108,7 +108,7 @@ public void write(ByteArrayOutputStream out) {
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof APalettedContainer that))
if (!(o instanceof PalettedContainer that))
return false;
return bitsPerEntry == that.bitsPerEntry && size == that.size && maxEntryValue == that.maxEntryValue
&& palettedContainerType == that.palettedContainerType && states.equals(that.states)
Expand All @@ -122,7 +122,7 @@ public int hashCode() {
return result;
}

public static APalettedContainer build(PalettedContainerType palettedContainerType, byte bitsPerEntry, List<Integer> states, long[] data) {
public static PalettedContainer build(PalettedContainerType palettedContainerType, byte bitsPerEntry, List<Integer> states, long[] data) {
// Special case for single-valued palette.
if (bitsPerEntry == 0)
return new SinglePalettedContainer(palettedContainerType, bitsPerEntry, states, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*
* @since TODO
*/
public class SinglePalettedContainer extends APalettedContainer {
public class SinglePalettedContainer extends PalettedContainer {

public SinglePalettedContainer(PalettedContainerType palettedContainerType, byte bitsPerEntry, List<Integer> states, long[] data) {
super(palettedContainerType, bitsPerEntry, states, data);
Expand Down

0 comments on commit f6d2ce0

Please sign in to comment.