Skip to content

Commit 307acda

Browse files
committed
ScheduleCommand.kt updated to 1.15.2 forge.
Signed-off-by: Pavel Erokhin (MairwunNx) <MairwunNx@gmail.com>
1 parent 265a315 commit 307acda

File tree

1 file changed

+103
-35
lines changed

1 file changed

+103
-35
lines changed

src/main/kotlin/com/mairwunnx/projectessentials/core/vanilla/commands/ScheduleCommand.kt

Lines changed: 103 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,50 @@
44
* added check on permissions and aliases register.
55
*/
66

7+
@file:Suppress("FunctionName")
8+
79
package com.mairwunnx.projectessentials.core.vanilla.commands
810

911
import com.mairwunnx.projectessentials.core.EntryPoint
1012
import com.mairwunnx.projectessentials.core.helpers.PERMISSION_LEVEL
1113
import com.mairwunnx.projectessentials.core.vanilla.utils.NativeCommandUtils
1214
import com.mojang.brigadier.CommandDispatcher
1315
import com.mojang.brigadier.arguments.IntegerArgumentType
16+
import com.mojang.brigadier.arguments.StringArgumentType
1417
import com.mojang.brigadier.context.CommandContext
1518
import com.mojang.brigadier.exceptions.CommandSyntaxException
19+
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType
1620
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType
21+
import com.mojang.brigadier.suggestion.SuggestionProvider
22+
import com.mojang.brigadier.suggestion.SuggestionsBuilder
1723
import com.mojang.datafixers.util.Either
1824
import net.minecraft.command.*
1925
import net.minecraft.command.arguments.FunctionArgument
2026
import net.minecraft.command.arguments.TimeArgument
27+
import net.minecraft.command.impl.FunctionCommand
2128
import net.minecraft.tags.Tag
2229
import net.minecraft.util.text.Style
2330
import net.minecraft.util.text.TranslationTextComponent
2431
import net.minecraft.util.text.event.HoverEvent
2532
import org.apache.logging.log4j.LogManager
33+
import java.util.function.Function
2634

2735
internal object ScheduleCommand {
2836
private val logger = LogManager.getLogger()
2937

30-
private val field_218913_a = SimpleCommandExceptionType(
31-
TranslationTextComponent("commands.schedule.same_tick")
38+
private val field_218913_a =
39+
SimpleCommandExceptionType(TranslationTextComponent("commands.schedule.same_tick"))
40+
private val field_229811_b_ = DynamicCommandExceptionType(
41+
Function { p_229818_0_: Any? ->
42+
TranslationTextComponent("commands.schedule.cleared.failure", p_229818_0_)
43+
}
3244
)
45+
private val field_229812_c_ =
46+
SuggestionProvider { p_229814_0_: CommandContext<CommandSource>, p_229814_1_: SuggestionsBuilder ->
47+
ISuggestionProvider.suggest(
48+
p_229814_0_.source.world.worldInfo.scheduledEvents.func_227574_a_(), p_229814_1_
49+
)
50+
}
3351

3452
fun register(p_218909_0_: CommandDispatcher<CommandSource>) {
3553
logger.info("Replacing `/schedule` vanilla command")
@@ -43,15 +61,45 @@ internal object ScheduleCommand {
4361
).suggests(FunctionCommand.FUNCTION_SUGGESTER).then(
4462
Commands.argument(
4563
"time", TimeArgument.func_218091_a()
46-
).executes { p_218911_0_: CommandContext<CommandSource> ->
47-
func_218908_a(
48-
p_218911_0_.source,
49-
FunctionArgument.func_218110_b(p_218911_0_, "function"),
50-
IntegerArgumentType.getInteger(p_218911_0_, "time")
64+
).executes { p_229823_0_ ->
65+
func_229816_a_(
66+
p_229823_0_.source,
67+
FunctionArgument.func_218110_b(p_229823_0_, "function"),
68+
IntegerArgumentType.getInteger(p_229823_0_, "time"),
69+
true
5170
)
52-
}
71+
}.then(
72+
Commands.literal("append").executes { p_229822_0_ ->
73+
func_229816_a_(
74+
p_229822_0_.source,
75+
FunctionArgument.func_218110_b(p_229822_0_, "function"),
76+
IntegerArgumentType.getInteger(p_229822_0_, "time"),
77+
false
78+
)
79+
}
80+
).then(
81+
Commands.literal("replace").executes { p_229821_0_ ->
82+
func_229816_a_(
83+
p_229821_0_.source,
84+
FunctionArgument.func_218110_b(p_229821_0_, "function"),
85+
IntegerArgumentType.getInteger(p_229821_0_, "time"),
86+
true
87+
)
88+
}
89+
)
5390
)
5491
)
92+
).then(
93+
Commands.literal("clear").then(
94+
Commands.argument(
95+
"function", StringArgumentType.greedyString()
96+
).suggests(field_229812_c_).executes { p_229813_0_ ->
97+
func_229817_a_(
98+
p_229813_0_.source,
99+
StringArgumentType.getString(p_229813_0_, "function")
100+
)
101+
}
102+
)
55103
)
56104
)
57105
}
@@ -84,52 +132,72 @@ internal object ScheduleCommand {
84132
}
85133
}
86134

87-
@Suppress("FunctionName")
88135
@Throws(CommandSyntaxException::class)
89-
private fun func_218908_a(
90-
p_218908_0_: CommandSource,
91-
p_218908_1_: Either<FunctionObject, Tag<FunctionObject>>,
92-
p_218908_2_: Int
136+
private fun func_229816_a_(
137+
p_229816_0_: CommandSource,
138+
p_229816_1_: Either<FunctionObject, Tag<FunctionObject>>,
139+
p_229816_2_: Int,
140+
p_229816_3_: Boolean
93141
): Int {
94-
checkPermissions(p_218908_0_)
142+
checkPermissions(p_229816_0_)
95143

96-
return if (p_218908_2_ == 0) {
144+
return if (p_229816_2_ == 0) {
97145
throw field_218913_a.create()
98146
} else {
99-
val i = p_218908_0_.world.gameTime + p_218908_2_.toLong()
100-
p_218908_1_.ifLeft { p_218910_4_ ->
101-
val resourcelocation = p_218910_4_.id
102-
p_218908_0_.world.worldInfo.scheduledEvents.scheduleReplaceDuplicate(
103-
resourcelocation.toString(),
104-
i,
105-
TimedFunction(resourcelocation)
106-
)
107-
p_218908_0_.sendFeedback(
147+
val i = p_229816_0_.world.gameTime + p_229816_2_.toLong()
148+
val timercallbackmanager =
149+
p_229816_0_.world.worldInfo.scheduledEvents
150+
151+
p_229816_1_.ifLeft { p_229820_6_ ->
152+
val resourcelocation = p_229820_6_.id
153+
val s = resourcelocation.toString()
154+
if (p_229816_3_) {
155+
timercallbackmanager.func_227575_a_(s)
156+
}
157+
timercallbackmanager.func_227576_a_(s, i, TimedFunction(resourcelocation))
158+
p_229816_0_.sendFeedback(
108159
TranslationTextComponent(
109160
"commands.schedule.created.function",
110161
resourcelocation,
111-
p_218908_2_,
162+
p_229816_2_,
112163
i
113164
), true
114165
)
115-
}.ifRight { p_218907_4_ ->
116-
val resourcelocation = p_218907_4_.id
117-
p_218908_0_.world.worldInfo.scheduledEvents
118-
.scheduleReplaceDuplicate(
119-
"#$resourcelocation",
120-
i,
121-
TimedFunctionTag(resourcelocation)
122-
)
123-
p_218908_0_.sendFeedback(
166+
}.ifRight { p_229819_6_ ->
167+
val resourcelocation = p_229819_6_.id
168+
val s = "#$resourcelocation"
169+
if (p_229816_3_) {
170+
timercallbackmanager.func_227575_a_(s)
171+
}
172+
timercallbackmanager.func_227576_a_(s, i, TimedFunctionTag(resourcelocation))
173+
p_229816_0_.sendFeedback(
124174
TranslationTextComponent(
125175
"commands.schedule.created.tag",
126176
resourcelocation,
127-
p_218908_2_,
177+
p_229816_2_,
128178
i
129179
), true
130180
)
131181
}
132182
Math.floorMod(i, 2147483647L).toInt()
133183
}
134184
}
185+
186+
187+
@Throws(CommandSyntaxException::class)
188+
private fun func_229817_a_(p_229817_0_: CommandSource, p_229817_1_: String): Int {
189+
val i = p_229817_0_.world.worldInfo.scheduledEvents.func_227575_a_(p_229817_1_)
190+
return if (i == 0) {
191+
throw field_229811_b_.create(p_229817_1_)
192+
} else {
193+
p_229817_0_.sendFeedback(
194+
TranslationTextComponent(
195+
"commands.schedule.cleared.success",
196+
i,
197+
p_229817_1_
198+
), true
199+
)
200+
i
201+
}
202+
}
135203
}

0 commit comments

Comments
 (0)