-
Notifications
You must be signed in to change notification settings - Fork 17
Vaan/feature/feature collection #690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
f1dc8cf
46ca61c
32da757
00fb44d
82a6f94
d84f381
125c20c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package io.github.pylonmc.pylon; | ||
|
|
||
| import com.destroystokyo.paper.MaterialSetTag; | ||
| import io.github.pylonmc.rebar.item.RebarItemTag; | ||
| import io.github.pylonmc.rebar.registry.RebarRegistry; | ||
| import org.bukkit.Material; | ||
|
|
||
| import static io.github.pylonmc.pylon.util.PylonUtils.pylonKey; | ||
|
|
||
| public class PylonItemTag { | ||
| public static final MaterialSetTag GLASSLIKE_BUKKIT = new MaterialSetTag(pylonKey("all_glass")) | ||
| .endsWith("_GLASS") | ||
| .endsWith("GLASS_PANE") | ||
| .add(Material.GLASS) | ||
| .add(Material.SEA_LANTERN) | ||
| .add(Material.BEACON) | ||
| .add(Material.GLOWSTONE) | ||
| .add(Material.REDSTONE_LAMP); | ||
|
|
||
| public static final RebarItemTag GLASSLIKE = new RebarItemTag( | ||
| GLASSLIKE_BUKKIT.getKey(), | ||
| GLASSLIKE_BUKKIT.getValues().toArray(new Material[0]) | ||
| ); | ||
|
|
||
| static { | ||
| RebarRegistry.ITEM_TAGS.register(GLASSLIKE); | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This just feels like a bad way to implement this imo. There’s no perm checks for placement or breaking, its manual place & break which is just prone to issues with other plugins, also you don’t set facing on the blockdata, does this work on all rotations? I would make the bedroll a normal bed item, prevent placement if its not night time, and then post successful place do most of the existing logic. Then on wake auto break with the actual method and give the bed directly to the player. That way we actually call events properly. We could also make a RebarBed block interface for onSleep, onWakeup, onSetSpawn which this could use but obv that can happen later (if ever)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see any realistic way on why the plugins should interact with the bed roll, but I can open an issue later I don't feel like adding that stuff because it doesn't seem that necessary to me nor I have a clear idea what you are trying to pitch (beside the permission checks) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| package io.github.pylonmc.pylon.content.tools; | ||
|
|
||
| import com.destroystokyo.paper.event.player.PlayerSetSpawnEvent; | ||
| import io.github.pylonmc.rebar.event.api.annotation.MultiHandler; | ||
| import io.github.pylonmc.rebar.item.RebarItem; | ||
| import io.github.pylonmc.rebar.item.base.RebarBlockInteractor; | ||
| import kotlin.Pair; | ||
| import org.bukkit.Bukkit; | ||
| import org.bukkit.Location; | ||
| import org.bukkit.Material; | ||
| import org.bukkit.World; | ||
| import org.bukkit.block.data.type.Bed; | ||
| import org.bukkit.block.Block; | ||
| import org.bukkit.block.BlockFace; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.Event; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.EventPriority; | ||
| import org.bukkit.event.Listener; | ||
| import org.bukkit.event.block.BlockBreakEvent; | ||
| import org.bukkit.event.player.PlayerInteractEvent; | ||
| import org.bukkit.event.world.TimeSkipEvent; | ||
| import org.bukkit.inventory.ItemStack; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
| import java.util.Map; | ||
| import java.util.UUID; | ||
|
|
||
| public final class BedRoll extends RebarItem implements RebarBlockInteractor { | ||
| public static final Map<UUID, Pair<Block, Block>> SLEEP_MAP = new HashMap<>(); | ||
| public static final HashSet<Location> BLOCKS = new HashSet<>(); | ||
|
|
||
| public BedRoll(@NotNull ItemStack stack) { | ||
| super(stack); | ||
| } | ||
|
|
||
| @Override | ||
| @MultiHandler(priorities = { EventPriority.NORMAL, EventPriority.MONITOR }) | ||
| public void onUsedToClickBlock(@NotNull PlayerInteractEvent event, @NotNull EventPriority priority) { | ||
| Player player = event.getPlayer(); | ||
| Block clicked = event.getClickedBlock(); | ||
| if (!event.getAction().isRightClick() | ||
| || clicked == null | ||
| || event.useItemInHand() == Event.Result.DENY | ||
| || player.isSneaking()) { | ||
| return; | ||
| } | ||
|
|
||
| if (priority == EventPriority.NORMAL) { | ||
| event.setUseInteractedBlock(Event.Result.DENY); | ||
| return; | ||
| } | ||
|
|
||
| World world = player.getWorld(); | ||
| if (world.getEnvironment() == World.Environment.NETHER || world.getEnvironment() == World.Environment.THE_END) { | ||
| player.getInventory().getItemInMainHand().subtract(); | ||
| world.createExplosion(clicked.getLocation(), 5f, true, true); | ||
| return; | ||
| } | ||
|
|
||
| if (!world.isBedWorks()) { | ||
| return; // we cannot sleep | ||
| } | ||
|
|
||
| UUID playerId = player.getUniqueId(); | ||
| if (SLEEP_MAP.containsKey(playerId)) { | ||
| return; // maybe error message | ||
| } | ||
|
|
||
| Block baseBed = clicked.getRelative(BlockFace.UP); | ||
| Block otherBed = baseBed.getRelative(player.getFacing()); | ||
| if (!baseBed.isEmpty() || !otherBed.isEmpty()) { | ||
| return; // maybe error message | ||
| } | ||
|
|
||
| baseBed.setBlockData( | ||
| Bukkit.createBlockData(Material.RED_BED, (bd) -> { | ||
| Bed bed = (Bed) bd; | ||
| bed.setPart(Bed.Part.FOOT); | ||
| }) | ||
| ); | ||
|
|
||
| otherBed.setBlockData( | ||
| Bukkit.createBlockData(Material.RED_BED, (bd) -> { | ||
| Bed bed = (Bed) bd; | ||
| bed.setPart(Bed.Part.HEAD); | ||
| }) | ||
| ); | ||
|
|
||
| Location bedLocation = baseBed.getLocation(); | ||
| player.teleport(bedLocation); | ||
|
|
||
| // put before just in case the event doesn't pick it up | ||
| SLEEP_MAP.put(playerId, new Pair<>(baseBed, otherBed)); | ||
| BLOCKS.add(baseBed.getLocation()); | ||
| BLOCKS.add(otherBed.getLocation()); | ||
| if (!player.sleep(bedLocation, true)) { | ||
| SLEEP_MAP.remove(playerId); | ||
| BLOCKS.remove(baseBed.getLocation()); | ||
| BLOCKS.remove(otherBed.getLocation()); | ||
| } | ||
| } | ||
|
|
||
| public static class BedRollListener implements Listener { | ||
|
|
||
| @EventHandler(ignoreCancelled = true) | ||
| public void changeRespawn(PlayerSetSpawnEvent event) { | ||
| if (event.getCause() != PlayerSetSpawnEvent.Cause.BED) return; | ||
| if (SLEEP_MAP.containsKey(event.getPlayer().getUniqueId())) event.setCancelled(true); | ||
| } | ||
|
|
||
| @EventHandler(ignoreCancelled = true) | ||
| public void sleepCompleted(TimeSkipEvent event) { | ||
| if (event.getSkipReason() != TimeSkipEvent.SkipReason.NIGHT_SKIP) return; | ||
| SLEEP_MAP.forEach((k, v) -> { | ||
| v.getFirst().setType(Material.AIR, false); | ||
| v.getSecond().setType(Material.AIR, false); | ||
| }); | ||
| SLEEP_MAP.clear(); | ||
| BLOCKS.clear(); | ||
| } | ||
|
|
||
| @EventHandler(ignoreCancelled = true) | ||
| public void preventBedRollBreak(BlockBreakEvent event) { | ||
| if (BLOCKS.contains(event.getBlock().getLocation())) event.setCancelled(true); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # how long it takes to scan an object | ||
| use-ticks: 10 | ||
| # after a successful scan, how long should the item be on cooldown | ||
| cooldown-ticks: 10 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| durability: 512 | ||
| mining-speed: 9.0 | ||
| mining-durability-damage: 1 | ||
| attack-durability-damage: 1 | ||
| attack-damage: 4.5 | ||
| attack-speed: 1.2 |
Uh oh!
There was an error while loading. Please reload this page.