Skip to content

Commit 7eb48da

Browse files
committed
Refactor HiddenSwitch to core
1 parent 426299c commit 7eb48da

File tree

7 files changed

+52
-22
lines changed

7 files changed

+52
-22
lines changed

craftbook-bukkit/build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ dependencies {
5757
}
5858

5959
tasks.named<Copy>("processResources") {
60+
// Avoid carrying project reference into task execution
6061
val internalVersion = project.internalVersion
6162
inputs.property("internalVersion", internalVersion)
6263
filesMatching("plugin.yml") {
63-
expand("internalVersion" to internalVersion)
64+
expand(mapOf("internalVersion" to internalVersion.get()))
6465
}
6566
filesMatching("paper-plugin.yml") {
66-
expand("internalVersion" to internalVersion)
67+
expand(mapOf("internalVersion" to internalVersion.get()))
6768
}
6869
}
6970

craftbook-bukkit/src/main/java/org/enginehub/craftbook/bukkit/mechanic/BukkitMechanicManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ public void setup() {
549549
.name("HiddenSwitch")
550550
.description(TranslatableComponent.of("craftbook.hiddenswitch.description"))
551551
.category(MechanicCategory.GENERAL)
552-
.className("org.enginehub.craftbook.mechanics.HiddenSwitch")
552+
.className("org.enginehub.craftbook.bukkit.mechanics.BukkitHiddenSwitch")
553553
.buildAndRegister();
554554

555555
// TODO CommandItems needs to load early (after variables).

craftbook-bukkit/src/main/java/org/enginehub/craftbook/mechanics/HiddenSwitch.java renamed to craftbook-bukkit/src/main/java/org/enginehub/craftbook/bukkit/mechanics/BukkitHiddenSwitch.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
* see <http://www.gnu.org/licenses/>.
1414
*/
1515

16-
package org.enginehub.craftbook.mechanics;
16+
package org.enginehub.craftbook.bukkit.mechanics;
1717

18-
import com.sk89q.util.yaml.YAMLProcessor;
1918
import com.sk89q.worldedit.util.formatting.text.TextComponent;
2019
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
2120
import net.kyori.adventure.text.Component;
@@ -36,13 +35,13 @@
3635
import org.bukkit.event.block.SignChangeEvent;
3736
import org.bukkit.event.player.PlayerInteractEvent;
3837
import org.bukkit.inventory.EquipmentSlot;
39-
import org.enginehub.craftbook.AbstractCraftBookMechanic;
4038
import org.enginehub.craftbook.ChangedSign;
4139
import org.enginehub.craftbook.CraftBook;
4240
import org.enginehub.craftbook.CraftBookPlayer;
4341
import org.enginehub.craftbook.bukkit.CraftBookPlugin;
4442
import org.enginehub.craftbook.mechanic.CraftBookMechanic;
4543
import org.enginehub.craftbook.mechanic.MechanicType;
44+
import org.enginehub.craftbook.mechanics.HiddenSwitch;
4645
import org.enginehub.craftbook.util.EventUtil;
4746
import org.enginehub.craftbook.util.LocationUtil;
4847
import org.enginehub.craftbook.util.ProtectionUtil;
@@ -51,9 +50,9 @@
5150
import java.util.ArrayList;
5251
import java.util.List;
5352

54-
public class HiddenSwitch extends AbstractCraftBookMechanic implements Listener {
53+
public class BukkitHiddenSwitch extends HiddenSwitch implements Listener {
5554

56-
public HiddenSwitch(MechanicType<? extends CraftBookMechanic> mechanicType) {
55+
public BukkitHiddenSwitch(MechanicType<? extends CraftBookMechanic> mechanicType) {
5756
super(mechanicType);
5857
}
5958

@@ -208,12 +207,4 @@ private boolean toggleSwitches(Block sign, BlockFace direction) {
208207

209208
return toggledSwitch;
210209
}
211-
212-
private boolean allowAnyFace;
213-
214-
@Override
215-
public void loadFromConfiguration(YAMLProcessor config) {
216-
config.setComment("allow-any-face", "Allows the Hidden Switch to be activated from any face of the block.");
217-
allowAnyFace = config.getBoolean("allow-any-face", true);
218-
}
219210
}

craftbook-bukkit/src/main/java/org/enginehub/craftbook/bukkit/mechanics/dispenser/BukkitDispenserRecipes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
public class BukkitDispenserRecipes extends DispenserRecipes implements Listener {
4949

50-
public static final Registry<DispenserRecipe> REGISTRY = new NamespacedRegistry<>("dispenser recipe", "craftbook");
50+
public static final Registry<DispenserRecipe> REGISTRY = new NamespacedRegistry<>("dispenser recipe", "craftbook:dispenser_recipe", "craftbook");
5151

5252
public BukkitDispenserRecipes(MechanicType<? extends CraftBookMechanic> mechanicType) {
5353
super(mechanicType);

craftbook-bukkit/src/main/java/org/enginehub/craftbook/bukkit/mechanics/variables/BukkitVariableManager.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
import org.enginehub.craftbook.mechanics.variables.VariableManager;
4444
import org.jspecify.annotations.Nullable;
4545

46-
import java.io.File;
46+
import java.nio.file.Files;
47+
import java.nio.file.Path;
4748
import java.util.List;
4849

4950
import static com.google.common.base.Preconditions.checkNotNull;
@@ -62,10 +63,9 @@ public void enable() throws MechanicInitializationException {
6263
CraftBookPlugin.logDebugMessage("Initializing Variables!", "startup.variables");
6364

6465
try {
65-
File varFile = CraftBook.getInstance().getPlatform().getWorkingDirectory().resolve("variables.yml").toFile();
66-
if (!varFile.exists()) {
67-
//noinspection ResultOfMethodCallIgnored
68-
varFile.createNewFile();
66+
Path varFile = CraftBook.getInstance().getPlatform().getWorkingDirectory().resolve("variables.yml");
67+
if (!Files.exists(varFile)) {
68+
Files.createFile(varFile);
6969
}
7070
variableConfiguration = new VariableConfiguration(new YAMLProcessor(varFile, true, YAMLFormat.EXTENDED));
7171
variableConfiguration.load();

craftbook-core/src/main/java/org/enginehub/craftbook/mechanic/MechanicTypes.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.enginehub.craftbook.mechanics.ChunkAnchor;
2525
import org.enginehub.craftbook.mechanics.CookingPot;
2626
import org.enginehub.craftbook.mechanics.Elevator;
27+
import org.enginehub.craftbook.mechanics.HiddenSwitch;
2728
import org.enginehub.craftbook.mechanics.JackOLantern;
2829
import org.enginehub.craftbook.mechanics.LightStone;
2930
import org.enginehub.craftbook.mechanics.LightSwitch;
@@ -71,6 +72,7 @@ public class MechanicTypes {
7172
public static final @Nullable MechanicType<Elevator> ELEVATOR = get("elevator");
7273
// public static final @Nullable MechanicType<Gate> GATE = get("gate");
7374
// public static final @Nullable MechanicType<HeadDrops> HEAD_DROPS = get("head_drops");
75+
public static final @Nullable MechanicType<HiddenSwitch> HIDDEN_SWITCH = get("hidden_switch");
7476
public static final @Nullable MechanicType<JackOLantern> JACK_O_LANTERN = get("jack_o_lantern");
7577
public static final @Nullable MechanicType<LightSwitch> LIGHT_SWITCH = get("light_switch");
7678
public static final @Nullable MechanicType<LightStone> LIGHTSTONE = get("lightstone");
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* CraftBook Copyright (C) EngineHub and Contributors <https://enginehub.org/>
3+
*
4+
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
5+
* License as published by the Free
6+
* Software Foundation, either version 3 of the License, or (at your option) any later version.
7+
*
8+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9+
* warranty of MERCHANTABILITY or
10+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
11+
*
12+
* You should have received a copy of the GNU General Public License along with this program. If not,
13+
* see <http://www.gnu.org/licenses/>.
14+
*/
15+
16+
package org.enginehub.craftbook.mechanics;
17+
18+
import com.sk89q.util.yaml.YAMLProcessor;
19+
import org.enginehub.craftbook.AbstractCraftBookMechanic;
20+
import org.enginehub.craftbook.mechanic.CraftBookMechanic;
21+
import org.enginehub.craftbook.mechanic.MechanicType;
22+
23+
public class HiddenSwitch extends AbstractCraftBookMechanic {
24+
25+
public HiddenSwitch(MechanicType<? extends CraftBookMechanic> mechanicType) {
26+
super(mechanicType);
27+
}
28+
29+
protected boolean allowAnyFace;
30+
31+
@Override
32+
public void loadFromConfiguration(YAMLProcessor config) {
33+
config.setComment("allow-any-face", "Allows the Hidden Switch to be activated from any face of the block.");
34+
allowAnyFace = config.getBoolean("allow-any-face", true);
35+
}
36+
}

0 commit comments

Comments
 (0)