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

Performance improvements and some cleanup

This commit is contained in:
TheBusyBiscuit 2020-01-12 18:10:09 +01:00
parent b6ca510094
commit 08f25c58a9
23 changed files with 91 additions and 71 deletions

View File

@ -28,6 +28,9 @@
* Aded preset messages.yml files * Aded preset messages.yml files
* Added user-configurable localization * Added user-configurable localization
* Added many more options to the messages.yml * Added many more options to the messages.yml
* Added custom model data support for Languages
* Added Grind Stone Recipes for Prismarine
* Added String to the Bio Reactor
### Changes ### Changes
* Removed Solar Array * Removed Solar Array
@ -40,6 +43,7 @@
* Fixed #1366 * Fixed #1366
* Fixed GitHub cache * Fixed GitHub cache
* Fixed #1364 * Fixed #1364
* Fixed Bio Reactor not accepting melons
## Release Candidate 4 (06 Jan 2020) ## Release Candidate 4 (06 Jan 2020)
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#4 https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#4

View File

@ -53,6 +53,7 @@ public class LocalizationService extends SlimefunLocalization {
save(); save();
} }
// Load included Languages (with their ID and texture)
private void loadLanguages() { private void loadLanguages() {
addLanguage("en", "a1701f21835a898b20759fb30a583a38b994abf60d3912ab4ce9f2311e74f72"); addLanguage("en", "a1701f21835a898b20759fb30a583a38b994abf60d3912ab4ce9f2311e74f72");
} }
@ -74,6 +75,7 @@ public class LocalizationService extends SlimefunLocalization {
@Override @Override
public boolean hasLanguage(String language) { public boolean hasLanguage(String language) {
// Checks if our jar files contains a .yml file for this id
return plugin.getClass().getResource("/languages/messages_" + language + ".yml") != null; return plugin.getClass().getResource("/languages/messages_" + language + ".yml") != null;
} }

View File

@ -21,8 +21,9 @@ public class UpdaterService {
plugin.getLogger().log(Level.WARNING, "It looks like you are using an unofficially modified build of Slimefun!"); plugin.getLogger().log(Level.WARNING, "It looks like you are using an unofficially modified build of Slimefun!");
plugin.getLogger().log(Level.WARNING, "Auto-Updates have been disabled, this build is not considered safe."); plugin.getLogger().log(Level.WARNING, "Auto-Updates have been disabled, this build is not considered safe.");
plugin.getLogger().log(Level.WARNING, "Do not report bugs encountered in this Version of Slimefun."); plugin.getLogger().log(Level.WARNING, "Do not report bugs encountered in this Version of Slimefun.");
updater = null;
} }
if (version.startsWith("DEV - ")) { else if (version.startsWith("DEV - ")) {
// If we are using a development build, we want to switch to our custom // If we are using a development build, we want to switch to our custom
updater = new GitHubBuildsUpdater(plugin, file, "TheBusyBiscuit/Slimefun4/master"); updater = new GitHubBuildsUpdater(plugin, file, "TheBusyBiscuit/Slimefun4/master");
} }

View File

@ -16,7 +16,9 @@ public final class Language {
public Language(String id, FileConfiguration config, String hash) { public Language(String id, FileConfiguration config, String hash) {
this.id = id; this.id = id;
this.config = config; this.config = config;
this.item = SkullItem.fromHash(hash);
item = SkullItem.fromHash(hash);
SlimefunPlugin.getItemTextureService().setTexture(item, "_UI_LANGUAGE_" + id.toUpperCase());
} }
public String getID() { public String getID() {

View File

@ -87,14 +87,14 @@ public class BlockListener implements Listener {
blockHandler.onPlace(e.getPlayer(), e.getBlock(), sfItem); blockHandler.onPlace(e.getPlayer(), e.getBlock(), sfItem);
} }
else { else {
for (ItemHandler handler : SlimefunItem.getHandlers("BlockPlaceHandler")) { for (ItemHandler handler : SlimefunItem.getHandlers(BlockPlaceHandler.class)) {
if (((BlockPlaceHandler) handler).onBlockPlace(e, item)) break; if (((BlockPlaceHandler) handler).onBlockPlace(e, item)) break;
} }
} }
} }
} }
else { else {
for (ItemHandler handler : SlimefunItem.getHandlers("BlockPlaceHandler")) { for (ItemHandler handler : SlimefunItem.getHandlers(BlockPlaceHandler.class)) {
if (((BlockPlaceHandler) handler).onBlockPlace(e, item)) break; if (((BlockPlaceHandler) handler).onBlockPlace(e, item)) break;
} }
} }
@ -248,7 +248,7 @@ public class BlockListener implements Listener {
} }
else { else {
// Walk over all registered block break handlers until one says that it'll handle it. // Walk over all registered block break handlers until one says that it'll handle it.
for (ItemHandler handler : SlimefunItem.getHandlers("BlockBreakHandler")) { for (ItemHandler handler : SlimefunItem.getHandlers(BlockBreakHandler.class)) {
if (((BlockBreakHandler) handler).onBlockBreak(e, item, fortune, drops)) break; if (((BlockBreakHandler) handler).onBlockBreak(e, item, fortune, drops)) break;
} }
} }
@ -270,7 +270,7 @@ public class BlockListener implements Listener {
fortune = (e.getBlock().getType() == Material.LAPIS_ORE ? 4 + random.nextInt(5) : 1) * (fortune + 1); fortune = (e.getBlock().getType() == Material.LAPIS_ORE ? 4 + random.nextInt(5) : 1) * (fortune + 1);
} }
for (ItemHandler handler : SlimefunItem.getHandlers("BlockBreakHandler")) { for (ItemHandler handler : SlimefunItem.getHandlers(BlockBreakHandler.class)) {
if (((BlockBreakHandler) handler).onBlockBreak(e, item, fortune, drops)) break; if (((BlockBreakHandler) handler).onBlockBreak(e, item, fortune, drops)) break;
} }
} }

View File

@ -42,7 +42,7 @@ public class DamageListener implements Listener {
} }
if (item.getType() != Material.AIR && Slimefun.hasUnlocked(p, item, true)) { if (item.getType() != Material.AIR && Slimefun.hasUnlocked(p, item, true)) {
for (ItemHandler handler : SlimefunItem.getHandlers("EntityKillHandler")) { for (ItemHandler handler : SlimefunItem.getHandlers(EntityKillHandler.class)) {
if (((EntityKillHandler) handler).onKill(e, e.getEntity(), p, item)) return; if (((EntityKillHandler) handler).onKill(e, e.getEntity(), p, item)) return;
} }
} }

View File

@ -29,7 +29,7 @@ public class SlimefunBowListener implements Listener {
@EventHandler @EventHandler
public void onArrowSuccessfulHit(EntityDamageByEntityEvent e) { public void onArrowSuccessfulHit(EntityDamageByEntityEvent e) {
if (e.getDamager() instanceof Arrow && e.getEntity() instanceof LivingEntity && SlimefunPlugin.getUtilities().arrows.containsKey(e.getDamager().getUniqueId())) { if (e.getDamager() instanceof Arrow && e.getEntity() instanceof LivingEntity && SlimefunPlugin.getUtilities().arrows.containsKey(e.getDamager().getUniqueId())) {
for (ItemHandler handler : SlimefunItem.getHandlers("BowShootHandler")) { for (ItemHandler handler : SlimefunItem.getHandlers(BowShootHandler.class)) {
if (((BowShootHandler) handler).onHit(e, (LivingEntity) e.getEntity())) { if (((BowShootHandler) handler).onHit(e, (LivingEntity) e.getEntity())) {
break; break;
} }

View File

@ -100,8 +100,8 @@ public class SlimefunItemListener implements Listener {
if (slimefunItem != null) { if (slimefunItem != null) {
if (Slimefun.hasUnlocked(p, slimefunItem, true)) { if (Slimefun.hasUnlocked(p, slimefunItem, true)) {
slimefunItem.callItemHandler(ItemInteractionHandler.class, handler -> slimefunItem.callItemHandler(ItemInteractionHandler.class, handler ->
handler.onRightClick(e, p, item) handler.onRightClick(e, p, item)
); );
// Open the Backpack (also includes Coolers) // Open the Backpack (also includes Coolers)
if (slimefunItem instanceof SlimefunBackpack) { if (slimefunItem instanceof SlimefunBackpack) {
@ -140,7 +140,7 @@ public class SlimefunItemListener implements Listener {
} }
} }
else { else {
for (ItemHandler handler : SlimefunItem.getHandlers("ItemInteractionHandler")) { for (ItemHandler handler : SlimefunItem.getHandlers(ItemInteractionHandler.class)) {
if (((ItemInteractionHandler) handler).onRightClick(e, p, item)) return; if (((ItemInteractionHandler) handler).onRightClick(e, p, item)) return;
} }
} }
@ -278,7 +278,7 @@ public class SlimefunItemListener implements Listener {
@EventHandler @EventHandler
public void onItemDrop(PlayerDropItemEvent e) { public void onItemDrop(PlayerDropItemEvent e) {
for (ItemHandler handler : SlimefunItem.getHandlers("ItemDropHandler")) { for (ItemHandler handler : SlimefunItem.getHandlers(ItemDropHandler.class)) {
if (((ItemDropHandler) handler).onItemDrop(e, e.getPlayer(), e.getItemDrop())) return; if (((ItemDropHandler) handler).onItemDrop(e, e.getPlayer(), e.getItemDrop())) return;
} }
} }

View File

@ -1,8 +1,6 @@
package io.github.thebusybiscuit.slimefun4.utils; package io.github.thebusybiscuit.slimefun4.utils;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
@ -77,13 +75,13 @@ public final class ChestMenuUtils {
ItemStack item = indicator.clone(); ItemStack item = indicator.clone();
ItemMeta im = item.getItemMeta(); ItemMeta im = item.getItemMeta();
im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
((Damageable) im).setDamage(getDurability(item, timeleft, time));
if (im instanceof Damageable) {
((Damageable) im).setDamage(getDurability(item, timeleft, time));
}
im.setDisplayName(" "); im.setDisplayName(" ");
List<String> lore = new ArrayList<>(); im.setLore(Arrays.asList(getProgressBar(timeleft, time), "", getTimeLeft(timeleft / 2)));
lore.add(getProgressBar(timeleft, time));
lore.add("");
lore.add(getTimeLeft(timeleft / 2));
im.setLore(lore);
item.setItemMeta(im); item.setItemMeta(im);
menu.replaceExistingItem(slot, item); menu.replaceExistingItem(slot, item);

View File

@ -3,6 +3,7 @@ package me.mrCookieSlime.Slimefun.Objects.SlimefunItem;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -17,6 +18,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.collections.OptionalMap;
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
import io.github.thebusybiscuit.slimefun4.api.items.Placeable; import io.github.thebusybiscuit.slimefun4.api.items.Placeable;
import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactive; import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactive;
@ -56,7 +58,7 @@ public class SlimefunItem implements Placeable {
private boolean addon = false; private boolean addon = false;
private String permission = ""; private String permission = "";
private List<String> noPermissionTooltip; private List<String> noPermissionTooltip;
private final Set<ItemHandler> itemhandlers = new HashSet<>(); private final OptionalMap<Class<? extends ItemHandler>, ItemHandler> itemhandlers = new OptionalMap<>(HashMap::new);
private boolean ticking = false; private boolean ticking = false;
private BlockTicker blockTicker; private BlockTicker blockTicker;
private EnergyTicker energyTicker; private EnergyTicker energyTicker;
@ -223,13 +225,11 @@ public class SlimefunItem implements Placeable {
create(); create();
for (ItemHandler handler : itemhandlers) { for (ItemHandler handler : itemhandlers.values()) {
if (areItemHandlersPrivate()) continue; if (areItemHandlersPrivate()) continue;
Set<ItemHandler> handlerset = getHandlers(handler.toCodename()); Set<ItemHandler> handlerset = getHandlers(handler.getIdentifier());
handlerset.add(handler); handlerset.add(handler);
SlimefunPlugin.getUtilities().itemHandlers.put(handler.toCodename(), handlerset);
} }
if (SlimefunPlugin.getSettings().printOutLoading) { if (SlimefunPlugin.getSettings().printOutLoading) {
@ -402,16 +402,16 @@ public class SlimefunItem implements Placeable {
} }
public void addItemHandler(ItemHandler... handlers) { public void addItemHandler(ItemHandler... handlers) {
this.itemhandlers.addAll(Arrays.asList(handlers));
for (ItemHandler handler : handlers) { for (ItemHandler handler : handlers) {
itemhandlers.put(handler.getIdentifier(), handler);
if (handler instanceof BlockTicker) { if (handler instanceof BlockTicker) {
this.ticking = true; ticking = true;
SlimefunPlugin.getUtilities().tickers.add(getID()); SlimefunPlugin.getUtilities().tickers.add(getID());
this.blockTicker = (BlockTicker) handler; blockTicker = (BlockTicker) handler;
} }
else if (handler instanceof EnergyTicker) { else if (handler instanceof EnergyTicker) {
this.energyTicker = (EnergyTicker) handler; energyTicker = (EnergyTicker) handler;
EnergyNet.registerComponent(getID(), EnergyNetComponent.SOURCE); EnergyNet.registerComponent(getID(), EnergyNetComponent.SOURCE);
} }
} }
@ -437,8 +437,8 @@ public class SlimefunItem implements Placeable {
register(false); register(false);
} }
public static Set<ItemHandler> getHandlers(String codeid) { public static Set<ItemHandler> getHandlers(Class<? extends ItemHandler> identifier) {
return SlimefunPlugin.getUtilities().itemHandlers.getOrDefault(codeid, new HashSet<>()); return SlimefunPlugin.getUtilities().itemHandlers.computeIfAbsent(identifier, c -> new HashSet<>());
} }
/** /**
@ -563,8 +563,8 @@ public class SlimefunItem implements Placeable {
* *
* @return The Set of item handlers * @return The Set of item handlers
*/ */
public Set<ItemHandler> getHandlers() { public Collection<ItemHandler> getHandlers() {
return itemhandlers; return itemhandlers.values();
} }
/** /**
@ -579,7 +579,11 @@ public class SlimefunItem implements Placeable {
} }
public <T extends ItemHandler> void callItemHandler(Class<T> c, Consumer<T> callable) { public <T extends ItemHandler> void callItemHandler(Class<T> c, Consumer<T> callable) {
itemhandlers.stream().filter(c::isInstance).map(c::cast).forEach(callable); Optional<ItemHandler> handler = itemhandlers.get(c);
if (handler.isPresent()) {
callable.accept(c.cast(handler.get()));
}
} }
public boolean isTicking() { public boolean isTicking() {

View File

@ -11,7 +11,8 @@ public interface AutonomousMachineHandler extends ItemHandler {
boolean onBlockDispense(BlockDispenseEvent e, Block dispenser, Dispenser d, Block block, Block chest, SlimefunItem machine); boolean onBlockDispense(BlockDispenseEvent e, Block dispenser, Dispenser d, Block block, Block chest, SlimefunItem machine);
default String toCodename() { @Override
return "AutonomousMachineHandler"; default Class<? extends ItemHandler> getIdentifier() {
return AutonomousMachineHandler.class;
} }
} }

View File

@ -10,7 +10,8 @@ public interface BlockBreakHandler extends ItemHandler {
boolean onBlockBreak(BlockBreakEvent e, ItemStack item, int fortune, List<ItemStack> drops); boolean onBlockBreak(BlockBreakEvent e, ItemStack item, int fortune, List<ItemStack> drops);
default String toCodename() { @Override
return "BlockBreakHandler"; default Class<? extends ItemHandler> getIdentifier() {
return BlockBreakHandler.class;
} }
} }

View File

@ -8,7 +8,8 @@ public interface BlockPlaceHandler extends ItemHandler {
boolean onBlockPlace(BlockPlaceEvent e, ItemStack item); boolean onBlockPlace(BlockPlaceEvent e, ItemStack item);
default String toCodename() { @Override
return "BlockPlaceHandler"; default Class<? extends ItemHandler> getIdentifier() {
return BlockPlaceHandler.class;
} }
} }

View File

@ -1,10 +1,10 @@
package me.mrCookieSlime.Slimefun.Objects.handlers; package me.mrCookieSlime.Slimefun.Objects.handlers;
import org.bukkit.block.Block;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import org.bukkit.block.Block;
public abstract class BlockTicker implements ItemHandler { public abstract class BlockTicker implements ItemHandler {
protected boolean unique = true; protected boolean unique = true;
@ -37,8 +37,8 @@ public abstract class BlockTicker implements ItemHandler {
} }
@Override @Override
public String toCodename() { public Class<? extends ItemHandler> getIdentifier() {
return "BlockTicker"; return BlockTicker.class;
} }
/** /**

View File

@ -8,7 +8,8 @@ public interface BowShootHandler extends ItemHandler {
boolean onHit(EntityDamageByEntityEvent e, LivingEntity n); boolean onHit(EntityDamageByEntityEvent e, LivingEntity n);
default String toCodename() { @Override
return "BowShootHandler"; default Class<? extends ItemHandler> getIdentifier() {
return BowShootHandler.class;
} }
} }

View File

@ -10,7 +10,8 @@ public interface EntityKillHandler extends ItemHandler {
boolean onKill(EntityDeathEvent e, Entity entity, Player killer, ItemStack item); boolean onKill(EntityDeathEvent e, Entity entity, Player killer, ItemStack item);
default String toCodename() { @Override
return "EntityKillHandler"; default Class<? extends ItemHandler> getIdentifier() {
return EntityKillHandler.class;
} }
} }

View File

@ -9,8 +9,9 @@ public interface ItemConsumptionHandler extends ItemHandler {
boolean onConsume(PlayerItemConsumeEvent e, Player p, ItemStack item); boolean onConsume(PlayerItemConsumeEvent e, Player p, ItemStack item);
default String toCodename() { @Override
return "ItemConsumptionHandler"; default Class<? extends ItemHandler> getIdentifier() {
return ItemConsumptionHandler.class;
} }
} }

View File

@ -9,7 +9,8 @@ public interface ItemDropHandler extends ItemHandler {
boolean onItemDrop(PlayerDropItemEvent e, Player p, Item item); boolean onItemDrop(PlayerDropItemEvent e, Player p, Item item);
default String toCodename() { @Override
return "ItemDropHandler"; default Class<? extends ItemHandler> getIdentifier() {
} return ItemDropHandler.class;
}
} }

View File

@ -3,9 +3,9 @@ package me.mrCookieSlime.Slimefun.Objects.handlers;
@FunctionalInterface @FunctionalInterface
public interface ItemHandler { public interface ItemHandler {
String toCodename();
default boolean isPrivate() { default boolean isPrivate() {
return false; return false;
} }
Class<? extends ItemHandler> getIdentifier();
} }

View File

@ -10,8 +10,9 @@ public interface ItemInteractionHandler extends ItemHandler {
boolean onRightClick(ItemUseEvent e, Player p, ItemStack item); boolean onRightClick(ItemUseEvent e, Player p, ItemStack item);
default String toCodename() { @Override
return "ItemInteractionHandler"; default Class<? extends ItemHandler> getIdentifier() {
return ItemInteractionHandler.class;
} }
} }

View File

@ -10,7 +10,8 @@ public interface MultiBlockInteractionHandler extends ItemHandler {
boolean onInteract(Player p, MultiBlock mb, Block b); boolean onInteract(Player p, MultiBlock mb, Block b);
default String toCodename() { @Override
return "MultiBlockInteractionHandler"; default Class<? extends ItemHandler> getIdentifier() {
return MultiBlockInteractionHandler.class;
} }
} }

View File

@ -12,8 +12,8 @@ public abstract class EnergyTicker implements ItemHandler {
public abstract boolean explode(Location l); public abstract boolean explode(Location l);
@Override @Override
public String toCodename() { public Class<? extends ItemHandler> getIdentifier() {
return "EnergyTicker"; return EnergyTicker.class;
} }
} }

View File

@ -67,7 +67,7 @@ public final class Utilities {
public final List<Category> enabledCategories = new ArrayList<>(); public final List<Category> enabledCategories = new ArrayList<>();
public final Set<ItemStack> radioactiveItems = new HashSet<>(); public final Set<ItemStack> radioactiveItems = new HashSet<>();
public final Map<String, Set<ItemHandler>> itemHandlers = new HashMap<>(); public final Map<Class<? extends ItemHandler>, Set<ItemHandler>> itemHandlers = new HashMap<>();
public final Map<String, SlimefunBlockHandler> blockHandlers = new HashMap<>(); public final Map<String, SlimefunBlockHandler> blockHandlers = new HashMap<>();
public final Set<String> tickers = new HashSet<>(); public final Set<String> tickers = new HashSet<>();