generated from Slimefun/Addon-Template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If it still doesn't work, consider turn on backward compatiblity.
- Loading branch information
nahkd
authored and
nahkd
committed
Jul 22, 2020
1 parent
35113fa
commit 7c94a87
Showing
4 changed files
with
116 additions
and
116 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
92 changes: 46 additions & 46 deletions
92
src/main/java/me/nahkd/spigot/sfaddons/endrex/handlers/InventoryEventsHandlers.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 |
---|---|---|
@@ -1,46 +1,46 @@ | ||
package me.nahkd.spigot.sfaddons.endrex.handlers; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.inventory.InventoryClickEvent; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.ItemMeta; | ||
|
||
import me.mrCookieSlime.Slimefun.SlimefunPlugin; | ||
import me.nahkd.spigot.sfaddons.endrex.items.mysterious.MysteriousEquipment; | ||
import me.nahkd.spigot.sfaddons.endrex.utils.InventoryUtils; | ||
|
||
public class InventoryEventsHandlers implements Listener { | ||
|
||
@EventHandler | ||
public void click(InventoryClickEvent event) { | ||
if (event.getClickedInventory() != event.getInventory()) return; | ||
switch (event.getView().getTitle()) { | ||
case "Slimefun Guide": return; | ||
} | ||
|
||
ItemStack itemStack = event.getCurrentItem(); | ||
if (!InventoryUtils.isNotAir(itemStack)) return; | ||
ItemMeta meta = itemStack.getItemMeta(); | ||
Optional<String> id = SlimefunPlugin.getItemDataService().getItemData(meta); | ||
if (id.isPresent() && MysteriousEquipment.getMappedItems().containsKey(id.get())) { | ||
MysteriousEquipment equipment = MysteriousEquipment.getMappedItems().get(id.get()); | ||
if (meta.getLore().get(0).equals("§7Click to unlock")) { | ||
// Add crap to the item | ||
List<String> lore = meta.getLore(); | ||
lore.set(0, "§7§oMagically created"); | ||
meta.setLore(lore); | ||
|
||
equipment.applyEnchantment(meta); | ||
|
||
itemStack.setItemMeta(meta); | ||
event.setCurrentItem(new ItemStack(itemStack)); | ||
event.setCancelled(true); | ||
} | ||
} | ||
} | ||
|
||
} | ||
package me.nahkd.spigot.sfaddons.endrex.handlers; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.inventory.InventoryClickEvent; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.ItemMeta; | ||
|
||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; | ||
import me.nahkd.spigot.sfaddons.endrex.items.mysterious.MysteriousEquipment; | ||
import me.nahkd.spigot.sfaddons.endrex.utils.InventoryUtils; | ||
|
||
public class InventoryEventsHandlers implements Listener { | ||
|
||
@EventHandler | ||
public void click(InventoryClickEvent event) { | ||
if (event.getClickedInventory() != event.getInventory()) return; | ||
switch (event.getView().getTitle()) { | ||
case "Slimefun Guide": return; | ||
} | ||
|
||
ItemStack itemStack = event.getCurrentItem(); | ||
if (!InventoryUtils.isNotAir(itemStack)) return; | ||
ItemMeta meta = itemStack.getItemMeta(); | ||
Optional<String> id = SlimefunPlugin.getItemDataService().getItemData(meta); | ||
if (id.isPresent() && MysteriousEquipment.getMappedItems().containsKey(id.get())) { | ||
MysteriousEquipment equipment = MysteriousEquipment.getMappedItems().get(id.get()); | ||
if (meta.getLore().get(0).equals("§7Click to unlock")) { | ||
// Add crap to the item | ||
List<String> lore = meta.getLore(); | ||
lore.set(0, "§7§oMagically created"); | ||
meta.setLore(lore); | ||
|
||
equipment.applyEnchantment(meta); | ||
|
||
itemStack.setItemMeta(meta); | ||
event.setCurrentItem(new ItemStack(itemStack)); | ||
event.setCancelled(true); | ||
} | ||
} | ||
} | ||
|
||
} |
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
136 changes: 68 additions & 68 deletions
136
src/main/java/me/nahkd/spigot/sfaddons/endrex/structures/MysteryBoxesGenerator.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 |
---|---|---|
@@ -1,68 +1,68 @@ | ||
package me.nahkd.spigot.sfaddons.endrex.structures; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
import org.bukkit.Chunk; | ||
import org.bukkit.Material; | ||
import org.bukkit.World; | ||
import org.bukkit.World.Environment; | ||
import org.bukkit.block.Biome; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; | ||
import me.mrCookieSlime.Slimefun.cscorelib2.item.CustomItem; | ||
import me.nahkd.spigot.sfaddons.endrex.Endrex; | ||
import me.nahkd.spigot.sfaddons.endrex.items.EndrexItems; | ||
import me.nahkd.spigot.sfaddons.endrex.nahkdschem2.VectorInt; | ||
import me.nahkd.spigot.sfaddons.endrex.nahkdschem2.Schematic; | ||
import me.nahkd.spigot.sfaddons.endrex.nahkdschem2.loot.LootTableEntry; | ||
|
||
public class MysteryBoxesGenerator extends StructuresGenerator { | ||
|
||
Schematic schem; | ||
List<LootTableEntry> lootTable; | ||
|
||
public MysteryBoxesGenerator() { | ||
schem = Endrex.getSchematic("structures/other/mysterybox.nsm"); | ||
lootTable = Arrays.asList( | ||
new LootTableEntry(0.02, new ItemStack(Material.ENDER_PEARL, 3)), | ||
new LootTableEntry(0.03, new ItemStack(Material.ENDER_PEARL, 2)), | ||
new LootTableEntry(0.03, new ItemStack(Material.ENDER_PEARL, 1)), | ||
|
||
new LootTableEntry(0.02, new ItemStack(Material.EXPERIENCE_BOTTLE, 6)), | ||
new LootTableEntry(0.02, new ItemStack(Material.EXPERIENCE_BOTTLE, 3)), | ||
new LootTableEntry(0.03, new ItemStack(Material.EXPERIENCE_BOTTLE, 2)), | ||
|
||
new LootTableEntry(0.02, new CustomItem(EndrexItems.ENDERIUM.getItem(), 1)), | ||
new LootTableEntry(0.01, new CustomItem(EndrexItems.ENDERIUM.getItem(), 2)), | ||
|
||
new LootTableEntry(0.04, new ItemStack(Material.DIAMOND, 1)), | ||
new LootTableEntry(0.03, new ItemStack(Material.DIAMOND, 2)), | ||
new LootTableEntry(0.01, EndrexItems.ENDERIUM_SWORD.getItem()), | ||
new LootTableEntry(0.02, EndrexItems.MASK_OF_ENDER.getItem()), | ||
new LootTableEntry(0.02, SlimefunItems.RUNE_AIR), | ||
new LootTableEntry(0.03, SlimefunItems.RUNE_ENDER), | ||
new LootTableEntry(0.02, SlimefunItems.GOLD_16K), | ||
new LootTableEntry(0.01, SlimefunItems.BLANK_RUNE) | ||
); | ||
} | ||
|
||
@Override | ||
public void generateStructure(World world, Chunk newChunk, Random rand) { | ||
if (world.getEnvironment() != Environment.THE_END) return; | ||
if (newChunk.getX() >= -32 && newChunk.getZ() >= -32 && newChunk.getX() <= 32 && newChunk.getZ() <= 32) return; | ||
int mx = rand.nextInt(13); | ||
for (int i = 0; i < mx; i++) rand.nextInt(); | ||
double hit = rand.nextDouble(); | ||
if (hit <= 0.03) { | ||
int genX = rand.nextInt(9) + (newChunk.getX() * 16), | ||
genZ = rand.nextInt(9) + (newChunk.getZ() * 16), | ||
y = 100 + rand.nextInt(32); | ||
if (world.getBlockAt(genX, y, genZ).getBiome() == Biome.SMALL_END_ISLANDS) return; | ||
schem.pasteSchematic(world, new VectorInt(genX, y, genZ), lootTable); | ||
} | ||
} | ||
|
||
} | ||
package me.nahkd.spigot.sfaddons.endrex.structures; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
import org.bukkit.Chunk; | ||
import org.bukkit.Material; | ||
import org.bukkit.World; | ||
import org.bukkit.World.Environment; | ||
import org.bukkit.block.Biome; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; | ||
import me.mrCookieSlime.Slimefun.cscorelib2.item.CustomItem; | ||
import me.nahkd.spigot.sfaddons.endrex.Endrex; | ||
import me.nahkd.spigot.sfaddons.endrex.items.EndrexItems; | ||
import me.nahkd.spigot.sfaddons.endrex.nahkdschem2.VectorInt; | ||
import me.nahkd.spigot.sfaddons.endrex.nahkdschem2.Schematic; | ||
import me.nahkd.spigot.sfaddons.endrex.nahkdschem2.loot.LootTableEntry; | ||
|
||
public class MysteryBoxesGenerator extends StructuresGenerator { | ||
|
||
Schematic schem; | ||
List<LootTableEntry> lootTable; | ||
|
||
public MysteryBoxesGenerator() { | ||
schem = Endrex.getSchematic("structures/other/mysterybox.nsm"); | ||
lootTable = Arrays.asList( | ||
new LootTableEntry(0.02, new ItemStack(Material.ENDER_PEARL, 3)), | ||
new LootTableEntry(0.03, new ItemStack(Material.ENDER_PEARL, 2)), | ||
new LootTableEntry(0.03, new ItemStack(Material.ENDER_PEARL, 1)), | ||
|
||
new LootTableEntry(0.02, new ItemStack(Material.EXPERIENCE_BOTTLE, 6)), | ||
new LootTableEntry(0.02, new ItemStack(Material.EXPERIENCE_BOTTLE, 3)), | ||
new LootTableEntry(0.03, new ItemStack(Material.EXPERIENCE_BOTTLE, 2)), | ||
|
||
new LootTableEntry(0.02, new CustomItem(EndrexItems.ENDERIUM.getItem(), 1)), | ||
new LootTableEntry(0.01, new CustomItem(EndrexItems.ENDERIUM.getItem(), 2)), | ||
|
||
new LootTableEntry(0.04, new ItemStack(Material.DIAMOND, 1)), | ||
new LootTableEntry(0.03, new ItemStack(Material.DIAMOND, 2)), | ||
new LootTableEntry(0.01, EndrexItems.ENDERIUM_SWORD.getItem()), | ||
new LootTableEntry(0.02, EndrexItems.MASK_OF_ENDER.getItem()), | ||
new LootTableEntry(0.02, SlimefunItems.AIR_RUNE), | ||
new LootTableEntry(0.03, SlimefunItems.ENDER_RUNE), | ||
new LootTableEntry(0.02, SlimefunItems.GOLD_16K), | ||
new LootTableEntry(0.01, SlimefunItems.BLANK_RUNE) | ||
); | ||
} | ||
|
||
@Override | ||
public void generateStructure(World world, Chunk newChunk, Random rand) { | ||
if (world.getEnvironment() != Environment.THE_END) return; | ||
if (newChunk.getX() >= -32 && newChunk.getZ() >= -32 && newChunk.getX() <= 32 && newChunk.getZ() <= 32) return; | ||
int mx = rand.nextInt(13); | ||
for (int i = 0; i < mx; i++) rand.nextInt(); | ||
double hit = rand.nextDouble(); | ||
if (hit <= 0.03) { | ||
int genX = rand.nextInt(9) + (newChunk.getX() * 16), | ||
genZ = rand.nextInt(9) + (newChunk.getZ() * 16), | ||
y = 100 + rand.nextInt(32); | ||
if (world.getBlockAt(genX, y, genZ).getBiome() == Biome.SMALL_END_ISLANDS) return; | ||
schem.pasteSchematic(world, new VectorInt(genX, y, genZ), lootTable); | ||
} | ||
} | ||
|
||
} |