Skip to content

Commit

Permalink
feat: Finished base functions
Browse files Browse the repository at this point in the history
  • Loading branch information
CarmJos committed Jan 4, 2024
1 parent 2e2aa65 commit 048ae99
Show file tree
Hide file tree
Showing 11 changed files with 399 additions and 15 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@ see [Dependencies](https://github.com/ArtformGames/TempFlight/network/dependenc

## Commands

The main command is `/TempFlight` or `/tsp`.
The main command is `/TempFlight` or `/TempFly`.

```text
# subcommand <force-arg> <optional-arg>
@ Player command
- Description
# start <player> <time> [teleport-back]
@ Admin command
- Start a temporary flight for a player.
- If "teleport-back" is true, the player will be teleported
- back to the original location after the flight ends.
# stop <player>
@ Admin command
- Stop a temporary flight for a player.
```

Expand All @@ -57,7 +63,7 @@ Will be generated on the first boot up.

## Statistics

[![bStats](https://bstats.org/signatures/bukkit/TemplatePlugin.svg)](https://bstats.org/plugin/bukkit/TemplatePlugin/18946)
[![bStats](https://bstats.org/signatures/bukkit/TempFlight.svg)](https://bstats.org/plugin/bukkit/TempFlight/20647)

## Open Source Licence

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>

<project.package>${project.groupId}.plugin.${project.groupId}</project.package>
<deps.core.version>1.0.0</deps.core.version>
<deps.core.version>1.0.2</deps.core.version>
</properties>
<groupId>com.artformgames</groupId>
<artifactId>tempflight</artifactId>
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/com/artformgames/plugin/tempflight/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.artformgames.core.utils.GHUpdateChecker;
import com.artformgames.plugin.tempflight.conf.PluginConfig;
import com.artformgames.plugin.tempflight.conf.PluginMessages;
import com.artformgames.plugin.tempflight.listener.TempFlyListener;
import com.artformgames.plugin.tempflight.manager.FlightManager;
import org.bstats.bukkit.Metrics;

public class Main extends EasyPlugin {
Expand All @@ -16,10 +18,10 @@ public Main() {
}

protected MineConfiguration configuration;
protected FlightManager flightManager;

@Override
protected void load() {

log("Loading plugin configurations...");
configuration = new MineConfiguration(this);
configuration.initializeConfig(PluginConfig.class);
Expand All @@ -29,14 +31,18 @@ protected void load() {
@Override
protected boolean initialize() {

log("Initialize flight manager...");
this.flightManager = new FlightManager(this);

log("Register listeners...");
registerListener(new TempFlyListener());

log("Register commands...");


if (PluginConfig.METRICS.getNotNull()) {
log("Initializing bStats...");
new Metrics(this, 0);
new Metrics(this, 20647);
}

if (PluginConfig.CHECK_UPDATE.getNotNull()) {
Expand All @@ -53,6 +59,7 @@ protected boolean initialize() {
protected void shutdown() {

log("Shutting down...");
getFlightManager().shutdown();

}

Expand All @@ -77,4 +84,8 @@ public static Main getInstance() {
return instance;
}

public static FlightManager getFlightManager() {
return getInstance().flightManager;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//package com.artformgames.plugin.tempflight.command;
//
//import cc.carm.lib.easysql.api.util.TimeDateUtils;
//import org.bukkit.Bukkit;
//import org.bukkit.command.Command;
//import org.bukkit.command.CommandExecutor;
//import org.bukkit.command.CommandSender;
//import org.bukkit.command.ConsoleCommandSender;
//import org.bukkit.entity.Player;
//import org.jetbrains.annotations.NotNull;
//
//public class TempFlightCommand implements CommandExecutor {
//
// // /tempFlight <Player> <Time> [back]
//
// @Override
// public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
// @NotNull String label, @NotNull String[] args) {
// if (!PluginConfig.TEMP_FLY.ENABLE.getNotNull()) {
// PluginMessages.DISABLED.send(sender);
// return true;
// }
// if (!(sender instanceof ConsoleCommandSender)) {
// sender.sendMessage("该指令只能在控制台使用。");
// return true;
// }
//
// if (args.length < 2) return false;
//
// Player target = Bukkit.getPlayer(args[0]);
// if (target == null) {
// sender.sendMessage("目标玩家不在线。");
// return true;
// }
//
// long time = TimeStringUtils.toMilliSecPlus(args[1]);
// if (time < 0) {
// sender.sendMessage("时间格式错误。");
// return true;
// }
//
// boolean back = true;
// if (args.length > 2) {
// if (args[2].equalsIgnoreCase("0") || args[2].equalsIgnoreCase("false")) {
// back = false;
// } else if (!args[2].equalsIgnoreCase("1") && !args[2].equalsIgnoreCase("true")) {
// sender.sendMessage("参数错误,是否返回可选 true 或 false。");
// return true;
// }
// }
//
// TempFlyData data = UserHandler.get(target, TempFlyData.class);
// if (data == null) {
// sender.sendMessage("玩家暂未加载飞行时间数据,请稍后再试。");
// return true;
// }
//
// if (data.isTempFlying()) {
// sender.sendMessage("玩家正在进行临时飞行,无法再次操作。");
// PluginMessages.FLY.FLYING.send(target, TimeDateUtils.toDHMSStyle(data.getRemainMillis() / 1000));
// return true;
// }
//
// long cooldown = data.getCooldownMillis();
// if (cooldown > 0) {
// sender.sendMessage("玩家的临时飞行时间正在冷却中,请稍后再试。");
// PluginMessages.FLY.COOLING.send(target, TimeDateUtils.toDHMSStyle(cooldown / 1000));
// return true;
// }
//
// if (data.startFly(target, time, back ? target.getLocation() : null)) {
// sender.sendMessage("成功为玩家启用为期 " + (time / 1000) + " 秒的临时飞行。");
// PluginMessages.FLY.ENABLED.send(target, TimeDateUtils.toDHMSStyle(time / 1000));
// if (back) PluginMessages.FLY.WILL_BACK.send(target);
// } else {
// sender.sendMessage("玩家正在进行临时飞行,无法再次操作。");
// }
// return true;
// }
//
//}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.artformgames.plugin.tempflight.command;

import dev.rollczi.litecommands.annotations.argument.Arg;
import dev.rollczi.litecommands.annotations.command.Command;
import dev.rollczi.litecommands.annotations.description.Description;
import dev.rollczi.litecommands.annotations.optional.OptionalArg;
import dev.rollczi.litecommands.annotations.permission.Permission;
import org.bukkit.entity.Player;


@Command(name = "tempflight", aliases = {"tempfly"})
@Description("TempFlight commands")
@Permission("tempflight.admin")
public class TempFlightCommands {

void start(@Arg Player player, @Arg String duration, @OptionalArg Boolean back) {

}

void stop(@Arg Player player) {

}

}
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
package com.artformgames.plugin.tempflight.conf;

import cc.carm.lib.configuration.core.ConfigurationRoot;
import cc.carm.lib.configuration.core.Configuration;
import cc.carm.lib.configuration.core.annotation.HeaderComment;
import cc.carm.lib.configuration.core.value.ConfigValue;
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
import com.artformgames.core.utils.TimeStringUtils;

public class PluginConfig extends ConfigurationRoot {
public interface PluginConfig extends Configuration {

public static final ConfiguredValue<Boolean> DEBUG = ConfiguredValue.of(Boolean.class, false);
ConfiguredValue<Boolean> DEBUG = ConfiguredValue.of(Boolean.class, false);

@HeaderComment({
"Statistics Settings",
"This option is used to help developers count plug-in versions and usage, and it will never affect performance and user experience.",
"Of course, you can also choose to turn it off here for this plugin,",
"or turn it off for all plugins in the configuration file under \"plugins/bStats\"."
})
public static final ConfiguredValue<Boolean> METRICS = ConfiguredValue.of(Boolean.class, true);
ConfiguredValue<Boolean> METRICS = ConfiguredValue.of(Boolean.class, true);

@HeaderComment({
"Check update settings",
"This option is used by the plug-in to determine whether to check for updates.",
"If you do not want the plug-in to check for updates and prompt you, you can choose to close.",
"Checking for updates is an asynchronous operation that will never affect performance and user experience."
})
public static final ConfiguredValue<Boolean> CHECK_UPDATE = ConfiguredValue.of(Boolean.class, true);
ConfiguredValue<Boolean> CHECK_UPDATE = ConfiguredValue.of(Boolean.class, true);

@HeaderComment("The cooldown time for the player to use the flight command, format: 1d,2h,3m,4s")
ConfiguredValue<Long> COOLDOWN = ConfigValue.builder()
.asValue(Long.class).fromString()
.parseValue((v, d) -> TimeStringUtils.toMilliSecPlus(v))
.serializeValue(TimeStringUtils::toTimeString)
.defaults(60000L).build();


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,67 @@
package com.artformgames.plugin.tempflight.conf;

import cc.carm.lib.configuration.core.ConfigurationRoot;
import cc.carm.lib.configuration.core.Configuration;
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageListBuilder;
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageValueBuilder;
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessage;
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessageList;
import de.themoep.minedown.MineDown;
import me.clip.placeholderapi.PlaceholderAPI;
import net.md_5.bungee.api.chat.BaseComponent;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.function.BiFunction;

public interface PluginMessages extends Configuration {
static @NotNull CraftMessageListBuilder<BaseComponent[]> list() {
return ConfiguredMessageList.create(getParser())
.whenSend((sender, message) -> message.forEach(m -> sender.spigot().sendMessage(m)));
}

static @NotNull CraftMessageValueBuilder<BaseComponent[]> value() {
return ConfiguredMessage.create(getParser())
.whenSend((sender, message) -> sender.spigot().sendMessage(message));
}

private static @NotNull BiFunction<CommandSender, String, BaseComponent[]> getParser() {
return (sender, message) -> {
if (sender == null) return MineDown.parse(message);
if (sender instanceof Player player) {
return MineDown.parse(PlaceholderAPI.setPlaceholders(player, message));
} else {
return MineDown.parse(message);
}
};
}

ConfiguredMessageList<BaseComponent[]> COOLING = list()
.defaults("&fYou need to wait for &e%(time) &fseconds before you can use the timed flight again.")
.params("time")
.build();

ConfiguredMessageList<BaseComponent[]> FLYING = list()
.defaults("&fYou have enabled time-limited flying, and the remaining flight time is &e%(time) &fseconds.")
.params("time")
.build();

ConfiguredMessageList<BaseComponent[]> ENABLED = list()
.defaults("&fYou &a&l&Enabled &f for timed flights, and from now on you can fly &e%(time) &fseconds.")
.params("time")
.build();

ConfiguredMessageList<BaseComponent[]> DISABLED = list()
.defaults("&fYour timed flight has ended and your flight status has been automatically turned off.")
.build();

ConfiguredMessageList<BaseComponent[]> MODE_CHANGE = list()
.defaults("&fYou've switched to &eCreative Mode&f, so there's no longer a time limit for flying.")
.build();

ConfiguredMessageList<BaseComponent[]> WILL_BACK = list()
.defaults("&7Note: Teleport back to your current location after the flight is over!")
.build();


public class PluginMessages extends ConfigurationRoot {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.artformgames.plugin.tempflight.listener;

import com.artformgames.core.ArtCore;
import com.artformgames.plugin.tempflight.conf.PluginMessages;
import com.artformgames.plugin.tempflight.user.FlightAccount;
import org.bukkit.GameMode;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerGameModeChangeEvent;

public class TempFlyListener implements Listener {

@EventHandler
public void onModeChange(PlayerGameModeChangeEvent event) {
if (event.getNewGameMode() != GameMode.CREATIVE) return;

FlightAccount data = ArtCore.getHandler(event.getPlayer(), FlightAccount.class);

if (data.isTempFlying()) {
PluginMessages.MODE_CHANGE.send(event.getPlayer());
data.reset();
}

}

}
Loading

0 comments on commit 048ae99

Please sign in to comment.