Skip to content

Commit

Permalink
Merge branch 'master' into test-lockette
Browse files Browse the repository at this point in the history
  • Loading branch information
pop4959 committed Sep 2, 2024
2 parents 5f73a11 + 0b9b9b9 commit d3539b9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
6 changes: 4 additions & 2 deletions bukkit/src/main/java/org/popcraft/bolt/BoltPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ private void registerAccessTypes() {
bolt.getAccessRegistry().unregisterAll();
final ConfigurationSection protections = getConfig().getConfigurationSection("protections");
if (protections != null) {
for (final String type : protections.getKeys(false)) {
for (final String typeKey : protections.getKeys(false)) {
final String type = typeKey.toLowerCase();
final boolean requirePermission = protections.getBoolean("%s.require-permission".formatted(type), false);
final List<String> allows = protections.getStringList("%s.allows".formatted(type));
final List<String> permissions = allows.isEmpty() ? protections.getStringList(type) : allows;
Expand All @@ -310,7 +311,8 @@ private void registerAccessTypes() {
}
final ConfigurationSection access = getConfig().getConfigurationSection("access");
if (access != null) {
for (final String type : access.getKeys(false)) {
for (final String typeKey : access.getKeys(false)) {
final String type = typeKey.toLowerCase();
final boolean requirePermission = access.getBoolean("%s.require-permission".formatted(type), false);
final List<String> allows = access.getStringList("%s.allows".formatted(type));
final List<String> permissions = allows.isEmpty() ? access.getStringList(type) : allows;
Expand Down
31 changes: 26 additions & 5 deletions bukkit/src/main/java/org/popcraft/bolt/util/Doors.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.popcraft.bolt.util;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Sound;
import org.bukkit.Tag;
import org.bukkit.World;
Expand All @@ -27,11 +29,16 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;

public final class Doors {
private static final SourceResolver DOOR_SOURCE_RESOLVER = new SourceTypeResolver(Source.of(SourceTypes.DOOR));
private static final Map<BlockLocation, Integer> CLOSING = new ConcurrentHashMap<>();
private static final Set<PlayerInteractEvent> SELF_FIRED_EVENTS = ConcurrentHashMap.newKeySet();
// Future: Replace with Tag.MOB_INTERACTABLE_DOORS
private static final Tag<Material> MOB_INTERACTABLE_DOORS = Bukkit.getServer().getTag(Tag.REGISTRY_BLOCKS, NamespacedKey.minecraft("mob_interactable_doors"), Material.class);
// There is no tag for copper doors
private static final Function<Material, Boolean> IS_COPPER_DOOR = (material) -> material.name().contains("COPPER_DOOR");

private Doors() {
}
Expand All @@ -53,7 +60,7 @@ public static void handlePlayerInteract(final BoltPlugin plugin, final PlayerInt
}
if (plugin.isDoorsOpenDouble()) {
final Block hingedBlock = getHingedBlock(block);
if (hingedBlock != null && hingedBlock.getType().equals(block.getType()) && isDoor(hingedBlock) && isDoorOpenable(hingedBlock, openIron)) {
if (hingedBlock != null && areMatchingDoors(block, hingedBlock) && isDoor(hingedBlock) && isDoorOpenable(hingedBlock, openIron)) {
final Protection hingedProtection = plugin.findProtection(hingedBlock);
if (hingedProtection != null && plugin.canAccess(hingedProtection, player, Permission.INTERACT)) {
doors.add(hingedBlock);
Expand Down Expand Up @@ -151,16 +158,30 @@ public static Block getHingedBlock(final Block block) {
return block.getRelative(adjacentFace);
}

public static boolean areMatchingDoors(final Block door, final Block hinged) {
if (IS_COPPER_DOOR.apply(door.getType()) && IS_COPPER_DOOR.apply(hinged.getType())) {
// Should match regardless of oxidation level
return true;
}
return hinged.getType().equals(door.getType());
}

public static boolean isDoorOpenable(final Block block, final boolean openIron) {
final Material material = block.getType();
final Tag<Material> openableDoors = openIron ? Tag.DOORS : Tag.WOODEN_DOORS;
final Tag<Material> openableGates = Tag.FENCE_GATES;
final Tag<Material> openableTrapdoors = openIron ? Tag.TRAPDOORS : Tag.WOODEN_TRAPDOORS;
return openableDoors.isTagged(material) || openableGates.isTagged(material) || openableTrapdoors.isTagged(material);
if (openIron && Material.IRON_DOOR.equals(material)) {
return true;
}
if (MOB_INTERACTABLE_DOORS != null) {
return MOB_INTERACTABLE_DOORS.isTagged(material);
}
return Tag.DOORS.isTagged(material) || Tag.FENCES.isTagged(material) || Tag.TRAPDOORS.isTagged(material);
}

public static boolean isDoorOpenableNormally(final Block block) {
final Material material = block.getType();
if (MOB_INTERACTABLE_DOORS != null) {
return MOB_INTERACTABLE_DOORS.isTagged(material);
}
final boolean isIronDoor = Tag.DOORS.isTagged(material) && !Tag.WOODEN_DOORS.isTagged(material);
final boolean isIronTrapdoor = Tag.TRAPDOORS.isTagged(material) && !Tag.WOODEN_TRAPDOORS.isTagged(material);
return !isIronDoor && !isIronTrapdoor;
Expand Down
2 changes: 1 addition & 1 deletion bukkit/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: ${name}
version: ${version}
main: ${group}.bolt.BoltPlugin
api-version: 1.13
api-version: "1.20.6"
folia-supported: true
authors: [ ${ author } ]
description: ${description}
Expand Down

0 comments on commit d3539b9

Please sign in to comment.