generated from ArtformGames/TemplateSinglePlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
399 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/main/java/com/artformgames/plugin/tempflight/command/TempFlightCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
// } | ||
// | ||
//} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/artformgames/plugin/tempflight/command/TempFlightCommands.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
|
||
} | ||
|
||
} |
20 changes: 15 additions & 5 deletions
20
src/main/java/com/artformgames/plugin/tempflight/conf/PluginConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
|
||
} |
65 changes: 63 additions & 2 deletions
65
src/main/java/com/artformgames/plugin/tempflight/conf/PluginMessages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/artformgames/plugin/tempflight/listener/TempFlyListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.