Skip to content

Commit b30b695

Browse files
committed
port over remaining flag commands
1 parent 9839b70 commit b30b695

18 files changed

+591
-19
lines changed

Bukkit/src/main/java/com/plotsquared/bukkit/inject/CloudModule.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
1+
/*
2+
* PlotSquared, a land and world management plugin for Minecraft.
3+
* Copyright (C) IntellectualSites <https://intellectualsites.com>
4+
* Copyright (C) IntellectualSites team and contributors
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
119
package com.plotsquared.bukkit.inject;
220

3-
import cloud.commandframework.CloudCapability;
421
import cloud.commandframework.CommandManager;
522
import cloud.commandframework.bukkit.CloudBukkitCapabilities;
6-
import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator;
7-
import cloud.commandframework.minecraft.extras.AudienceProvider;
23+
import cloud.commandframework.execution.ExecutionCoordinator;
824
import cloud.commandframework.minecraft.extras.MinecraftExceptionHandler;
925
import cloud.commandframework.paper.PaperCommandManager;
1026
import com.google.inject.AbstractModule;
@@ -54,7 +70,7 @@ protected void configure() {
5470
try {
5571
final PaperCommandManager<PlotPlayer<?>> commandManager = new PaperCommandManager<PlotPlayer<?>>(
5672
this.bukkitPlatform,
57-
AsynchronousCommandExecutionCoordinator.<PlotPlayer<?>>builder().withAsynchronousParsing().build(),
73+
ExecutionCoordinator.asyncCoordinator(),
5874
CloudModule::convert,
5975
CloudModule::convert
6076
);

Core/src/main/java/com/plotsquared/core/commands/CommandRequirement.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
* PlotSquared, a land and world management plugin for Minecraft.
3+
* Copyright (C) IntellectualSites <https://intellectualsites.com>
4+
* Copyright (C) IntellectualSites team and contributors
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
119
package com.plotsquared.core.commands;
220

321
import cloud.commandframework.context.CommandContext;

Core/src/main/java/com/plotsquared/core/commands/CommonCommandRequirement.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
* PlotSquared, a land and world management plugin for Minecraft.
3+
* Copyright (C) IntellectualSites <https://intellectualsites.com>
4+
* Copyright (C) IntellectualSites team and contributors
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
119
package com.plotsquared.core.commands;
220

321
import cloud.commandframework.context.CommandContext;

Core/src/main/java/com/plotsquared/core/commands/PlotSquaredCaptionProvider.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
* PlotSquared, a land and world management plugin for Minecraft.
3+
* Copyright (C) IntellectualSites <https://intellectualsites.com>
4+
* Copyright (C) IntellectualSites team and contributors
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
119
package com.plotsquared.core.commands;
220

321
import cloud.commandframework.captions.Caption;

Core/src/main/java/com/plotsquared/core/commands/PlotSquaredCommandBean.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
* PlotSquared, a land and world management plugin for Minecraft.
3+
* Copyright (C) IntellectualSites <https://intellectualsites.com>
4+
* Copyright (C) IntellectualSites team and contributors
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
119
package com.plotsquared.core.commands;
220

321
import cloud.commandframework.Command;

Core/src/main/java/com/plotsquared/core/commands/PlotSquaredCommandManager.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
* PlotSquared, a land and world management plugin for Minecraft.
3+
* Copyright (C) IntellectualSites <https://intellectualsites.com>
4+
* Copyright (C) IntellectualSites team and contributors
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
119
package com.plotsquared.core.commands;
220

321
import cloud.commandframework.CommandManager;

Core/src/main/java/com/plotsquared/core/commands/PlotSquaredCommandMeta.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
* PlotSquared, a land and world management plugin for Minecraft.
3+
* Copyright (C) IntellectualSites <https://intellectualsites.com>
4+
* Copyright (C) IntellectualSites team and contributors
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
119
package com.plotsquared.core.commands;
220

321
import cloud.commandframework.keys.CloudKey;
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* PlotSquared, a land and world management plugin for Minecraft.
3+
* Copyright (C) IntellectualSites <https://intellectualsites.com>
4+
* Copyright (C) IntellectualSites team and contributors
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
package com.plotsquared.core.commands.command.setting.flag;
20+
21+
import cloud.commandframework.Command;
22+
import cloud.commandframework.context.CommandContext;
23+
import cloud.commandframework.keys.CloudKey;
24+
import com.google.inject.Inject;
25+
import com.plotsquared.core.commands.parser.PlotFlagParser;
26+
import com.plotsquared.core.commands.suggestions.FlagValueSuggestionProvider;
27+
import com.plotsquared.core.configuration.caption.CaptionUtility;
28+
import com.plotsquared.core.configuration.caption.TranslatableCaption;
29+
import com.plotsquared.core.events.PlotFlagAddEvent;
30+
import com.plotsquared.core.events.Result;
31+
import com.plotsquared.core.player.PlotPlayer;
32+
import com.plotsquared.core.plot.Plot;
33+
import com.plotsquared.core.plot.flag.FlagParseException;
34+
import com.plotsquared.core.plot.flag.PlotFlag;
35+
import com.plotsquared.core.util.EventDispatcher;
36+
import io.leangen.geantyref.TypeToken;
37+
import net.kyori.adventure.text.Component;
38+
import net.kyori.adventure.text.minimessage.tag.Tag;
39+
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
40+
import org.checkerframework.checker.nullness.qual.NonNull;
41+
42+
import static cloud.commandframework.arguments.standard.StringParser.greedyStringParser;
43+
import static com.plotsquared.core.commands.parser.PlotFlagParser.plotFlagParser;
44+
45+
public final class FlagAddCommand extends FlagCommandBean {
46+
47+
private static final CloudKey<PlotFlag<?, ?>> COMPONENT_FLAG = CloudKey.of("flag", new TypeToken<PlotFlag<?, ?>>() {});
48+
private static final CloudKey<String> COMPONENT_VALUE = CloudKey.of("value", String.class);
49+
50+
private final EventDispatcher eventDispatcher;
51+
52+
@Inject
53+
public FlagAddCommand(final @NonNull EventDispatcher eventDispatcher) {
54+
this.eventDispatcher = eventDispatcher;
55+
}
56+
57+
@Override
58+
protected Command.@NonNull Builder<PlotPlayer<?>> configurePlotCommand(
59+
final Command.@NonNull Builder<PlotPlayer<?>> builder
60+
) {
61+
return builder.literal("add")
62+
.required(COMPONENT_FLAG, plotFlagParser(PlotFlagParser.FlagSource.GLOBAL))
63+
.required(COMPONENT_VALUE, greedyStringParser(), new FlagValueSuggestionProvider(COMPONENT_FLAG));
64+
}
65+
66+
@Override
67+
public void execute(final @NonNull CommandContext<PlotPlayer<?>> commandContext) {
68+
final PlotPlayer<?> player = commandContext.sender();
69+
final Plot plot = commandContext.inject(Plot.class).orElseThrow();
70+
final PlotFlag<?, ?> flag = commandContext.get(COMPONENT_FLAG);
71+
final String flagValue = commandContext.get(COMPONENT_VALUE);
72+
73+
final PlotFlagAddEvent event = this.eventDispatcher.callFlagAdd(flag, plot);
74+
if (event.getEventResult() == Result.DENY) {
75+
player.sendMessage(
76+
TranslatableCaption.of("events.event_denied"),
77+
TagResolver.resolver("value", Tag.inserting(Component.text("Flag set")))
78+
);
79+
return;
80+
}
81+
if (event.getEventResult() != Result.FORCE) {
82+
final String[] split = flagValue.split(",");
83+
for (final String entry : split) {
84+
if (!checkPermValue(player, flag, flag.getName(), entry)) {
85+
return;
86+
}
87+
}
88+
}
89+
90+
final String sanitizedValue = CaptionUtility.stripClickEvents(flag, flagValue);
91+
final PlotFlag<?, ?> parsedFlag;
92+
try {
93+
parsedFlag = flag.parse(flagValue);
94+
} catch (final FlagParseException e) {
95+
player.sendMessage(
96+
TranslatableCaption.of("flag.flag_parse_error"),
97+
TagResolver.builder()
98+
.tag("flag_name", Tag.inserting(Component.text(flag.getName())))
99+
.tag("flag_value", Tag.inserting(Component.text(e.getValue())))
100+
.tag("error", Tag.inserting(e.getErrorMessage().toComponent(player)))
101+
.build()
102+
);
103+
return;
104+
}
105+
106+
final boolean result = plot.setFlag(plot.getFlagContainer().getFlag(flag.getClass()).merge(parsedFlag.getValue()));
107+
if (!result) {
108+
player.sendMessage(TranslatableCaption.of("flag.flag_not_added"));
109+
return;
110+
}
111+
112+
player.sendMessage(
113+
TranslatableCaption.of("flag.flag_added"),
114+
TagResolver.builder()
115+
.tag("flag", Tag.inserting(Component.text(flag.getName())))
116+
.tag("value", Tag.inserting(Component.text(parsedFlag.toString())))
117+
.build()
118+
);
119+
}
120+
}

Core/src/main/java/com/plotsquared/core/commands/command/setting/flag/FlagCommandBean.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
* PlotSquared, a land and world management plugin for Minecraft.
3+
* Copyright (C) IntellectualSites <https://intellectualsites.com>
4+
* Copyright (C) IntellectualSites team and contributors
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
119
package com.plotsquared.core.commands.command.setting.flag;
220

321
import cloud.commandframework.Command;

0 commit comments

Comments
 (0)