Skip to content

Commit

Permalink
2.1.5 计分板依赖改为GameCore,实现自动下载依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
lt-name committed Mar 23, 2023
1 parent 8d910f4 commit a787edf
Show file tree
Hide file tree
Showing 8 changed files with 312 additions and 74 deletions.
Binary file removed lib/AutoUpData_v1.2.3.jar
Binary file not shown.
Binary file removed lib/[Tips前置(v1.2.7)]ScoreboardAPI-1.3.jar
Binary file not shown.
25 changes: 11 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.smallaswater.tips</groupId>
<artifactId>Tips</artifactId>
<version>2.1.5-SNAPSHOT</version>
<version>2.1.5<!-- -SNAPSHOT--></version>


<properties>
Expand Down Expand Up @@ -58,6 +58,12 @@
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>cn.lanink</groupId>
<artifactId>MemoriesOfTime-GameCore</artifactId>
<version>1.6.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.smallaswater.ServerInfo</groupId>
<artifactId>ServerInfo</artifactId>
Expand All @@ -71,11 +77,10 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>a.au</groupId>
<artifactId>autoupdata</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/AutoUpData_v1.2.3.jar</systemPath>
<groupId>com.smallaswater.autoupdata</groupId>
<artifactId>AutoUpData</artifactId>
<version>1.2.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>smallaswater.achievement</groupId>
Expand All @@ -84,14 +89,6 @@
<scope>system</scope>
<systemPath>${project.basedir}/lib/achievements_v1.0-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
<groupId>gt.creeperface.nukkit.scoreboardapi</groupId>
<artifactId>ScoreboardAPI</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/[Tips前置(v1.2.7)]ScoreboardAPI-1.3.jar</systemPath>
</dependency>

</dependencies>

<build>
Expand Down
35 changes: 14 additions & 21 deletions src/main/java/tip/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import cn.nukkit.plugin.PluginBase;
import cn.nukkit.utils.BossBarColor;
import cn.nukkit.utils.Config;
import de.theamychan.scoreboard.network.Scoreboard;
import tip.bossbar.BossBarApi;
import tip.commands.TipsCommand;
import tip.lib.viewcompass.ViewCompassVariable;
Expand All @@ -22,10 +21,7 @@
import tip.messages.defaults.TipMessage;
import tip.tasks.*;

import tip.utils.Api;
import tip.utils.OnListener;
import tip.utils.PlayerConfig;
import tip.utils.ThemeManager;
import tip.utils.*;
import tip.utils.variables.VariableManager;
import tip.utils.variables.defaults.DefaultVariables;
import tip.windows.ListenerWindow;
Expand Down Expand Up @@ -53,7 +49,7 @@ public class Main extends PluginBase implements Listener {


private VariableManager varManager;
public Map<Player, Scoreboard> scoreboards = new HashMap<>();
public Set<Player> scoreboards = new HashSet<>();

public LinkedHashMap<Player,BossBarTask> tasks = new LinkedHashMap<>();

Expand Down Expand Up @@ -82,8 +78,8 @@ public void onEnable() {
}
executor = Executors.newCachedThreadPool();

if(Server.getInstance().getPluginManager().getPlugin("AutoUpData") != null){
if(AutoData.defaultUpData(this,getFile(),"SmallasWater","Tips")){
if(Server.getInstance().getPluginManager().getPlugin("AutoUpData") != null) {
if(AutoData.defaultUpData(this,getFile(),"SmallasWater","Tips")) {
return;
}
}
Expand All @@ -97,13 +93,11 @@ public void onEnable() {
this.getServer().getPluginManager().registerEvents(new OnListener(),this);
this.getServer().getPluginManager().registerEvents(new ListenerWindow(),this);

try {
Class.forName("de.theamychan.scoreboard.api.ScoreboardAPI");
Main.getInstance().getLogger().info("检测到 ScoreboardAPI 成功开启计分板功能");
if (GameCoreDownload.checkAndDownload() == 1) {
this.getLogger().error("MemoriesOfTime-GameCore依赖 下载失败,无法使用计分板功能!");
} else {
Main.getInstance().getLogger().info("检测到 MemoriesOfTime-GameCore 成功开启计分板功能");
scoreboard = true;

} catch (Exception e) {
Main.getInstance().getLogger().info("未检测到计分板API 无法使用计分板功能");
}
AddPlayerTask.add(new TipTask(Main.getInstance(),Main.getInstance().getConfig().getInt("自定义刷新刻度.底部",20)));

Expand Down Expand Up @@ -132,14 +126,11 @@ private Config getLevelMessage() {
public void init(){
this.saveDefaultConfig();
this.reloadConfig();
theme = getConfig().getString("默认样式","default");
getLogger().info("当前样式为: "+theme);
tasks = new LinkedHashMap<>();
showMessages = new MessageManager();
this.getLogger().info("加载成功");
if(!new File(this.getDataFolder()+"/Tips变量.txt").exists()){
this.saveResource("Tips变量.txt","/Tips变量.txt",true);
}

this.saveResource("Tips变量.txt","/Tips变量.txt",true); //每次加载时写入,保证是最新的

if(!new File(this.getDataFolder()+"/theme").exists()){
if(!new File(this.getDataFolder()+"/theme").mkdirs()){
getLogger().info("创建 theme 文件夹失败");
Expand All @@ -160,12 +151,14 @@ public void init(){
}
//加载风格
loadTheme();
theme = getConfig().getString("默认样式","default");
getLogger().info("当前样式已设置为: "+theme);

showMessages.addAll(getManagerByConfig(getLevelMessage()));
//开始加载Message
playerConfigs = new LinkedList<>();
// 初始化注册类

this.getLogger().info("插件加载完成~");
}

public void loadPlayerConfig(Player player){
Expand Down
64 changes: 26 additions & 38 deletions src/main/java/tip/tasks/ScoreBoardTask.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package tip.tasks;

import cn.lanink.gamecore.GameCore;
import cn.lanink.gamecore.scoreboard.ScoreboardUtil;
import cn.lanink.gamecore.scoreboard.base.IScoreboard;
import cn.lanink.gamecore.scoreboard.ltname.SimpleScoreboard;
import cn.nukkit.Player;
import cn.nukkit.Server;
import cn.nukkit.scheduler.PluginTask;
import cn.nukkit.utils.TextFormat;
import de.theamychan.scoreboard.api.ScoreboardAPI;
import de.theamychan.scoreboard.network.DisplaySlot;
import de.theamychan.scoreboard.network.Scoreboard;
import de.theamychan.scoreboard.network.ScoreboardDisplay;
import tip.Main;
import tip.messages.BaseMessage;
import tip.messages.defaults.ScoreBoardMessage;
import tip.utils.Api;


import java.util.ArrayList;
import java.util.LinkedList;


Expand All @@ -22,63 +21,52 @@
*/
public class ScoreBoardTask {

private Player player;
private Main main;
private final Player player;
private final Main main;
private IScoreboard scoreboard = null;

public ScoreBoardTask(Player player,Main main) {
this.player = player;
this.main = main;

try {
Class.forName("cn.lanink.gamecore.scoreboard.ScoreboardUtil");
scoreboard = ScoreboardUtil.getScoreboard();
} catch (Exception ignored) {

}
}

private Main getOwner() {
return main;
}

public void onRun() {
try{
Class.forName("de.theamychan.scoreboard.api.ScoreboardAPI");
}catch (Exception e){
player.sendActionBar(TextFormat.RED+"计分板未安装\n\n\n\n");
if (this.scoreboard == null) {
return;
}
// for (Player player : Server.getInstance().getOnlinePlayers().values()) {
if (player == null || !player.isOnline()) {
return;
}
ScoreBoardMessage message = (ScoreBoardMessage) Api.getSendPlayerMessage(player.getName(), player.level.getFolderName(), BaseMessage.BaseTypes.SCORE_BOARD);
if (message == null) {
if (getOwner().scoreboards.containsKey(player)) {
ScoreboardAPI.removeScorebaord(player,
Main.getInstance().scoreboards.get(player));
}
return;
} else if (!message.isOpen()) {
if (getOwner().scoreboards.containsKey(player)) {
ScoreboardAPI.removeScorebaord(player,
Main.getInstance().scoreboards.get(player));
if (message == null || !message.isOpen()) {
if (getOwner().scoreboards.contains(player)) {
this.scoreboard.closeScoreboard(player);
getOwner().scoreboards.remove(player);
}
return;
}

if (player.isOnline()) {
try {
Scoreboard scoreboard = ScoreboardAPI.createScoreboard();
String title = message.getTitle();

ScoreboardDisplay scoreboardDisplay = scoreboard.addDisplay(DisplaySlot.SIDEBAR,
"dumy", Api.strReplace(title, player));
LinkedList<String> list = message.getMessages();
for (int line = 0; line < list.size(); line++) {
String s = list.get(line);

scoreboardDisplay.addLine(Api.strReplace(s,player), line);
}
try {
getOwner().scoreboards.get(player).hideFor(player);
} catch (Exception ignored) {
String title = Api.strReplace(message.getTitle(), player);
ArrayList<String> list = new ArrayList<>();
for (String ms : message.getMessages()) {
list.add(Api.strReplace(ms, player));
}
scoreboard.showFor(player);
Main.getInstance().scoreboards.put(player, scoreboard);
this.scoreboard.showScoreboard(player, title, list);
Main.getInstance().scoreboards.add(player);
} catch (Exception ignored) {
}
}
Expand Down
Loading

0 comments on commit a787edf

Please sign in to comment.