1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Post-PR refactoring

This commit is contained in:
TheBusyBiscuit 2020-07-07 10:54:32 +02:00
parent f304406aa8
commit 0984afb3c6
7 changed files with 39 additions and 34 deletions

View File

@ -60,7 +60,7 @@
<url>https://repo.destroystokyo.com/repository/maven-public/</url>
</repository>
<repository>
<id>worldedit-worldguard-repo</id>
<id>worldedit-repo</id>
<url>https://maven.sk89q.com/repo/</url>
</repository>
<repository>

View File

@ -1,29 +1,26 @@
package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces;
import io.github.thebusybiscuit.slimefun4.core.attributes.ItemAttribute;
package io.github.thebusybiscuit.slimefun4.core.attributes;
/**
* This interface, when attached to a {@link SlimefunItem}, provides an easy method for adding
* This interface, when attached to a {@link SlimefunItem}, provides an easy method for adding
* a % chance to drop for an {@link SlimefunItem} on {@link entityDeathEvent}, this chance is 0-100
* and used in conjunction with the MOB_DROP {@link RecipeType}.
* and used in conjunction with the MOB_DROP {@link RecipeType}.
*
* @author dNiym
*
* @see BasicCircuitBoard
* @see MobDropListener.
* @see BasicCircuitBoard
* @see MobDropListener
*
*/
@FunctionalInterface
public interface RandomMobDrop extends ItemAttribute {
/**
* Implement this method to make the object have a variable chance of being
* added to the dropList when {@link EntityType} (specified in the recipe)
* added to the dropList when {@link EntityType} (specified in the recipe)
* is killed by the {@link Player}
*
* @return The integer chance (0-100%) {@link SlimefunItem} has to drop.
*/
public int getDropChance();
public int getMobDropChance();
}

View File

@ -46,7 +46,6 @@ import io.github.thebusybiscuit.slimefun4.core.services.plugins.ThirdPartyPlugin
import io.github.thebusybiscuit.slimefun4.core.services.profiler.SlimefunProfiler;
import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientAltar;
import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.Cooler;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.BasicCircuitBoard;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.reactors.Reactor;
import io.github.thebusybiscuit.slimefun4.implementation.items.tools.GrapplingHook;
import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.SeismicAxe;
@ -426,8 +425,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
new WitherListener(this);
new IronGolemListener(this);
new PlayerInteractEntityListener(this);
new MobDropListener(this, (BasicCircuitBoard) SlimefunItems.BASIC_CIRCUIT_BOARD.getItem());
new MobDropListener(this);
// Item-specific Listeners
new VampireBladeListener(this, (VampireBlade) SlimefunItems.BLADE_OF_VAMPIRES.getItem());

View File

@ -1,21 +1,21 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.electric;
package io.github.thebusybiscuit.slimefun4.implementation.items.misc;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent;
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
import io.github.thebusybiscuit.slimefun4.core.attributes.RandomMobDrop;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.RandomMobDrop;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class BasicCircuitBoard extends SimpleSlimefunItem<ItemUseHandler> implements NotPlaceable, RandomMobDrop {
private final ItemSetting<Boolean> dropSetting = new ItemSetting<>("drop-from-golems", true);
private final ItemSetting<Integer> chance = new ItemSetting<> ("golem-drop-chance", 75);
private final ItemSetting<Integer> chance = new ItemSetting<>("golem-drop-chance", 75);
public BasicCircuitBoard(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
@ -25,7 +25,7 @@ public class BasicCircuitBoard extends SimpleSlimefunItem<ItemUseHandler> implem
}
@Override
public int getDropChance() {
public int getMobDropChance() {
return chance.getValue();
}

View File

@ -1,6 +1,5 @@
package io.github.thebusybiscuit.slimefun4.implementation.listeners;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
@ -12,18 +11,17 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.core.attributes.RandomMobDrop;
import io.github.thebusybiscuit.slimefun4.core.handlers.EntityKillHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.BasicCircuitBoard;
import io.github.thebusybiscuit.slimefun4.implementation.items.misc.BasicCircuitBoard;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.RandomMobDrop;
import me.mrCookieSlime.Slimefun.api.Slimefun;
public class MobDropListener implements Listener {
public MobDropListener(SlimefunPlugin plugin, BasicCircuitBoard circuitBoard) {
public MobDropListener(SlimefunPlugin plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler
@ -33,8 +31,10 @@ public class MobDropListener implements Listener {
ItemStack item = p.getInventory().getItemInMainHand();
Set<ItemStack> customDrops = SlimefunPlugin.getRegistry().getMobDrops(e.getEntityType());
if (customDrops != null && !customDrops.isEmpty())
if (customDrops != null && !customDrops.isEmpty()) {
addDrops(p, customDrops, e.getDrops());
}
if (item.getType() != Material.AIR) {
SlimefunItem sfItem = SlimefunItem.getByItem(item);
@ -52,15 +52,17 @@ public class MobDropListener implements Listener {
for (ItemStack drop : customDrops) {
if (Slimefun.hasUnlocked(p, drop, true)) {
SlimefunItem sfi = SlimefunItem.getByItem(drop);
if (sfi instanceof RandomMobDrop && ((RandomMobDrop)sfi).getDropChance() <= random)
continue;
if (sfi instanceof BasicCircuitBoard && !((BasicCircuitBoard)sfi).isDroppedFromGolems())
if (sfi instanceof RandomMobDrop && ((RandomMobDrop) sfi).getMobDropChance() <= random) {
continue;
}
if (sfi instanceof BasicCircuitBoard && !((BasicCircuitBoard) sfi).isDroppedFromGolems()) {
continue;
}
drops.add(drop.clone());
}
}
}
}

View File

@ -217,9 +217,13 @@ public final class PostSetup {
}
for (SlimefunItem item : SlimefunPlugin.getRegistry().getEnabledSlimefunItems()) {
if (item instanceof AContainer && ((AContainer) item).getMachineIdentifier().equals("ELECTRIC_SMELTERY")) {
List<MachineRecipe> recipes = ((AContainer) item).getMachineRecipes();
Collections.sort(recipes, Comparator.comparingInt(recipe -> recipe == null ? 0 : -recipe.getInput().length));
if (item instanceof AContainer) {
AContainer machine = (AContainer) item;
if (machine.getMachineIdentifier().equals("ELECTRIC_SMELTERY")) {
List<MachineRecipe> recipes = machine.getMachineRecipes();
Collections.sort(recipes, Comparator.comparingInt(recipe -> recipe == null ? 0 : -recipe.getInput().length));
}
}
}
}
@ -254,8 +258,12 @@ public final class PostSetup {
private static void registerMachineRecipe(String machine, int seconds, ItemStack[] input, ItemStack[] output) {
for (SlimefunItem item : SlimefunPlugin.getRegistry().getEnabledSlimefunItems()) {
if (item instanceof AContainer && ((AContainer) item).getMachineIdentifier().equals(machine)) {
((AContainer) item).registerRecipe(seconds, input, output);
if (item instanceof AContainer) {
AContainer container = (AContainer) item;
if (container.getMachineIdentifier().equals(machine)) {
container.registerRecipe(seconds, input, output);
}
}
}
}

View File

@ -56,7 +56,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.cargo.CargoManage
import io.github.thebusybiscuit.slimefun4.implementation.items.cargo.CargoOutputNode;
import io.github.thebusybiscuit.slimefun4.implementation.items.cargo.ReactorAccessPort;
import io.github.thebusybiscuit.slimefun4.implementation.items.cargo.TrashCan;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.BasicCircuitBoard;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.Capacitor;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.EnergyRegulator;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.JetBoots;
@ -138,6 +137,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.medical.Medicine;
import io.github.thebusybiscuit.slimefun4.implementation.items.medical.Rag;
import io.github.thebusybiscuit.slimefun4.implementation.items.medical.Splint;
import io.github.thebusybiscuit.slimefun4.implementation.items.medical.Vitamins;
import io.github.thebusybiscuit.slimefun4.implementation.items.misc.BasicCircuitBoard;
import io.github.thebusybiscuit.slimefun4.implementation.items.misc.CoolantCell;
import io.github.thebusybiscuit.slimefun4.implementation.items.misc.OrganicFertilizer;
import io.github.thebusybiscuit.slimefun4.implementation.items.misc.OrganicFood;