Skip to content

Commit dc4209d

Browse files
committed
v1.0.3
1 parent 8c30722 commit dc4209d

File tree

7 files changed

+27
-61
lines changed

7 files changed

+27
-61
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Starlin_L2
22
[![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>
3-
![Build](https://img.shields.io/github/workflow/status/katorlys/Starlin_L2/Build?style=for-the-badge)
3+
![Build](https://img.shields.io/github/workflow/status/katorlys/Starlin_L2/Build?style=for-the-badge) ![Codacy](https://img.shields.io/codacy/grade/b187c52b9b754ed8a670a3017201c05f?style=for-the-badge)
44

55
## Introduction
66
Starlin_L2 Minecraft Spigot plugin made for StarlinWorld (星林宇宙) server.<br>
@@ -15,7 +15,7 @@ Main functions:<br>
1515
![](https://cdn.jsdelivr.net/gh/katorly/Gallery001/plugins/2022-01-20_14.52.png)
1616

1717
## Commands
18-
- `/l2 time [player]` Displays the first-join time and monthly online time of the excutor or the specific player.
18+
- `/l2 time [player]` Displays the first-join time and total online time of the excutor or the specific player.
1919

2020
## Config
2121
### timedata.yml

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<artifactId>starlin_l2</artifactId>
66
<groupId>com.github.katorly</groupId>
7-
<version>1.0.2</version>
7+
<version>1.0.3</version>
88

99
<!-- Repositories -->
1010
<repositories>

src/main/java/com/github/katorly/starlin_l2/CommandHandler.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
3737
messageSender.sendMessage(player, "&b&l星林宇宙 &r&8>> &7您 (&f" + pname + "&7) 的游玩信息:");
3838
messageSender.sendMessage(player, " &7首次加入: &f" + first_time);
3939
messageSender.sendMessage(player, " &7总计时长: &f" + total_time + " 小时");
40+
messageSender.sendMessage(player, " &7游玩信息在您退出重进后会更新.");
4041
}
4142
} else if (args.length == 2) {
4243
Player p = null;
@@ -57,6 +58,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
5758
sender.sendMessage(messageSender.Color("&b&l星林宇宙 &r&8>> &7玩家 &f" + pname + "&7 的游玩信息:"));
5859
sender.sendMessage(messageSender.Color(" &7首次加入: &f" + first_time));
5960
sender.sendMessage(messageSender.Color(" &7总计时长: &f" + total_time + " 小时"));
61+
sender.sendMessage(messageSender.Color(" &7游玩信息在该玩家退出重进后会更新."));
6062
} else {
6163
sender.sendMessage(messageSender.Color("&b&l星林宇宙 &r&8>> &7玩家不在线或不存在!"));
6264
}
@@ -81,7 +83,7 @@ public List<String> onTabComplete(CommandSender sender, Command commandd, String
8183
return sub;
8284
}
8385
if (args.length == 2) {
84-
if (args[0] == "time") {
86+
if (Objects.equals(args[0], "time")) {
8587
List<String> sub = new ArrayList<>();
8688
for (Player player : Bukkit.getOnlinePlayers()) {
8789
sub.add(player.getName());

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

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

88
import com.github.katorly.starlin_l2.backup.configReader;
99
import com.github.katorly.starlin_l2.backup.messageSender;
10-
import com.github.katorly.starlin_l2.utils.MonthlyPlayTime;
10+
import com.github.katorly.starlin_l2.utils.PlayTime;
1111

1212
import org.bukkit.Location;
1313
import org.bukkit.Material;
@@ -26,27 +26,10 @@ public class EventListener implements Listener {
2626

2727
@EventHandler
2828
public void onPlayerJoin(PlayerJoinEvent e) throws ParseException {
29-
30-
FileConfiguration timedata = starlin_l2.timedata.getConfig(); //Check whether player has joined before.
31-
long t = System.currentTimeMillis();
32-
SimpleDateFormat d = new SimpleDateFormat("yyyy");
33-
String year = d.format(t);
34-
String u = e.getPlayer().getUniqueId().toString();
35-
if (!starlin_l2.timedata.getConfig().contains(u)) { //if not
36-
timedata.set(u + ".name", e.getPlayer().getName());
37-
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm");
38-
String timenow = dateFormat.format(t);
39-
timedata.set(u + ".first-time", timenow);
40-
timedata.set(u + ".total", 0.0);
41-
configReader.save(starlin_l2.timedata);
42-
}
43-
if (!starlin_l2.timedata.getConfig().contains(u + ".month-time." + year)) {
44-
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");
45-
configReader.save(starlin_l2.timedata);
46-
}
4729

48-
MonthlyPlayTime.initialize(e.getPlayer()); //Get player's join time.
30+
PlayTime.initialize(e.getPlayer()); //Get player's join time and check whether player has joined before.
4931

32+
long t = System.currentTimeMillis();
5033
FileConfiguration monthly = starlin_l2.monthly.getConfig(); //Record monthly players.
5134
String pname = e.getPlayer().getName();
5235
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM");
@@ -94,7 +77,7 @@ public void run() {
9477

9578
@EventHandler //Count player's monthly play time.
9679
public void onPlayerLeave(PlayerQuitEvent e) throws ParseException {
97-
MonthlyPlayTime.settle(e.getPlayer());
80+
PlayTime.settle(e.getPlayer());
9881
}
9982

10083
@EventHandler //Prevent crops from being trampled.
Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
package com.github.katorly.starlin_l2;
22

33
import java.text.ParseException;
4-
import java.text.SimpleDateFormat;
54
import java.util.HashMap;
65
import java.util.Map;
76
import java.util.UUID;
87

98
import com.github.katorly.starlin_l2.backup.configReader;
10-
import com.github.katorly.starlin_l2.utils.MonthlyPlayTime;
9+
import com.github.katorly.starlin_l2.utils.PlayTime;
1110

1211
import org.bukkit.Bukkit;
13-
import org.bukkit.configuration.file.FileConfiguration;
1412
import org.bukkit.entity.Player;
1513
import org.bukkit.event.HandlerList;
1614
import org.bukkit.plugin.java.JavaPlugin;
17-
import org.bukkit.scheduler.BukkitRunnable;
1815

1916
public class starlin_l2 extends JavaPlugin {
2017
public static starlin_l2 INSTANCE;
@@ -38,20 +35,19 @@ public void onEnable() {
3835
Bukkit.getLogger().info("[starlin_l2] Starlin_L2 enabled! Made for StarlinWorld server only.");
3936
for (Player p : Bukkit.getOnlinePlayers()) {
4037
try {
41-
MonthlyPlayTime.initialize(p);
38+
PlayTime.initialize(p);
4239
} catch (ParseException e) {
4340
Bukkit.getLogger().severe("[starlin_l2] Error counting player's monthly play time.");
4441
e.printStackTrace();
4542
}
4643
}
47-
this.timeCounter();
4844
}
4945

5046
@Override
5147
public void onDisable() {
5248
for (Player p : Bukkit.getOnlinePlayers()) {
5349
try {
54-
MonthlyPlayTime.settle(p);
50+
PlayTime.settle(p);
5551
} catch (ParseException e) {
5652
Bukkit.getLogger().severe("[starlin_l2] Error counting player's monthly play time.");
5753
e.printStackTrace();
@@ -61,29 +57,4 @@ public void onDisable() {
6157
configReader.save(timedata);
6258
Bukkit.getLogger().info("[starlin_l2] Starlin_L2 disabled!");
6359
}
64-
65-
public void timeCounter() { //Counts the player's play time.
66-
new BukkitRunnable() {
67-
@Override
68-
public void run() {
69-
for (Player player : Bukkit.getOnlinePlayers()) {
70-
FileConfiguration timedata = starlin_l2.timedata.getConfig();
71-
String u = player.getUniqueId().toString();
72-
if (!starlin_l2.timedata.getConfig().contains(u)) { //if data not exist
73-
timedata.set(u + ".name", player.getName());
74-
long t = System.currentTimeMillis();
75-
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm");
76-
String timenow = dateFormat.format(t);
77-
timedata.set(u + ".first-time", timenow);
78-
timedata.set(u + ".total", 0.0);
79-
configReader.save(starlin_l2.timedata);
80-
} else {
81-
Double newtotal = Double.valueOf(String.format("%.1f", timedata.getDouble(u + ".total"))) + 0.1; //if data exist
82-
timedata.set(u + ".total", Double.valueOf(String.format("%.1f", newtotal)));
83-
configReader.save(starlin_l2.timedata);
84-
}
85-
}
86-
}
87-
}.runTaskTimer(this, 7200L, 7200L);
88-
}
8960
}

src/main/java/com/github/katorly/starlin_l2/utils/MonthlyPlayTime.java renamed to src/main/java/com/github/katorly/starlin_l2/utils/PlayTime.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import org.bukkit.configuration.file.FileConfiguration;
1111
import org.bukkit.entity.Player;
1212

13-
public class MonthlyPlayTime {
13+
public class PlayTime {
1414
public static void initialize(Player p) throws ParseException { //Get player's join time.
1515
long t = System.currentTimeMillis();
1616
SimpleDateFormat dnow = new SimpleDateFormat("yyyy-MM-dd HH:mm");
@@ -19,14 +19,22 @@ public static void initialize(Player p) throws ParseException { //Get player's j
1919
starlin_l2.INSTANCE.StartTime.put(p.getPlayer().getUniqueId(), t1);
2020
}
2121

22-
public static void settle(Player p) throws ParseException { //Count player's monthly play time.
22+
public static void settle(Player p) throws ParseException { //Count player's total & monthly play time.
2323
FileConfiguration timedata = starlin_l2.timedata.getConfig();
2424
long t = System.currentTimeMillis();
2525
SimpleDateFormat d = new SimpleDateFormat("yyyy");
2626
String year = d.format(t);
2727
String u = p.getPlayer().getUniqueId().toString();
2828
Long minutes;
29-
if (!starlin_l2.timedata.getConfig().contains(u + ".month-time." + year)) {
29+
if (!starlin_l2.timedata.getConfig().contains(u)) {
30+
timedata.set(u + ".name", p.getName());
31+
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm");
32+
String timenow = dateFormat.format(t);
33+
timedata.set(u + ".first-time", timenow);
34+
timedata.set(u + ".total", 0.0);
35+
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");
36+
configReader.save(starlin_l2.timedata);
37+
} else if (!starlin_l2.timedata.getConfig().contains(u + ".month-time." + year)) {
3038
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");
3139
configReader.save(starlin_l2.timedata);
3240
} else {
@@ -45,6 +53,8 @@ public static void settle(Player p) throws ParseException { //Count player's mon
4553
mtime[month - 1] = String.format("%.1f", Double.valueOf(mtime[month - 1]) + minutes / 60.0);
4654
String newtime = String.join(",", mtime);
4755
timedata.set(u + ".month-time." + year, newtime);
56+
Double newtotal = Double.valueOf(String.format("%.1f", timedata.getDouble(u + ".total"))) + minutes / 60.0;
57+
timedata.set(u + ".total", Double.valueOf(String.format("%.1f", newtotal)));
4858
configReader.save(starlin_l2.timedata);
4959
}
5060
}

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: starlin_l2
2-
version: "1.0.2"
2+
version: "1.0.3"
33
author: Katorly
44
main: com.github.katorly.starlin_l2.starlin_l2
55
api-version: 1.18

0 commit comments

Comments
 (0)