This repository has been archived by the owner on Feb 14, 2024. It is now read-only.
generated from katorlys/Template
-
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
9 changed files
with
230 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ vscode: | |
- vscjava.vscode-java-pack | ||
- vscjava.vscode-java-debug | ||
- redhat.fabric8-analytics | ||
- redhat.vscode-xml |
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,9 +1,38 @@ | ||
# Starlin_L2 | ||
[![License](https://img.shields.io/badge/license-CC%20BY--NC--ND--4.0-green?style=for-the-badge)](http://creativecommons.org/licenses/by-nc-nd/4.0) ![Pull Requests](https://img.shields.io/github/issues-pr-closed/katorlys/Starlin_L2?style=for-the-badge) ![Issues](https://img.shields.io/github/issues-closed/katorlys/Starlin_L2?style=for-the-badge) | ||
[![License](https://img.shields.io/badge/license-CC%20BY--NC--ND--4.0-green?style=for-the-badge)](http://creativecommons.org/licenses/by-nc-nd/4.0) ![Pull Requests](https://img.shields.io/github/issues-pr-closed/katorlys/Starlin_L2?style=for-the-badge) ![Issues](https://img.shields.io/github/issues-closed/katorlys/Starlin_L2?style=for-the-badge)<br> | ||
![Build](https://img.shields.io/github/workflow/status/katorlys/Starlin_L2/Build?style=for-the-badge) | ||
|
||
## Introduction | ||
Starlin_L2 Minecraft Spigot plugin made for StarlinWorld (星林宇宙) server.<br> | ||
|
||
Main functions:<br> | ||
- Prevent players from stucking in the Nether Portal when logging in. | ||
- Prevent crops from being trampled. | ||
![](https://cdn.jsdelivr.net/gh/katorly/Gallery001/plugins/2022-01-20_13.37.53.png) | ||
- Prevent crops from being trampled. | ||
![](https://cdn.jsdelivr.net/gh/katorly/Gallery001/plugins/2022-01-20_12.58.39.png) | ||
- 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) | ||
|
||
## Commands | ||
- `/l2 time [player]` Displays the first-join time and monthly online time of the excutor or the specific player. | ||
|
||
## Config | ||
### timedata.yml | ||
```yml | ||
12345678-aaaa-bbbb-cccc-123412341234: #Player's UUID | ||
name: Katorly #Player's ID | ||
first-time: 2022.01.01 00:00 #Player's first-join time | ||
total: 10.5 #Player's total online time | ||
month-time: | ||
'2022': 19.2,11.5,0.7,8.0,3.5,0.0,7.2,9.9,48.3,0.0,1.1,0.6 | ||
``` | ||
This is generated by the plugin, do not edit if you don't know what you're doing. | ||
### monthly.yml | ||
```yml | ||
'2022': #Year | ||
'01': #Month | ||
- Katorly #Playerlist | ||
- player2 | ||
``` | ||
This is generated by the plugin, do not edit if you don't know what you're doing. |
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
94 changes: 94 additions & 0 deletions
94
src/main/java/com/github/katorly/starlin_l2/CommandHandler.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,94 @@ | ||
package com.github.katorly.starlin_l2; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import com.github.katorly.starlin_l2.backup.messageSender; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.command.TabExecutor; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.entity.Player; | ||
|
||
public class CommandHandler implements TabExecutor { | ||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
FileConfiguration timedata = starlin_l2.timedata.getConfig(); | ||
if (command.getName().equalsIgnoreCase("l2")) { | ||
if (args.length < 1) { | ||
sender.sendMessage(messageSender.Color("&b&l星林宇宙 &r&8>> &7用法: /l2 <参数>. 可用参数: time")); | ||
} else if (Objects.equals(args[0], "time")) { //Get player's play time information. | ||
if (args.length == 1) { | ||
if (!(sender instanceof Player)) { | ||
sender.sendMessage(messageSender.Color("&b&l星林宇宙 &r&8>> &7用法: /l2 time <玩家ID>.")); | ||
} else { | ||
Player player = (Player) sender; | ||
String u = player.getUniqueId().toString(); | ||
String pname = player.getName().toString(); | ||
String first_time; | ||
if (starlin_l2.timedata.getConfig().contains(u + ".first-time")) first_time = timedata.getString(u + ".first-time"); | ||
else first_time = "未知"; | ||
String total_time; | ||
if (starlin_l2.timedata.getConfig().contains(u + ".total")) total_time = String.format("%.1f", timedata.getDouble(u + ".total")); | ||
else total_time = "未知"; | ||
messageSender.sendMessage(player, "&b&l星林宇宙 &r&8>> &7您 (&f" + pname + "&7) 的游玩信息:"); | ||
messageSender.sendMessage(player, " &7首次加入: &f" + first_time); | ||
messageSender.sendMessage(player, " &7总计时长: &f" + total_time + " 小时"); | ||
} | ||
} else if (args.length == 2) { | ||
Player p = null; | ||
for (Player player : Bukkit.getOnlinePlayers()) { | ||
if (Objects.equals(args[1], player.getName())) { | ||
p = player; | ||
} | ||
} | ||
if (p != null) { | ||
String u = p.getUniqueId().toString(); | ||
String pname = p.getName().toString(); | ||
String first_time; | ||
if (starlin_l2.timedata.getConfig().contains(u + ".first-time")) first_time = timedata.getString(u + ".first-time"); | ||
else first_time = "未知"; | ||
String total_time; | ||
if (starlin_l2.timedata.getConfig().contains(u + ".total")) total_time = String.format("%.1f", timedata.getDouble(u + ".total")); | ||
else total_time = "未知"; | ||
sender.sendMessage(messageSender.Color("&b&l星林宇宙 &r&8>> &7玩家 &f" + pname + "&7 的游玩信息:")); | ||
sender.sendMessage(messageSender.Color(" &7首次加入: &f" + first_time)); | ||
sender.sendMessage(messageSender.Color(" &7总计时长: &f" + total_time + " 小时")); | ||
} else { | ||
sender.sendMessage(messageSender.Color("&b&l星林宇宙 &r&8>> &7玩家不在线或不存在!")); | ||
} | ||
} else { | ||
sender.sendMessage(messageSender.Color("&b&l星林宇宙 &r&8>> &7用法: /l2 time [玩家ID].")); | ||
} | ||
} else { | ||
sender.sendMessage(messageSender.Color("&b&l星林宇宙 &r&8>> &7用法: /l2 <参数>. 可用参数: time")); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public List<String> onTabComplete(CommandSender sender, Command commandd, String label, String[] args) { | ||
if (!(sender instanceof Player)) { | ||
return null; | ||
} | ||
if (args.length == 1) { | ||
List<String> sub = new ArrayList<>(); | ||
sub.add("time"); | ||
return sub; | ||
} | ||
if (args.length == 2) { | ||
if (args[0] == "time") { | ||
List<String> sub = new ArrayList<>(); | ||
for (Player player : Bukkit.getOnlinePlayers()) { | ||
sub.add(player.getName()); | ||
} | ||
return sub; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
src/main/java/com/github/katorly/starlin_l2/utils/MonthlyPlayTime.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,52 @@ | ||
package com.github.katorly.starlin_l2.utils; | ||
|
||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
import com.github.katorly.starlin_l2.starlin_l2; | ||
import com.github.katorly.starlin_l2.backup.configReader; | ||
|
||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.entity.Player; | ||
|
||
public class MonthlyPlayTime { | ||
public static void initialize(Player p) throws ParseException { //Get player's join time. | ||
long t = System.currentTimeMillis(); | ||
SimpleDateFormat dnow = new SimpleDateFormat("yyyy-MM-dd HH:mm"); | ||
Date d1 = dnow.parse(dnow.format(t)); | ||
Long t1 = d1.getTime(); | ||
starlin_l2.INSTANCE.StartTime.put(p.getPlayer().getUniqueId(), t1); | ||
} | ||
|
||
public static void settle(Player p) throws ParseException { //Count player's monthly play time. | ||
FileConfiguration timedata = starlin_l2.timedata.getConfig(); | ||
long t = System.currentTimeMillis(); | ||
SimpleDateFormat d = new SimpleDateFormat("yyyy"); | ||
String year = d.format(t); | ||
String u = p.getPlayer().getUniqueId().toString(); | ||
Long minutes; | ||
if (!starlin_l2.timedata.getConfig().contains(u + ".month-time." + year)) { | ||
timedata.set(u + ".month-time." + year, "0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0"); | ||
configReader.save(starlin_l2.timedata); | ||
} else { | ||
if (starlin_l2.INSTANCE.StartTime.containsKey(p.getPlayer().getUniqueId())) { | ||
Long t1 =starlin_l2.INSTANCE.StartTime.get(p.getPlayer().getUniqueId()); | ||
SimpleDateFormat dnow = new SimpleDateFormat("yyyy-MM-dd HH:mm"); | ||
Date d2 = dnow.parse(dnow.format(t)); | ||
Long t2 = d2.getTime(); | ||
minutes = (t2 - t1) / (1000 * 60); | ||
starlin_l2.INSTANCE.StartTime.remove(p.getPlayer().getUniqueId()); | ||
String ytime = timedata.getString(u + ".month-time." + year); | ||
String[] mtime = ytime.split(","); | ||
SimpleDateFormat n = new SimpleDateFormat("M"); | ||
String m = n.format(t); | ||
int month = Integer.valueOf(m); | ||
mtime[month - 1] = String.format("%.1f", Double.valueOf(mtime[month - 1]) + minutes / 60.0); | ||
String newtime = String.join(",", mtime); | ||
timedata.set(u + ".month-time." + year, newtime); | ||
configReader.save(starlin_l2.timedata); | ||
} | ||
} | ||
} | ||
} |
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,10 @@ | ||
name: starlin_l2 | ||
version: "1.0.1" | ||
version: "1.0.2" | ||
author: Katorly | ||
main: com.github.katorly.starlin_l2.starlin_l2 | ||
api-version: 1.18 | ||
description: A Spigot plugin made for StarlinWorld. | ||
commands: | ||
l2: | ||
description: The main command of Starlin_L2. | ||
usage: /l2 |