Skip to content

Commit

Permalink
[CI SKIP] Removed usage of CompoundTag#getValue with individual gette…
Browse files Browse the repository at this point in the history
…rs and setters
  • Loading branch information
OmerBenGera committed Apr 29, 2022
1 parent cbbd340 commit 9db41dc
Show file tree
Hide file tree
Showing 26 changed files with 217 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void onEntityDeath(EntityDeathEvent e) {
List<ItemStack> dropItems = new ArrayList<>(e.getDrops());
for (ItemStack itemStack : dropItems) {
if (itemStack != null && !EntityUtils.isEquipment(e.getEntity(), itemStack) &&
!plugin.getNMSTags().getNBTTag(itemStack).getValue().containsKey("WildChests")) {
!plugin.getNMSTags().getNBTTag(itemStack).containsKey("WildChests")) {
int newAmount = (int) (itemStack.getAmount() * mobDropsMultiplier);

if (Bukkit.getPluginManager().isPluginEnabled("WildStacker")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
import com.bgsoftware.superiorskyblock.schematic.data.SchematicEntity;
import com.bgsoftware.superiorskyblock.serialization.Serializers;
import com.bgsoftware.superiorskyblock.tag.CompoundTag;
import com.bgsoftware.superiorskyblock.tag.FloatTag;
import com.bgsoftware.superiorskyblock.tag.IntTag;
import com.bgsoftware.superiorskyblock.tag.ListTag;
import com.bgsoftware.superiorskyblock.tag.StringTag;
import com.bgsoftware.superiorskyblock.tag.Tag;
import com.bgsoftware.superiorskyblock.threads.Executor;
import com.bgsoftware.superiorskyblock.utils.debug.PluginDebugger;
Expand All @@ -27,7 +24,6 @@
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.Consumer;
Expand All @@ -48,26 +44,26 @@ public SuperiorSchematic(String name, CompoundTag compoundTag) {
super(name);
this.compoundTag = compoundTag;

int xSize = SuperiorSchematicDeserializer.readNumberFromTag(compoundTag.getValue().get("xSize"));
int ySize = SuperiorSchematicDeserializer.readNumberFromTag(compoundTag.getValue().get("ySize"));
int zSize = SuperiorSchematicDeserializer.readNumberFromTag(compoundTag.getValue().get("zSize"));
int xSize = compoundTag.getInt("xSize");
int ySize = compoundTag.getInt("ySize");
int zSize = compoundTag.getInt("zSize");

int offsetX = ((IntTag) compoundTag.getValue().getOrDefault("offsetX", new IntTag(xSize / 2))).getValue();
int offsetY = ((IntTag) compoundTag.getValue().getOrDefault("offsetY", new IntTag(ySize / 2))).getValue();
int offsetZ = ((IntTag) compoundTag.getValue().getOrDefault("offsetZ", new IntTag(zSize / 2))).getValue();
int offsetX = compoundTag.getInt("offsetX", xSize / 2);
int offsetY = compoundTag.getInt("offsetY", ySize / 2);
int offsetZ = compoundTag.getInt("offsetZ", zSize / 2);

this.offset = SBlockOffset.fromOffsets(offsetX, offsetY, offsetZ).negate();
this.yaw = ((FloatTag) compoundTag.getValue().getOrDefault("yaw", new FloatTag(0))).getValue();
this.pitch = ((FloatTag) compoundTag.getValue().getOrDefault("pitch", new FloatTag(0))).getValue();
this.yaw = compoundTag.getFloat("yaw");
this.pitch = compoundTag.getFloat("pitch");

if (!compoundTag.getValue().containsKey("blocks")) {
ListTag blocksList = compoundTag.getList("blocks");
if (blocksList == null) {
this.blocks = Collections.emptyList();
} else {
List<Tag<?>> blocksList = ((ListTag) compoundTag.getValue().get("blocks")).getValue();
Set<SchematicBlock> schematicBlocks = new TreeSet<>(SchematicBlock::compareTo);

for (Tag<?> tag : blocksList) {
SchematicBlock schematicBlock = SuperiorSchematicDeserializer.deserializeSchematicBlock(tag);
SchematicBlock schematicBlock = SuperiorSchematicDeserializer.deserializeSchematicBlock((CompoundTag) tag);
if (schematicBlock != null && schematicBlock.getCombinedId() > 0) {
schematicBlocks.add(schematicBlock);
readBlock(schematicBlock);
Expand All @@ -77,18 +73,17 @@ public SuperiorSchematic(String name, CompoundTag compoundTag) {
this.blocks = Collections.unmodifiableList(new LinkedList<>(schematicBlocks));
}


if (!compoundTag.getValue().containsKey("entities")) {
ListTag entitiesList = compoundTag.getList("entities");
if (entitiesList == null) {
this.entities = Collections.emptyList();
} else {
List<Tag<?>> entitiesList = ((ListTag) compoundTag.getValue().get("entities")).getValue();
List<SchematicEntity> entities = new LinkedList<>();

for (Tag<?> tag : entitiesList) {
Map<String, Tag<?>> compoundValue = ((CompoundTag) tag).getValue();
EntityType entityType = EntityType.valueOf(((StringTag) compoundValue.get("entityType")).getValue());
CompoundTag entityTag = (CompoundTag) compoundValue.get("NBT");
BlockOffset blockOffset = Serializers.OFFSET_SERIALIZER.deserialize(((StringTag) compoundValue.get("offset")).getValue());
CompoundTag compound = (CompoundTag) tag;
EntityType entityType = EntityType.valueOf(compound.getString("entityType"));
CompoundTag entityTag = compound.getCompound("NBT");
BlockOffset blockOffset = Serializers.OFFSET_SERIALIZER.deserialize(compound.getString("offset"));
entities.add(new SchematicEntity(entityType, entityTag, blockOffset));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
import com.bgsoftware.superiorskyblock.SuperiorSkyblockPlugin;
import com.bgsoftware.superiorskyblock.schematic.data.SchematicBlock;
import com.bgsoftware.superiorskyblock.schematic.data.SchematicPosition;
import com.bgsoftware.superiorskyblock.tag.ByteTag;
import com.bgsoftware.superiorskyblock.tag.CompoundTag;
import com.bgsoftware.superiorskyblock.tag.IntTag;
import com.bgsoftware.superiorskyblock.tag.ListTag;
import com.bgsoftware.superiorskyblock.tag.StringTag;
import com.bgsoftware.superiorskyblock.tag.Tag;
import com.bgsoftware.superiorskyblock.tag.TagUtils;
import com.bgsoftware.superiorskyblock.utils.debug.PluginDebugger;
Expand Down Expand Up @@ -52,13 +49,6 @@ private SuperiorSchematicDeserializer() {

}

public static int readNumberFromTag(Tag<?> tag) {
if (tag instanceof ByteTag)
return ((ByteTag) tag).getValue();
else
return ((IntTag) tag).getValue();
}

public static void convertOldTileEntity(CompoundTag compoundTag) {
CompoundTag tileEntity = new CompoundTag();

Expand Down Expand Up @@ -186,44 +176,43 @@ public static void convertOldTileEntity(CompoundTag compoundTag) {
}

@Nullable
public static SchematicBlock deserializeSchematicBlock(Tag<?> tag) {
Map<String, Tag<?>> compoundValue = ((CompoundTag) tag).getValue();
SchematicPosition schematicPosition = SchematicPosition.of(((StringTag) compoundValue.get("blockPosition")).getValue());
public static SchematicBlock deserializeSchematicBlock(CompoundTag compoundTag) {
SchematicPosition schematicPosition = SchematicPosition.of(compoundTag.getString("blockPosition"));
int x = schematicPosition.getX();
int y = schematicPosition.getY();
int z = schematicPosition.getZ();
int combinedId;

if (compoundValue.containsKey("combinedId")) {
combinedId = ((IntTag) compoundValue.get("combinedId")).getValue();
} else if (compoundValue.containsKey("id") && compoundValue.containsKey("data")) {
int id = ((IntTag) compoundValue.get("id")).getValue();
int data = ((IntTag) compoundValue.get("data")).getValue();
if (compoundTag.containsKey("combinedId")) {
combinedId = compoundTag.getInt("combinedId");
} else if (compoundTag.containsKey("id") && compoundTag.containsKey("data")) {
int id = compoundTag.getInt("id");
int data = compoundTag.getInt("data");
combinedId = id + (data << 12);
} else if (compoundValue.containsKey("type")) {
} else if (compoundTag.containsKey("type")) {
Material type;

try {
type = Material.valueOf(((StringTag) compoundValue.get("type")).getValue());
type = Material.valueOf(compoundTag.getString("type"));
} catch (Exception ignored) {
return null;
}

int data = ((IntTag) compoundValue.getOrDefault("data", new IntTag(0))).getValue();
int data = compoundTag.getInt("data");

combinedId = plugin.getNMSAlgorithms().getCombinedId(type, (byte) data);
} else {
SuperiorSkyblockPlugin.log("&cCouldn't find combinedId for the block " + x + ", " + y + ", " + z + " - skipping...");
return null;
}

byte skyLightLevel = ((ByteTag) compoundValue.getOrDefault("skyLightLevel", new ByteTag((byte) 0))).getValue();
byte blockLightLevel = ((ByteTag) compoundValue.getOrDefault("blockLightLevel", new ByteTag((byte) 0))).getValue();
byte skyLightLevel = compoundTag.getByte("skyLightLevel");
byte blockLightLevel = compoundTag.getByte("blockLightLevel");

SuperiorSchematicDeserializer.convertOldTileEntity((CompoundTag) tag);
SuperiorSchematicDeserializer.convertOldTileEntity(compoundTag);

CompoundTag statesTag = (CompoundTag) compoundValue.get("states");
CompoundTag tileEntity = (CompoundTag) compoundValue.get("tileEntity");
CompoundTag statesTag = compoundTag.getCompound("states");
CompoundTag tileEntity = compoundTag.getCompound("tileEntity");

return new SchematicBlock(combinedId, SBlockOffset.fromOffsets(x, y, z), skyLightLevel, blockLightLevel, statesTag, tileEntity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public Schematic parseSchematic(DataInputStream inputStream, String schematicNam
try {
CompoundTag compoundTag = (CompoundTag) Tag.fromStream(inputStream, 0);

if (ServerVersion.isLegacy() && compoundTag.getValue().containsKey("version") &&
!compoundTag.getValue().get("version").getValue().equals(ServerVersion.getBukkitVersion()))
if (ServerVersion.isLegacy() && compoundTag.containsKey("version") &&
!ServerVersion.getBukkitVersion().equals(compoundTag.getString("version")))
SuperiorSkyblockPlugin.log("&cSchematic " + schematicName + " was created in a different version, may cause issues.");

if (!compoundTag.getValue().isEmpty())
if (!compoundTag.isEmpty())
return new SuperiorSchematic(schematicName, compoundTag);
} catch (IOException ignored) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
*
* @author Graham Edgecombe
*/
public final class ByteTag extends Tag<Byte> {
public final class ByteTag extends NumberTag<Byte> {

static final Class<?> CLASS = getNNTClass("NBTTagByte");

Expand Down

0 comments on commit 9db41dc

Please sign in to comment.