Skip to content

Commit 9c98356

Browse files
committed
Start moving stuff to brig
1 parent 1b7ab7c commit 9c98356

File tree

17 files changed

+470
-215
lines changed

17 files changed

+470
-215
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<dependency>
6565
<groupId>io.papermc.paper</groupId>
6666
<artifactId>paper-api</artifactId>
67-
<version>1.20.2-R0.1-SNAPSHOT</version>
67+
<version>1.21.5-R0.1-SNAPSHOT</version>
6868
<scope>provided</scope>
6969
</dependency>
7070
</dependencies>

src/main/java/simplexity/simplefly/ConfigValues.java

Lines changed: 0 additions & 65 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 simplexity.simplefly;
2+
3+
import net.kyori.adventure.text.minimessage.MiniMessage;
4+
import org.bukkit.NamespacedKey;
5+
6+
public class Constants {
7+
8+
9+
10+
public static final NamespacedKey FLY_STATUS = new NamespacedKey(SimpleFly.getInstance(), "flystatus");
11+
public static final String FLY_PERMISSION = "simplefly.fly";
12+
public static final String FLY_SPEED_PERMISSION = "simplefly.flyspeed";
13+
public static final String FLY_OTHERS_PERMISSION = "simplefly.others.fly";
14+
public static final String FLY_SPEED_OTHERS_PERMISSION = "simplefly.others.flyspeed";
15+
16+
}
Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package simplexity.simplefly;
22

3+
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
34
import org.bukkit.Bukkit;
45
import org.bukkit.NamespacedKey;
56
import org.bukkit.entity.Player;
@@ -11,11 +12,13 @@
1112
import org.bukkit.event.player.PlayerRespawnEvent;
1213
import org.bukkit.persistence.PersistentDataContainer;
1314
import org.bukkit.persistence.PersistentDataType;
15+
import simplexity.simplefly.config.ConfigValues;
16+
import simplexity.simplefly.config.LocaleMessage;
1417

1518
public class FlyListeners implements Listener {
16-
17-
private static final NamespacedKey flyStatus = Util.flyStatus;
18-
19+
20+
private static final NamespacedKey flyStatus = Constants.FLY_STATUS;
21+
1922
@EventHandler
2023
public void onPlayerLogin(PlayerJoinEvent joinEvent) {
2124
if (!ConfigValues.sessionPersistentFlight) {
@@ -25,45 +28,40 @@ public void onPlayerLogin(PlayerJoinEvent joinEvent) {
2528
PersistentDataContainer playerPDC = player.getPersistentDataContainer();
2629
Bukkit.getScheduler().runTaskLater(SimpleFly.getInstance(), () -> {
2730
boolean flyEnabled = playerPDC.getOrDefault(flyStatus, PersistentDataType.BOOLEAN, false);
28-
if (flyEnabled && player.hasPermission(Util.flyPermission)) {
29-
player.setAllowFlight(true);
30-
if (player.getFallDistance() > 0f) {
31-
player.setFlying(true);
32-
}
33-
Util.sendUserMessage(player, ConfigValues.flySetOwn, ConfigValues.enabled, null);
31+
if (flyEnabled && player.hasPermission(Constants.FLY_PERMISSION)) {
32+
FlyLogic.flyEnable(player);
33+
player.sendRichMessage(LocaleMessage.FLY_SET_OWN.getMessage(),
34+
Placeholder.parsed("value", LocaleMessage.ENABLED.getMessage()));
3435
return;
3536
}
36-
if (flyEnabled && !player.hasPermission(Util.flyPermission)) {
37-
playerPDC.set(flyStatus, PersistentDataType.BOOLEAN, false);
37+
if (flyEnabled && !player.hasPermission(Constants.FLY_PERMISSION)) {
38+
FlyLogic.flyDisable(player);
3839
}
3940
}, 10);
4041
}
41-
42+
4243
@EventHandler
4344
public void onWorldChange(PlayerChangedWorldEvent worldEvent) {
4445
if (!ConfigValues.worldChangePersistentFlight) return;
4546
Player player = worldEvent.getPlayer();
4647
PersistentDataContainer playerPDC = player.getPersistentDataContainer();
4748
Boolean flyEnabled = playerPDC.getOrDefault(flyStatus, PersistentDataType.BOOLEAN, false);
4849
if (flyEnabled) {
49-
player.setAllowFlight(true);
50-
if (player.getFallDistance() > 0f) {
51-
player.setFlying(true);
52-
}
50+
FlyLogic.flyEnable(player);
5351
}
5452
}
55-
53+
5654
@EventHandler
5755
public void onRespawn(PlayerRespawnEvent respawnEvent) {
5856
if (!ConfigValues.respawnPersistentFlight) return;
5957
Player player = respawnEvent.getPlayer();
6058
PersistentDataContainer playerPDC = player.getPersistentDataContainer();
6159
Boolean flyEnabled = playerPDC.getOrDefault(flyStatus, PersistentDataType.BOOLEAN, false);
6260
if (flyEnabled) {
63-
player.setAllowFlight(true);
61+
FlyLogic.flyEnable(player);
6462
}
6563
}
66-
64+
6765
@EventHandler
6866
public void onGamemodeChange(PlayerGameModeChangeEvent gameModeChangeEvent) {
6967
if (!ConfigValues.gamemodeChangePersistentFlight) return;
@@ -72,13 +70,9 @@ public void onGamemodeChange(PlayerGameModeChangeEvent gameModeChangeEvent) {
7270
Bukkit.getScheduler().runTaskLater(SimpleFly.getInstance(), () -> {
7371
Boolean flyEnabled = playerPDC.getOrDefault(flyStatus, PersistentDataType.BOOLEAN, false);
7472
if (flyEnabled) {
75-
player.setAllowFlight(true);
76-
if (player.getFallDistance() > 0f) {
77-
player.setFlying(true);
78-
}
73+
FlyLogic.flyEnable(player);
7974
}
8075
}, 10);
8176
}
82-
83-
77+
8478
}
Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,50 @@
11
package simplexity.simplefly;
22

3+
import org.bukkit.Location;
34
import org.bukkit.NamespacedKey;
5+
import org.bukkit.block.Block;
46
import org.bukkit.entity.Player;
57
import org.bukkit.persistence.PersistentDataContainer;
68
import org.bukkit.persistence.PersistentDataType;
79

810
public class FlyLogic {
911

10-
private static final NamespacedKey flyStatus = Util.flyStatus;
12+
private static final NamespacedKey flyStatus = Constants.FLY_STATUS;
1113

12-
public static boolean flyEnabled(Player player) {
14+
public static boolean flyToggle(Player player) {
1315
PersistentDataContainer playerPDC = player.getPersistentDataContainer();
1416
Boolean flyState = playerPDC.get(flyStatus, PersistentDataType.BOOLEAN);
15-
//If they have no set flystate, or it's off, set true, set flying
1617
if (flyState == null || !flyState) {
17-
playerPDC.set(flyStatus, PersistentDataType.BOOLEAN, true);
18-
player.setAllowFlight(true);
19-
player.setFlying(true);
18+
flyEnable(player);
2019
return true;
2120
}
22-
//If their current flystate is on, set false
23-
playerPDC.set(flyStatus, PersistentDataType.BOOLEAN, false);
21+
flyDisable(player);
22+
return false;
23+
}
24+
25+
public static void setFlyStatus(Player player, boolean enable){
26+
if (enable && willFall(player)) player.setFlying(true);
27+
player.getPersistentDataContainer().set(flyStatus, PersistentDataType.BOOLEAN, enable);
28+
player.setAllowFlight(enable);
29+
}
30+
public static void flyEnable(Player player) {
31+
player.getPersistentDataContainer().set(flyStatus, PersistentDataType.BOOLEAN, true);
32+
player.setAllowFlight(true);
33+
if (willFall(player)) {
34+
player.setFlying(true);
35+
}
36+
}
37+
38+
public static void flyDisable(Player player){
39+
player.getPersistentDataContainer().set(flyStatus, PersistentDataType.BOOLEAN, false);
2440
player.setAllowFlight(false);
2541
player.setFlying(false);
26-
return false;
42+
}
43+
44+
private static boolean willFall(Player player){
45+
Location location = player.getLocation();
46+
Block blockBelow = location.clone().add(0, -1, 0).getBlock();
47+
Block blockTwoBelow = location.clone().add(0, -2, 0).getBlock();
48+
return blockBelow.isPassable() && blockTwoBelow.isPassable();
2749
}
2850
}

src/main/java/simplexity/simplefly/SimpleFly.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package simplexity.simplefly;
22

3+
import io.papermc.paper.plugin.lifecycle.event.LifecycleEvent;
4+
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
35
import net.kyori.adventure.text.minimessage.MiniMessage;
46
import org.bukkit.Server;
57
import org.bukkit.plugin.java.JavaPlugin;
68
import simplexity.simplefly.commands.Fly;
79
import simplexity.simplefly.commands.FlyReload;
810
import simplexity.simplefly.commands.FlySpeed;
11+
import simplexity.simplefly.config.ConfigValues;
912

1013
public final class SimpleFly extends JavaPlugin {
1114

@@ -33,8 +36,9 @@ public void onEnable() {
3336
this.saveDefaultConfig();
3437
ConfigValues.reloadConfigValues();
3538
this.getServer().getPluginManager().registerEvents(new simplexity.simplefly.FlyListeners(), this);
36-
this.getCommand("fly").setExecutor(new Fly());
37-
this.getCommand("flyspeed").setExecutor(new FlySpeed());
39+
this.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, commands -> {
40+
commands.registrar().register(Fly.createCommand().build());
41+
});
3842
this.getCommand("flyreload").setExecutor(new FlyReload());
3943
}
4044

src/main/java/simplexity/simplefly/Util.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,17 @@
33
import net.kyori.adventure.text.Component;
44
import net.kyori.adventure.text.minimessage.MiniMessage;
55
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
6-
import org.bukkit.NamespacedKey;
76
import org.bukkit.command.CommandSender;
87

98
public class Util {
10-
9+
1110
private static final MiniMessage miniMessage = SimpleFly.getMiniMessage();
12-
13-
public static final NamespacedKey flyStatus = new NamespacedKey(SimpleFly.getInstance(), "flystatus");
14-
public static final String flyPermission = "simplefly.fly";
15-
public static final String flySpeedPermission = "simplefly.flyspeed";
16-
public static final String flyOthersPermission = "simplefly.others.fly";
17-
public static final String flySpeedOthersPermission = "simplefly.others.flyspeed";
18-
11+
1912
public static void sendUserMessage(CommandSender sender, String message) {
2013
if (message.isEmpty()) return;
2114
sender.sendMessage(miniMessage.deserialize(message));
2215
}
23-
16+
2417
public static void sendUserMessage(CommandSender userToSendTo, String message,
2518
String value, CommandSender userToParse) {
2619
if (message.isEmpty()) return;

src/main/java/simplexity/simplefly/commands/CommandUtils.java

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package simplexity.simplefly.commands;
2+
3+
import com.mojang.brigadier.Message;
4+
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
5+
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
6+
import io.papermc.paper.command.brigadier.MessageComponentSerializer;
7+
import net.kyori.adventure.text.minimessage.MiniMessage;
8+
import simplexity.simplefly.SimpleFly;
9+
import simplexity.simplefly.config.LocaleMessage;
10+
11+
public class Exceptions {
12+
private static final MiniMessage miniMessage = SimpleFly.getMiniMessage();
13+
14+
public static final SimpleCommandExceptionType ERROR_MUST_BE_PLAYER = new SimpleCommandExceptionType(
15+
parseMessage(LocaleMessage.ERROR_MUST_BE_PLAYER));
16+
17+
public static final SimpleCommandExceptionType NO_USERS_FOUND = new SimpleCommandExceptionType(
18+
parseMessage(LocaleMessage.ERROR_INVALID_PLAYER));
19+
20+
public static final SimpleCommandExceptionType MUST_SPECIFY_FLY_STATE = new SimpleCommandExceptionType(
21+
parseMessage(LocaleMessage.ERROR_MUST_PROVIDE_STATE)
22+
);
23+
24+
25+
private static Message parseMessage(LocaleMessage message) {
26+
return MessageComponentSerializer.message().serialize(
27+
miniMessage.deserialize(message.getMessage())
28+
);
29+
}
30+
}

0 commit comments

Comments
 (0)