generated from Slimefun/Addon-Template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Creative Transmitter/Capacitor/Generator Added Electric Poison Extractor Added Slime Meal Added Alarm Clock Some electric machines now show recipe inputs and outputs in the guide Fixed a couple typos
- Loading branch information
Showing
8 changed files
with
404 additions
and
23 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
137 changes: 137 additions & 0 deletions
137
src/main/java/me/bunnky/idreamofeasy/slimefun/items/AlarmClock.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,137 @@ | ||
package me.bunnky.idreamofeasy.slimefun.items; | ||
|
||
import io.github.bakedlibs.dough.chat.ChatInput; | ||
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; | ||
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; | ||
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; | ||
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; | ||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; | ||
import me.bunnky.idreamofeasy.IDreamOfEasy; | ||
import me.bunnky.idreamofeasy.utils.IDOEUtility; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.Sound; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.scheduler.BukkitRunnable; | ||
|
||
import java.util.HashMap; | ||
import java.util.UUID; | ||
|
||
public class AlarmClock extends SlimefunItem { | ||
|
||
private final HashMap<UUID, Long> playerTimers = new HashMap<>(); | ||
private final HashMap<UUID, Boolean> alarmMode = new HashMap<>(); | ||
private final HashMap<UUID, BukkitRunnable> alarmTasks = new HashMap<>(); | ||
|
||
public AlarmClock(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { | ||
super(itemGroup, item, recipeType, recipe); | ||
IDOEUtility.setGlow(item); | ||
|
||
addItemHandler(onUse()); | ||
} | ||
|
||
private ItemUseHandler onUse() { | ||
return e -> { | ||
Player p = e.getPlayer(); | ||
UUID playerId = p.getUniqueId(); | ||
cancelAlarm(playerId); | ||
|
||
if (p.isSneaking()) { | ||
boolean isAlarmMode = alarmMode.getOrDefault(playerId, false); | ||
alarmMode.put(playerId, !isAlarmMode); | ||
|
||
if (!alarmMode.get(playerId)) { | ||
cancelAlarm(playerId); | ||
p.sendMessage("§cAlarm mode is now disabled."); | ||
} else { | ||
p.sendMessage("§aAlarm mode enabled."); | ||
} | ||
} else { | ||
p.sendMessage("§aEnter timer length in seconds"); | ||
|
||
ChatInput.waitForPlayer(IDreamOfEasy.getInstance(), p, msg -> { | ||
try { | ||
long duration = Long.parseLong(msg) * 1000; | ||
long endTime = System.currentTimeMillis() + duration; | ||
playerTimers.put(playerId, endTime); | ||
p.sendMessage("§eTimer set for §f" + duration / 1000 + "§es."); | ||
startTimer(p); | ||
} catch (NumberFormatException ex) { | ||
p.sendMessage("§cInvalid input. Please enter a valid number in seconds."); | ||
} | ||
}); | ||
} | ||
}; | ||
} | ||
|
||
private void startTimer(Player player) { | ||
UUID playerId = player.getUniqueId(); | ||
|
||
new BukkitRunnable() { | ||
@Override | ||
public void run() { | ||
Long endTime = playerTimers.get(playerId); | ||
if (endTime == null) { | ||
return; | ||
} | ||
|
||
long remainingTime = endTime - System.currentTimeMillis(); | ||
|
||
if (remainingTime <= 0) { | ||
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_BELL, 1.0f, 2.0f); | ||
|
||
Bukkit.getScheduler().runTaskLater(IDreamOfEasy.getInstance(), () -> { | ||
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_BELL, 1.0f, 1.5f); | ||
}, 2L); | ||
|
||
Bukkit.getScheduler().runTaskLater(IDreamOfEasy.getInstance(), () -> { | ||
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_BELL, 1.0f, 1.0f); | ||
}, 4L); | ||
|
||
playerTimers.remove(playerId); | ||
this.cancel(); | ||
player.sendMessage("§eTime's up!"); | ||
|
||
if (alarmMode.getOrDefault(playerId, false)) { | ||
startAlarmTask(player.getUniqueId()); | ||
} | ||
} | ||
} | ||
}.runTaskTimer(IDreamOfEasy.getInstance(), 0, 0); | ||
} | ||
|
||
private void startAlarmTask(UUID playerId) { | ||
BukkitRunnable alarmTask = new BukkitRunnable() { | ||
@Override | ||
public void run() { | ||
if (alarmMode.getOrDefault(playerId, false)) { | ||
Player player = Bukkit.getPlayer(playerId); | ||
if (player != null) { | ||
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_BELL, 1.0f, 2.0f); | ||
|
||
Bukkit.getScheduler().runTaskLater(IDreamOfEasy.getInstance(), () -> { | ||
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_BELL, 1.0f, 1.5f); | ||
}, 2L); | ||
|
||
Bukkit.getScheduler().runTaskLater(IDreamOfEasy.getInstance(), () -> { | ||
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_BELL, 1.0f, 1.0f); | ||
}, 4L); | ||
|
||
} | ||
} else { | ||
this.cancel(); | ||
} | ||
} | ||
}; | ||
alarmTask.runTaskTimer(IDreamOfEasy.getInstance(), 0, 10); | ||
alarmTasks.put(playerId, alarmTask); | ||
} | ||
|
||
private void cancelAlarm(UUID playerId) { | ||
BukkitRunnable task = alarmTasks.get(playerId); | ||
if (task != null) { | ||
task.cancel(); | ||
alarmTasks.remove(playerId); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/me/bunnky/idreamofeasy/slimefun/items/SlimeMeal.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,41 @@ | ||
package me.bunnky.idreamofeasy.slimefun.items; | ||
|
||
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; | ||
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; | ||
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; | ||
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; | ||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; | ||
import me.bunnky.idreamofeasy.utils.IDOEUtility; | ||
import org.bukkit.GameMode; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.EntityType; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.entity.Slime; | ||
import org.bukkit.event.player.PlayerInteractEvent; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
public class SlimeMeal extends SlimefunItem { | ||
|
||
public SlimeMeal(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { | ||
super(itemGroup, item, recipeType, recipe); | ||
addItemHandler(onUse()); | ||
IDOEUtility.setGlow(item); | ||
} | ||
|
||
private ItemUseHandler onUse() { | ||
return e -> { | ||
PlayerInteractEvent event = e.getInteractEvent(); | ||
Player p = event.getPlayer(); | ||
Entity entity = p.getTargetEntity(5); | ||
|
||
if (entity != null && entity.getType() == EntityType.SLIME) { | ||
Slime slime = (Slime) entity; | ||
int newSize = Math.min(slime.getSize() + 1, 20); | ||
slime.setSize(newSize); | ||
if (p.getGameMode() == GameMode.SURVIVAL) { | ||
event.getItem().setAmount(event.getItem().getAmount() - 1); | ||
} | ||
} | ||
}; | ||
} | ||
} |
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
78 changes: 78 additions & 0 deletions
78
src/main/java/me/bunnky/idreamofeasy/slimefun/machines/ElectricPoisonExtractor.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,78 @@ | ||
package me.bunnky.idreamofeasy.slimefun.machines; | ||
|
||
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; | ||
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; | ||
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; | ||
import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem; | ||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; | ||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe; | ||
import org.bukkit.Material; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.PotionMeta; | ||
import org.bukkit.potion.PotionType; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ElectricPoisonExtractor extends AContainer implements RecipeDisplayItem { | ||
|
||
public ElectricPoisonExtractor(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { | ||
super(itemGroup, item, recipeType, recipe); | ||
} | ||
|
||
@Override | ||
protected void registerDefaultRecipes() { | ||
registerRecipe(4, new ItemStack[] { new ItemStack(Material.GLASS_BOTTLE), new ItemStack(Material.POISONOUS_POTATO) }, new ItemStack[] { createPoisonPotion(PotionType.STRONG_POISON) }); | ||
registerRecipe(6, new ItemStack[] { new ItemStack(Material.GLASS_BOTTLE), new ItemStack(Material.PUFFERFISH) }, new ItemStack[] { createPoisonPotion(PotionType.LONG_POISON) }); | ||
registerRecipe(6, new ItemStack[] { new ItemStack(Material.GLASS_BOTTLE), new ItemStack(Material.SPIDER_EYE, 2) }, new ItemStack[] { createPoisonPotion(PotionType.POISON) }); | ||
registerRecipe(8, new ItemStack[] { new ItemStack(Material.GLASS_BOTTLE), new ItemStack(Material.ROTTEN_FLESH, 8) }, new ItemStack[] { createPoisonPotion(PotionType.POISON) }); | ||
registerRecipe(4, new ItemStack[] { new ItemStack(Material.GLASS_BOTTLE), new ItemStack(Material.RED_MUSHROOM, 4) }, new ItemStack[] { createPoisonPotion(PotionType.POISON) }); | ||
registerRecipe(4, new ItemStack[] { new ItemStack(Material.GLASS_BOTTLE), new ItemStack(Material.BROWN_MUSHROOM, 4) }, new ItemStack[] { createPoisonPotion(PotionType.POISON) }); | ||
} | ||
|
||
private ItemStack createPoisonPotion(PotionType type) { | ||
ItemStack potion = new ItemStack(Material.POTION); | ||
PotionMeta potionMeta = (PotionMeta) potion.getItemMeta(); | ||
|
||
if (potionMeta != null) { | ||
switch (type) { | ||
case LONG_POISON: | ||
potionMeta.setBasePotionType(PotionType.LONG_POISON); | ||
break; | ||
case STRONG_POISON: | ||
potionMeta.setBasePotionType(PotionType.STRONG_POISON); | ||
break; | ||
default: | ||
potionMeta.setBasePotionType(PotionType.POISON); | ||
break; | ||
} | ||
|
||
potion.setItemMeta(potionMeta); | ||
} | ||
|
||
return potion; | ||
} | ||
|
||
@Override | ||
public List<ItemStack> getDisplayRecipes() { | ||
List<ItemStack> displayRecipes = new ArrayList<>(recipes.size() * 2); | ||
|
||
for (MachineRecipe recipe : recipes) { | ||
displayRecipes.add(recipe.getInput()[recipe.getInput().length - 1]); | ||
displayRecipes.add(recipe.getOutput()[0]); | ||
} | ||
|
||
return displayRecipes; | ||
} | ||
|
||
@Override | ||
public ItemStack getProgressBar() { | ||
return createPoisonPotion(PotionType.POISON); | ||
} | ||
|
||
@Override | ||
public @NotNull String getMachineIdentifier() { | ||
return "IDOE_ELECTRIC_POISON_EXTRACTOR"; | ||
} | ||
} |
Oops, something went wrong.