-
Notifications
You must be signed in to change notification settings - Fork 0
Register voting booth furniture and start due elections #70
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
Changes from all commits
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,45 @@ | ||
| package net.tfminecraft.simplefactions.government; | ||
|
|
||
| public final class VotingBlock { | ||
| private VotingBlock() { | ||
| } | ||
|
|
||
| public static String furnitureId(String configPath) { | ||
| String path = typedPath(configPath, "iaf"); | ||
| return path == null || path.isBlank() ? null : path; | ||
| } | ||
|
|
||
| public static boolean matches(String configPath, String namespacedId) { | ||
| if (namespacedId == null || namespacedId.isBlank()) { | ||
| return false; | ||
| } | ||
| String configured = furnitureId(configPath); | ||
| return configured != null && configured.equalsIgnoreCase(namespacedId); | ||
| } | ||
|
|
||
| private static String typedPath(String configPath, String expectedType) { | ||
| if (configPath == null || configPath.isBlank()) { | ||
| return null; | ||
| } | ||
| String trimmed = configPath.trim(); | ||
| int openParen = trimmed.indexOf('('); | ||
| int closeParen = trimmed.indexOf(')', openParen + 1); | ||
| String type; | ||
| String path; | ||
| if (openParen >= 0 && closeParen > openParen) { | ||
| type = trimmed.substring(0, openParen); | ||
| path = trimmed.substring(openParen + 1, closeParen); | ||
| } else { | ||
| int dot = trimmed.indexOf('.'); | ||
| if (dot <= 0) { | ||
| return null; | ||
| } | ||
| type = trimmed.substring(0, dot); | ||
| path = trimmed.substring(dot + 1); | ||
| } | ||
| if (!type.equalsIgnoreCase(expectedType)) { | ||
| return null; | ||
| } | ||
| return path.trim(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package net.tfminecraft.simplefactions.managers; | ||
|
|
||
| import org.bukkit.block.Block; | ||
| import org.bukkit.entity.Entity; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.EventPriority; | ||
| import org.bukkit.event.Listener; | ||
| import org.bukkit.event.block.Action; | ||
|
|
||
| import dev.lone.itemsadder.api.Events.FurnitureBreakEvent; | ||
| import dev.lone.itemsadder.api.Events.FurnitureInteractEvent; | ||
| import dev.lone.itemsadder.api.Events.FurniturePlaceSuccessEvent; | ||
| import net.tfminecraft.simplefactions.Cache; | ||
| import net.tfminecraft.simplefactions.government.VotingBlock; | ||
|
|
||
| public class VotingBoothListener implements Listener { | ||
| private final FactionManager factions; | ||
|
|
||
| public VotingBoothListener(FactionManager factions) { | ||
| this.factions = factions; | ||
| } | ||
|
|
||
| @EventHandler | ||
| public void openVotingFurniture(FurnitureInteractEvent event) { | ||
| Action action = event.getAction(); | ||
| if (action != null && action != Action.RIGHT_CLICK_AIR && action != Action.RIGHT_CLICK_BLOCK) return; | ||
| if (!VotingBlock.matches(Cache.votingBlock, event.getNamespacedID())) return; | ||
| Entity entity = event.getBukkitEntity(); | ||
| if (entity == null) return; | ||
| if (factions.presentBooth(event.getPlayer(), entity.getLocation().getBlock())) { | ||
| event.setCancelled(true); | ||
| } | ||
| } | ||
|
|
||
| @EventHandler | ||
| public void placeVotingFurniture(FurniturePlaceSuccessEvent event) { | ||
| if (!VotingBlock.matches(Cache.votingBlock, event.getNamespacedID())) return; | ||
| Entity entity = event.getBukkitEntity(); | ||
| if (entity == null) return; | ||
| factions.registerVotingBooth(event.getPlayer(), entity.getLocation().getBlock()); | ||
| } | ||
|
|
||
| @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||
| public void breakVotingFurniture(FurnitureBreakEvent event) { | ||
| if (!VotingBlock.matches(Cache.votingBlock, event.getNamespacedID())) return; | ||
| Entity entity = event.getBukkitEntity(); | ||
| if (entity == null) return; | ||
| Block block = entity.getLocation().getBlock(); | ||
| factions.unregisterVotingBooth(event.getPlayer(), block); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ version: ${project.version} | |
| author: Drefvelin | ||
|
|
||
| depend: [DenarEconomy, TLibs] | ||
| softdepend: [MMOItems, MythicLib, MMOCore, TFMCWeb, VehicleFramework, VFBuilders, ConditionalEvents, RPCharacters] | ||
| softdepend: [MMOItems, MythicLib, MMOCore, TFMCWeb, VehicleFramework, VFBuilders, ConditionalEvents, RPCharacters, ItemsAdder] | ||
|
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. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: rg -n 'paper|spigot|api-version|minecraft|1\.21' pom.xml src/main/resources/plugin.yml .githubRepository: TF-Minecraft/SimpleFactions Length of output: 1017 🏁 Script executed: set -e
printf '%s\n' '--- pom paper/support declarations ---'
sed -n '55,75p' pom.xml
printf '%s\n' '--- plugin descriptor ---'
sed -n '1,15p' src/main/resources/plugin.yml
printf '%s\n' '--- repository support references ---'
rg -n -i 'paper|spigot|minecraft|server version|supported version|1\.21' README.md docs .github pom.xml src/main/resources 2>/dev/null || true
printf '%s\n' '--- ItemsAdder handler declarations ---'
rg -n -C 3 'FurnitureInteractEvent|FurniturePlaceSuccessEvent|FurnitureBreakEvent' src/main/java/net/tfminecraft/simplefactions/managers/FactionManager.java
printf '%s\n' '--- listener registration path ---'
sed -n '245,265p' src/main/java/net/tfminecraft/simplefactions/SimpleFactions.java
sed -n '400,430p' src/main/java/net/tfminecraft/simplefactions/SimpleFactions.javaRepository: TF-Minecraft/SimpleFactions Length of output: 9773 Isolate the ItemsAdder handlers from When ItemsAdder is absent on the repository’s declared Paper target, Paper 1.21.10 can skip every Move the ItemsAdder handlers to a separate listener and register that listener only when ItemsAdder is enabled. 🤖 Prompt for AI Agents |
||
|
|
||
| commands: | ||
| faction: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package net.tfminecraft.simplefactions.government; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| import java.time.Instant; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class ElectionCountdownTest { | ||
|
|
||
| @Test | ||
| void formatTimeUntil_countsWholeDaysAndHours() { | ||
| Instant now = Instant.parse("2026-09-21T08:15:00Z"); | ||
| Instant next = Instant.parse("2026-09-28T00:00:00Z"); | ||
| assertEquals("6d 15h", Government.formatTimeUntil(now, next)); | ||
| } | ||
|
|
||
| @Test | ||
| void formatTimeUntil_pastTargetIsZero() { | ||
| Instant now = Instant.parse("2026-09-28T08:15:00Z"); | ||
| Instant next = Instant.parse("2026-09-28T00:00:00Z"); | ||
| assertEquals("0d 0h", Government.formatTimeUntil(now, next)); | ||
| assertEquals("0d 0h", Government.formatTimeUntil(now, null)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package net.tfminecraft.simplefactions.government; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class VotingBlockTest { | ||
|
|
||
| @Test | ||
| void furnitureId_readsItemsAdderFurniturePath() { | ||
| assertEquals("tfmc:voting_booth", VotingBlock.furnitureId("iaf(tfmc:voting_booth)")); | ||
| assertEquals("tfmc:voting_booth", VotingBlock.furnitureId("iaf.tfmc:voting_booth")); | ||
| assertNull(VotingBlock.furnitureId("v(chiseled_bookshelf)")); | ||
| assertNull(VotingBlock.furnitureId(null)); | ||
| } | ||
|
|
||
| @Test | ||
| void matches_comparesNamespacedId() { | ||
| assertTrue(VotingBlock.matches("iaf(tfmc:voting_booth)", "tfmc:voting_booth")); | ||
| assertTrue(VotingBlock.matches("iaf(tfmc:voting_booth)", "TFMC:Voting_Booth")); | ||
| assertFalse(VotingBlock.matches("iaf(tfmc:voting_booth)", "tfmc:bank")); | ||
| assertFalse(VotingBlock.matches("v(chiseled_bookshelf)", "tfmc:voting_booth")); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.