-
Notifications
You must be signed in to change notification settings - Fork 6
Add initial rail generator implementation #86
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2355b5a
refactor(generator): add reusable generation execution support
Jasupa fccfc54
feat(rail): add rail generator
Jasupa 3e3c2fb
feat(generator): expose rail generator
Jasupa ca41e3c
fix(generator): address rail review feedback
Jasupa 49314ed
fix(generator): derive generator commands from type enum
Jasupa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
22 changes: 22 additions & 0 deletions
22
.../java/net/buildtheearth/buildteamtools/modules/generator/components/rail/PositionKey.java
|
Jasupa marked this conversation as resolved.
|
This file contains hidden or 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,22 @@ | ||
| package net.buildtheearth.buildteamtools.modules.generator.components.rail; | ||
|
|
||
| import org.bukkit.util.Vector; | ||
|
|
||
| record PositionKey(int x, int y, int z) { | ||
|
|
||
| static PositionKey from(Vector vector) { | ||
| return new PositionKey( | ||
| vector.getBlockX(), | ||
| vector.getBlockY(), | ||
| vector.getBlockZ() | ||
| ); | ||
| } | ||
|
|
||
| static PositionKey of(int x, int y, int z) { | ||
| return new PositionKey(x, y, z); | ||
| } | ||
|
|
||
| Vector toVector() { | ||
| return new Vector(x, y, z); | ||
| } | ||
| } |
59 changes: 52 additions & 7 deletions
59
src/main/java/net/buildtheearth/buildteamtools/modules/generator/components/rail/Rail.java
This file contains hidden or 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 |
|---|---|---|
| @@ -1,27 +1,72 @@ | ||
| package net.buildtheearth.buildteamtools.modules.generator.components.rail; | ||
|
|
||
| import com.alpsbte.alpslib.utils.ChatHelper; | ||
| import com.alpsbte.alpslib.utils.GeneratorUtils; | ||
| import com.sk89q.worldedit.regions.ConvexPolyhedralRegion; | ||
| import com.sk89q.worldedit.regions.CuboidRegion; | ||
| import com.sk89q.worldedit.regions.Polygonal2DRegion; | ||
| import com.sk89q.worldedit.regions.Region; | ||
| import net.buildtheearth.buildteamtools.modules.generator.GeneratorModule; | ||
| import net.buildtheearth.buildteamtools.modules.generator.model.GeneratorComponent; | ||
| import net.buildtheearth.buildteamtools.modules.generator.model.GeneratorType; | ||
| import org.bukkit.Sound; | ||
| import org.bukkit.entity.Player; | ||
|
|
||
| import java.util.Set; | ||
| import java.util.UUID; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| public class Rail extends GeneratorComponent { | ||
|
|
||
| private final Set<UUID> preparingPlayers = ConcurrentHashMap.newKeySet(); | ||
|
|
||
| public Rail() { | ||
| super(GeneratorType.RAILWAY); | ||
| super(GeneratorType.RAIL); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean checkForPlayer(Player p) { | ||
| return !GeneratorUtils.checkForNoWorldEditSelection(p); | ||
| public boolean checkForPlayer(Player player) { | ||
| if (GeneratorUtils.checkForNoWorldEditSelection(player)) | ||
| return false; | ||
|
|
||
| Region region = GeneratorUtils.getWorldEditSelection(player); | ||
|
|
||
| if (isSupportedRailSelection(region)) | ||
| return true; | ||
|
|
||
| player.sendMessage(ChatHelper.PREFIX_COMPONENT.append(ChatHelper.getErrorComponent( | ||
| "Rail Generator supports cuboid, polygonal and convex WorldEdit selections." | ||
|
Jasupa marked this conversation as resolved.
|
||
| ))); | ||
| player.closeInventory(); | ||
| player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1.0F, 1.0F); | ||
| return false; | ||
| } | ||
|
|
||
| private boolean isSupportedRailSelection(Region region) { | ||
| return region instanceof CuboidRegion | ||
| || region instanceof Polygonal2DRegion | ||
| || region instanceof ConvexPolyhedralRegion; | ||
| } | ||
|
|
||
| @Override | ||
| public void generate(Player p) { | ||
| if (!GeneratorModule.getInstance().getRail().checkForPlayer(p)) | ||
| public void generate(Player player) { | ||
| if (GeneratorModule.getInstance().isGenerating(player) || !preparingPlayers.add(player.getUniqueId())) { | ||
| sendAlreadyGeneratingMessage(player); | ||
| return; | ||
| } | ||
|
|
||
| if (!checkForPlayer(player)) { | ||
| preparingPlayers.remove(player.getUniqueId()); | ||
| return; | ||
| } | ||
|
|
||
| new RailScripts(player, this, () -> preparingPlayers.remove(player.getUniqueId())); | ||
| } | ||
|
|
||
| new RailScripts(p, this); | ||
| private void sendAlreadyGeneratingMessage(Player player) { | ||
| player.sendMessage(ChatHelper.PREFIX_COMPONENT.append(ChatHelper.getErrorComponent( | ||
| "Rail Generator is already running. Please wait until the current generation is finished." | ||
| ))); | ||
| player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1.0F, 1.0F); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.