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

[CI skip] Refactoring

This commit is contained in:
TheBusyBiscuit 2020-03-15 17:43:51 +01:00
parent be7aaae6e9
commit ca26368847
54 changed files with 255 additions and 152 deletions

3
.gitignore vendored
View File

@ -5,4 +5,5 @@
*.iml
/target
/.idea/
dependency-reduced-pom.xml
dependency-reduced-pom.xml
javadoc.xml

View File

@ -15,13 +15,14 @@ import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.collections.KeyMap;
import io.github.thebusybiscuit.cscorelib2.config.Config;
import io.github.thebusybiscuit.slimefun4.api.geo.GEOResource;
import io.github.thebusybiscuit.slimefun4.core.attributes.WitherProof;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout;
import io.github.thebusybiscuit.slimefun4.implementation.guide.BookSlimefunGuide;
import io.github.thebusybiscuit.slimefun4.implementation.guide.CheatSheetSlimefunGuide;
import io.github.thebusybiscuit.slimefun4.implementation.guide.ChestSlimefunGuide;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.Research;
import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler;
@ -47,15 +48,20 @@ public class SlimefunRegistry {
private final List<SlimefunItem> slimefunItems = new ArrayList<>();
private final List<SlimefunItem> enabledItems = new ArrayList<>();
private final KeyMap<Research> researchIds = new KeyMap<>();
private final List<Category> categories = new ArrayList<>();
private final List<Research> researches = new LinkedList<>();
private final List<MultiBlock> multiblocks = new LinkedList<>();
private final List<Research> researches = new LinkedList<>();
private final List<String> researchRanks = new ArrayList<>();
private final Set<UUID> researchingPlayers = new HashSet<>();
private final KeyMap<Research> researchIds = new KeyMap<>();
private boolean enableResearches;
private boolean freeCreativeResearches;
private boolean researchFireworks;
private final Set<String> tickers = new HashSet<>();
private final Set<SlimefunItem> radioactive = new HashSet<>();
private final Set<String> activeChunks = new HashSet<>();
private final Set<UUID> researchingPlayers = new HashSet<>();
private final KeyMap<GEOResource> geoResources = new KeyMap<>();
@ -63,7 +69,7 @@ public class SlimefunRegistry {
private final Set<String> energyCapacitors = new HashSet<>();
private final Set<String> energyConsumers = new HashSet<>();
private final Set<String> chargeableBlocks = new HashSet<>();
private final Set<String> witherProofBlocks = new HashSet<>();
private final Map<String, WitherProof> witherProofBlocks = new HashMap<>();
private final Map<String, BlockStorage> worlds = new HashMap<>();
private final Map<String, BlockInfoConfig> chunks = new HashMap<>();
@ -81,12 +87,17 @@ public class SlimefunRegistry {
private final Map<Integer, List<GuideHandler>> guideHandlers = new HashMap<>();
private final Map<String, ItemStack> automatedCraftingChamberRecipes = new HashMap<>();
public SlimefunRegistry() {
boolean showVanillaRecipes = SlimefunPlugin.getCfg().getBoolean("options.show-vanilla-recipes-in-guide");
public void load(Config cfg) {
boolean showVanillaRecipes = cfg.getBoolean("options.show-vanilla-recipes-in-guide");
layouts.put(SlimefunGuideLayout.CHEST, new ChestSlimefunGuide(showVanillaRecipes));
layouts.put(SlimefunGuideLayout.CHEAT_SHEET, new CheatSheetSlimefunGuide(showVanillaRecipes));
layouts.put(SlimefunGuideLayout.BOOK, new BookSlimefunGuide());
researchRanks.addAll(cfg.getStringList("research-ranks"));
freeCreativeResearches = cfg.getBoolean("options.allow-free-creative-research");
researchFireworks = cfg.getBoolean("options.research-unlock-fireworks");
}
public List<Category> getEnabledCategories() {
@ -119,6 +130,34 @@ public class SlimefunRegistry {
return researches;
}
public KeyMap<Research> getResearchIds() {
return researchIds;
}
public Set<UUID> getCurrentlyResearchingPlayers() {
return researchingPlayers;
}
public List<String> getResearchRanks() {
return researchRanks;
}
public void setResearchingEnabled(boolean enabled) {
enableResearches = enabled;
}
public boolean isResearchingEnabled() {
return enableResearches;
}
public boolean isFreeCreativeResearchingEnabled() {
return freeCreativeResearches;
}
public boolean isResearchFireworkEnabled() {
return researchFireworks;
}
public List<MultiBlock> getMultiBlocks() {
return multiblocks;
}
@ -147,18 +186,10 @@ public class SlimefunRegistry {
return activeChunks;
}
public Set<UUID> getCurrentlyResearchingPlayers() {
return researchingPlayers;
}
public Map<String, SlimefunItem> getSlimefunItemIds() {
return slimefunIds;
}
public KeyMap<Research> getResearchIds() {
return researchIds;
}
public Map<String, Integer> getEnergyCapacities() {
return capacities;
}
@ -225,7 +256,7 @@ public class SlimefunRegistry {
return chargeableBlocks;
}
public Set<String> getWitherProofBlocks() {
public Map<String, WitherProof> getWitherProofBlocks() {
return witherProofBlocks;
}

View File

@ -0,0 +1,46 @@
package io.github.thebusybiscuit.slimefun4.core.attributes;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
/**
* This interface, when attached to a {@link SlimefunItem}, provides an easy method for damaging
* an {@link ItemStack}, see {@link #damageItem(Player, ItemStack)}.
*
* It also provides a simple {@link #isDamageable()} method, in case you wanna add a config
* option that decides whether or not this {@link SlimefunItem} shall be damageable.
*
* @author TheBusyBiscuit
*
*/
@FunctionalInterface
public interface DamageableItem extends ItemAttribute {
boolean isDamageable();
default void damageItem(Player p, ItemStack item) {
if (isDamageable() && item != null && item.getType() != Material.AIR && item.getAmount() > 0) {
if (item.getEnchantments().containsKey(Enchantment.DURABILITY) && Math.random() * 100 <= (60 + Math.floorDiv(40, (item.getEnchantmentLevel(Enchantment.DURABILITY) + 1)))) {
return;
}
ItemMeta meta = item.getItemMeta();
Damageable damageable = (Damageable) meta;
if (damageable.getDamage() >= item.getType().getMaxDurability()) {
item.setAmount(0);
}
else {
damageable.setDamage(damageable.getDamage() + 1);
item.setItemMeta(meta);
}
}
}
}

View File

@ -18,7 +18,7 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
* @see EnergyNet
*
*/
public interface EnergyNetComponent {
public interface EnergyNetComponent extends ItemAttribute {
/**
* This method returns the Type of {@link EnergyNetComponentType} this {@link SlimefunItem} represents.

View File

@ -0,0 +1,18 @@
package io.github.thebusybiscuit.slimefun4.core.attributes;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
/**
* An empty interface that only serves the purpose of bundling together all
* interfaces of that kind.
*
* An {@link ItemAttribute} must be attached to a {@link SlimefunItem}.
*
* @author TheBusyBiscuit
*
* @see SlimefunItem
*
*/
public interface ItemAttribute {
}

View File

@ -12,7 +12,7 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
* @author TheBusyBiscuit
*
*/
public interface Radioactive {
public interface Radioactive extends ItemAttribute {
/**
* This method returns the level of {@link Radioactivity} for this {@link Radioactive} item.

View File

@ -28,7 +28,7 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AGenerator;
*
*/
@FunctionalInterface
public interface RecipeDisplayItem {
public interface RecipeDisplayItem extends ItemAttribute {
/**
* This is the list of items to display alongside this {@link SlimefunItem}.

View File

@ -13,6 +13,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
* @see SoulboundItem
*
*/
public interface Soulbound {
public interface Soulbound extends ItemAttribute {
}

View File

@ -1,7 +1,9 @@
package io.github.thebusybiscuit.slimefun4.core.attributes;
import org.bukkit.block.Block;
import org.bukkit.entity.Wither;
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.WitherProofBlock;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
/**
@ -14,6 +16,18 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
* @see WitherProofBlock
*
*/
public interface WitherProof {
@FunctionalInterface
public interface WitherProof extends ItemAttribute {
/**
* This method is called when a {@link Wither} tried to attack the given {@link Block}.
* You can use this method to play particles or even damage the {@link Wither}.
*
* @param block
* The {@link Block} which was attacked.
* @param wither
* The {@link Wither} who attacked.
*/
void onAttack(Block block, Wither wither);
}

View File

@ -17,6 +17,12 @@ import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
import io.github.thebusybiscuit.slimefun4.core.commands.subcommands.Commands;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
/**
* This {@link CommandExecutor} holds the functionality of our {@code /slimefun} command.
*
* @author TheBusyBiscuit
*
*/
public class SlimefunCommand implements CommandExecutor, Listener {
private final SlimefunPlugin plugin;

View File

@ -10,7 +10,7 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
class CheatCommand extends SubCommand {
public CheatCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
CheatCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
super(plugin, cmd);
}

View File

@ -10,7 +10,7 @@ import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
class DebugFishCommand extends SubCommand {
public DebugFishCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
DebugFishCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
super(plugin, cmd);
}

View File

@ -19,7 +19,7 @@ class ElevatorCommand extends SubCommand {
private final ElevatorPlate elevatorPlate;
public ElevatorCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
ElevatorCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
super(plugin, cmd);
elevatorPlate = ((ElevatorPlate) SlimefunItem.getByID("ELEVATOR_PLATE"));

View File

@ -18,7 +18,7 @@ class GiveCommand extends SubCommand {
private static final String PLACEHOLDER_ITEM = "%item%";
private static final String PLACEHOLDER_AMOUNT = "%amount%";
public GiveCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
GiveCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
super(plugin, cmd);
}

View File

@ -11,7 +11,7 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
class GuideCommand extends SubCommand {
public GuideCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
GuideCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
super(plugin, cmd);
}

View File

@ -8,7 +8,7 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
class HelpCommand extends SubCommand {
public HelpCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
HelpCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
super(plugin, cmd);
}

View File

@ -11,7 +11,7 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
class OpenGuideCommand extends SubCommand {
public OpenGuideCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
OpenGuideCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
super(plugin, cmd);
}

View File

@ -17,7 +17,7 @@ class ResearchCommand extends SubCommand {
private static final String PLACEHOLDER_PLAYER = "%player%";
private static final String PLACEHOLDER_RESEARCH = "%research%";
public ResearchCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
ResearchCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
super(plugin, cmd);
}

View File

@ -13,7 +13,7 @@ import me.mrCookieSlime.Slimefun.api.PlayerProfile;
class SearchCommand extends SubCommand {
public SearchCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
SearchCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
super(plugin, cmd);
}

View File

@ -14,7 +14,7 @@ import me.mrCookieSlime.Slimefun.api.PlayerProfile;
class StatsCommand extends SubCommand {
public StatsCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
StatsCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
super(plugin, cmd);
}

View File

@ -12,7 +12,7 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
class TeleporterCommand extends SubCommand {
public TeleporterCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
TeleporterCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
super(plugin, cmd);
}

View File

@ -9,7 +9,7 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
class TimingsCommand extends SubCommand {
public TimingsCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
TimingsCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
super(plugin, cmd);
}

View File

@ -16,7 +16,7 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
class VersionsCommand extends SubCommand {
public VersionsCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
VersionsCommand(SlimefunPlugin plugin, SlimefunCommand cmd) {
super(plugin, cmd);
}

View File

@ -161,7 +161,7 @@ public final class SlimefunGuideSettings {
i++;
}
if (SlimefunPlugin.getSettings().researchFireworksEnabled) {
if (SlimefunPlugin.getRegistry().isResearchFireworkEnabled()) {
if (!PersistentDataAPI.hasByte(p, FIREWORKS_KEY) || PersistentDataAPI.getByte(p, FIREWORKS_KEY) == (byte) 1) {
menu.addItem(i, new CustomItem(Material.FIREWORK_ROCKET, "&bFireworks: &aYes", "", "&7When researching items, you will", "&7be presented with a big firework.", "", "&7\u21E8 &eClick to disable your fireworks"), (pl, slot, item, action) -> {
PersistentDataAPI.setByte(pl, FIREWORKS_KEY, (byte) 0);

View File

@ -10,7 +10,7 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
class AddonsChart extends AdvancedPie {
public AddonsChart() {
AddonsChart() {
super("installed_addons", () -> {
Map<String, Integer> addons = new HashMap<>();

View File

@ -6,7 +6,7 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
class AutoUpdaterChart extends SimplePie {
public AutoUpdaterChart() {
AutoUpdaterChart() {
super("auto_updates", () -> {
boolean enabled = SlimefunPlugin.getCfg().getBoolean("options.auto-update");
return enabled ? "enabled" : "disabled";

View File

@ -10,7 +10,7 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
class CommandChart extends AdvancedPie {
public CommandChart() {
CommandChart() {
super("commands_ran", () -> {
Map<String, Integer> commands = new HashMap<>();

View File

@ -6,7 +6,7 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
class GuideLayoutChart extends SimplePie {
public GuideLayoutChart() {
GuideLayoutChart() {
super("guide_layout", () -> {
boolean book = SlimefunPlugin.getCfg().getBoolean("guide.default-view-book");

View File

@ -48,6 +48,7 @@ public class MetricsService {
metrics.addCustomChart(new GuideLayoutChart());
metrics.addCustomChart(new AddonsChart());
metrics.addCustomChart(new CommandChart());
metrics.addCustomChart(new ServerSizeChart());
}
}

View File

@ -12,7 +12,7 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
class PlayerLanguageChart extends AdvancedPie {
public PlayerLanguageChart() {
PlayerLanguageChart() {
super("player_languages", () -> {
Map<String, Integer> languages = new HashMap<>();

View File

@ -6,9 +6,9 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
class ResearchesEnabledChart extends SimplePie {
public ResearchesEnabledChart() {
ResearchesEnabledChart() {
super("servers_with_researches_enabled", () -> {
boolean enabled = SlimefunPlugin.getSettings().researchesEnabled;
boolean enabled = SlimefunPlugin.getRegistry().isFreeCreativeResearchingEnabled();
return enabled ? "enabled" : "disabled";
});
}

View File

@ -6,7 +6,7 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
class ResourcePackChart extends SimplePie {
public ResourcePackChart() {
ResourcePackChart() {
super("resourcepack", () -> {
String version = SlimefunPlugin.getItemTextureService().getVersion();

View File

@ -7,7 +7,7 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
class ServerLanguageChart extends SimplePie {
public ServerLanguageChart() {
ServerLanguageChart() {
super("language", () -> {
Language language = SlimefunPlugin.getLocal().getDefaultLanguage();
boolean supported = SlimefunPlugin.getLocal().isLanguageLoaded(language.getID());

View File

@ -0,0 +1,40 @@
package io.github.thebusybiscuit.slimefun4.core.services.metrics;
import org.bstats.bukkit.Metrics.SimplePie;
import org.bukkit.Bukkit;
class ServerSizeChart extends SimplePie {
ServerSizeChart() {
super("server_size", () -> {
int players = Bukkit.getOnlinePlayers().size();
if (players < 10) {
return "0-10";
}
if (players < 25) {
return "10-25";
}
if (players < 50) {
return "25-50";
}
if (players < 100) {
return "50-100";
}
if (players < 200) {
return "100-200";
}
if (players < 300) {
return "200-300";
}
return "300+";
});
}
}

View File

@ -6,7 +6,7 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
class BranchChart extends SimplePie {
public BranchChart() {
BranchChart() {
super("branch", SlimefunPlugin.getUpdater().getBranch()::getName);
}

View File

@ -12,7 +12,7 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
class ClearLagHook implements Listener {
public ClearLagHook(SlimefunPlugin plugin) {
ClearLagHook(SlimefunPlugin plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

View File

@ -16,7 +16,7 @@ import me.mrCookieSlime.Slimefun.api.BlockStorage;
class WorldEditHook {
public WorldEditHook() {
WorldEditHook() {
WorldEdit.getInstance().getEventBus().register(this);
}

View File

@ -203,7 +203,7 @@ public class BookSlimefunGuide implements SlimefunGuideImplementation {
openCategory(profile, category, true, page);
}
else {
if (!(p.getGameMode() == GameMode.CREATIVE && SlimefunPlugin.getSettings().researchesFreeInCreative)) {
if (!(p.getGameMode() == GameMode.CREATIVE && SlimefunPlugin.getRegistry().isFreeCreativeResearchingEnabled())) {
p.setLevel(p.getLevel() - research.getCost());
}

View File

@ -220,12 +220,12 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
openCategory(profile, category, true, page);
}
else {
if (!(pl.getGameMode() == GameMode.CREATIVE && SlimefunPlugin.getSettings().researchesFreeInCreative)) {
if (!(pl.getGameMode() == GameMode.CREATIVE && SlimefunPlugin.getRegistry().isFreeCreativeResearchingEnabled())) {
pl.setLevel(pl.getLevel() - research.getCost());
}
if (pl.getGameMode() == GameMode.CREATIVE) {
research.unlock(pl, SlimefunPlugin.getSettings().researchesFreeInCreative);
research.unlock(pl, SlimefunPlugin.getRegistry().isFreeCreativeResearchingEnabled());
Slimefun.runSync(() -> openCategory(profile, category, survival, page), 5L);
}
else {

View File

@ -1,5 +1,6 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.blocks;
import org.bukkit.block.Block;
import org.bukkit.entity.Wither;
import org.bukkit.inventory.ItemStack;
@ -29,4 +30,9 @@ public class WitherProofBlock extends SlimefunItem implements WitherProof {
super(category, item, recipeType, recipe, recipeOutput);
}
@Override
public void onAttack(Block block, Wither wither) {
// In this implementation we simply do nothing.
}
}

View File

@ -12,6 +12,7 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import io.github.thebusybiscuit.slimefun4.core.attributes.DamageableItem;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
@ -20,7 +21,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.HandledBlock;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.DamageableItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.NotPlaceable;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockBreakHandler;
import me.mrCookieSlime.Slimefun.api.BlockStorage;

View File

@ -11,11 +11,11 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.materials.MaterialTools;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import io.github.thebusybiscuit.slimefun4.core.attributes.DamageableItem;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
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.DamageableItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.NotPlaceable;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockBreakHandler;
import me.mrCookieSlime.Slimefun.api.Slimefun;

View File

@ -7,11 +7,11 @@ import org.bukkit.event.Event.Result;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
import io.github.thebusybiscuit.slimefun4.core.attributes.DamageableItem;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
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.DamageableItem;
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;

View File

@ -10,11 +10,11 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
import io.github.thebusybiscuit.cscorelib2.recipes.MinecraftRecipe;
import io.github.thebusybiscuit.slimefun4.core.attributes.DamageableItem;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
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.DamageableItem;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockBreakHandler;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.Slimefun;

View File

@ -18,11 +18,11 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.Vector;
import io.github.thebusybiscuit.slimefun4.core.attributes.DamageableItem;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
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.DamageableItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.NotPlaceable;
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;

View File

@ -15,6 +15,7 @@ import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.core.attributes.WitherProof;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
@ -88,8 +89,13 @@ public class BlockPhysicsListener implements Listener {
if (e.getEntity() instanceof Wither) {
String id = BlockStorage.checkID(e.getBlock());
if (id != null && SlimefunPlugin.getRegistry().getWitherProofBlocks().contains(id)) {
e.setCancelled(true);
if (id != null) {
WitherProof witherproof = SlimefunPlugin.getRegistry().getWitherProofBlocks().get(id);
if (witherproof != null) {
e.setCancelled(true);
witherproof.onAttack(e.getBlock(), (Wither) e.getEntity());
}
}
}
}

View File

@ -53,17 +53,8 @@ public class ButcherAndroidListener implements Listener {
private void addExtraDrops(List<ItemStack> items, EntityType entityType) {
Random random = ThreadLocalRandom.current();
switch (entityType) {
case BLAZE:
items.add(new ItemStack(Material.BLAZE_ROD, 1 + random.nextInt(2)));
break;
case WITHER_SKELETON:
if (random.nextInt(250) < 2) {
items.add(new ItemStack(Material.WITHER_SKELETON_SKULL));
}
break;
default:
break;
if (entityType == EntityType.WITHER_SKELETON && random.nextInt(250) < 2) {
items.add(new ItemStack(Material.WITHER_SKELETON_SKULL));
}
}
}

View File

@ -32,7 +32,7 @@ public class ExplosionsListener implements Listener {
if (id != null) {
blocks.remove();
if (!id.equalsIgnoreCase("HARDENED_GLASS") && !SlimefunPlugin.getRegistry().getWitherProofBlocks().contains(id)) {
if (!id.equalsIgnoreCase("HARDENED_GLASS") && !SlimefunPlugin.getRegistry().getWitherProofBlocks().containsKey(id)) {
boolean success = true;
SlimefunItem sfItem = SlimefunItem.getByID(id);

View File

@ -84,7 +84,7 @@ public class Research implements Keyed {
* @return Whether this {@link Research} is enabled or not
*/
public boolean isEnabled() {
return SlimefunPlugin.getSettings().researchesEnabled && enabled;
return SlimefunPlugin.getRegistry().isResearchingEnabled() && enabled;
}
/**
@ -162,7 +162,7 @@ public class Research implements Keyed {
*/
public boolean canUnlock(Player p) {
if (!isEnabled()) return true;
return (p.getGameMode() == GameMode.CREATIVE && SlimefunPlugin.getSettings().researchesFreeInCreative) || p.getLevel() >= this.cost;
return (p.getGameMode() == GameMode.CREATIVE && SlimefunPlugin.getRegistry().isFreeCreativeResearchingEnabled()) || p.getLevel() >= this.cost;
}
/**
@ -187,7 +187,7 @@ public class Research implements Keyed {
profile.setResearched(this, true);
SlimefunPlugin.getLocal().sendMessage(p, "messages.unlocked", true, msg -> msg.replace("%research%", getName(p)));
if (SlimefunPlugin.getSettings().researchFireworksEnabled && (!PersistentDataAPI.hasByte(p, SlimefunGuideSettings.FIREWORKS_KEY) || PersistentDataAPI.getByte(p, SlimefunGuideSettings.FIREWORKS_KEY) == (byte) 1)) {
if (SlimefunPlugin.getRegistry().isResearchFireworkEnabled() && (!PersistentDataAPI.hasByte(p, SlimefunGuideSettings.FIREWORKS_KEY) || PersistentDataAPI.getByte(p, SlimefunGuideSettings.FIREWORKS_KEY) == (byte) 1)) {
FireworkUtils.launchRandom(p, 1);
}
};

View File

@ -63,7 +63,7 @@ public class SlimefunItem implements Placeable {
private String wiki = null;
private final OptionalMap<Class<? extends ItemHandler>, ItemHandler> itemhandlers = new OptionalMap<>(HashMap::new);
private boolean ticking = false;
private BlockTicker blockTicker;
private GeneratorTicker energyTicker;
@ -277,7 +277,7 @@ public class SlimefunItem implements Placeable {
}
if (this instanceof WitherProof) {
SlimefunPlugin.getRegistry().getWitherProofBlocks().add(id);
SlimefunPlugin.getRegistry().getWitherProofBlocks().put(id, (WitherProof) this);
}
if (this instanceof EnergyNetComponent && !SlimefunPlugin.getRegistry().getEnergyCapacities().containsKey(getID())) {

View File

@ -1,34 +1,11 @@
package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
@FunctionalInterface
public interface DamageableItem {
boolean isDamageable();
default void damageItem(Player p, ItemStack item) {
if (isDamageable() && item != null && item.getType() != Material.AIR && item.getAmount() > 0) {
if (item.getEnchantments().containsKey(Enchantment.DURABILITY) && Math.random() * 100 <= (60 + Math.floorDiv(40, (item.getEnchantmentLevel(Enchantment.DURABILITY) + 1)))) {
return;
}
ItemMeta meta = item.getItemMeta();
Damageable damageable = (Damageable) meta;
if (damageable.getDamage() >= item.getType().getMaxDurability()) {
item.setAmount(0);
}
else {
damageable.setDamage(damageable.getDamage() + 1);
item.setItemMeta(meta);
}
}
}
/**
*
* @deprecated Moved to {@code io.github.thebusybiscuit.slimefun4.core.attributes.DamageableItem}
*
*/
@Deprecated
public interface DamageableItem extends io.github.thebusybiscuit.slimefun4.core.attributes.DamageableItem {
}

View File

@ -76,7 +76,6 @@ import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.PlayerProfile;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu;
import me.mrCookieSlime.Slimefun.utils.ConfigCache;
/**
* This is the main class of Slimefun.
@ -90,9 +89,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
public static SlimefunPlugin instance;
private RecipeSnapshot recipeSnapshot;
private SlimefunRegistry registry;
private final SlimefunRegistry registry = new SlimefunRegistry();
private MinecraftVersion minecraftVersion = MinecraftVersion.UNKNOWN;
// Services - Systems that fulfill certain tasks, treat them as a black box
@ -108,19 +105,19 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
private final ThirdPartyPluginService thirdPartySupportService = new ThirdPartyPluginService(this);
private LocalizationService local;
private GPSNetwork gpsNetwork;
private NetworkManager networkManager;
private ProtectionManager protections;
private TickerTask ticker;
private SlimefunCommand command;
private RecipeSnapshot recipeSnapshot;
private Config researches;
private Config items;
private Config whitelist;
private Config config;
private GPSNetwork gps;
private ConfigCache settings;
private SlimefunCommand command;
// Listeners that need to be accessed elsewhere
private AncientAltarListener ancientAltarListener;
private BackpackListener backpackListener;
@ -147,8 +144,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
// Setup config.yml
config = new Config(this);
registry = new SlimefunRegistry();
settings = new ConfigCache(config);
registry.load(config);
// Loading all extra configs
researches = new Config(this, "Researches.yml");
@ -164,7 +160,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
networkManager = new NetworkManager(config.getInt("options.max-network-size"));
// Setting up other stuff
gps = new GPSNetwork();
gpsNetwork = new GPSNetwork();
// Setting up bStats
metricsService.start();
@ -201,8 +197,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
getLogger().log(Level.SEVERE, "An Error occured while initializing Slimefun Researches for Slimefun " + getVersion(), x);
}
settings.researchesEnabled = getResearchCfg().getBoolean("enable-researching");
registry.setResearchingEnabled(getResearchCfg().getBoolean("enable-researching"));
PostSetup.setupWiki();
// Setting up GitHub Connectors...
@ -375,6 +370,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
return true;
}
getLogger().log(Level.WARNING, "We could not determine the version of Minecraft you were using ({0})", currentVersion);;
return false;
}
@ -471,11 +467,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
}
public static GPSNetwork getGPSNetwork() {
return instance.gps;
}
public static ConfigCache getSettings() {
return instance.settings;
return instance.gpsNetwork;
}
public static TickerTask getTicker() {

View File

@ -13,7 +13,6 @@ import java.util.UUID;
import java.util.function.Consumer;
import java.util.stream.IntStream;
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
@ -24,6 +23,7 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.config.Config;
import io.github.thebusybiscuit.slimefun4.api.items.HashedArmorpiece;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerBackpack;
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Objects.Research;
@ -50,12 +50,7 @@ public final class PlayerProfile {
private final Map<Integer, PlayerBackpack> backpacks = new HashMap<>();
private final LinkedList<Object> guideHistory = new LinkedList<>();
private final HashedArmorpiece[] armor = {
new HashedArmorpiece(),
new HashedArmorpiece(),
new HashedArmorpiece(),
new HashedArmorpiece()
};
private final HashedArmorpiece[] armor = { new HashedArmorpiece(), new HashedArmorpiece(), new HashedArmorpiece(), new HashedArmorpiece() };
private PlayerProfile(OfflinePlayer p) {
this.uuid = p.getUniqueId();
@ -196,7 +191,7 @@ public final class PlayerProfile {
}
public String getTitle() {
List<String> titles = SlimefunPlugin.getSettings().researchesTitles;
List<String> titles = SlimefunPlugin.getRegistry().getResearchRanks();
float fraction = (float) researches.size() / SlimefunPlugin.getRegistry().getResearches().size();
int index = (int) (fraction * (titles.size() - 1));

View File

@ -1,21 +0,0 @@
package me.mrCookieSlime.Slimefun.utils;
import java.util.List;
import io.github.thebusybiscuit.cscorelib2.config.Config;
// Soon this class can be discarded
public final class ConfigCache {
public boolean researchesEnabled;
public final boolean researchesFreeInCreative;
public final boolean researchFireworksEnabled;
public final List<String> researchesTitles;
public ConfigCache(Config cfg) {
researchesFreeInCreative = cfg.getBoolean("options.allow-free-creative-research");
researchesTitles = cfg.getStringList("research-ranks");
researchFireworksEnabled = cfg.getBoolean("options.research-unlock-fireworks");
}
}