Skip to content

Commit e9fe13f

Browse files
Jakubk15vLuckyyy
andauthored
GH-994 Add lightning command (#1076)
* Add lightning command, move Catboy feature to troll package * Change @context annotation to @sender, remove misleading shortcut, move catboy to separate package, change interface name * Add executor to LightningCommand for target player * Make LightningCommand package-private * Review. --------- Co-authored-by: vLuckyyy <[email protected]>
1 parent 81cd9a6 commit e9fe13f

File tree

9 files changed

+103
-30
lines changed

9 files changed

+103
-30
lines changed

eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/PluginConfiguration.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
import com.eternalcode.core.database.DatabaseType;
66
import com.eternalcode.core.feature.afk.AfkSettings;
77
import com.eternalcode.core.feature.automessage.AutoMessageSettings;
8-
import com.eternalcode.core.feature.catboy.CatBoySettings;
8+
import com.eternalcode.core.feature.catboy.CatboyConfig;
99
import com.eternalcode.core.feature.chat.ChatSettings;
1010
import com.eternalcode.core.feature.helpop.HelpOpSettings;
1111
import com.eternalcode.core.feature.jail.JailSettings;
12+
import com.eternalcode.core.feature.lightning.LightningConfig;
1213
import com.eternalcode.core.feature.randomteleport.RandomTeleportSettingsImpl;
1314
import com.eternalcode.core.feature.serverlinks.ServerLinksConfig;
1415
import com.eternalcode.core.feature.spawn.SpawnSettings;
@@ -391,21 +392,12 @@ public Set<String> allowedCommands() {
391392
}
392393

393394
@Bean
394-
@Comment({ " ", "# 4fun Section" })
395-
FunSection fun = new FunSection();
395+
@Comment({ " ", "# Settings for catboy feature" })
396+
public CatboyConfig catboy = new CatboyConfig();
396397

397-
public static class FunSection extends OkaeriConfig implements CatBoySettings {
398-
@Comment({
399-
"# Speed of player walk speed while using /catboy feature",
400-
"# Default minecraft walk speed is 0.2"
401-
})
402-
public float catboyWalkSpeed = 0.4F;
403-
404-
@Override
405-
public float getCatboyWalkSpeed() {
406-
return this.catboyWalkSpeed;
407-
}
408-
}
398+
@Bean
399+
@Comment({ " ", "# Settings for lightning strike" })
400+
public LightningConfig lightning = new LightningConfig();
409401

410402
@Bean
411403
@Comment({ " ", "# ServerLinks Section" })

eternalcore-core/src/main/java/com/eternalcode/core/feature/catboy/CatBoySettings.java

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.eternalcode.core.feature.catboy;
2+
3+
import eu.okaeri.configs.OkaeriConfig;
4+
import eu.okaeri.configs.annotation.Comment;
5+
import lombok.Getter;
6+
import lombok.experimental.Accessors;
7+
8+
@Getter
9+
@Accessors(fluent = true)
10+
public class CatboyConfig extends OkaeriConfig implements CatboySettings {
11+
@Comment({
12+
"# Speed of player walk speed while using /catboy feature",
13+
"# Default minecraft walk speed is 0.2"
14+
})
15+
public float catboyWalkSpeed = 0.4F;
16+
}

eternalcore-core/src/main/java/com/eternalcode/core/feature/catboy/CatboyController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import com.eternalcode.core.injector.annotations.component.Controller;
88
import com.eternalcode.core.publish.Subscribe;
99
import com.eternalcode.core.publish.event.EternalShutdownEvent;
10-
import java.time.Duration;
11-
import java.util.Optional;
1210
import org.bukkit.Server;
1311
import org.bukkit.Sound;
1412
import org.bukkit.World;
@@ -21,6 +19,9 @@
2119
import org.bukkit.event.entity.EntityDismountEvent;
2220
import org.bukkit.event.player.PlayerQuitEvent;
2321

22+
import java.time.Duration;
23+
import java.util.Optional;
24+
2425
@Controller
2526
class CatboyController implements Listener {
2627

eternalcore-core/src/main/java/com/eternalcode/core/feature/catboy/CatboyServiceImpl.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
import com.eternalcode.core.feature.catboy.event.CatboySwitchEvent;
77
import com.eternalcode.core.injector.annotations.Inject;
88
import com.eternalcode.core.injector.annotations.component.Service;
9+
import org.bukkit.entity.Cat;
10+
import org.bukkit.entity.Player;
11+
912
import java.util.Collection;
1013
import java.util.Collections;
1114
import java.util.HashMap;
1215
import java.util.Map;
1316
import java.util.Optional;
1417
import java.util.UUID;
15-
import org.bukkit.entity.Cat;
16-
import org.bukkit.entity.Player;
1718

1819
@Service
1920
class CatboyServiceImpl implements CatboyService {
@@ -23,19 +24,19 @@ class CatboyServiceImpl implements CatboyService {
2324
private final EventCaller eventCaller;
2425

2526
private final CatBoyEntityService catBoyEntityService;
26-
private final CatBoySettings catBoySettings;
27+
private final CatboySettings catboySettings;
2728
private final MinecraftScheduler scheduler;
2829

2930
@Inject
3031
CatboyServiceImpl(
3132
EventCaller eventCaller,
3233
CatBoyEntityService catBoyEntityService,
33-
CatBoySettings catBoySettings,
34+
CatboySettings catboySettings,
3435
MinecraftScheduler scheduler
3536
) {
3637
this.eventCaller = eventCaller;
3738
this.catBoyEntityService = catBoyEntityService;
38-
this.catBoySettings = catBoySettings;
39+
this.catboySettings = catboySettings;
3940
this.scheduler = scheduler;
4041
}
4142

@@ -46,7 +47,7 @@ public void markAsCatboy(Player player, Cat.Type type) {
4647

4748
Cat cat = this.catBoyEntityService.createCatboyEntity(player, type);
4849
player.addPassenger(cat);
49-
player.setWalkSpeed(this.catBoySettings.getCatboyWalkSpeed());
50+
player.setWalkSpeed(this.catboySettings.catboyWalkSpeed());
5051
this.eventCaller.callEvent(new CatboySwitchEvent(player, true));
5152
}
5253

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.eternalcode.core.feature.catboy;
2+
3+
public interface CatboySettings {
4+
5+
float catboyWalkSpeed();
6+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.eternalcode.core.feature.lightning;
2+
3+
import com.eternalcode.core.injector.annotations.Inject;
4+
import dev.rollczi.litecommands.annotations.argument.Arg;
5+
import dev.rollczi.litecommands.annotations.command.Command;
6+
import dev.rollczi.litecommands.annotations.context.Sender;
7+
import dev.rollczi.litecommands.annotations.execute.Execute;
8+
import dev.rollczi.litecommands.annotations.permission.Permission;
9+
import org.bukkit.block.Block;
10+
import org.bukkit.entity.Player;
11+
12+
@Command(name = "lightning", aliases = { "strike" })
13+
@Permission("eternalcore.lightning")
14+
class LightningCommand {
15+
16+
private final LightningSettings settings;
17+
18+
@Inject
19+
public LightningCommand(LightningSettings settings) {
20+
this.settings = settings;
21+
}
22+
23+
@Execute
24+
void execute(@Sender Player player) {
25+
Block block = player.getTargetBlockExact(this.settings.maxLightningBlockDistance());
26+
if (block == null) {
27+
if (this.settings.lightningStrikePlayerIfNoBlock()) {
28+
player.getWorld().strikeLightning(player.getLocation());
29+
return;
30+
}
31+
return;
32+
}
33+
block.getWorld().strikeLightning(block.getLocation());
34+
}
35+
36+
@Execute
37+
void player(@Sender Player sender, @Arg Player target) {
38+
target.getWorld().strikeLightning(sender.getLocation());
39+
}
40+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.eternalcode.core.feature.lightning;
2+
3+
import eu.okaeri.configs.OkaeriConfig;
4+
import eu.okaeri.configs.annotation.Comment;
5+
import lombok.Getter;
6+
import lombok.experimental.Accessors;
7+
8+
@Getter
9+
@Accessors(fluent = true)
10+
public class LightningConfig extends OkaeriConfig implements LightningSettings {
11+
@Comment({" ", "# Maximum distance for the lightning strike block when using /lightning."})
12+
@Comment("# If you will look at a block that is further than this distance, the lightning will strike at the player.")
13+
public int maxLightningBlockDistance = 100;
14+
15+
@Comment({" ", "# If there is no block in the range of lightning strike, should the lightning strike the player?"})
16+
public boolean lightningStrikePlayerIfNoBlock = true;
17+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.eternalcode.core.feature.lightning;
2+
3+
public interface LightningSettings {
4+
5+
int maxLightningBlockDistance();
6+
boolean lightningStrikePlayerIfNoBlock();
7+
}

0 commit comments

Comments
 (0)