-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
multiblockcraft criterion, some optimizations
- Loading branch information
Showing
20 changed files
with
204 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/me/char321/sfadvancements/api/criteria/MultiBlockCraftCriterion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package me.char321.sfadvancements.api.criteria; | ||
|
||
import me.char321.sfadvancements.SFAdvancements; | ||
import me.char321.sfadvancements.util.ConfigUtils; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.configuration.ConfigurationSection; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
public class MultiBlockCraftCriterion extends Criterion { | ||
private final ItemStack item; | ||
|
||
public static MultiBlockCraftCriterion loadFromConfig(ConfigurationSection config) { | ||
String id = config.getName(); | ||
|
||
if (!SFAdvancements.instance().isMultiBlockCraftEvent()) { | ||
SFAdvancements.warn("Multiblock craft events are not available on this version of Slimefun! for criterion " + id); | ||
return null; | ||
} | ||
|
||
int amount = config.getInt("amount"); | ||
if (amount == 0) { | ||
amount = 1; | ||
} | ||
|
||
String name = config.getString("name"); | ||
if(name == null) { | ||
name = id; | ||
} | ||
|
||
name = ChatColor.translateAlternateColorCodes('&', name); | ||
|
||
ItemStack item = ConfigUtils.getItem(config, "item"); | ||
if (item == null) { | ||
SFAdvancements.warn("unknown item for multiblock craft criterion " + id); | ||
return null; | ||
} | ||
|
||
return new MultiBlockCraftCriterion(id, amount, name, item); | ||
} | ||
|
||
/** | ||
* | ||
* @param id | ||
* @param count | ||
* @param name | ||
* @param item the output item of the multiblock craft | ||
*/ | ||
public MultiBlockCraftCriterion(String id, int count, String name, ItemStack item) { | ||
super(id, count, name); | ||
this.item = item; | ||
} | ||
|
||
public ItemStack getItem() { | ||
return item; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/me/char321/sfadvancements/core/AdvancementsItemGroup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/me/char321/sfadvancements/core/command/DumpItemCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
.../me/char321/sfadvancements/core/criteria/completer/MultiBlockCraftCriterionCompleter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package me.char321.sfadvancements.core.criteria.completer; | ||
|
||
import io.github.thebusybiscuit.slimefun4.api.events.MultiBlockCraftEvent; | ||
import io.github.thebusybiscuit.slimefun4.api.events.ResearchUnlockEvent; | ||
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; | ||
import io.github.thebusybiscuit.slimefun4.api.researches.Research; | ||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; | ||
import me.char321.sfadvancements.SFAdvancements; | ||
import me.char321.sfadvancements.api.criteria.Criterion; | ||
import me.char321.sfadvancements.api.criteria.MultiBlockCraftCriterion; | ||
import me.char321.sfadvancements.api.criteria.ResearchCriterion; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.Material; | ||
import org.bukkit.NamespacedKey; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerJoinEvent; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import java.util.*; | ||
|
||
public class MultiBlockCraftCriterionCompleter implements CriterionCompleter, Listener { | ||
private final Map<Material, Set<MultiBlockCraftCriterion>> criteria = new EnumMap<>(Material.class); | ||
|
||
public MultiBlockCraftCriterionCompleter() { | ||
Bukkit.getPluginManager().registerEvents(this, SFAdvancements.instance()); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||
public void onMultiBlockCraft(MultiBlockCraftEvent e) { | ||
performCriteria(e.getPlayer(), e.getOutput()); | ||
} | ||
|
||
private void performCriteria(Player player, ItemStack output) { | ||
Set<MultiBlockCraftCriterion> allcriteria = criteria.get(output.getType()); | ||
if (allcriteria == null) { | ||
return; | ||
} | ||
|
||
for (MultiBlockCraftCriterion criterion : allcriteria) { | ||
if (SlimefunUtils.isItemSimilar(output, criterion.getItem(), false, false)) { | ||
criterion.perform(player); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void register(Criterion criterion) { | ||
if (!(getCriterionClass().isInstance(criterion))) { | ||
throw new IllegalArgumentException("criterion must be an " + getCriterionClass().getName()); | ||
} | ||
|
||
MultiBlockCraftCriterion criterion1 = ((MultiBlockCraftCriterion) criterion); | ||
Material material = criterion1.getItem().getType(); | ||
criteria.computeIfAbsent(material, k -> new HashSet<>()).add(criterion1); | ||
} | ||
|
||
@Override | ||
public Class<? extends Criterion> getCriterionClass() { | ||
return MultiBlockCraftCriterion.class; | ||
} | ||
|
||
@Override | ||
public void reload() { | ||
criteria.clear(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.