Fixes some code style issues

This commit is contained in:
Christian Koop 2023-06-18 00:26:03 +02:00
parent 82e8dd03c0
commit 9e73e2a87d
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
3 changed files with 24 additions and 24 deletions

View File

@ -23,7 +23,7 @@ public class SItemStack {
public SItemStack(CompatibleHand hand, Player player) {
this.item = hand.getItem(player);
this.sItem = Nms.getImplementations().getWorld().getItemStack(item);
this.sItem = Nms.getImplementations().getWorld().getItemStack(this.item);
}
public ItemStack addDamage(Player player, int damage) {
@ -37,24 +37,24 @@ public class SItemStack {
* @param damage the amount of damage to apply to the item
*/
public ItemStack addDamage(Player player, int damage, boolean respectVanillaUnbreakingEnchantments) {
if (item == null) {
if (this.item == null) {
return null;
}
if (item.getItemMeta() == null) {
return item;
if (this.item.getItemMeta() == null) {
return this.item;
}
int maxDurability = item.getType().getMaxDurability();
int maxDurability = this.item.getType().getMaxDurability();
int durability;
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_11)
? Nms.getImplementations().getNbt().of(item).has("Unbreakable")
: item.getItemMeta().isUnbreakable()) {
return item;
? Nms.getImplementations().getNbt().of(this.item).has("Unbreakable")
: this.item.getItemMeta().isUnbreakable()) {
return this.item;
} else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
// ItemStack.setDurability(short) still works in 1.13-1.14, but use these methods now
ItemMeta meta = item.getItemMeta();
ItemMeta meta = this.item.getItemMeta();
if (meta instanceof Damageable) {
Damageable damageable = ((Damageable) meta);
@ -63,25 +63,25 @@ public class SItemStack {
}
damageable.setDamage(((Damageable) meta).getDamage() + damage);
item.setItemMeta(meta);
this.item.setItemMeta(meta);
durability = damageable.getDamage();
} else {
return item;
return this.item;
}
} else {
if (respectVanillaUnbreakingEnchantments) {
damage = shouldApplyDamage(item.getEnchantmentLevel(Enchantment.DURABILITY), damage);
damage = shouldApplyDamage(this.item.getEnchantmentLevel(Enchantment.DURABILITY), damage);
}
item.setDurability((short) Math.max(0, item.getDurability() + damage));
durability = item.getDurability();
this.item.setDurability((short) Math.max(0, this.item.getDurability() + damage));
durability = this.item.getDurability();
}
if (durability >= maxDurability && player != null) {
destroy(player);
}
return item;
return this.item;
}
public void destroy(Player player) {
@ -89,15 +89,15 @@ public class SItemStack {
}
public void destroy(Player player, int amount) {
PlayerItemBreakEvent breakEvent = new PlayerItemBreakEvent(player, item);
PlayerItemBreakEvent breakEvent = new PlayerItemBreakEvent(player, this.item);
Bukkit.getServer().getPluginManager().callEvent(breakEvent);
sItem.breakItem(player, amount);
this.sItem.breakItem(player, amount);
CompatibleSound.ENTITY_ITEM_BREAK.play(player);
}
public ItemStack getItem() {
return item;
return this.item;
}
private static int shouldApplyDamage(int unbreakingEnchantLevel, int damageAmount) {

View File

@ -41,7 +41,7 @@ public class SSpawner {
*/
public int spawn(int amountToSpawn, String particle, Set<CompatibleMaterial> canSpawnOn, SpawnedEntity spawned,
EntityType... types) {
if (location.getWorld() == null) {
if (this.location.getWorld() == null) {
return 0;
}
@ -60,7 +60,7 @@ public class SSpawner {
int amountSpawned = 0;
while (spawnCountUsed-- > 0) {
EntityType type = types[ThreadLocalRandom.current().nextInt(types.length)];
LivingEntity entity = sSpawner.spawnEntity(type, particle, spawned, canSpawnOn);
LivingEntity entity = this.sSpawner.spawnEntity(type, particle, spawned, canSpawnOn);
if (entity != null) {
// If this entity is indeed stackable then spawn a single stack with the desired stack size.
@ -79,6 +79,6 @@ public class SSpawner {
}
public Location getLocation() {
return location;
return this.location;
}
}

View File

@ -29,13 +29,13 @@ public class SWorld {
public List<LivingEntity> getLivingEntities() {
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_17)) {
return world.getLivingEntities();
return this.world.getLivingEntities();
}
return sWorld.getLivingEntities();
return this.sWorld.getLivingEntities();
}
public World getWorld() {
return world;
return this.world;
}
}