Skip to content

Commit

Permalink
static method
Browse files Browse the repository at this point in the history
  • Loading branch information
mcchampions committed Dec 27, 2024
1 parent 619da91 commit 4bf996c
Show file tree
Hide file tree
Showing 20 changed files with 42 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ private Optional<ItemStack> checkRecipe(
return Optional.empty();
}

private Optional<ItemStack> checkPedestals(
public static Optional<ItemStack> checkPedestals(
List<ItemStackWrapper> items, AltarRecipe recipe) {
for (int i = 0; i < 8; i++) {
if (SlimefunUtils.isItemSimilar(items.get(i), recipe.getInput().get(0), true)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void onInteract(PlayerRightClickEvent e) {
}
}

private boolean hasUnlockedRecipe(Player p, ItemStack item) {
private static boolean hasUnlockedRecipe(Player p, ItemStack item) {
for (Recipe recipe : Slimefun.getMinecraftRecipeService().getRecipesFor(item)) {
if (recipe instanceof Keyed keyed && !p.hasDiscoveredRecipe(keyed.getKey())) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void onClick(InventoryClickEvent e) {
}
}

private boolean isAllowed(SlimefunBackpack backpack, @Nullable ItemStack item) {
public static boolean isAllowed(SlimefunBackpack backpack, @Nullable ItemStack item) {
if (item == null || item.getType() == Material.AIR) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.thebusybiscuit.slimefun4.implementation.listeners;

import com.xzavier0722.mc.plugin.slimefun4.storage.callback.IAsyncReadCallback;
import com.xzavier0722.mc.plugin.slimefun4.storage.controller.ASlimefunDataContainer;
import com.xzavier0722.mc.plugin.slimefun4.storage.controller.BlockDataController;
import com.xzavier0722.mc.plugin.slimefun4.storage.controller.SlimefunBlockData;
import com.xzavier0722.mc.plugin.slimefun4.storage.controller.SlimefunUniversalBlockData;
Expand Down Expand Up @@ -66,7 +67,7 @@ public void onBlockPlaceExisting(BlockPlaceEvent e) {

// Fixes #2636 - This will solve the "ghost blocks" issue
if (e.getBlockReplacedState().getType().isAir()) {
var blockData = StorageCacheUtils.getBlock(loc);
SlimefunBlockData blockData = StorageCacheUtils.getBlock(loc);
if (blockData != null && blockData.isPendingRemove()) {
e.setCancelled(true);
return;
Expand Down Expand Up @@ -147,7 +148,7 @@ public void onBlockPlace(BlockPlaceEvent e) {
.getBlockDataController()
.createUniversalBlock(block.getLocation(), sfItem.getId());

if (Slimefun.getBlockDataService().isTileEntity(block.getType())) {
if (BlockDataService.isTileEntity(block.getType())) {
Slimefun.getBlockDataService().updateUniversalDataUUID(block, data.getKey());
}
} else {
Expand All @@ -174,12 +175,12 @@ public void onBlockBreak(BlockBreakEvent e) {
return;
}

var heldItem = e.getPlayer().getInventory().getItemInMainHand();
var block = e.getBlock();
var blockData = StorageCacheUtils.hasBlock(block.getLocation())
ItemStack heldItem = e.getPlayer().getInventory().getItemInMainHand();
Block block = e.getBlock();
ASlimefunDataContainer blockData = StorageCacheUtils.hasBlock(block.getLocation())
? StorageCacheUtils.getBlock(block.getLocation())
: StorageCacheUtils.getUniversalBlock(block);
var sfItem = blockData == null ? null : SlimefunItem.getById(blockData.getSfId());
SlimefunItem sfItem = blockData == null ? null : SlimefunItem.getById(blockData.getSfId());

// If there is a Slimefun Block here, call our BreakEvent and, if cancelled, cancel this event
// and return
Expand Down Expand Up @@ -216,7 +217,7 @@ public void onBlockBreak(BlockBreakEvent e) {

if (!blockData.isDataLoaded()) {
e.setDropItems(false);
var type = block.getType();
Material type = block.getType();
StorageCacheUtils.executeAfterLoad(
blockData,
() -> {
Expand Down Expand Up @@ -246,7 +247,7 @@ public void onBlockBreak(BlockBreakEvent e) {
}
}

private void callToolHandler(BlockBreakEvent e, ItemStack item, int fortune, List<ItemStack> drops) {
public static void callToolHandler(BlockBreakEvent e, ItemStack item, int fortune, List<ItemStack> drops) {
SlimefunItem tool = SlimefunItem.getByItem(item);

if (tool != null) {
Expand All @@ -258,8 +259,8 @@ private void callToolHandler(BlockBreakEvent e, ItemStack item, int fortune, Lis
}
}

private void callBlockHandler(BlockBreakEvent e, ItemStack item, List<ItemStack> drops) {
var loc = e.getBlock().getLocation();
public static void callBlockHandler(BlockBreakEvent e, ItemStack item, List<ItemStack> drops) {
Location loc = e.getBlock().getLocation();
SlimefunItem sfItem = StorageCacheUtils.getSfItem(loc);

if (sfItem != null && !sfItem.useVanillaBlockBreaking()) {
Expand All @@ -274,7 +275,7 @@ private void callBlockHandler(BlockBreakEvent e, ItemStack item, List<ItemStack>
}
}

private void dropItems(
public static void dropItems(
BlockBreakEvent e, ItemStack item, Block block, @Nullable SlimefunItem sfBlock, List<ItemStack> drops) {
if (!drops.isEmpty()) {
// Fixes #2560
Expand Down Expand Up @@ -308,8 +309,8 @@ private void checkForSensitiveBlockAbove(Player player, Block block, ItemStack i
Block blockAbove = block.getRelative(BlockFace.UP);

if (SlimefunTag.SENSITIVE_MATERIALS.isTagged(blockAbove.getType())) {
var loc = blockAbove.getLocation();
var blockData = StorageCacheUtils.getBlock(loc);
Location loc = blockAbove.getLocation();
SlimefunBlockData blockData = StorageCacheUtils.getBlock(loc);
SlimefunItem sfItem = StorageCacheUtils.getSfItem(loc);

if (sfItem != null && !sfItem.useVanillaBlockBreaking()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void onResult(SlimefunBlockData result) {
}
}

private void callHandler(BlockBreakHandler handler, Block b) {
public static void callHandler(BlockBreakHandler handler, Block b) {
if (handler.isExplosionAllowed(b)) {
b.setType(Material.AIR);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void onDeath(EntityDeathEvent e) {
* @param entityType
* The {@link EntityType} of the killed entity
*/
private void addExtraDrops(List<ItemStack> drops, EntityType entityType) {
public static void addExtraDrops(List<ItemStack> drops, EntityType entityType) {
Random random = ThreadLocalRandom.current();

if (entityType == EntityType.WITHER_SKELETON && random.nextInt(250) < 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public void onCargoNodePlace(BlockPlaceEvent e) {
}
}

private boolean isCargoNode(ItemStack item) {
public static boolean isCargoNode(ItemStack item) {
return SlimefunItem.getByItem(item) instanceof CargoNode;
}

private boolean isContainer(Block block) {
public static boolean isContainer(Block block) {
return block.getState() instanceof Container
|| Slimefun.getDatabaseManager().getBlockDataController().getBlockData(block.getLocation()) != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void onBlockExplode(BlockExplodeEvent e) {
removeResistantBlocks(e.blockList().iterator());
}

private void removeResistantBlocks(Iterator<Block> blocks) {
public static void removeResistantBlocks(Iterator<Block> blocks) {
while (blocks.hasNext()) {
Block block = blocks.next();
var loc = block.getLocation();
Expand Down Expand Up @@ -92,7 +92,7 @@ public void onResult(SlimefunBlockData result) {
}
}

private void handleExplosion(BlockBreakHandler handler, Block block) {
public static void handleExplosion(BlockBreakHandler handler, Block block) {
if (handler.isExplosionAllowed(block)) {
block.setType(Material.AIR);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void onToggleSneak(PlayerToggleSneakEvent e) {
}
}

private void handleChestplate(Player p, @Nullable SlimefunItem chestplate) {
public static void handleChestplate(Player p, @Nullable SlimefunItem chestplate) {
if (chestplate == null || !chestplate.canUse(p, true)) {
return;
}
Expand All @@ -78,7 +78,7 @@ private void handleChestplate(Player p, @Nullable SlimefunItem chestplate) {
}
}

private void handleBoots(Player p, @Nullable SlimefunItem boots) {
public static void handleBoots(Player p, @Nullable SlimefunItem boots) {
if (boots instanceof JetBoots jetBoots && boots.canUse(p, true)) {
double speed = jetBoots.getSpeed();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void onInventoryCreativeEvent(InventoryCreativeEvent e) {
}
}

private boolean isActualMiddleClick(InventoryCreativeEvent e, Block b) {
public static boolean isActualMiddleClick(InventoryCreativeEvent e, Block b) {
/*
* On a middle click outside the user inventory, cursor will be set
* to the actual block that is middle clicked, while currentItem will be AIR.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private boolean compareMaterialsVertical(
&& (bottom == null || equals(b.getRelative(BlockFace.DOWN).getType(), bottom));
}

private boolean equals(Material a, Material b) {
public static boolean equals(Material a, Material b) {
if (a == b) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void onPlayerJoin(PlayerJoinEvent e) {
addGracePeriod(e.getPlayer());
}

private void addGracePeriod(Player entity) {
public static void addGracePeriod(Player entity) {
RadiationUtils.clearExposure(entity);
RadiationTask.addGracePeriod(entity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private void onFallDamage(EntityDamageEvent e) {
return;
}

if (boots instanceof StomperBoots stomperBoots) {
if (boots instanceof StomperBoots) {
e.setCancelled(true);
StomperBoots.stomp(e);
} else if (boots instanceof LongFallBoots longFallBoots) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void onInteract(PlayerRightClickEvent e) {
}
}

private void openGuide(Player p, PlayerRightClickEvent e, SlimefunGuideMode layout) {
public static void openGuide(Player p, PlayerRightClickEvent e, SlimefunGuideMode layout) {
SlimefunGuideOpenEvent event = new SlimefunGuideOpenEvent(p, e.getItem(), layout);
Bukkit.getPluginManager().callEvent(event);

Expand All @@ -76,7 +76,7 @@ private void openGuide(Player p, PlayerRightClickEvent e, SlimefunGuideMode layo
}
}

private Result tryOpenGuide(Player p, PlayerRightClickEvent e, SlimefunGuideMode layout) {
public static Result tryOpenGuide(Player p, PlayerRightClickEvent e, SlimefunGuideMode layout) {
ItemStack item = e.getItem();
if (SlimefunUtils.isItemSimilar(item, SlimefunGuide.getItem(layout), false, false)) {
if (!Slimefun.getWorldSettingsService().isWorldEnabled(p.getWorld())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void onRightClick(PlayerInteractEvent e) {
}
}

private boolean rightClickItem(PlayerInteractEvent e, PlayerRightClickEvent event, boolean defaultValue) {
public static boolean rightClickItem(PlayerInteractEvent e, PlayerRightClickEvent event, boolean defaultValue) {
Optional<SlimefunItem> optional = event.getSlimefunItem();

if (optional.isPresent()) {
Expand All @@ -100,7 +100,7 @@ private boolean rightClickItem(PlayerInteractEvent e, PlayerRightClickEvent even
return defaultValue;
}

private boolean rightClickBlock(PlayerRightClickEvent event) {
public static boolean rightClickBlock(PlayerRightClickEvent event) {
Optional<SlimefunItem> optional = event.getSlimefunBlock();

if (optional.isPresent()) {
Expand All @@ -127,7 +127,7 @@ private boolean rightClickBlock(PlayerRightClickEvent event) {
return true;
}

private void openInventory(Player p, SlimefunItem item, Block clickedBlock, PlayerRightClickEvent event) {
public static void openInventory(Player p, SlimefunItem item, Block clickedBlock, PlayerRightClickEvent event) {
try {
if (!p.isSneaking() || event.getItem().getType() == Material.AIR) {
event.getInteractEvent().setCancelled(true);
Expand Down Expand Up @@ -195,7 +195,7 @@ public void onResult(SlimefunBlockData result) {
}
}

private void openMenu(DirtyChestMenu menu, Block b, Player p) {
public static void openMenu(DirtyChestMenu menu, Block b, Player p) {
if (menu != null) {
if (menu.canOpen(b, p)) {
menu.open(p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private void onProjectileDamage(EntityDamageByEntityEvent e) {
* @param projectile
* The {@link Projectile} that hit this {@link Player}
*/
private void returnProjectile(Player p, Projectile projectile) {
public static void returnProjectile(Player p, Projectile projectile) {
Vector direction = p.getEyeLocation().getDirection().multiply(2.0);
Location loc = p.getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ());

Expand Down Expand Up @@ -174,7 +174,7 @@ public void onKill(EntityDeathEvent e) {
}
}

private Collection<ItemStack> getExtraDrops(LivingEntity entity, Collection<ItemStack> drops) {
public static Collection<ItemStack> getExtraDrops(LivingEntity entity, Collection<ItemStack> drops) {
List<ItemStack> items = new ArrayList<>(drops);

// Prevent duplication of items stored inside a Horse's chest
Expand Down Expand Up @@ -401,7 +401,7 @@ public void onBlockBreak(BlockBreakEvent e) {
}
}

private int getAmountWithFortune(Material type, int fortuneLevel) {
public static int getAmountWithFortune(Material type, int fortuneLevel) {
if (fortuneLevel > 0) {
Random random = ThreadLocalRandom.current();
int amount = random.nextInt(fortuneLevel + 2) - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void onResult(SlimefunBlockData result) {
}
}

private void teleport(String ownerUid, Player p, Block b) {
public static void teleport(String ownerUid, Player p, Block b) {
Slimefun.getGPSNetwork().getTeleportationManager().openTeleporterGUI(p, UUID.fromString(ownerUid), b);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void onPreTrade(InventoryClickEvent e) {
}
}

private boolean isUnallowed(@Nullable SlimefunItem item) {
public static boolean isUnallowed(@Nullable SlimefunItem item) {
return item != null
&& !(item instanceof VanillaItem)
&& !(item instanceof SyntheticEmerald)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void onPrepareSmith(PrepareSmithingEvent e) {
}
}

private int materialSlot() {
public static int materialSlot() {
if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_20)) {
return 2;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void onEntityKill(EntityDeathEvent e) {
}
}

private boolean canDrop(Player p, ItemStack item) {
public static boolean canDrop(Player p, ItemStack item) {
SlimefunItem sfItem = SlimefunItem.getByItem(item);

if (sfItem == null) {
Expand Down

0 comments on commit 4bf996c

Please sign in to comment.