new block

This commit is contained in:
AlphaAE
2019-04-30 00:22:43 +08:00
parent eb1d2d4fbe
commit be5a27d7e3
7 changed files with 87 additions and 15 deletions

View File

@ -1,6 +1,6 @@
package com.alphaae.mcpe.servers;
public interface Config {
int JOIN_WAITING_TIME = 174;
int JOIN_WAITING_TIME = 200;
}

View File

@ -0,0 +1,12 @@
package com.alphaae.mcpe.servers;
import com.alphaae.mcpe.servers.model.RePlayer;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class StaticData {
public static Map<UUID, RePlayer> rePlayerMap = new HashMap<>();
}

View File

@ -8,6 +8,7 @@ import cn.nukkit.event.player.PlayerQuitEvent;
import com.alphaae.mcpe.servers.event.block.joinquit.DisplayInfoBlock;
import com.alphaae.mcpe.servers.event.block.joinquit.JoinQuitEventBlock;
import com.alphaae.mcpe.servers.event.block.joinquit.JoinWindowBlock;
import com.alphaae.mcpe.servers.event.block.joinquit.LoadPlayerDataBlock;
import java.util.ArrayList;
import java.util.List;
@ -20,6 +21,7 @@ public class JoinQuitEvent implements Listener {
eventBlockList = new ArrayList<>();
eventBlockList.add(new DisplayInfoBlock());
eventBlockList.add(new JoinWindowBlock());
eventBlockList.add(new LoadPlayerDataBlock());
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)

View File

@ -12,6 +12,10 @@ import cn.nukkit.scheduler.TaskHandler;
import cn.nukkit.utils.TextFormat;
import com.alphaae.mcpe.servers.Config;
import com.alphaae.mcpe.servers.MainPlugin;
import com.alphaae.mcpe.servers.StaticData;
import com.alphaae.mcpe.servers.model.RePlayer;
import java.util.UUID;
public class DisplayInfoBlock implements JoinQuitEventBlock {
@ -20,6 +24,7 @@ public class DisplayInfoBlock implements JoinQuitEventBlock {
public DisplayInfoBlock() {
}
@Override
public void onPlayerJoin(PlayerJoinEvent event) {
final Player player = event.getPlayer();
@ -27,12 +32,13 @@ public class DisplayInfoBlock implements JoinQuitEventBlock {
infoHandler = MainPlugin.getPlugin().getServer().getScheduler().scheduleDelayedRepeatingTask(new Task() {
@Override
public void onRun(int i) {
String name = player.getName();
String name = player.getDisplayName();
int ping = player.getPing();
String uuid = player.getUniqueId().toString();
int coin = 2000;
UUID uuid = player.getUniqueId();
RePlayer rePlayer = StaticData.rePlayerMap.get(uuid);
int coin = rePlayer.getCoin();
player.sendActionBar(TextFormat.colorize("&b" + name + " &f延迟: " + ping + "ms 硬币: " + coin));
player.sendActionBar(TextFormat.colorize("" + name + " &f延迟: " + ping + "ms 硬币: " + coin));
}
}, Config.JOIN_WAITING_TIME, 12);
} catch (Exception e) {
@ -42,6 +48,7 @@ public class DisplayInfoBlock implements JoinQuitEventBlock {
}
@Override
public void onPlayerQuit(PlayerQuitEvent event) {
if (infoHandler != null)
infoHandler.cancel();

View File

@ -0,0 +1,31 @@
package com.alphaae.mcpe.servers.event.block.joinquit;
import cn.nukkit.Player;
import cn.nukkit.event.player.PlayerJoinEvent;
import cn.nukkit.event.player.PlayerQuitEvent;
import cn.nukkit.utils.TextFormat;
import com.alphaae.mcpe.servers.StaticData;
import com.alphaae.mcpe.servers.model.RePlayer;
public class LoadPlayerDataBlock implements JoinQuitEventBlock {
@Override
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
//读取数据
String title = "[称号]";
player.setDisplayName(TextFormat.colorize("&e" + title + " &b" + player.getName() + "&f"));
RePlayer rePlayer = new RePlayer(player, title, 4000);
StaticData.rePlayerMap.put(player.getUniqueId(), rePlayer);
}
@Override
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
StaticData.rePlayerMap.remove(player.getUniqueId());
}
}

View File

@ -0,0 +1,30 @@
package com.alphaae.mcpe.servers.model;
import cn.nukkit.Player;
public class RePlayer {
private Player player;
private String title;
private int coin;
public RePlayer(Player player, String title, int coin) {
this.player = player;
this.title = title;
this.coin = coin;
}
public Player getPlayer() {
return player;
}
public String getTitle() {
return title;
}
public int getCoin() {
return coin;
}
}

View File

@ -1,10 +0,0 @@
package com.alphaae.mcpe.servers.model;
import cn.nukkit.Player;
public class SuPlayer {
private Player player;
private String name;
}