Skip to content

Commit f83a3d0

Browse files
authored
v1.0.6 (#4)
* v1.0.6: 65% progress * Fixed vanilla recipes being removed onDisable * Cooldown after player use `/su info` * Fixed other plugins' recipes being removed onDisable * yaml selection * Update to Spigot 1.18.2
1 parent 904fa59 commit f83a3d0

File tree

15 files changed

+200
-52
lines changed

15 files changed

+200
-52
lines changed

.vscode/settings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"git.autofetch": true,
3+
"git.confirmSync": false,
4+
"files.autoSave": "afterDelay",
5+
"files.autoSaveDelay": 1000,
6+
"editor.formatOnType":true,
7+
"java.configuration.updateBuildConfiguration": "automatic",
8+
"yaml.schemas": {
9+
"https://json.schemastore.org/bukkit-plugin.json": "file:///src/main/resources/plugin.yml"
10+
}
11+
}

.vscode/tasks.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "build",
8+
"type": "shell",
9+
"command": "mvn -B clean verify",
10+
"group": "build"
11+
},
12+
{
13+
"label": "test",
14+
"type": "shell",
15+
"command": "mvn -B test",
16+
"group": "test"
17+
}
18+
]
19+
}

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ Main functions:<br>
1212
- Record player's first-join time and monthly online time.
1313
- Record the server's monthly players.
1414
![](https://cdn.jsdelivr.net/gh/katorly/Gallery001/plugins/2022-01-20_14.52.png)
15+
- Players can check their first-join time and total online time.
16+
- Players can check their current gaming status.
1517
- Conveniently manage player's flying permission.
1618
- Displays the help document when player excutes `/help`.
19+
- Forces server to delay shutdown progress and inform players (including players who just joined) that the server is going to shutdown when `/stop`, `/restart` or `/reload` being excuted.
1720
- Modifys colored concretes' recipe into the following **shapeless** recipe:
1821
![](https://cdn.jsdelivr.net/gh/katorly/Gallery001/plugins/2022_03_11_11.28.30.PNG)
1922

@@ -29,9 +32,12 @@ For server OPs,
2932
## Config
3033
### config.yml
3134
```yml
35+
# The help document URL you want to display.
3236
help-document: "https://star-lin.feishu.cn/docs/doccnow2uz3RoK28RKLJleq0Qug"
37+
# Delay (minutes) before server shutting down.
38+
server-close-countdown: 10
3339
```
34-
The document URL you want to display.
40+
3541
3642
### timedata.yml
3743
```yml

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<artifactId>StarlinUtils</artifactId>
66
<groupId>com.github.katorly</groupId>
7-
<version>1.0.5</version>
7+
<version>1.0.6</version>
88

99
<!-- Repositories -->
1010
<repositories>
@@ -20,7 +20,7 @@
2020
<dependency>
2121
<groupId>org.spigotmc</groupId>
2222
<artifactId>spigot-api</artifactId>
23-
<version>1.18.1-R0.1-SNAPSHOT</version>
23+
<version>1.18.2-R0.1-SNAPSHOT</version>
2424
<type>jar</type>
2525
<scope>provided</scope>
2626
</dependency>
@@ -33,8 +33,8 @@
3333
<artifactId>maven-compiler-plugin</artifactId>
3434
<version>3.8.1</version>
3535
<configuration>
36-
<source>1.7</source>
37-
<target>1.7</target>
36+
<source>1.8</source>
37+
<target>1.8</target>
3838
</configuration>
3939
</plugin>
4040
</plugins>

src/main/java/com/github/katorly/starlinutils/EventListener.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
import java.text.SimpleDateFormat;
55
import java.util.ArrayList;
66
import java.util.List;
7+
import java.util.Objects;
78

89
import com.github.katorly.starlinutils.backup.ConfigReader;
910
import com.github.katorly.starlinutils.backup.Messager;
11+
import com.github.katorly.starlinutils.utils.CloseServer;
1012
import com.github.katorly.starlinutils.utils.PlayTime;
1113

14+
import org.bukkit.Bukkit;
1215
import org.bukkit.Location;
1316
import org.bukkit.Material;
1417
import org.bukkit.World;
@@ -17,16 +20,22 @@
1720
import org.bukkit.event.EventHandler;
1821
import org.bukkit.event.Listener;
1922
import org.bukkit.event.block.Action;
23+
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
2024
import org.bukkit.event.player.PlayerInteractEvent;
2125
import org.bukkit.event.player.PlayerJoinEvent;
2226
import org.bukkit.event.player.PlayerQuitEvent;
27+
import org.bukkit.event.server.ServerCommandEvent;
2328
import org.bukkit.scheduler.BukkitRunnable;
2429

2530
public class EventListener implements Listener {
2631

2732
@EventHandler
2833
public void onPlayerJoin(PlayerJoinEvent e) throws ParseException {
2934

35+
if (StarlinUtils.serverClosing) { //Check whether server is going to close.
36+
Messager.sendTitle(e.getPlayer(), "&b&l服务器即将重启", "&7请保管好个人物品!");
37+
}
38+
3039
PlayTime.initialize(e.getPlayer()); //Get player's join time and check whether player has joined before.
3140

3241
long t = System.currentTimeMillis();
@@ -86,4 +95,28 @@ public void onCropTrample(PlayerInteractEvent e) {
8695
e.setCancelled(true);
8796
}
8897
}
98+
99+
@EventHandler
100+
public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
101+
if (Objects.equals(e.getMessage(), "/help") && !e.getPlayer().isOp()) { //Displays the help document when player excutes "/help".
102+
e.setCancelled(true);
103+
FileConfiguration config = StarlinUtils.config.getConfig();
104+
Messager.senderMessage(e.getPlayer(), "&b&l星林宇宙 &r&8>> &7新手指南: &f" + config.getString("help-document"));
105+
} else if (Objects.equals(e.getMessage(), "/stop") || Objects.equals(e.getMessage(), "/reload") || Objects.equals(e.getMessage(), "/restart")) {
106+
if (e.getPlayer().isOp()) {
107+
e.setCancelled(true);
108+
CloseServer.close();
109+
}
110+
}
111+
}
112+
113+
@EventHandler
114+
public void onConsoleCommand(ServerCommandEvent e) {
115+
if (Objects.equals(e.getCommand(), "stop") || Objects.equals(e.getCommand(), "reload") || Objects.equals(e.getCommand(), "restart")) {
116+
e.setCancelled(true);
117+
CloseServer.close();
118+
FileConfiguration config = StarlinUtils.config.getConfig();
119+
Bukkit.getLogger().info("[StarlinUtils] 已执行重启命令. 还有" + config.getInt("server-close-countdown") + "秒重启.");
120+
}
121+
}
89122
}

src/main/java/com/github/katorly/starlinutils/Recipe.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ public static void registerConcreteRecipe() { //Add colored concrete recipe onEn
2727
}
2828

2929
public static void concreteRecipe(Material concrete, Material dye) { //8*colored concrete = 1*dye + 8*stones.
30-
ShapelessRecipe concreteRecipe = new ShapelessRecipe(new NamespacedKey(StarlinUtils.INSTANCE, concrete.toString() + "_recipe"), new ItemStack(concrete, 8));
30+
ShapelessRecipe concreteRecipe = new ShapelessRecipe(new NamespacedKey(StarlinUtils.INSTANCE, concrete.toString() + "_starlin_recipe"), new ItemStack(concrete, 8));
3131
concreteRecipe = concreteRecipe.addIngredient(1, dye).addIngredient(8, Material.STONE);
3232
Bukkit.addRecipe(concreteRecipe);
33+
StarlinUtils.INSTANCE.recipeKeys.add(concreteRecipe.getKey());
3334
}
3435
}

src/main/java/com/github/katorly/starlinutils/StarlinUtils.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.github.katorly.starlinutils;
22

33
import java.text.ParseException;
4+
import java.util.ArrayList;
45
import java.util.HashMap;
6+
import java.util.List;
57
import java.util.Map;
68
import java.util.UUID;
79

@@ -11,6 +13,7 @@
1113
import com.github.katorly.starlinutils.utils.PlayTime;
1214

1315
import org.bukkit.Bukkit;
16+
import org.bukkit.NamespacedKey;
1417
import org.bukkit.entity.Player;
1518
import org.bukkit.event.HandlerList;
1619
import org.bukkit.plugin.java.JavaPlugin;
@@ -25,24 +28,27 @@ public StarlinUtils() {
2528
public static ConfigReader timedata;
2629
public static ConfigReader monthly;
2730
public Map<UUID, Long> StartTime = new HashMap<>();
31+
public static boolean serverClosing = false;
32+
public final List<NamespacedKey> recipeKeys = new ArrayList<>();
2833

2934
@Override
3035
public void onEnable() {
3136
getServer().getPluginManager().registerEvents(new EventListener(),this);
3237
getServer().getPluginManager().registerEvents(new AprilFools(),this);
3338
config = new ConfigReader(this,"","config.yml");
3439
config.saveDefaultConfig();
35-
timedata = new ConfigReader(this,"","timedata.yml");
36-
monthly = new ConfigReader(this,"","monthly.yml");
40+
timedata = new ConfigReader(this, "", "timedata.yml");
41+
timedata.saveDefaultConfig();
42+
monthly = new ConfigReader(this, "", "monthly.yml");
43+
monthly.saveDefaultConfig();
3744
Bukkit.getPluginCommand("su").setExecutor(new su());
3845
Bukkit.getPluginCommand("su").setTabCompleter(new su());
39-
Bukkit.getPluginCommand("help").setExecutor(new help());
4046
Bukkit.getPluginCommand("givefly").setExecutor(new givefly());
4147
Bukkit.getPluginCommand("givefly").setTabCompleter(new givefly());
4248
Bukkit.getPluginCommand("listfly").setExecutor(new listfly());
4349
Bukkit.getPluginCommand("delfly").setExecutor(new delfly());
4450
Bukkit.getPluginCommand("delfly").setTabCompleter(new delfly());
45-
Recipe.registerConcreteRecipe(); //Add colored concrete
51+
Recipe.registerConcreteRecipe(); //Add colored concrete recipe
4652
Bukkit.getLogger().info("[StarlinUtils] Repo: https://github.com/katorlys/StarlinUtils");
4753
Bukkit.getLogger().info("[StarlinUtils] StarlinUtils enabled! Made for StarlinWorld server only.");
4854
for (Player p : Bukkit.getOnlinePlayers()) {
@@ -65,11 +71,12 @@ public void onDisable() {
6571
e.printStackTrace();
6672
}
6773
}
68-
Bukkit.clearRecipes();
74+
recipeKeys.forEach(Bukkit::removeRecipe);
75+
recipeKeys.clear();
6976
HandlerList.unregisterAll(this);
70-
ConfigReader.save(config);
71-
ConfigReader.save(timedata);
72-
ConfigReader.save(monthly);
77+
config.reloadConfig();
78+
timedata.reloadConfig();
79+
monthly.reloadConfig();
7380
Bukkit.getLogger().info("[StarlinUtils] StarlinUtils disabled!");
7481
}
7582
}

src/main/java/com/github/katorly/starlinutils/backup/ConfigReader.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,22 @@ public void saveDefaultConfig() {
3939
public FileConfiguration getConfig() {
4040
if (!filepath.exists())
4141
this.saveDefaultConfig();
42+
if (!file.exists())
43+
this.saveDefaultConfig();
4244
if (config == null)
4345
this.reloadConfig();
4446
return config;
4547
}
4648

4749
/**
48-
* Reload the config. This will remove all the comments in it.
50+
* Reload the config.
4951
*
5052
*/
5153
public void reloadConfig() {
54+
if (!filepath.exists())
55+
this.saveDefaultConfig();
56+
if (!file.exists())
57+
this.saveDefaultConfig();
5258
if (filepath == null)
5359
filepath = new File(plugin.getDataFolder(), path);
5460
if (file == null)
@@ -62,12 +68,14 @@ public void reloadConfig() {
6268
}
6369

6470
/**
65-
* Save the config to apply changes.
71+
* Save the config to apply changes. This will remove all the comments in it.
6672
*
6773
*/
6874
public void saveConfig() {
6975
if (!filepath.exists())
7076
this.saveDefaultConfig();
77+
if (!file.exists())
78+
this.saveDefaultConfig();
7179
try {
7280
config.save(file);
7381
} catch (Throwable t) {

src/main/java/com/github/katorly/starlinutils/commands/help.java

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/main/java/com/github/katorly/starlinutils/commands/su.java

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.ArrayList;
44
import java.util.List;
55
import java.util.Objects;
6+
import java.util.UUID;
67

78
import com.github.katorly.starlinutils.StarlinUtils;
89
import com.github.katorly.starlinutils.backup.Messager;
@@ -13,8 +14,11 @@
1314
import org.bukkit.command.TabExecutor;
1415
import org.bukkit.configuration.file.FileConfiguration;
1516
import org.bukkit.entity.Player;
17+
import org.bukkit.scheduler.BukkitRunnable;
1618

1719
public class su implements TabExecutor {
20+
public List<UUID> suCooldown = new ArrayList<>();
21+
1822
@Override
1923
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
2024
FileConfiguration timedata = StarlinUtils.timedata.getConfig();
@@ -70,17 +74,29 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
7074
if (!(sender instanceof Player)) {
7175
Messager.senderMessage(sender, "&b&l星林宇宙 &r&8>> &7只有玩家才能查看自己的游戏状态!");
7276
} else {
73-
Player p= (Player) sender;
74-
Messager.senderMessage(p, "&b&l星林宇宙 &r&8>> &7您当前的游戏状态:");
75-
Messager.senderMessage(p, " &7游戏ID: &f" + p.getName());
76-
Messager.senderMessage(p, " &7UUID: &f" + p.getUniqueId());
77-
Messager.senderMessage(p, " &7生命值: &f" + p.getHealth());
78-
Messager.senderMessage(p, " &7饱食度: &f" + p.getFoodLevel());
79-
Messager.senderMessage(p, " &7经验等级: &f" + p.getLevel());
80-
Messager.senderMessage(p, " &7游戏模式: &f" + p.getGameMode());
81-
Messager.senderMessage(p, " &7面朝: &f" + p.getFacing());
82-
Messager.senderMessage(p, " &7当前位置: &f" + p.getWorld().getName() + ", " + String.format("%.2f", p.getLocation().getX()) + ", " + String.format("%.2f", p.getLocation().getY()) + ", " + String.format("%.2f", p.getLocation().getZ()));
83-
Messager.senderMessage(p, " &7延迟: &f" + p.getPing() + "ms");
77+
final Player p= (Player) sender;
78+
if (!suCooldown.contains(p.getUniqueId())) {
79+
Messager.senderMessage(p, "&b&l星林宇宙 &r&8>> &7您当前的游戏状态:");
80+
Messager.senderMessage(p, " &7游戏ID: &f" + p.getName());
81+
Messager.senderMessage(p, " &7UUID: &f" + p.getUniqueId());
82+
Messager.senderMessage(p, " &7生命值: &f" + p.getHealth());
83+
Messager.senderMessage(p, " &7饱食度: &f" + p.getFoodLevel());
84+
Messager.senderMessage(p, " &7经验等级: &f" + p.getLevel());
85+
Messager.senderMessage(p, " &7游戏模式: &f" + p.getGameMode());
86+
Messager.senderMessage(p, " &7面朝: &f" + p.getFacing());
87+
Messager.senderMessage(p, " &7当前位置: &f" + p.getWorld().getName() + ", " + String.format("%.2f", p.getLocation().getX()) + ", " + String.format("%.2f", p.getLocation().getY()) + ", " + String.format("%.2f", p.getLocation().getZ()));
88+
Messager.senderMessage(p, " &7延迟: &f" + p.getPing() + "ms");
89+
suCooldown.add(p.getUniqueId());
90+
FileConfiguration config = StarlinUtils.config.getConfig();
91+
new BukkitRunnable() {
92+
@Override
93+
public void run() {
94+
suCooldown.remove(p.getUniqueId());
95+
}
96+
}.runTaskLater(StarlinUtils.INSTANCE, config.getInt("su-command-cooldown") * 20);
97+
} else { //cooldown
98+
Messager.senderMessage(p, "&b&l星林宇宙 &r&8>> &7您操作太频繁了!");
99+
}
84100
}
85101
} else {
86102
Messager.senderMessage(sender, "&b&l星林宇宙 &r&8>> &7用法: /su <参数>. 可用参数: time");

0 commit comments

Comments
 (0)