Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooy1 committed Dec 31, 2020
1 parent adcf3bc commit c1969ca
Show file tree
Hide file tree
Showing 26 changed files with 437 additions and 511 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<dependency>
<groupId>io.github.mooy1</groupId>
<artifactId>InfinityLib</artifactId>
<version>4c37d7b</version>
<version>4d619f6</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.mooy1.infinityexpansion;

import io.github.mooy1.infinityexpansion.implementation.mobdata.MobSimulationChamber;
import io.github.mooy1.infinityexpansion.implementation.storage.StorageUnit;
import io.github.mooy1.infinityexpansion.implementation.blocks.StorageUnit;
import io.github.mooy1.infinityexpansion.lists.InfinityRecipes;
import io.github.mooy1.infinityexpansion.setup.Setup;
import io.github.mooy1.infinityexpansion.setup.commands.Changelog;
Expand Down Expand Up @@ -34,32 +34,26 @@ public class InfinityExpansion extends JavaPlugin implements SlimefunAddon {
@Override
public void onEnable() {
instance = this;

//config

PluginUtils.setup(this, "Mooy1/InfinityExpansion/master", getFile());
MessageUtils.setPrefix(ChatColor.DARK_GRAY + "[" + ChatColor.AQUA + "Infinity" + ChatColor.GRAY + "Expansion" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " ");
new CommandLib(this, "infinityexpansion", "infinityexpansion.admin", "/ie, /ix, /infinity");
CommandLib.addCommands(new Changelog(), new GiveRecipe(), new ResetConfig());
setupConfigOptions(getConfig());

//stats
@SuppressWarnings("unused")
final Metrics metrics = new Metrics(this, 8991);

//items
InfinityRecipes.preItems();

Setup.setup(this);

//set enabled infinity recipes
InfinityRecipes.setup(this);

//spam console

InfinityRecipes.postItems(this);

for (String line : getChangeLog()) {
getLogger().log(Level.INFO, line);
}

PluginUtils.runSync(() -> PluginUtils.log("Infinity Expansion will soon be moving some content to another addon! keep an eye out for its release!"), 300);

//ticker
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> {
if (currentTick < 60) {
currentTick++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.github.mooy1.infinityexpansion.utils.RecipeUtils;
import io.github.mooy1.infinitylib.filter.FilterType;
import io.github.mooy1.infinitylib.filter.ItemFilter;
import io.github.mooy1.infinitylib.filter.MultiFilter;
import io.github.mooy1.infinitylib.objects.AbstractContainer;
import io.github.mooy1.infinitylib.player.MessageUtils;
Expand Down Expand Up @@ -62,6 +63,8 @@ public abstract class Crafter extends AbstractContainer {
};
private static final int STATUS_SLOT = 23;

private static final int EMPTY = new MultiFilter(FilterType.MIN_AMOUNT, new ItemFilter[9]).hashCode();

public Crafter(Category category, SlimefunItemStack stack, RecipeType recipeType, ItemStack[] recipe) {
super(category, stack, recipeType, recipe);

Expand Down Expand Up @@ -189,6 +192,10 @@ private void craft(@Nonnull BlockMenu inv, @Nonnull Player p) {
private Pair<SlimefunItemStack, int[]> getOutput(@Nonnull BlockMenu inv) {

MultiFilter input = MultiFilter.fromMenu(FilterType.MIN_AMOUNT, inv, INPUT_SLOTS);

if (input.hashCode() == EMPTY) {
return null;
}

SlimefunItemStack output = this.recipes.get(input);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.mooy1.infinityexpansion.implementation.items;
package io.github.mooy1.infinityexpansion.implementation.blocks;

import com.google.common.collect.MapDifference;
import com.google.common.collect.Maps;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package io.github.mooy1.infinityexpansion.implementation.items;
package io.github.mooy1.infinityexpansion.implementation.blocks;

import io.github.mooy1.infinityexpansion.lists.Categories;
import io.github.mooy1.infinityexpansion.lists.InfinityRecipes;
import io.github.mooy1.infinityexpansion.lists.Items;
import io.github.mooy1.infinityexpansion.setup.InfinityCategory;
import io.github.mooy1.infinityexpansion.utils.RecipeUtils;
import io.github.mooy1.infinitylib.filter.FilterType;
import io.github.mooy1.infinitylib.filter.ItemFilter;
import io.github.mooy1.infinitylib.filter.MultiFilter;
import io.github.mooy1.infinitylib.objects.AbstractContainer;
import io.github.mooy1.infinitylib.player.MessageUtils;
Expand All @@ -16,10 +17,10 @@
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
import me.mrCookieSlime.Slimefun.cscorelib2.inventory.ItemUtils;
import me.mrCookieSlime.Slimefun.cscorelib2.item.CustomItem;
import org.bukkit.ChatColor;
import org.bukkit.Location;
Expand Down Expand Up @@ -58,6 +59,7 @@ public class InfinityWorkbench extends AbstractContainer implements EnergyNetCom
24, 25, 26
};
private static final int RECIPE_SLOT = 7;
private static final int EMPTY = new MultiFilter(FilterType.MIN_AMOUNT, new ItemFilter[36]).hashCode();

public InfinityWorkbench() {
super(Categories.MAIN_MATERIALS, Items.INFINITY_WORKBENCH, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[] {
Expand Down Expand Up @@ -102,7 +104,7 @@ public void onNewInstance(@Nonnull BlockMenu menu, @Nonnull Block b) {
return false;
});
menu.addMenuClickHandler(RECIPE_SLOT, (p, slot, item, action) -> {
InfinityCategory.openFromWorkBench(p, menu);
InfinityCategory.open(p, new InfinityCategory.BackEntry(menu, null, null), true);
return false;
});
}
Expand Down Expand Up @@ -154,7 +156,7 @@ public void craft(@Nonnull Block b, @Nonnull BlockMenu inv, @Nonnull Player p)
return;
}

ItemStack output = getOutput(inv);
SlimefunItemStack output = getOutput(inv);

if (output == null) { //invalid
MessageUtils.messageWithCD(p, 1000, ChatColor.RED + "Invalid Recipe!");
Expand All @@ -171,9 +173,10 @@ public void craft(@Nonnull Block b, @Nonnull BlockMenu inv, @Nonnull Player p)
inv.consumeItem(slot);
}
}
MessageUtils.message(p, ChatColor.GREEN + "Successfully crafted: " + ChatColor.WHITE + ItemUtils.getItemName(output));

MessageUtils.message(p, ChatColor.GREEN + "Successfully crafted: " + ChatColor.WHITE + output.getDisplayName());

inv.pushItem(output, OUTPUT_SLOTS);
inv.pushItem(output.clone(), OUTPUT_SLOTS);
setCharge(b.getLocation(), 0);

}
Expand All @@ -185,8 +188,12 @@ public void craft(@Nonnull Block b, @Nonnull BlockMenu inv, @Nonnull Player p)
* @return output if any
*/
@Nullable
public ItemStack getOutput(@Nonnull BlockMenu inv) {
return InfinityRecipes.RECIPES.inverse().get(MultiFilter.fromMenu(FilterType.MIN_AMOUNT, inv, INPUT_SLOTS));
public SlimefunItemStack getOutput(@Nonnull BlockMenu inv) {
MultiFilter filter = MultiFilter.fromMenu(FilterType.MIN_AMOUNT, inv, INPUT_SLOTS);
if (filter.hashCode() == EMPTY) {
return null;
}
return InfinityRecipes.RECIPES.get(filter);
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.mooy1.infinityexpansion.implementation.storage;
package io.github.mooy1.infinityexpansion.implementation.blocks;

import io.github.mooy1.infinityexpansion.implementation.abstracts.Crafter;
import io.github.mooy1.infinityexpansion.lists.Categories;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.mooy1.infinityexpansion.implementation.storage;
package io.github.mooy1.infinityexpansion.implementation.blocks;

import io.github.mooy1.infinityexpansion.InfinityExpansion;
import io.github.mooy1.infinityexpansion.implementation.abstracts.LoreStorage;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.mooy1.infinityexpansion.implementation.items;
package io.github.mooy1.infinityexpansion.implementation.blocks;

import io.github.mooy1.infinityexpansion.InfinityExpansion;
import io.github.mooy1.infinityexpansion.lists.Items;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.mooy1.infinityexpansion.implementation.items;
package io.github.mooy1.infinityexpansion.implementation.blocks;

import io.github.mooy1.infinityexpansion.lists.Categories;
import io.github.mooy1.infinityexpansion.lists.Items;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.github.mooy1.infinitylib.general.LocationUtils;
import io.github.mooy1.infinitylib.items.LoreUtils;
import io.github.mooy1.infinitylib.math.RandomUtils;
import io.github.mooy1.infinitylib.player.LeaveListener;
import io.github.mooy1.infinitylib.player.MessageUtils;
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
Expand All @@ -31,7 +32,6 @@
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
Expand All @@ -48,6 +48,7 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;

/**
* A VeinMiner rune, most code from {@link SoulboundRune}
Expand All @@ -61,7 +62,7 @@ public class VeinMinerRune extends SlimefunItem implements Listener, NotPlaceabl
private static final int MAX = 64;
private static final long CD = 1000;
private static NamespacedKey key = null;
private static final Map<Player, Long> CDS = new HashMap<>();
private static final Map<UUID, Long> CDS = new HashMap<>();
private static final String[] LORE = {"", ChatColor.AQUA + "Veinminer - Crouch to use"};
private static final Set<String> ALLOWED = new HashSet<>(Arrays.asList(
"_ORE", "_LOG", "_WOOD", "GILDED", "SOUL", "GRAVEL",
Expand All @@ -76,7 +77,7 @@ public VeinMinerRune(InfinityExpansion plugin) {
new ItemStack(Material.REDSTONE_ORE), SlimefunItems.BLANK_RUNE, new ItemStack(Material.LAPIS_ORE),
Items.MAGSTEEL, SlimefunItems.MAGIC_LUMP_3, Items.MAGSTEEL,
});

new LeaveListener(CDS);
plugin.getServer().getPluginManager().registerEvents(this, plugin);
key = new NamespacedKey(plugin, "vein_miner");
}
Expand Down Expand Up @@ -207,11 +208,12 @@ public void onBlockBreak(BlockBreakEvent e) {

if (BlockStorage.hasBlockInfo(l)) return;

if (CDS.containsKey(p) && System.currentTimeMillis() - CDS.get(p) < CD) {
MessageUtils.messageWithCD(p, 500, ChatColor.GOLD + "Wait " + ChatColor.YELLOW + (CD - (System.currentTimeMillis() - CDS.get(p))) + ChatColor.GOLD + " ms before using again!");
Long prev = CDS.get(p.getUniqueId());
if (prev != null && System.currentTimeMillis() - prev < CD) {
MessageUtils.messageWithCD(p, 500, ChatColor.GOLD + "Wait " + ChatColor.YELLOW + (CD - (System.currentTimeMillis() - prev)) + ChatColor.GOLD + " ms before using again!");
return;
}
CDS.put(p, System.currentTimeMillis());
CDS.put(p.getUniqueId(), System.currentTimeMillis());

Set<Block> found = new HashSet<>();
Set<Location> checked = new HashSet<>();
Expand Down Expand Up @@ -273,9 +275,4 @@ private void getVein(Set<Location> checked, Set<Block> found, Location l, Block
}
}

@EventHandler
private void onPlayerLeave(PlayerQuitEvent e) {
CDS.remove(e.getPlayer());
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.mooy1.infinityexpansion.implementation.machines;
package io.github.mooy1.infinityexpansion.implementation.generators;

import io.github.mooy1.infinityexpansion.lists.Categories;
import io.github.mooy1.infinityexpansion.lists.InfinityRecipes;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.mooy1.infinityexpansion.implementation.machines;
package io.github.mooy1.infinityexpansion.implementation.generators;

import io.github.mooy1.infinityexpansion.lists.Categories;
import io.github.mooy1.infinityexpansion.lists.InfinityRecipes;
Expand Down
Loading

0 comments on commit c1969ca

Please sign in to comment.