Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

Commit

Permalink
v1.0.6 (#4)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
katorly authored Mar 28, 2022
1 parent 904fa59 commit f83a3d0
Show file tree
Hide file tree
Showing 15 changed files with 200 additions and 52 deletions.
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"git.autofetch": true,
"git.confirmSync": false,
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 1000,
"editor.formatOnType":true,
"java.configuration.updateBuildConfiguration": "automatic",
"yaml.schemas": {
"https://json.schemastore.org/bukkit-plugin.json": "file:///src/main/resources/plugin.yml"
}
}
19 changes: 19 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "mvn -B clean verify",
"group": "build"
},
{
"label": "test",
"type": "shell",
"command": "mvn -B test",
"group": "test"
}
]
}
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ Main functions:<br>
- Record player's first-join time and monthly online time.
- Record the server's monthly players.
![](https://cdn.jsdelivr.net/gh/katorly/Gallery001/plugins/2022-01-20_14.52.png)
- Players can check their first-join time and total online time.
- Players can check their current gaming status.
- Conveniently manage player's flying permission.
- Displays the help document when player excutes `/help`.
- 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.
- Modifys colored concretes' recipe into the following **shapeless** recipe:
![](https://cdn.jsdelivr.net/gh/katorly/Gallery001/plugins/2022_03_11_11.28.30.PNG)

Expand All @@ -29,9 +32,12 @@ For server OPs,
## Config
### config.yml
```yml
# The help document URL you want to display.
help-document: "https://star-lin.feishu.cn/docs/doccnow2uz3RoK28RKLJleq0Qug"
# Delay (minutes) before server shutting down.
server-close-countdown: 10
```
The document URL you want to display.
### timedata.yml
```yml
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<artifactId>StarlinUtils</artifactId>
<groupId>com.github.katorly</groupId>
<version>1.0.5</version>
<version>1.0.6</version>

<!-- Repositories -->
<repositories>
Expand All @@ -20,7 +20,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.1-R0.1-SNAPSHOT</version>
<version>1.18.2-R0.1-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
Expand All @@ -33,8 +33,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/com/github/katorly/starlinutils/EventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.github.katorly.starlinutils.backup.ConfigReader;
import com.github.katorly.starlinutils.backup.Messager;
import com.github.katorly.starlinutils.utils.CloseServer;
import com.github.katorly.starlinutils.utils.PlayTime;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
Expand All @@ -17,16 +20,22 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.server.ServerCommandEvent;
import org.bukkit.scheduler.BukkitRunnable;

public class EventListener implements Listener {

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

if (StarlinUtils.serverClosing) { //Check whether server is going to close.
Messager.sendTitle(e.getPlayer(), "&b&l服务器即将重启", "&7请保管好个人物品!");
}

PlayTime.initialize(e.getPlayer()); //Get player's join time and check whether player has joined before.

long t = System.currentTimeMillis();
Expand Down Expand Up @@ -86,4 +95,28 @@ public void onCropTrample(PlayerInteractEvent e) {
e.setCancelled(true);
}
}

@EventHandler
public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
if (Objects.equals(e.getMessage(), "/help") && !e.getPlayer().isOp()) { //Displays the help document when player excutes "/help".
e.setCancelled(true);
FileConfiguration config = StarlinUtils.config.getConfig();
Messager.senderMessage(e.getPlayer(), "&b&l星林宇宙 &r&8>> &7新手指南: &f" + config.getString("help-document"));
} else if (Objects.equals(e.getMessage(), "/stop") || Objects.equals(e.getMessage(), "/reload") || Objects.equals(e.getMessage(), "/restart")) {
if (e.getPlayer().isOp()) {
e.setCancelled(true);
CloseServer.close();
}
}
}

@EventHandler
public void onConsoleCommand(ServerCommandEvent e) {
if (Objects.equals(e.getCommand(), "stop") || Objects.equals(e.getCommand(), "reload") || Objects.equals(e.getCommand(), "restart")) {
e.setCancelled(true);
CloseServer.close();
FileConfiguration config = StarlinUtils.config.getConfig();
Bukkit.getLogger().info("[StarlinUtils] 已执行重启命令. 还有" + config.getInt("server-close-countdown") + "秒重启.");
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/github/katorly/starlinutils/Recipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public static void registerConcreteRecipe() { //Add colored concrete recipe onEn
}

public static void concreteRecipe(Material concrete, Material dye) { //8*colored concrete = 1*dye + 8*stones.
ShapelessRecipe concreteRecipe = new ShapelessRecipe(new NamespacedKey(StarlinUtils.INSTANCE, concrete.toString() + "_recipe"), new ItemStack(concrete, 8));
ShapelessRecipe concreteRecipe = new ShapelessRecipe(new NamespacedKey(StarlinUtils.INSTANCE, concrete.toString() + "_starlin_recipe"), new ItemStack(concrete, 8));
concreteRecipe = concreteRecipe.addIngredient(1, dye).addIngredient(8, Material.STONE);
Bukkit.addRecipe(concreteRecipe);
StarlinUtils.INSTANCE.recipeKeys.add(concreteRecipe.getKey());
}
}
23 changes: 15 additions & 8 deletions src/main/java/com/github/katorly/starlinutils/StarlinUtils.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.github.katorly.starlinutils;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

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

import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -25,24 +28,27 @@ public StarlinUtils() {
public static ConfigReader timedata;
public static ConfigReader monthly;
public Map<UUID, Long> StartTime = new HashMap<>();
public static boolean serverClosing = false;
public final List<NamespacedKey> recipeKeys = new ArrayList<>();

@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(new EventListener(),this);
getServer().getPluginManager().registerEvents(new AprilFools(),this);
config = new ConfigReader(this,"","config.yml");
config.saveDefaultConfig();
timedata = new ConfigReader(this,"","timedata.yml");
monthly = new ConfigReader(this,"","monthly.yml");
timedata = new ConfigReader(this, "", "timedata.yml");
timedata.saveDefaultConfig();
monthly = new ConfigReader(this, "", "monthly.yml");
monthly.saveDefaultConfig();
Bukkit.getPluginCommand("su").setExecutor(new su());
Bukkit.getPluginCommand("su").setTabCompleter(new su());
Bukkit.getPluginCommand("help").setExecutor(new help());
Bukkit.getPluginCommand("givefly").setExecutor(new givefly());
Bukkit.getPluginCommand("givefly").setTabCompleter(new givefly());
Bukkit.getPluginCommand("listfly").setExecutor(new listfly());
Bukkit.getPluginCommand("delfly").setExecutor(new delfly());
Bukkit.getPluginCommand("delfly").setTabCompleter(new delfly());
Recipe.registerConcreteRecipe(); //Add colored concrete
Recipe.registerConcreteRecipe(); //Add colored concrete recipe
Bukkit.getLogger().info("[StarlinUtils] Repo: https://github.com/katorlys/StarlinUtils");
Bukkit.getLogger().info("[StarlinUtils] StarlinUtils enabled! Made for StarlinWorld server only.");
for (Player p : Bukkit.getOnlinePlayers()) {
Expand All @@ -65,11 +71,12 @@ public void onDisable() {
e.printStackTrace();
}
}
Bukkit.clearRecipes();
recipeKeys.forEach(Bukkit::removeRecipe);
recipeKeys.clear();
HandlerList.unregisterAll(this);
ConfigReader.save(config);
ConfigReader.save(timedata);
ConfigReader.save(monthly);
config.reloadConfig();
timedata.reloadConfig();
monthly.reloadConfig();
Bukkit.getLogger().info("[StarlinUtils] StarlinUtils disabled!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,22 @@ public void saveDefaultConfig() {
public FileConfiguration getConfig() {
if (!filepath.exists())
this.saveDefaultConfig();
if (!file.exists())
this.saveDefaultConfig();
if (config == null)
this.reloadConfig();
return config;
}

/**
* Reload the config. This will remove all the comments in it.
* Reload the config.
*
*/
public void reloadConfig() {
if (!filepath.exists())
this.saveDefaultConfig();
if (!file.exists())
this.saveDefaultConfig();
if (filepath == null)
filepath = new File(plugin.getDataFolder(), path);
if (file == null)
Expand All @@ -62,12 +68,14 @@ public void reloadConfig() {
}

/**
* Save the config to apply changes.
* Save the config to apply changes. This will remove all the comments in it.
*
*/
public void saveConfig() {
if (!filepath.exists())
this.saveDefaultConfig();
if (!file.exists())
this.saveDefaultConfig();
try {
config.save(file);
} catch (Throwable t) {
Expand Down
20 changes: 0 additions & 20 deletions src/main/java/com/github/katorly/starlinutils/commands/help.java

This file was deleted.

38 changes: 27 additions & 11 deletions src/main/java/com/github/katorly/starlinutils/commands/su.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

import com.github.katorly.starlinutils.StarlinUtils;
import com.github.katorly.starlinutils.backup.Messager;
Expand All @@ -13,8 +14,11 @@
import org.bukkit.command.TabExecutor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

public class su implements TabExecutor {
public List<UUID> suCooldown = new ArrayList<>();

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
FileConfiguration timedata = StarlinUtils.timedata.getConfig();
Expand Down Expand Up @@ -70,17 +74,29 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if (!(sender instanceof Player)) {
Messager.senderMessage(sender, "&b&l星林宇宙 &r&8>> &7只有玩家才能查看自己的游戏状态!");
} else {
Player p= (Player) sender;
Messager.senderMessage(p, "&b&l星林宇宙 &r&8>> &7您当前的游戏状态:");
Messager.senderMessage(p, " &7游戏ID: &f" + p.getName());
Messager.senderMessage(p, " &7UUID: &f" + p.getUniqueId());
Messager.senderMessage(p, " &7生命值: &f" + p.getHealth());
Messager.senderMessage(p, " &7饱食度: &f" + p.getFoodLevel());
Messager.senderMessage(p, " &7经验等级: &f" + p.getLevel());
Messager.senderMessage(p, " &7游戏模式: &f" + p.getGameMode());
Messager.senderMessage(p, " &7面朝: &f" + p.getFacing());
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()));
Messager.senderMessage(p, " &7延迟: &f" + p.getPing() + "ms");
final Player p= (Player) sender;
if (!suCooldown.contains(p.getUniqueId())) {
Messager.senderMessage(p, "&b&l星林宇宙 &r&8>> &7您当前的游戏状态:");
Messager.senderMessage(p, " &7游戏ID: &f" + p.getName());
Messager.senderMessage(p, " &7UUID: &f" + p.getUniqueId());
Messager.senderMessage(p, " &7生命值: &f" + p.getHealth());
Messager.senderMessage(p, " &7饱食度: &f" + p.getFoodLevel());
Messager.senderMessage(p, " &7经验等级: &f" + p.getLevel());
Messager.senderMessage(p, " &7游戏模式: &f" + p.getGameMode());
Messager.senderMessage(p, " &7面朝: &f" + p.getFacing());
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()));
Messager.senderMessage(p, " &7延迟: &f" + p.getPing() + "ms");
suCooldown.add(p.getUniqueId());
FileConfiguration config = StarlinUtils.config.getConfig();
new BukkitRunnable() {
@Override
public void run() {
suCooldown.remove(p.getUniqueId());
}
}.runTaskLater(StarlinUtils.INSTANCE, config.getInt("su-command-cooldown") * 20);
} else { //cooldown
Messager.senderMessage(p, "&b&l星林宇宙 &r&8>> &7您操作太频繁了!");
}
}
} else {
Messager.senderMessage(sender, "&b&l星林宇宙 &r&8>> &7用法: /su <参数>. 可用参数: time");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.github.katorly.starlinutils.utils;

import com.github.katorly.starlinutils.StarlinUtils;
import com.github.katorly.starlinutils.backup.Messager;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.scheduler.BukkitRunnable;

public class CloseServer {
public static void close() {
if (!StarlinUtils.serverClosing) {
StarlinUtils.serverClosing = true;
FileConfiguration config = StarlinUtils.config.getConfig();
Messager.broadcastTitle("&b&l服务器" + config.getInt("server-close-countdown") + "秒后重启", "&7请保管好个人物品!");
new BukkitRunnable() {
@Override
public void run() {
StarlinUtils.INSTANCE.getServer().shutdown();
}
}.runTaskLater(StarlinUtils.INSTANCE, config.getInt("server-close-countdown") * 20);
}
}
}
Loading

0 comments on commit f83a3d0

Please sign in to comment.