├── .github
├── FUNDING.yml
└── ISSUE_TEMPLATE
│ ├── bug-report.md
│ └── feature-request.md
├── .gitignore
├── .vscode
└── settings.json
├── LICENSE
├── README.md
├── pom.xml
└── src
└── main
├── java
└── com
│ └── github
│ └── yuttyann
│ └── scriptblockplus
│ ├── BlockCoords.java
│ ├── Scheduler.java
│ ├── ScriptBlock.java
│ ├── ScriptBlockAPI.java
│ ├── command
│ ├── BaseCommand.java
│ ├── CommandUsage.java
│ ├── ScriptBlockPlusCommand.java
│ ├── SubCommand.java
│ └── subcommand
│ │ ├── BackupCommand.java
│ │ ├── DatamigrCommand.java
│ │ ├── ReloadCommand.java
│ │ ├── ScriptCommand.java
│ │ ├── SelectorCommand.java
│ │ └── ToolCommand.java
│ ├── enums
│ ├── ActionKey.java
│ ├── CommandLog.java
│ ├── IndexType.java
│ ├── MatchType.java
│ ├── Permission.java
│ ├── TeamColor.java
│ └── splittype
│ │ ├── Argument.java
│ │ ├── Filter.java
│ │ └── Repeat.java
│ ├── event
│ ├── BlockClickEvent.java
│ ├── DelayEndEvent.java
│ ├── DelayRunEvent.java
│ ├── FileReloadEvent.java
│ ├── RunItemEvent.java
│ ├── ScriptBlockEvent.java
│ ├── ScriptReadEndEvent.java
│ ├── ScriptReadStartEvent.java
│ └── TriggerEvent.java
│ ├── file
│ ├── Backup.java
│ ├── Lang.java
│ ├── SBFile.java
│ ├── SBFiles.java
│ ├── SBLoader.java
│ ├── config
│ │ ├── ConfigAdapter.java
│ │ ├── ConfigKey.java
│ │ ├── ConfigKeys.java
│ │ ├── ReplaceKey.java
│ │ ├── SBConfig.java
│ │ └── YamlConfig.java
│ └── json
│ │ ├── BaseElement.java
│ │ ├── BaseJson.java
│ │ ├── CacheJson.java
│ │ ├── GsonHolder.java
│ │ ├── SubElementMap.java
│ │ ├── annotation
│ │ ├── Alternate.java
│ │ ├── Exclude.java
│ │ └── JsonTag.java
│ │ ├── basic
│ │ ├── OneJson.java
│ │ ├── SingleJson.java
│ │ ├── ThreeJson.java
│ │ └── TwoJson.java
│ │ ├── builder
│ │ ├── BlockCoordsAdapter.java
│ │ ├── CollectionType.java
│ │ ├── FieldExclusion.java
│ │ ├── NumberAdapter.java
│ │ ├── ScriptKeyAdapter.java
│ │ └── ValueHolderAdapter.java
│ │ ├── derived
│ │ ├── BlockScriptJson.java
│ │ ├── PlayerCountJson.java
│ │ ├── PlayerTimerJson.java
│ │ └── element
│ │ │ ├── BlockScript.java
│ │ │ ├── PlayerCount.java
│ │ │ ├── PlayerTimer.java
│ │ │ └── ValueHolder.java
│ │ └── legacy
│ │ ├── ConvertList.java
│ │ ├── FormatVersion.java
│ │ ├── LegacyEnumFactory.java
│ │ ├── LegacyFormatJson.java
│ │ └── LegacyReflectiveFactory.java
│ ├── hook
│ ├── HookPlugin.java
│ ├── nms
│ │ ├── AnvilGUI.java
│ │ ├── GlowEntity.java
│ │ └── GlowEntityPacket.java
│ └── plugin
│ │ ├── DiscordSRV.java
│ │ ├── Placeholder.java
│ │ ├── VaultEconomy.java
│ │ └── VaultPermission.java
│ ├── item
│ ├── ChangeSlot.java
│ ├── ItemAction.java
│ ├── RunItem.java
│ ├── action
│ │ ├── BlockSelector.java
│ │ ├── ScriptEditor.java
│ │ ├── ScriptManager.java
│ │ ├── ScriptViewer.java
│ │ └── TickRunnable.java
│ └── gui
│ │ ├── CustomGUI.java
│ │ ├── GUIItem.java
│ │ ├── UserWindow.java
│ │ └── custom
│ │ ├── SearchGUI.java
│ │ ├── SettingGUI.java
│ │ └── ToolBoxGUI.java
│ ├── listener
│ ├── BlockListener.java
│ ├── InteractListener.java
│ ├── PlayerListener.java
│ ├── TriggerListener.java
│ └── trigger
│ │ ├── BreakTrigger.java
│ │ ├── HitTrigger.java
│ │ ├── InteractTrigger.java
│ │ └── WalkTrigger.java
│ ├── manager
│ ├── APIManager.java
│ ├── EndProcessManager.java
│ ├── OptionManager.java
│ ├── OptionMap.java
│ └── SBInstance.java
│ ├── player
│ ├── BaseSBPlayer.java
│ ├── PlayerMap.java
│ ├── SBPlayer.java
│ └── SBPlayerMap.java
│ ├── region
│ ├── CuboidRegion.java
│ ├── CuboidRegionIterator.java
│ ├── CuboidRegionPaste.java
│ ├── CuboidRegionRemove.java
│ ├── PlayerRegion.java
│ └── Region.java
│ ├── script
│ ├── SBClipboard.java
│ ├── SBOperation.java
│ ├── ScriptEdit.java
│ ├── ScriptKey.java
│ ├── ScriptMap.java
│ ├── ScriptRead.java
│ ├── endprocess
│ │ ├── EndInventory.java
│ │ ├── EndMoneyCost.java
│ │ ├── EndPlayerCount.java
│ │ └── EndProcess.java
│ └── option
│ │ ├── BaseOption.java
│ │ ├── Option.java
│ │ ├── OptionIndex.java
│ │ ├── OptionTag.java
│ │ ├── chat
│ │ ├── ActionBar.java
│ │ ├── BypassOP.java
│ │ ├── Command.java
│ │ ├── Console.java
│ │ ├── Say.java
│ │ ├── Server.java
│ │ ├── Title.java
│ │ └── ToPlayer.java
│ │ ├── discord
│ │ ├── DiscordChannel.java
│ │ ├── DiscordRole.java
│ │ ├── DiscordRoleAdd.java
│ │ └── DiscordRoleRemove.java
│ │ ├── other
│ │ ├── Amount.java
│ │ ├── BlockType.java
│ │ ├── EventInvalid.java
│ │ ├── Execute.java
│ │ ├── IfAction.java
│ │ ├── ItemCost.java
│ │ ├── ItemHand.java
│ │ ├── PlaySound.java
│ │ └── PlayerAction.java
│ │ ├── time
│ │ ├── Cooldown.java
│ │ ├── Delay.java
│ │ ├── OldCooldown.java
│ │ └── TimerOption.java
│ │ └── vault
│ │ ├── BypassGroup.java
│ │ ├── BypassPerm.java
│ │ ├── Group.java
│ │ ├── GroupAdd.java
│ │ ├── GroupRemove.java
│ │ ├── MoneyCost.java
│ │ ├── Perm.java
│ │ ├── PermAdd.java
│ │ └── PermRemove.java
│ ├── selector
│ ├── CommandSelector.java
│ ├── EntitySelector.java
│ └── split
│ │ ├── Split.java
│ │ ├── SplitType.java
│ │ └── SplitValue.java
│ └── utils
│ ├── ArrayUtils.java
│ ├── FileUtils.java
│ ├── ItemUtils.java
│ ├── NMSHelper.java
│ ├── StreamUtils.java
│ ├── StringUtils.java
│ ├── Utils.java
│ ├── collection
│ ├── ObjectMap.java
│ └── ReuseIterator.java
│ ├── kyori
│ ├── KyoriGson.java
│ └── KyoriLegacy.java
│ ├── raytrace
│ ├── RayResult.java
│ ├── RayTrace.java
│ └── SBBoundingBox.java
│ ├── reflect
│ ├── ClassType.java
│ ├── Reflection.java
│ ├── SimpleReflection.java
│ └── matcher
│ │ ├── AbstractReflectionMatcher.java
│ │ ├── ConstructorMatcher.java
│ │ ├── DeepConstructorMatcher.java
│ │ ├── DeepFieldMatcher.java
│ │ ├── DeepMethodMatcher.java
│ │ ├── FieldMatcher.java
│ │ ├── MethodMatcher.java
│ │ └── ReflectionMatcher.java
│ ├── server
│ ├── CraftBukkit.java
│ ├── NetMinecraft.java
│ └── minecraft
│ │ ├── Minecraft.java
│ │ ├── NativeAccessor.java
│ │ ├── PaperRemappedAccessor.java
│ │ ├── SpigotAccessor_v1_14.java
│ │ ├── SpigotAccessor_v1_17.java
│ │ ├── SpigotAccessor_v1_20_5.java
│ │ └── SpigotAccessor_v1_9.java
│ ├── unmodifiable
│ ├── UnmodifiableBlockCoords.java
│ ├── UnmodifiableItemStack.java
│ └── UnmodifiableLocation.java
│ └── version
│ ├── McVersion.java
│ └── Version.java
└── resources
├── config
├── en.yml
├── ja.yml
└── zh.yml
├── message
├── en.yml
├── ja.yml
└── zh.yml
└── plugin.yml
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: yuttyann
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug-report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report/不具合報告
3 | about: Create a report to help us improve/不具合の報告等
4 | title: ''
5 | labels: 不具合/Bug
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug/不具合の概要**
11 | A clear and concise description of what the bug is.
12 |
13 | **Server/サーバー**
14 | Type: (For example Spigot etc...)
15 | Version: (For example 1.16.4 etc...)
16 | Plugins: (For example ScriptBlockPlus-2.0.7 / ProtocolLib-4.5.1 etc...)
17 |
18 | **To Reproduce/再現手順**
19 | Steps to reproduce the behavior: (Texts..)
20 |
21 | **Expected behavior/期待される動作**
22 | A clear and concise description of what you expected to happen.
23 |
24 | **Screenshots/スクリーンショット**
25 | If applicable, add screenshots to help explain your problem.
26 |
27 | **Additional context/備考**
28 | Add any other context about the problem here.
29 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature-request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request/機能追加・要望
3 | about: Suggest an idea for this project/機能追加・要望等
4 | title: ''
5 | labels: 機能追加・要望/Enhancement
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe./問題の説明**
11 | A clear and concise description of what the problem is.
12 | Ex. I'm always frustrated when [...]
13 |
14 | **Describe the solution you'd like/何をしたいのか**
15 | A clear and concise description of what you want to happen.
16 |
17 | **Describe alternatives you've considered/代替案**
18 | A clear and concise description of any alternative solutions or features you've considered.
19 |
20 | **Additional context/備考**
21 | Add any other context or screenshots about the feature request here.
22 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Java
2 | *.class
3 | *.jar
4 | *.war
5 | *.ear
6 |
7 | # JavaDoc
8 | javadoc-latest
9 |
10 | # Visual Studio Code
11 | .vscode/*
12 |
13 | # Eclipse
14 | .project
15 | .classpath
16 | .settings
17 |
18 | # Idea
19 | .idea
20 | *.iml
21 | *.iws
22 | *.ipr
23 |
24 | # OS
25 | Thumbs.db
26 | .DS_Store
27 |
28 | # Gradle
29 | .gradle
30 | !gradle-wrapper.jar
31 |
32 | # Maven
33 | target
34 |
35 | # Build
36 | out
37 | build
38 | bin
39 |
40 | # Text
41 | plugin.txt
42 | header.txt
43 |
44 | # Markdown
45 | WIKI_EN.md
46 | WIKI_JP.md
47 |
48 | # Other
49 | *.log
50 | *.swp
51 | *.bak
52 |
53 | dependency-reduced-pom.xml
54 |
55 | .codegpt
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "java.configuration.updateBuildConfiguration": "automatic",
3 | "java.compile.nullAnalysis.mode": "disabled"
4 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/command/CommandUsage.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.command;
17 |
18 | import com.github.yuttyann.scriptblockplus.enums.Permission;
19 | import com.github.yuttyann.scriptblockplus.utils.StreamUtils;
20 | import com.github.yuttyann.scriptblockplus.utils.StringUtils;
21 | import org.bukkit.command.CommandSender;
22 | import org.jetbrains.annotations.NotNull;
23 | import org.jetbrains.annotations.Nullable;
24 |
25 | import java.util.ArrayList;
26 | import java.util.List;
27 | import java.util.Optional;
28 |
29 | /**
30 | * ScriptBlockPlus CommandUsage クラス
31 | * @author yuttyann44581
32 | */
33 | public class CommandUsage {
34 |
35 | private final List NODES = new ArrayList<>();
36 |
37 | private String text;
38 |
39 | public CommandUsage(@Nullable String text) {
40 | this(text, (String) null);
41 | }
42 |
43 | public CommandUsage(@Nullable String text, @Nullable String... nodes) {
44 | setText(text);
45 | addNode(nodes);
46 | }
47 |
48 | public CommandUsage(@Nullable String text, @Nullable Permission... permissions) {
49 | setText(text);
50 | StreamUtils.forEach(permissions, p -> addNode(p.getNode()));
51 | }
52 |
53 | @NotNull
54 | public String getText() {
55 | return text;
56 | }
57 |
58 | @NotNull
59 | public List getNodes() {
60 | return NODES;
61 | }
62 |
63 | public final boolean hasText() {
64 | return StringUtils.isNotEmpty(text);
65 | }
66 |
67 | public boolean hasPermission(@NotNull CommandSender sender) {
68 | if (NODES == null || NODES.size() == 0) {
69 | return true;
70 | }
71 | return NODES.stream().anyMatch(s -> Permission.has(sender, s));
72 | }
73 |
74 | @NotNull
75 | public CommandUsage setText(@Nullable String text) {
76 | this.text = text;
77 | return this;
78 | }
79 |
80 | @NotNull
81 | public CommandUsage addNode(@Nullable String... nodes) {
82 | var value = Optional.ofNullable(nodes);
83 | if (value.isPresent() && value.get().length > 0) {
84 | StreamUtils.forEach(value.get(), NODES::add);
85 | }
86 | return this;
87 | }
88 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/command/subcommand/BackupCommand.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.command.subcommand;
17 |
18 | import java.io.IOException;
19 | import java.nio.file.Files;
20 | import java.util.Arrays;
21 | import java.util.List;
22 |
23 | import org.bukkit.command.Command;
24 | import org.bukkit.command.CommandSender;
25 | import org.jetbrains.annotations.NotNull;
26 |
27 | import com.github.yuttyann.scriptblockplus.ScriptBlock;
28 | import com.github.yuttyann.scriptblockplus.command.BaseCommand;
29 | import com.github.yuttyann.scriptblockplus.command.CommandUsage;
30 | import com.github.yuttyann.scriptblockplus.command.SubCommand;
31 | import com.github.yuttyann.scriptblockplus.enums.Permission;
32 | import com.github.yuttyann.scriptblockplus.file.Backup;
33 | import com.github.yuttyann.scriptblockplus.file.SBFile;
34 | import com.github.yuttyann.scriptblockplus.file.config.SBConfig;
35 | import com.github.yuttyann.scriptblockplus.utils.FileUtils;
36 |
37 | public class BackupCommand extends SubCommand {
38 |
39 | private final Permission PERMISSION = Permission.COMMAND_BACKUP;
40 |
41 | public BackupCommand(@NotNull BaseCommand baseCommand) {
42 | super(baseCommand);
43 | }
44 |
45 | @Override
46 | @NotNull
47 | protected List getNames() {
48 | return Arrays.asList("backup");
49 | }
50 |
51 | @Override
52 | @NotNull
53 | protected List getUsages() {
54 | return Arrays.asList(new CommandUsage(SBConfig.BACKUP_COMMAND.getValue(), PERMISSION));
55 | }
56 |
57 | @Override
58 | protected boolean runCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label) {
59 | if (!hasPermission(sender, PERMISSION, false)) {
60 | return false;
61 | }
62 | var dataFolder = ScriptBlock.getInstance().getDataFolder();
63 | if (!dataFolder.exists() || FileUtils.isEmpty(dataFolder)) {
64 | SBConfig.ERROR_PLUGIN_BACKUP.send(sender);
65 | return true;
66 | }
67 | try {
68 | var backup = new Backup(new SBFile(dataFolder, "backup"), path -> path.contains(SBFile.setSeparator("/backup/")));
69 | Files.walkFileTree(backup.getFrom(), backup);
70 | SBConfig.PLUGIN_BACKUP.send(sender);
71 | } catch (IOException ex) {
72 | ex.printStackTrace();
73 | }
74 | return true;
75 | }
76 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/command/subcommand/ReloadCommand.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.command.subcommand;
17 |
18 | import java.util.Arrays;
19 | import java.util.List;
20 |
21 | import com.github.yuttyann.scriptblockplus.command.BaseCommand;
22 | import com.github.yuttyann.scriptblockplus.command.CommandUsage;
23 | import com.github.yuttyann.scriptblockplus.command.SubCommand;
24 | import com.github.yuttyann.scriptblockplus.enums.Permission;
25 | import com.github.yuttyann.scriptblockplus.file.SBFiles;
26 | import com.github.yuttyann.scriptblockplus.file.config.SBConfig;
27 | import com.github.yuttyann.scriptblockplus.file.json.BaseJson;
28 | import com.github.yuttyann.scriptblockplus.file.json.CacheJson;
29 | import com.github.yuttyann.scriptblockplus.item.gui.CustomGUI;
30 | import com.github.yuttyann.scriptblockplus.item.gui.UserWindow;
31 |
32 | import org.bukkit.command.Command;
33 | import org.bukkit.command.CommandSender;
34 | import org.jetbrains.annotations.NotNull;
35 |
36 | /**
37 | * ScriptBlockPlus ReloadCommand コマンドクラス
38 | * @author yuttyann44581
39 | */
40 | public class ReloadCommand extends SubCommand {
41 |
42 | private final Permission PERMISSION = Permission.COMMAND_RELOAD;
43 |
44 | public ReloadCommand(@NotNull BaseCommand baseCommand) {
45 | super(baseCommand);
46 | }
47 |
48 | @Override
49 | @NotNull
50 | protected List getNames() {
51 | return Arrays.asList("reload");
52 | }
53 |
54 | @Override
55 | @NotNull
56 | protected List getUsages() {
57 | return Arrays.asList(new CommandUsage(SBConfig.RELOAD_COMMAND.getValue(), PERMISSION));
58 | }
59 |
60 | @Override
61 | protected boolean runCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label) {
62 | if (!hasPermission(sender, PERMISSION, false)) {
63 | return false;
64 | }
65 | SBFiles.reload();
66 | BaseJson.clear();
67 | CacheJson.loading();
68 | UserWindow.closeAll();
69 | CustomGUI.reload();
70 | SBConfig.ALL_FILE_RELOAD.send(sender);
71 | return true;
72 | }
73 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/command/subcommand/ToolCommand.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.command.subcommand;
17 |
18 | import java.util.Arrays;
19 | import java.util.List;
20 |
21 | import com.github.yuttyann.scriptblockplus.command.BaseCommand;
22 | import com.github.yuttyann.scriptblockplus.command.CommandUsage;
23 | import com.github.yuttyann.scriptblockplus.command.SubCommand;
24 | import com.github.yuttyann.scriptblockplus.enums.Permission;
25 | import com.github.yuttyann.scriptblockplus.file.config.SBConfig;
26 | import com.github.yuttyann.scriptblockplus.item.gui.CustomGUI;
27 | import com.github.yuttyann.scriptblockplus.item.gui.UserWindow;
28 | import com.github.yuttyann.scriptblockplus.item.gui.custom.ToolBoxGUI;
29 |
30 | import org.bukkit.command.Command;
31 | import org.bukkit.command.CommandSender;
32 | import org.bukkit.entity.Player;
33 | import org.jetbrains.annotations.NotNull;
34 |
35 | /**
36 | * ScriptBlockPlus ToolCommand コマンドクラス
37 | * @author yuttyann44581
38 | */
39 | public class ToolCommand extends SubCommand {
40 |
41 | private final Permission PERMISSION = Permission.COMMAND_TOOL;
42 |
43 | public ToolCommand(@NotNull BaseCommand baseCommand) {
44 | super(baseCommand);
45 | }
46 |
47 | @Override
48 | @NotNull
49 | protected List getNames() {
50 | return Arrays.asList("tool");
51 | }
52 |
53 | @Override
54 | @NotNull
55 | protected List getUsages() {
56 | return Arrays.asList(new CommandUsage(SBConfig.TOOL_COMMAND.getValue(), PERMISSION));
57 | }
58 |
59 | @Override
60 | protected boolean runCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label) {
61 | if (!hasPermission(sender, PERMISSION)) {
62 | return false;
63 | }
64 | CustomGUI.getWindow(ToolBoxGUI.class, (Player) sender).ifPresent(UserWindow::open);
65 | return true;
66 | }
67 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/enums/ActionKey.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.enums;
17 |
18 | import org.jetbrains.annotations.NotNull;
19 |
20 | /**
21 | * ScriptBlockPlus ActionKey 列挙型
22 | * @author yuttyann44581
23 | */
24 | public enum ActionKey {
25 |
26 | /**
27 | * スクリプトの作成
28 | */
29 | CREATE("create"),
30 |
31 | /**d
32 | * スクリプトの追加
33 | */
34 | ADD("add"),
35 |
36 | /**
37 | * スクリプトの削除
38 | */
39 | REMOVE("remove"),
40 |
41 | /**
42 | * スクリプトの表示
43 | */
44 | VIEW("view"),
45 |
46 | /**
47 | * スクリプトのネームタグ
48 | */
49 | NAMETAG("nametag"),
50 |
51 | /**
52 | * セレクターの設定
53 | */
54 | REDSTONE("redstone");
55 |
56 | private final String name;
57 |
58 | ActionKey(@NotNull String name) {
59 | this.name = name;
60 | }
61 |
62 | @NotNull
63 | public String getName() {
64 | return name;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/enums/IndexType.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.enums;
17 |
18 | /**
19 | * ScriptBlockPlus IndexType 列挙型
20 | * @author yuttyann44581
21 | */
22 | public enum IndexType {
23 |
24 | /**
25 | * 先頭に追加
26 | */
27 | TOP(-2),
28 |
29 | /**
30 | * 最後尾に追加
31 | */
32 | LAST(-1),
33 |
34 | /**
35 | * 指定したオプションより一つ前に追加
36 | */
37 | BEFORE(0),
38 |
39 | /**
40 | * 指定したオプションより一つ後に追加
41 | */
42 | AFTER(1);
43 |
44 | private final int amount;
45 |
46 | IndexType(int amount) {
47 | this.amount = amount;
48 | }
49 |
50 | public int getAmount() {
51 | return amount;
52 | }
53 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/enums/MatchType.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.enums;
17 |
18 | /**
19 | * ScriptBlockPlus MatchType 列挙型
20 | * @author yuttyann44581
21 | */
22 | public enum MatchType {
23 |
24 | /**
25 | * アイテムのID
26 | */
27 | TYPE,
28 |
29 | /**
30 | * アイテムのダメージ値
31 | */
32 | META,
33 |
34 | /**
35 | * アイテムの名前
36 | */
37 | NAME,
38 |
39 | /**
40 | * アイテムの説明文
41 | */
42 | LORE,
43 |
44 | /**
45 | * アイテムの個数
46 | */
47 | AMOUNT;
48 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/enums/TeamColor.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.enums;
17 |
18 | import org.bukkit.Bukkit;
19 | import org.bukkit.ChatColor;
20 | import org.bukkit.scoreboard.Scoreboard;
21 | import org.bukkit.scoreboard.Team;
22 | import org.bukkit.scoreboard.Team.Option;
23 | import org.bukkit.scoreboard.Team.OptionStatus;
24 | import org.jetbrains.annotations.NotNull;
25 |
26 | import com.github.yuttyann.scriptblockplus.utils.version.McVersion;
27 |
28 | public enum TeamColor {
29 | BLACK(ChatColor.BLACK),
30 | DARK_BLUE(ChatColor.DARK_BLUE),
31 | DARK_GREEN(ChatColor.DARK_GREEN),
32 | DARK_AQUA(ChatColor.DARK_AQUA),
33 | DARK_RED(ChatColor.DARK_RED),
34 | DARK_PURPLE(ChatColor.DARK_PURPLE),
35 | GOLD(ChatColor.GOLD),
36 | GRAY(ChatColor.GRAY),
37 | DARK_GRAY(ChatColor.DARK_GRAY),
38 | BLUE(ChatColor.BLUE),
39 | GREEN(ChatColor.GREEN),
40 | AQUA(ChatColor.AQUA),
41 | RED(ChatColor.RED),
42 | LIGHT_PURPLE(ChatColor.LIGHT_PURPLE),
43 | YELLOW(ChatColor.YELLOW),
44 | WHITE(ChatColor.WHITE);
45 |
46 | private static final String PREFIX = "SBP_";
47 | private static final Scoreboard SCOREBOARD = Bukkit.getScoreboardManager().getMainScoreboard();
48 |
49 | private final ChatColor chatColor;
50 |
51 | TeamColor(@NotNull ChatColor chatColor) {
52 | this.chatColor = chatColor;
53 | }
54 |
55 | @NotNull
56 | public String getName() {
57 | return PREFIX + chatColor.name();
58 | }
59 |
60 | @NotNull
61 | public Team getTeam() {
62 | var name = getName();
63 | var team = SCOREBOARD.getTeam(name);
64 | if (team == null) {
65 | team = SCOREBOARD.registerNewTeam(name);
66 | if (McVersion.V_1_12.isSupported()) {
67 | team.setColor(chatColor);
68 | }
69 | team.setPrefix(chatColor.toString());
70 | team.setSuffix(chatColor.toString());
71 | team.setOption(Option.COLLISION_RULE, OptionStatus.NEVER);
72 | }
73 | return team;
74 | }
75 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/enums/splittype/Argument.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.enums.splittype;
17 |
18 | import com.github.yuttyann.scriptblockplus.selector.split.SplitType;
19 | import com.github.yuttyann.scriptblockplus.utils.StringUtils;
20 |
21 | import org.jetbrains.annotations.NotNull;
22 | import org.jetbrains.annotations.Nullable;
23 |
24 | /**
25 | * ScriptBlockPlus Argument 列挙型
26 | *
27 | * Minecraft "1.12.2" までのセレクターの引数です。
28 | * @author yuttyann44581
29 | */
30 | public enum Argument implements SplitType {
31 | X("x="),
32 | Y("y="),
33 | Z("z="),
34 | DX("dx="),
35 | DY("dy="),
36 | DZ("dz="),
37 | R("r="),
38 | RM("rm="),
39 | RX("rx="),
40 | RXM("rxm="),
41 | RY("ry="),
42 | RYM("rym="),
43 | C("c="),
44 | L("l="),
45 | LM("lm="),
46 | M("m="),
47 | TAG("tag="),
48 | TEAM("team="),
49 | TYPE("type="),
50 | NAME("name="),
51 | SCORE("score_=", "score_", "="),
52 | SCORE_MIN("score__min=", "score_", "_min=");
53 |
54 | private final String syntax, prefix, suffix;
55 |
56 | Argument(@NotNull String syntax) {
57 | this(syntax, null, null);
58 | }
59 |
60 | Argument(@NotNull String syntax, @Nullable String prefix, @Nullable String suffix) {
61 | this.syntax = syntax;
62 | this.prefix = prefix;
63 | this.suffix = suffix;
64 | }
65 |
66 | @Override
67 | @NotNull
68 | public String getValue(@NotNull String argument) {
69 | switch (this) {
70 | case SCORE: case SCORE_MIN:
71 | var objective = argument.substring(prefix.length(), argument.lastIndexOf(suffix));
72 | return StringUtils.removeStart(argument, prefix + objective + suffix) + "*" + objective;
73 | default:
74 | return StringUtils.removeStart(argument, syntax);
75 | }
76 | }
77 |
78 | @Override
79 | public boolean match(@NotNull String argument) {
80 | switch (this) {
81 | case SCORE:
82 | return argument.startsWith(prefix) && argument.lastIndexOf(SCORE_MIN.suffix) == -1;
83 | case SCORE_MIN:
84 | return argument.startsWith(prefix) && argument.lastIndexOf(suffix) > 0;
85 | default:
86 | return argument.startsWith(syntax);
87 | }
88 | }
89 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/enums/splittype/Filter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.enums.splittype;
17 |
18 | import com.github.yuttyann.scriptblockplus.selector.split.SplitType;
19 | import com.github.yuttyann.scriptblockplus.utils.StringUtils;
20 |
21 | import org.jetbrains.annotations.NotNull;
22 |
23 | /**
24 | * ScriptBlockPlus Filter 列挙型
25 | * @author yuttyann44581
26 | */
27 | public enum Filter implements SplitType {
28 |
29 | /**
30 | * OPの所持、不所持を判定します。
31 | */
32 | OP("op="),
33 |
34 | /**
35 | * 権限の所持、不所持を判定します。
36 | */
37 | PERM("perm="),
38 |
39 | /**
40 | * 実行回数を判定します。
41 | */
42 | LIMIT("limit=");
43 |
44 | private final String syntax;
45 |
46 | Filter(@NotNull String syntax) {
47 | this.syntax = syntax;
48 | }
49 |
50 | @NotNull
51 | public String getSyntax() {
52 | return syntax;
53 | }
54 |
55 | @NotNull
56 | public static String getPrefix() {
57 | return "filter{";
58 | }
59 |
60 | @Override
61 | @NotNull
62 | public String getValue(@NotNull String argument) {
63 | return StringUtils.removeStart(argument, syntax);
64 | }
65 |
66 | @Override
67 | public boolean match(@NotNull String argument) {
68 | return argument.startsWith(syntax);
69 | }
70 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/enums/splittype/Repeat.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.enums.splittype;
17 |
18 | import com.github.yuttyann.scriptblockplus.selector.split.SplitType;
19 | import com.github.yuttyann.scriptblockplus.utils.StringUtils;
20 |
21 | import org.jetbrains.annotations.NotNull;
22 |
23 | /**
24 | * ScriptBlockPlus Repeat 列挙型
25 | * @author yuttyann44581
26 | */
27 | public enum Repeat implements SplitType {
28 |
29 | /**
30 | * リピートの時間を設定します。
31 | */
32 | TICK("tick="),
33 |
34 | /**
35 | * リピート開始までの時間を設定します。
36 | */
37 | DELAY("delay="),
38 |
39 | /**
40 | * 実行回数を設定します。
41 | */
42 | LIMIT("limit=");
43 |
44 | private final String syntax;
45 |
46 | Repeat(@NotNull String syntax) {
47 | this.syntax = syntax;
48 | }
49 |
50 | @NotNull
51 | public String getSyntax() {
52 | return syntax;
53 | }
54 |
55 | @NotNull
56 | public static String getPrefix() {
57 | return "repeat{";
58 | }
59 |
60 | @Override
61 | @NotNull
62 | public String getValue(@NotNull String argument) {
63 | return StringUtils.removeStart(argument, syntax);
64 | }
65 |
66 | @Override
67 | public boolean match(@NotNull String argument) {
68 | return argument.startsWith(syntax);
69 | }
70 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/event/DelayEndEvent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.event;
17 |
18 | import com.github.yuttyann.scriptblockplus.script.ScriptRead;
19 |
20 | import org.bukkit.event.Event;
21 | import org.bukkit.event.HandlerList;
22 | import org.jetbrains.annotations.NotNull;
23 |
24 | /**
25 | * ScriptBlockPlus DelayEndEvent イベントクラス
26 | * @author yuttyann44581
27 | */
28 | public class DelayEndEvent extends Event {
29 |
30 | private static final HandlerList HANDLERS = new HandlerList();
31 |
32 | private final ScriptRead scriptRead;
33 |
34 | /**
35 | * コンストラクタ
36 | * @param scriptRead - {@link ScriptRead}のインスタンス
37 | */
38 | public DelayEndEvent(@NotNull ScriptRead scriptRead) {
39 | super(scriptRead.isAsynchronous());
40 | this.scriptRead = scriptRead;
41 | }
42 |
43 | /**
44 | * {@link ScriptRead}のインスタンスを取得します。
45 | * @return {@link ScriptRead} - インスタンス
46 | */
47 | @NotNull
48 | public ScriptRead getScriptRead() {
49 | return scriptRead;
50 | }
51 |
52 | @Override
53 | @NotNull
54 | public HandlerList getHandlers() {
55 | return HANDLERS;
56 | }
57 |
58 | @NotNull
59 | public static HandlerList getHandlerList() {
60 | return HANDLERS;
61 | }
62 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/event/DelayRunEvent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.event;
17 |
18 | import com.github.yuttyann.scriptblockplus.script.ScriptRead;
19 |
20 | import org.bukkit.event.Event;
21 | import org.bukkit.event.HandlerList;
22 | import org.jetbrains.annotations.NotNull;
23 |
24 | /**
25 | * ScriptBlockPlus DelayRunEvent イベントクラス
26 | * @author yuttyann44581
27 | */
28 | public class DelayRunEvent extends Event {
29 |
30 | private static final HandlerList HANDLERS = new HandlerList();
31 |
32 | private final ScriptRead scriptRead;
33 |
34 | /**
35 | * コンストラクタ
36 | * @param scriptRead - {@link ScriptRead}のインスタンス
37 | */
38 | public DelayRunEvent(@NotNull ScriptRead scriptRead) {
39 | super(scriptRead.isAsynchronous());
40 | this.scriptRead = scriptRead;
41 | }
42 |
43 | /**
44 | * {@link ScriptRead}のインスタンスを取得します。
45 | * @return {@link ScriptRead} - インスタンス
46 | */
47 | @NotNull
48 | public ScriptRead getScriptRead() {
49 | return scriptRead;
50 | }
51 |
52 | @Override
53 | @NotNull
54 | public HandlerList getHandlers() {
55 | return HANDLERS;
56 | }
57 |
58 | @NotNull
59 | public static HandlerList getHandlerList() {
60 | return HANDLERS;
61 | }
62 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/event/FileReloadEvent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.event;
17 |
18 | import org.bukkit.event.Event;
19 | import org.bukkit.event.HandlerList;
20 | import org.jetbrains.annotations.NotNull;
21 |
22 | /**
23 | * ScriptBlockPlus FileReloadEvent イベントクラス
24 | * @author yuttyann44581
25 | */
26 | public class FileReloadEvent extends Event {
27 |
28 | private static final HandlerList HANDLERS = new HandlerList();
29 |
30 | @Override
31 | @NotNull
32 | public HandlerList getHandlers() {
33 | return HANDLERS;
34 | }
35 |
36 | @NotNull
37 | public static HandlerList getHandlerList() {
38 | return HANDLERS;
39 | }
40 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/event/ScriptReadEndEvent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.event;
17 |
18 | import java.util.UUID;
19 |
20 | import com.github.yuttyann.scriptblockplus.script.ScriptRead;
21 |
22 | import org.bukkit.event.Event;
23 | import org.bukkit.event.HandlerList;
24 | import org.jetbrains.annotations.NotNull;
25 |
26 | /**
27 | * ScriptBlockPlus ScriptReadEndEvent イベントクラス
28 | * @author yuttyann44581
29 | */
30 | public class ScriptReadEndEvent extends Event {
31 |
32 | private static final HandlerList HANDLERS = new HandlerList();
33 |
34 | private final UUID uuid;
35 | private final com.github.yuttyann.scriptblockplus.script.option.Option.Result result;
36 | private final ScriptRead scriptRead;
37 |
38 | /**
39 | * コンストラクタ
40 | * @param uuid - スクリプトの{@link UUID}
41 | * @param scriptRead - {@link ScriptRead}のインスタンス
42 | */
43 | public ScriptReadEndEvent(@NotNull UUID uuid, @NotNull com.github.yuttyann.scriptblockplus.script.option.Option.Result result, @NotNull ScriptRead scriptRead) {
44 | super(scriptRead.isAsynchronous());
45 | this.uuid = uuid;
46 | this.result = result;
47 | this.scriptRead = scriptRead;
48 | }
49 |
50 | /**
51 | * スクリプトの{@link UUID}を取得します。
52 | * @return {@link UUID} - スクリプトの{@link UUID}
53 | */
54 | @NotNull
55 | public UUID getUniqueId() {
56 | return uuid;
57 | }
58 |
59 | /**
60 | * スクリプトの実行結果を取得します。
61 | * @return {@code Result} - 成功した場合は{@code Result#SUCCESS}
62 | */
63 | @NotNull
64 | public com.github.yuttyann.scriptblockplus.script.option.Option.Result getResult() {
65 | return result;
66 | }
67 |
68 | /**
69 | * {@link ScriptRead}のインスタンスを取得します。
70 | * @return {@link ScriptRead} - インスタンス
71 | */
72 | @NotNull
73 | public ScriptRead getScriptRead() {
74 | return scriptRead;
75 | }
76 |
77 | @Override
78 | @NotNull
79 | public HandlerList getHandlers() {
80 | return HANDLERS;
81 | }
82 |
83 | @NotNull
84 | public static HandlerList getHandlerList() {
85 | return HANDLERS;
86 | }
87 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/event/ScriptReadStartEvent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.event;
17 |
18 | import java.util.UUID;
19 |
20 | import com.github.yuttyann.scriptblockplus.script.ScriptRead;
21 |
22 | import org.bukkit.event.Event;
23 | import org.bukkit.event.HandlerList;
24 | import org.jetbrains.annotations.NotNull;
25 |
26 | /**
27 | * ScriptBlockPlus ScriptReadStartEvent イベントクラス
28 | * @author yuttyann44581
29 | */
30 | public class ScriptReadStartEvent extends Event {
31 |
32 | private static final HandlerList HANDLERS = new HandlerList();
33 |
34 | private final UUID uuid;
35 | private final ScriptRead scriptRead;
36 |
37 | /**
38 | * コンストラクタ
39 | * @param uuid - スクリプトの{@link UUID}
40 | * @param scriptRead - {@link ScriptRead}のインスタンス
41 | */
42 | public ScriptReadStartEvent(@NotNull UUID uuid, @NotNull ScriptRead scriptRead) {
43 | super(scriptRead.isAsynchronous());
44 | this.uuid = uuid;
45 | this.scriptRead = scriptRead;
46 | }
47 |
48 | /**
49 | * スクリプトの{@link UUID}を取得します。
50 | * @return {@link UUID} - スクリプトの{@link UUID}
51 | */
52 | @NotNull
53 | public UUID getUniqueId() {
54 | return uuid;
55 | }
56 |
57 | /**
58 | * {@link ScriptRead}のインスタンスを取得します。
59 | * @return {@link ScriptRead} - インスタンス
60 | */
61 | @NotNull
62 | public ScriptRead getScriptRead() {
63 | return scriptRead;
64 | }
65 |
66 | @Override
67 | @NotNull
68 | public HandlerList getHandlers() {
69 | return HANDLERS;
70 | }
71 |
72 | @NotNull
73 | public static HandlerList getHandlerList() {
74 | return HANDLERS;
75 | }
76 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/file/Backup.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.file;
17 |
18 | import java.io.IOException;
19 | import java.nio.file.FileVisitResult;
20 | import java.nio.file.Files;
21 | import java.nio.file.Path;
22 | import java.nio.file.SimpleFileVisitor;
23 | import java.nio.file.StandardCopyOption;
24 | import java.nio.file.attribute.BasicFileAttributes;
25 | import java.text.SimpleDateFormat;
26 | import java.util.Date;
27 | import java.util.function.Predicate;
28 |
29 | import org.jetbrains.annotations.NotNull;
30 |
31 | import com.google.common.base.Predicates;
32 |
33 | /**
34 | * Corelate-Common Backup
35 | * @author yuttyann44581
36 | */
37 | public class Backup extends SimpleFileVisitor {
38 |
39 | public static final SimpleDateFormat SHORT_DATE_FORMAT;
40 |
41 | static {
42 | SHORT_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
43 | // SHORT_DATE_FORMAT.setTimeZone(Utils.DATE_FORMAT.getTimeZone());
44 | }
45 |
46 | private final Path from, to;
47 | private final Predicate filter;
48 |
49 | public Backup(@NotNull SBFile backup) {
50 | this(backup, Predicates.alwaysTrue());
51 | }
52 |
53 | public Backup(@NotNull SBFile backup, @NotNull Predicate filter) {
54 | var name = SHORT_DATE_FORMAT.format(new Date());
55 | var size = backup.listNames((file, path) -> path.startsWith(name)).size() + 1;
56 | this.from = backup.getParentFile().toPath();
57 | this.to = new SBFile(backup, name + '-' + size).toPath();
58 | this.filter = filter;
59 | }
60 |
61 | @NotNull
62 | public Path getFrom() {
63 | return from;
64 | }
65 |
66 | @NotNull
67 | public Path getTo() {
68 | return to;
69 | }
70 |
71 | @Override
72 | @NotNull
73 | public FileVisitResult visitFile(@NotNull Path path, @NotNull BasicFileAttributes attributes) throws IOException {
74 | if (!filter.test(path.toString())) {
75 | var targetFile = to.resolve(from.relativize(path));
76 | var parentDir = targetFile.getParent();
77 | Files.createDirectories(parentDir);
78 | Files.copy(path, targetFile, StandardCopyOption.REPLACE_EXISTING);
79 | }
80 | return FileVisitResult.CONTINUE;
81 | }
82 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/file/Lang.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.file;
17 |
18 | import com.github.yuttyann.scriptblockplus.file.config.YamlConfig;
19 | import com.github.yuttyann.scriptblockplus.utils.FileUtils;
20 | import com.github.yuttyann.scriptblockplus.utils.StringUtils;
21 | import org.bukkit.plugin.Plugin;
22 | import org.jetbrains.annotations.NotNull;
23 |
24 | import java.io.File;
25 | import java.io.IOException;
26 | import java.util.Locale;
27 |
28 | /**
29 | * ScriptBlockPlus Lang クラス
30 | * @author yuttyann44581
31 | */
32 | public final class Lang {
33 |
34 | private static final String DEFAULT_LANGUAGE = "en";
35 |
36 | private final Plugin plugin;
37 | private final String language;
38 | private final String filePath;
39 | private final String directory;
40 |
41 | public Lang(@NotNull Plugin plugin, @NotNull String language, @NotNull String filePath, @NotNull String directory) {
42 | this.plugin = plugin;
43 | this.language = StringUtils.isEmpty(language) ? DEFAULT_LANGUAGE : language.toLowerCase(Locale.ROOT);
44 | this.filePath = filePath;
45 | this.directory = directory;
46 | }
47 |
48 | @NotNull
49 | public String getLanguage() {
50 | return language;
51 | }
52 |
53 | @NotNull
54 | public YamlConfig load() {
55 | return YamlConfig.load(plugin, getFile(), false).setInnerPath(getPath());
56 | }
57 |
58 | @NotNull
59 | public String getPath() {
60 | var path = directory + "/" + language + ".yml";
61 | var code = FileUtils.getResource(plugin, path) != null ? language : DEFAULT_LANGUAGE;
62 | var file = new SBFile(plugin.getDataFolder(), StringUtils.replace(this.filePath, "{code}", code));
63 | return !file.exists() && !code.equals(language) ? directory + "/" + code + ".yml" : path;
64 | }
65 |
66 | @NotNull
67 | public File getFile() {
68 | var path = directory + "/" + language + ".yml";
69 | var code = FileUtils.getResource(plugin, path) != null ? language : DEFAULT_LANGUAGE;
70 | var file = new SBFile(plugin.getDataFolder(), StringUtils.replace(this.filePath, "{code}", code));
71 | if (!file.exists()) {
72 | if (!code.equals(language)) {
73 | path = directory + "/" + code + ".yml";
74 | }
75 | try {
76 | FileUtils.copyFileFromPlugin(plugin, file, path);
77 | } catch (IOException e) {
78 | e.printStackTrace();
79 | }
80 | }
81 | return file;
82 | }
83 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/file/SBFile.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.file;
17 |
18 | import java.io.File;
19 | import java.io.FilenameFilter;
20 | import java.net.URI;
21 | import java.util.ArrayList;
22 | import java.util.List;
23 |
24 | import org.jetbrains.annotations.NotNull;
25 |
26 | /**
27 | * ScriptBlockPlus SBFile クラス
28 | *
29 | * 生成時に環境に合うセパレータに置換します。
30 | * @author yuttyann44581
31 | */
32 | public class SBFile extends File {
33 |
34 | private static final long serialVersionUID = -303311616177581242L;
35 |
36 | public SBFile(@NotNull URI uri) {
37 | super(uri);
38 | }
39 |
40 | public SBFile(@NotNull String path) {
41 | super(setSeparator(path));
42 | }
43 |
44 | public SBFile(@NotNull File parent, @NotNull String child) {
45 | super(parent, setSeparator(child));
46 | }
47 |
48 | public SBFile(@NotNull String parent, @NotNull String child) {
49 | super(setSeparator(parent), setSeparator(child));
50 | }
51 |
52 | @NotNull
53 | public static String setSeparator(@NotNull String path) {
54 | if (separatorChar != '/') {
55 | return path.replace('/', separatorChar);
56 | }
57 | return path;
58 | }
59 |
60 | @NotNull
61 | public List listNames(@NotNull FilenameFilter filter) {
62 | var names = list();
63 | if (names == null) {
64 | return new ArrayList<>();
65 | }
66 | var list = new ArrayList(names.length);
67 | for (int i = 0, l = names.length; i < l; i++) {
68 | var name = names[i];
69 | if (filter.accept(this, name)) {
70 | list.add(name);
71 | }
72 | }
73 | return list;
74 | }
75 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/file/SBFiles.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.file;
17 |
18 | import com.github.yuttyann.scriptblockplus.ScriptBlock;
19 | import com.github.yuttyann.scriptblockplus.event.FileReloadEvent;
20 | import com.github.yuttyann.scriptblockplus.file.config.ConfigKeys;
21 | import com.github.yuttyann.scriptblockplus.file.config.YamlConfig;
22 | import org.bukkit.Bukkit;
23 | import org.bukkit.plugin.Plugin;
24 | import org.jetbrains.annotations.NotNull;
25 |
26 | import java.util.*;
27 |
28 | /**
29 | * ScriptBlockPlus SBFiles クラス
30 | * @author yuttyann44581
31 | */
32 | public final class SBFiles {
33 |
34 | private static final Map FILES = new HashMap<>();
35 |
36 | public static final String PATH_CONFIG = "config_{code}.yml";
37 | public static final String PATH_MESSAGE = "message_{code}.yml";
38 |
39 | public static void reload() {
40 | // ScriptBlockのインスタンス
41 | var plugin = ScriptBlock.getInstance();
42 |
43 | // ファイルの内容を読み込む
44 | ConfigKeys.clear();
45 | ConfigKeys.load(loadLang(plugin, PATH_CONFIG, "config"));
46 | ConfigKeys.load(loadLang(plugin, PATH_MESSAGE, "message"));
47 |
48 | // リロードを行ったことを知らせるイベントを呼ぶ
49 | Bukkit.getPluginManager().callEvent(new FileReloadEvent());
50 | }
51 |
52 | @NotNull
53 | public static Map getFiles() {
54 | return Collections.unmodifiableMap(FILES);
55 | }
56 |
57 | public static Optional getFile(@NotNull Plugin plugin, @NotNull String filePath) {
58 | return Optional.ofNullable(FILES.get(plugin.getName() + "_" + filePath));
59 | }
60 |
61 | @NotNull
62 | public static YamlConfig loadFile(@NotNull Plugin plugin, @NotNull String filePath, boolean isCopyFile) {
63 | return putFile(plugin, filePath, YamlConfig.load(plugin, filePath, isCopyFile));
64 | }
65 |
66 | @NotNull
67 | public static YamlConfig loadLang(@NotNull Plugin plugin, @NotNull String filePath, @NotNull String directoryPath) {
68 | return putFile(plugin, filePath, new Lang(plugin, Locale.getDefault().getLanguage(), filePath, directoryPath).load());
69 | }
70 |
71 | @NotNull
72 | private static YamlConfig putFile(@NotNull Plugin plugin, @NotNull String name, @NotNull YamlConfig yaml) {
73 | FILES.put(plugin.getName() + "_" + name, yaml);
74 | return yaml;
75 | }
76 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/file/config/ConfigAdapter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.file.config;
17 |
18 | import org.jetbrains.annotations.NotNull;
19 | import org.jetbrains.annotations.Nullable;
20 |
21 | import java.util.Map;
22 |
23 | /**
24 | * ScriptBlockPlus ConfigAdapter クラス
25 | * @author yuttyann44581
26 | */
27 | @SuppressWarnings("unchecked")
28 | public final class ConfigAdapter {
29 |
30 | private final Map map;
31 |
32 | /**
33 | * コンストラクタ
34 | * @param map - マップ
35 | */
36 | public ConfigAdapter(@NotNull Map map) {
37 | this.map = map;
38 | }
39 |
40 | /**
41 | * 全ての要素をクリアします。
42 | */
43 | public void clear() {
44 | map.clear();
45 | }
46 |
47 | /**
48 | * ファイルに含まれている全ての要素をロードします。
49 | * @param yaml - ファイル
50 | */
51 | public void load(@NotNull YamlConfig yaml) {
52 | yaml.getKeys(true).forEach(s -> map.put(s, yaml.get(s)));
53 | }
54 |
55 | /**
56 | * 値を取得します。
57 | * @param - 値の型
58 | * @param key - キー
59 | * @return {@link T} - 値
60 | */
61 | @Nullable
62 | public T get(@NotNull String key) {
63 | return (T) map.get(key);
64 | }
65 |
66 | /**
67 | * 値を取得します。
68 | * @param - 値の型
69 | * @param key - キー
70 | * @param def - デフォルトの値
71 | * @return {@link T} - 値
72 | */
73 | @NotNull
74 | public T get(@NotNull String key, @NotNull T def) {
75 | T value = get(key);
76 | return value == null ? def : value;
77 | }
78 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/file/config/ReplaceKey.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.file.config;
17 |
18 | import com.github.yuttyann.scriptblockplus.utils.StringUtils;
19 | import org.jetbrains.annotations.NotNull;
20 |
21 | import java.util.Optional;
22 |
23 | /**
24 | * ScriptBlockPlus ReplaceKey クラス
25 | * @author yuttyann44581
26 | */
27 | public class ReplaceKey implements ConfigKey {
28 |
29 | private final ConfigKey configKey;
30 | private final String[] replaceKeys;
31 |
32 | protected Object[] args = {};
33 | protected String result = null;
34 |
35 | /**
36 | * コンストラクタ
37 | * @param configKey - コンフィグのキー
38 | * @param replaceKeys - 検索する文字列
39 | */
40 | public ReplaceKey(@NotNull ConfigKey configKey, @NotNull String... replaceKeys) {
41 | this.configKey = configKey;
42 | this.replaceKeys = replaceKeys;
43 | }
44 |
45 | /**
46 | * コンフィグのキーを取得します。
47 | * @return {@link ConfigKey}<{@link String}> - コンフィグのキー
48 | */
49 | @NotNull
50 | protected final ConfigKey getConfigKey() {
51 | return configKey;
52 | }
53 |
54 | /**
55 | * 値を取得します。
56 | * @return {@link Optional}<{@link String}> - 値
57 | */
58 | @Override
59 | @NotNull
60 | public Optional get() {
61 | return configKey.get();
62 | }
63 |
64 | /**
65 | * 要素を取得します。
66 | * @param - 要素の型
67 | * @param index - 位置
68 | * @param classOf - 要素のクラス
69 | * @return
70 | */
71 | @NotNull
72 | public final T getArgument(final int index, @NotNull Class classOf) {
73 | return classOf.cast(args[index]);
74 | }
75 |
76 | /**
77 | * 置換を行います。
78 | * @param replaces - 置換する要素
79 | * @return {@link ReplaceKey} - 置換後のキー
80 | */
81 | @NotNull
82 | public ReplaceKey replace(@NotNull Object... replaces) {
83 | if (replaces.length != replaceKeys.length) {
84 | throw new IllegalArgumentException("Size are not equal.");
85 | }
86 | var replaceKey = new ReplaceKey(configKey, replaceKeys);
87 | replaceKey.args = replaces;
88 | replaceKey.result = replaceKey.configKey.getValue();
89 | for (int i = 0; i < replaces.length; i++) {
90 | replaceKey.result = StringUtils.replace(replaceKey.result, replaceKey.replaceKeys[i], replaceKey.args[i]);
91 | }
92 | return replaceKey;
93 | }
94 |
95 | @Override
96 | public String toString() {
97 | return result == null ? configKey.toString() : result;
98 | }
99 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/file/json/BaseElement.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.file.json;
17 |
18 | import java.util.Objects;
19 |
20 | import org.jetbrains.annotations.NotNull;
21 |
22 | /**
23 | * ScriptBlockPlus BaseElement クラス
24 | * @author yuttyann44581
25 | */
26 | public abstract class BaseElement implements Cloneable {
27 |
28 | /**
29 | * 引数同士を比較します。
30 | * @param argument1 - 引数1
31 | * @param argument2 - 引数2
32 | * @return {@code boolean} - 引数が一致するのかどうか
33 | */
34 | protected boolean compare(@NotNull Object argument1, @NotNull Object argument2) {
35 | return Objects.equals(argument1, argument2);
36 | }
37 |
38 | /**
39 | * エレメントのクラスを取得します。
40 | * @return {@link Class}<? extends {@link BaseElement}> - エレメントのクラス
41 | */
42 | @NotNull
43 | public Class extends BaseElement> getElementType() {
44 | return BaseElement.class;
45 | }
46 |
47 | @Override
48 | public BaseElement clone() throws CloneNotSupportedException {
49 | return (BaseElement) super.clone();
50 | }
51 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/file/json/annotation/Alternate.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.file.json.annotation;
17 |
18 | import java.lang.annotation.Retention;
19 | import java.lang.annotation.Target;
20 |
21 | import com.google.gson.annotations.SerializedName;
22 |
23 | import static java.lang.annotation.ElementType.FIELD;
24 | import static java.lang.annotation.ElementType.METHOD;
25 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
26 |
27 | /**
28 | * ScriptBlockPlus Alternate 注釈
29 | *
30 | * Gsonのバージョンが古い場合に呼び出されます。
31 | *
32 | * {@link SerializedName#alternate()}と同等の機能を持っています。
33 | * @author yuttyann44581
34 | */
35 | @Target({ FIELD, METHOD })
36 | @Retention(RUNTIME)
37 | public @interface Alternate {
38 |
39 | /**
40 | * デシリアライズした時の代替名を取得します。
41 | * @return {@link String} - 代替名
42 | */
43 | String[] value() default {};
44 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/file/json/annotation/Exclude.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.file.json.annotation;
17 |
18 | import java.lang.annotation.Retention;
19 | import java.lang.annotation.Target;
20 |
21 | import static java.lang.annotation.ElementType.FIELD;
22 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
23 |
24 | /**
25 | * ScriptBlockPlus Exclude 注釈
26 | *
27 | * この注釈を付与することで、デシリアライズをスルーすることが出来ます。
28 | * @author yuttyann44581
29 | */
30 | @Target(FIELD)
31 | @Retention(RUNTIME)
32 | public @interface Exclude {
33 |
34 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/file/json/annotation/JsonTag.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.file.json.annotation;
17 |
18 | import org.jetbrains.annotations.NotNull;
19 |
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.Target;
22 |
23 | import static java.lang.annotation.ElementType.TYPE;
24 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
25 |
26 | /**
27 | * ScriptBlockPlus JsonTag 注釈
28 | * @author yuttyann44581
29 | */
30 | @Target(TYPE)
31 | @Retention(RUNTIME)
32 | public @interface JsonTag {
33 |
34 | /**
35 | * ディレクトリのパスを取得します。
36 | *
57 | * 整形を行う際に利用されます。
58 | * @return {@link String} - インデント
59 | */
60 | @NotNull
61 | String indent() default " ";
62 |
63 | /**
64 | * ファイルを保存した時にキャッシュを削除するのかどうか。
65 | * @return {@link boolean} - 削除を行う場合は{@code true}
66 | */
67 | boolean temporary() default false;
68 |
69 | /**
70 | * ファイルが存在する時のみキャッシュを保存するのかどうか。
71 | * @return {@link boolean} - ファイルが存在する時のみキャッシュを保存する場合は{@code true}
72 | */
73 | boolean cachefileexists() default false;
74 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/file/json/builder/BlockCoordsAdapter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.file.json.builder;
17 |
18 | import java.lang.reflect.Type;
19 |
20 | import com.github.yuttyann.scriptblockplus.BlockCoords;
21 | import com.google.gson.JsonDeserializationContext;
22 | import com.google.gson.JsonDeserializer;
23 | import com.google.gson.JsonElement;
24 | import com.google.gson.JsonParseException;
25 | import com.google.gson.JsonSerializationContext;
26 | import com.google.gson.JsonSerializer;
27 |
28 | import org.jetbrains.annotations.NotNull;
29 |
30 | /**
31 | * ScriptBlockPlus BlockCoordsAdapter クラス
32 | * @author yuttyann44581
33 | */
34 | public final class BlockCoordsAdapter implements JsonSerializer, JsonDeserializer {
35 |
36 | @Override
37 | @NotNull
38 | public JsonElement serialize(@NotNull BlockCoords blockCoords, @NotNull Type typeOfSrc, @NotNull JsonSerializationContext context) {
39 | return context.serialize(blockCoords.getFullCoords());
40 | }
41 |
42 | @Override
43 | @NotNull
44 | public BlockCoords deserialize(@NotNull JsonElement json, @NotNull Type typeOfT, @NotNull JsonDeserializationContext context) throws JsonParseException {
45 | return BlockCoords.fromString(json.getAsString());
46 | }
47 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/file/json/builder/CollectionType.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.file.json.builder;
17 |
18 | import java.lang.reflect.ParameterizedType;
19 | import java.lang.reflect.Type;
20 | import java.util.Collection;
21 |
22 | import com.github.yuttyann.scriptblockplus.file.json.BaseJson;
23 |
24 | import org.jetbrains.annotations.NotNull;
25 | import org.jetbrains.annotations.Nullable;
26 |
27 | /**
28 | * ScriptBlockPlus CollectionType クラス
29 | * @author yuttyann44581
30 | */
31 | @SuppressWarnings("rawtypes")
32 | public final class CollectionType implements ParameterizedType {
33 |
34 | private final Type[] types;
35 | private final Class extends Collection> rawType;
36 |
37 | public CollectionType(@NotNull Class extends Collection> rawType, @NotNull BaseJson> json) throws ClassNotFoundException {
38 | var type = json.getClass().getGenericSuperclass();
39 | var args = ((ParameterizedType) type).getActualTypeArguments();
40 | this.types = new Type[] { Class.forName(args[args.length - 1].getTypeName()) };
41 | this.rawType = rawType;
42 | }
43 |
44 | @Override
45 | @NotNull
46 | public Type[] getActualTypeArguments() {
47 | return types;
48 | }
49 |
50 | @Override
51 | @NotNull
52 | public Type getRawType() {
53 | return rawType;
54 | }
55 |
56 | @Override
57 | @Nullable
58 | public Type getOwnerType() {
59 | return null;
60 | }
61 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/file/json/builder/FieldExclusion.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.file.json.builder;
17 |
18 | import com.github.yuttyann.scriptblockplus.file.json.annotation.Exclude;
19 | import com.google.gson.ExclusionStrategy;
20 | import com.google.gson.FieldAttributes;
21 | import org.jetbrains.annotations.NotNull;
22 |
23 | /**
24 | * ScriptBlockPlus FieldExclusion クラス
25 | * @author yuttyann44581
26 | */
27 | public final class FieldExclusion implements ExclusionStrategy {
28 |
29 | @Override
30 | public boolean shouldSkipField(@NotNull FieldAttributes field) {
31 | return field.getAnnotation(Exclude.class) != null;
32 | }
33 |
34 | @Override
35 | public boolean shouldSkipClass(@NotNull Class> clazz) {
36 | return false;
37 | }
38 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/yuttyann/scriptblockplus/file/json/builder/NumberAdapter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * ScriptBlockPlus - Allow you to add script to any blocks.
3 | * Copyright (C) 2021 yuttyann44581
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by the Free Software Foundation,
7 | * either version 3 of the License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | * See the GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License along with this program.
14 | * If not, see .
15 | */
16 | package com.github.yuttyann.scriptblockplus.file.json.builder;
17 |
18 | import java.io.IOException;
19 | import java.util.ArrayList;
20 |
21 | import com.github.yuttyann.scriptblockplus.file.json.BaseJson;
22 | import com.google.gson.TypeAdapter;
23 | import com.google.gson.internal.LinkedTreeMap;
24 | import com.google.gson.stream.JsonReader;
25 | import com.google.gson.stream.JsonWriter;
26 |
27 | import org.jetbrains.annotations.NotNull;
28 | import org.jetbrains.annotations.Nullable;
29 |
30 | /**
31 | * ScriptBlockPlus NumberAdapter クラス
32 | * @author yuttyann44581
33 | */
34 | public final class NumberAdapter extends TypeAdapter