Repository navigation
JoyBank - банковская система #13
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
Open
gafrus06
wants to merge
7
commits into
JouTak:master
Choose a base branch
from
gafrus06:bank-terminal
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
02bc08d
feat: initialize JoyBank plugin and add first command
gafrus06 2b1c8a1
feat: add Joy coins and admin give command
gafrus06 1f11121
feat: add persistent player balances
gafrus06 6974c45
feat: add persistent transaction history
gafrus06 ca41b2e
feat: implement cash deposit and withdrawal logic
gafrus06 3f521f6
feat: implement persistent ATM banking and custom Joy coins
gafrus06 89626c7
fix: address pr review commets
gafrus06 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| # Plugin properties | ||
| repo=https://github.com/JouTak/TemplatePlugin-Java | ||
| repo=https://github.com/gafrus06/TemplatePlugin-Java | ||
| group=ru.joutak | ||
| name=Template-Java | ||
| version=1.0.0 | ||
| name=JoyBank | ||
| version=0.1.0 | ||
|
|
||
| # Gradle properties | ||
| org.gradle.parallel=true |
20 changes: 20 additions & 0 deletions
20
resourcepack/JoyBankPack/assets/minecraft/items/gold_nugget.json
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,20 @@ | ||
| { | ||
| "model": { | ||
| "type": "minecraft:range_dispatch", | ||
| "property": "minecraft:custom_model_data", | ||
| "index": 0, | ||
| "entries": [ | ||
| { | ||
| "threshold": 1001.0, | ||
| "model": { | ||
| "type": "minecraft:model", | ||
| "model": "minecraft:item/joy_coin" | ||
| } | ||
| } | ||
| ], | ||
| "fallback": { | ||
| "type": "minecraft:model", | ||
| "model": "minecraft:item/gold_nugget" | ||
| } | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
resourcepack/JoyBankPack/assets/minecraft/models/item/joy_coin.json
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,6 @@ | ||
| { | ||
| "parent": "minecraft:item/generated", | ||
| "textures": { | ||
| "layer0": "minecraft:item/joy_coin" | ||
| } | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,6 @@ | ||
| { | ||
| "pack": { | ||
| "pack_format": 55, | ||
| "description": "JoyBank Resource Pack" | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
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,90 @@ | ||
| package ru.joutak.template; | ||
|
|
||
| import lombok.Getter; | ||
| import org.bukkit.plugin.java.JavaPlugin; | ||
| import ru.joutak.template.atm.AtmService; | ||
| import ru.joutak.template.atm.listener.AtmMenuListener; | ||
| import ru.joutak.template.coin.CoinService; | ||
| import ru.joutak.template.command.JoyCommand; | ||
| import ru.joutak.template.bank.BankService; | ||
| import ru.joutak.template.storage.AccountRepository; | ||
| import ru.joutak.template.storage.YamlAccountRepository; | ||
| import ru.joutak.template.storage.AtmRepository; | ||
| import ru.joutak.template.storage.YamlAtmRepository; | ||
| import ru.joutak.template.atm.listener.AtmCreationListener; | ||
| import ru.joutak.template.gui.AtmMenu; | ||
| import ru.joutak.template.atm.listener.AtmProtectionListener; | ||
|
|
||
| import ru.joutak.template.atm.listener.AtmInteractionListener; | ||
|
|
||
| public final class JoyBankPlugin extends JavaPlugin { | ||
| @Getter | ||
| private static JoyBankPlugin instance; | ||
| private CoinService coinService; | ||
| private BankService bankService; | ||
| private AtmService atmService; | ||
| private AtmMenu atmMenu; | ||
|
|
||
| @Override | ||
| public void onEnable() { | ||
| instance = this; | ||
| coinService = new CoinService(this); | ||
| AccountRepository accountRepository = | ||
| new YamlAccountRepository(this); | ||
| bankService = new BankService(accountRepository); | ||
|
|
||
| AtmRepository atmRepository = | ||
| new YamlAtmRepository(this); | ||
|
|
||
| atmService = | ||
| new AtmService(atmRepository); | ||
|
|
||
| atmMenu = new AtmMenu(bankService); | ||
|
|
||
| getCommand("joy") | ||
| .setExecutor( | ||
| new JoyCommand(coinService, bankService) | ||
| ); | ||
| getLogger().info( | ||
| String.format("Плагин %s версии %s включен!", getPluginMeta().getName(), getPluginMeta().getVersion()) | ||
| ); | ||
|
|
||
| getServer() | ||
| .getPluginManager() | ||
| .registerEvents( | ||
| new AtmCreationListener(atmService), | ||
| this | ||
| ); | ||
| getServer() | ||
| .getPluginManager() | ||
| .registerEvents( | ||
| new AtmInteractionListener( | ||
| atmService, | ||
| atmMenu | ||
| ), | ||
| this | ||
| ); | ||
| getServer() | ||
| .getPluginManager() | ||
| .registerEvents( | ||
| new AtmMenuListener( | ||
| coinService, | ||
| bankService, | ||
| atmService, | ||
| atmMenu | ||
| ), | ||
| this | ||
| ); | ||
| getServer() | ||
| .getPluginManager() | ||
| .registerEvents( | ||
| new AtmProtectionListener(atmService), | ||
| this | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public void onDisable() { | ||
|
|
||
| } | ||
| } |
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,15 @@ | ||
| package ru.joutak.template.atm; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| public record Atm( | ||
| UUID id, | ||
| UUID worldId, | ||
| int barrelX, | ||
| int barrelY, | ||
| int barrelZ, | ||
| int signX, | ||
| int signY, | ||
| int signZ | ||
| ) { | ||
| } |
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,102 @@ | ||
| package ru.joutak.template.atm; | ||
|
|
||
| import org.bukkit.Location; | ||
| import org.bukkit.World; | ||
| import ru.joutak.template.storage.AtmRepository; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.UUID; | ||
|
|
||
| public class AtmService { | ||
|
|
||
| private final AtmRepository atmRepository; | ||
| private final Map<UUID, Atm> atms = new HashMap<>(); | ||
|
|
||
| public AtmService(AtmRepository atmRepository) { | ||
| this.atmRepository = atmRepository; | ||
|
|
||
| for (Atm atm : atmRepository.findAll()) { | ||
| atms.put(atm.id(), atm); | ||
| } | ||
| } | ||
|
|
||
| public Atm register( | ||
| Location barrelLocation, | ||
| Location signLocation | ||
| ) { | ||
| Atm atm = new Atm( | ||
| UUID.randomUUID(), | ||
| barrelLocation.getWorld().getUID(), | ||
|
|
||
| barrelLocation.getBlockX(), | ||
| barrelLocation.getBlockY(), | ||
| barrelLocation.getBlockZ(), | ||
|
|
||
| signLocation.getBlockX(), | ||
| signLocation.getBlockY(), | ||
| signLocation.getBlockZ() | ||
| ); | ||
| atmRepository.save(atm); | ||
| atms.put(atm.id(), atm); | ||
|
|
||
| return atm; | ||
| } | ||
|
|
||
| public Optional<Atm> findByBlock(Location location) { | ||
| World world = location.getWorld(); | ||
|
|
||
| if (world == null) { | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| for (Atm atm : atms.values()) { | ||
|
|
||
| if (!atm.worldId().equals(world.getUID())) { | ||
| continue; | ||
| } | ||
|
|
||
| int x = location.getBlockX(); | ||
| int y = location.getBlockY(); | ||
| int z = location.getBlockZ(); | ||
|
|
||
| boolean isBarrel = | ||
| x == atm.barrelX() | ||
| && y == atm.barrelY() | ||
| && z == atm.barrelZ(); | ||
|
|
||
| boolean isSign = | ||
| x == atm.signX() | ||
| && y == atm.signY() | ||
| && z == atm.signZ(); | ||
|
|
||
| boolean isBase = | ||
| x == atm.barrelX() | ||
| && y == atm.barrelY() - 1 | ||
| && z == atm.barrelZ(); | ||
|
|
||
| if (isBarrel || isSign || isBase) { | ||
| return Optional.of(atm); | ||
| } | ||
| } | ||
|
|
||
| return Optional.empty(); | ||
| } | ||
|
|
||
| public Collection<Atm> getAll() { | ||
| return atms.values(); | ||
| } | ||
|
|
||
| public void unregister(UUID atmId) { | ||
|
|
||
| atmRepository.delete(atmId); | ||
| atms.remove(atmId); | ||
| } | ||
|
Member
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. тот же момент, что выше |
||
| public Optional<Atm> findById(UUID atmId) { | ||
| return Optional.ofNullable( | ||
| atms.get(atmId) | ||
| ); | ||
| } | ||
| } | ||
92 changes: 92 additions & 0 deletions
92
src/main/java/ru/joutak/template/atm/listener/AtmCreationListener.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 |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| package ru.joutak.template.atm.listener; | ||
|
|
||
| import org.bukkit.Material; | ||
| import org.bukkit.block.Block; | ||
| import org.bukkit.block.data.BlockData; | ||
| import org.bukkit.block.data.type.WallSign; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.Listener; | ||
| import org.bukkit.event.block.SignChangeEvent; | ||
| import ru.joutak.template.atm.AtmService; | ||
|
|
||
| public class AtmCreationListener implements Listener { | ||
|
|
||
| private final AtmService atmService; | ||
|
|
||
| public AtmCreationListener(AtmService atmService) { | ||
| this.atmService = atmService; | ||
| } | ||
|
|
||
| @EventHandler | ||
| public void onSignChange(SignChangeEvent event) { | ||
|
|
||
| String firstLine = event.getLine(0); | ||
|
|
||
| if (firstLine == null | ||
| || !firstLine.equalsIgnoreCase("[joybank]")) { | ||
| return; | ||
| } | ||
|
|
||
| if (!event.getPlayer() | ||
| .hasPermission("joybank.atm.create")) { | ||
|
|
||
| event.getPlayer().sendMessage( | ||
| "У вас нет прав на создание банкомата." | ||
| ); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| Block signBlock = event.getBlock(); | ||
|
|
||
| BlockData blockData = signBlock.getBlockData(); | ||
|
|
||
| if (!(blockData instanceof WallSign wallSign)) { | ||
| event.getPlayer().sendMessage( | ||
| "Табличка должна быть прикреплена к боку бочки." | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| Block barrel = signBlock.getRelative( | ||
| wallSign.getFacing().getOppositeFace() | ||
| ); | ||
|
|
||
| if (barrel.getType() != Material.BARREL) { | ||
| event.getPlayer().sendMessage( | ||
| "Табличка должна быть прикреплена к бочке." | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| Block base = barrel.getRelative(0, -1, 0); | ||
|
|
||
| if (base.getType() != Material.IRON_BLOCK) { | ||
| event.getPlayer().sendMessage( | ||
| "Под бочкой должен находиться железный блок." | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| if (atmService.findByBlock(barrel.getLocation()).isPresent()) { | ||
| event.getPlayer().sendMessage( | ||
| "Этот банкомат уже зарегистрирован." | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| atmService.register( | ||
| barrel.getLocation(), | ||
| signBlock.getLocation() | ||
| ); | ||
|
|
||
| event.setLine(0, "JOY BANK"); | ||
| event.setLine(1, "Банкомат"); | ||
| event.setLine(2, ""); | ||
| event.setLine(3, ""); | ||
|
|
||
| event.getPlayer().sendMessage( | ||
| "Банкомат успешно зарегистрирован." | ||
| ); | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Здесь стоит поменять порядок: если по какой-либо причине не удастся сохранить банкомат в репозиторий, то в памяти он останется до перезагрузки