This commit is contained in:
AlphaAE
2019-05-02 19:42:43 +08:00
parent b36c37b5ab
commit 01333107f7
5 changed files with 60 additions and 27 deletions

View File

@ -1,13 +1,17 @@
package com.alphaae.mcpe.servers.event;
import cn.nukkit.Player;
import cn.nukkit.entity.Entity;
import cn.nukkit.event.EventHandler;
import cn.nukkit.event.EventPriority;
import cn.nukkit.event.Listener;
import cn.nukkit.event.player.PlayerInteractEntityEvent;
import cn.nukkit.event.player.PlayerInteractEvent;
import cn.nukkit.event.player.PlayerItemHeldEvent;
import cn.nukkit.item.Item;
import cn.nukkit.utils.TextFormat;
import com.alphaae.mcpe.servers.form.FormWindowMeun;
import com.alphaae.mcpe.servers.form.FormWindowOtherPlayer;
public class PlayerInteractSetEvent implements Listener {
@ -34,4 +38,23 @@ public class PlayerInteractSetEvent implements Listener {
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
Player player = event.getPlayer();
Entity entity = event.getEntity();
Item item = event.getItem();
if (player != null && entity != null && item != null) {
try {
Player player2 = (Player) entity;
// player.sendMessage("你触碰了玩家" + player.getName());
// player2.sendMessage("你被" + player.getName() + "触碰了");
FormWindowOtherPlayer formWindowOtherPlayer = new FormWindowOtherPlayer(player, player2);
player.showFormWindow(formWindowOtherPlayer);
} catch (Exception e) {
player.sendMessage(TextFormat.colorize("&4非玩家单位"));
}
}
}
}

View File

@ -24,21 +24,26 @@ public class DisplayInfoBlock implements JoinQuitEventBlock {
public void onPlayerJoin(PlayerJoinEvent event) {
final Player player = event.getPlayer();
final UUID uuid = player.getUniqueId();
final String name = player.getDisplayName();
try {
infoHandler = MainPlugin.getPlugin().getServer().getScheduler().scheduleDelayedRepeatingTask(new Task() {
@Override
public void onRun(int i) {
String name = player.getDisplayName();
int ping = player.getPing();
RePlayer rePlayer = StaticData.rePlayerMap.get(uuid);
int coin = rePlayer.getCoin();
try {
int ping = player.getPing();
RePlayer rePlayer = StaticData.rePlayerMap.get(uuid);
int coin = rePlayer.getCoin();
player.sendActionBar(TextFormat.colorize("" + name + " &f延迟: " + ping + "ms 硬币: " + coin));
player.sendActionBar(TextFormat.colorize("" + name + " &f延迟: " + ping + "ms 硬币: " + coin));
} catch (Exception e) {
cancel();
}
}
}, Config.JOIN_WAITING_TIME, 36);
} catch (Exception e) {
infoHandler.cancel();
if (infoHandler != null)
infoHandler.cancel();
e.printStackTrace();
}

View File

@ -24,9 +24,14 @@ public class JoinWindowBlock implements JoinQuitEventBlock {
private void showJoinWindow(Player player) {
new NukkitRunnable() {
public void run() {
String joinText = MainPlugin.getPlugin().getConfig().getString("join-text");
FormWindowSimple form = new FormWindowSimple("公告", "欢迎你 " + player.getName() + " \n\n" + joinText);
player.showFormWindow(form);
try {
String joinText = MainPlugin.getPlugin().getConfig().getString("join-text");
FormWindowSimple form = new FormWindowSimple("公告", "欢迎你 " + player.getName() + " \n\n" + joinText);
player.showFormWindow(form);
} catch (Exception e) {
e.printStackTrace();
cancel();
}
}
}.runTaskLater(MainPlugin.getPlugin(), Config.JOIN_WAITING_TIME);
}

View File

@ -21,12 +21,11 @@ public class FormWindowMeun extends FormWindow {
private FormResponseSimple response;
public FormWindowMeun(Player player) {
this.title = "";
this.buttons = new ArrayList();
String name = player.getName();
RePlayer rePlayer = StaticData.rePlayerMap.get(player.getUniqueId());
this.title = "";
this.buttons = new ArrayList();
this.content = TextFormat.colorize("&b" + name + "&f\n" +
"---------------------------------\n" +
"称号: " + rePlayer.getTitle() + "\n" +

View File

@ -5,6 +5,9 @@ import cn.nukkit.form.element.ElementButton;
import cn.nukkit.form.element.ElementButtonImageData;
import cn.nukkit.form.response.FormResponseSimple;
import cn.nukkit.form.window.FormWindow;
import cn.nukkit.utils.TextFormat;
import com.alphaae.mcpe.servers.StaticData;
import com.alphaae.mcpe.servers.model.RePlayer;
import com.google.gson.Gson;
import java.util.ArrayList;
@ -17,24 +20,22 @@ public class FormWindowOtherPlayer extends FormWindow {
private List<ElementButton> buttons;
private FormResponseSimple response;
public FormWindowOtherPlayer(Player player) {
this.title = "";
this.content = "";
this.response = null;
public FormWindowOtherPlayer(Player player, Player player2) {
// String name = player.getName();
// RePlayer rePlayer = StaticData.rePlayerMap.get(player.getUniqueId());
String name2 = player2.getName();
RePlayer rePlayer2 = StaticData.rePlayerMap.get(player2.getUniqueId());
String name = player.getName();
String coin = "2000";
String content = "" + name + "\n" +
"---------------------------------\n---------------------------------\n" +
"硬币: " + coin + "\n" +
"";
this.title = name;
this.content = content;
this.title = "玩家:" + name2;
this.buttons = new ArrayList();
this.content = TextFormat.colorize("&b" + name2 + "&f\n" +
"---------------------------------\n" +
"称号: " + rePlayer2.getTitle() + "\n" +
"---------------------------------\n" +
"");
buttons.add(new ElementButton("", new ElementButtonImageData(ElementButtonImageData.IMAGE_DATA_TYPE_PATH, "")));
buttons.add(new ElementButton("组队", new ElementButtonImageData(ElementButtonImageData.IMAGE_DATA_TYPE_PATH, "textures/items/iron_helmet.png")));
buttons.add(new ElementButton("交易", new ElementButtonImageData(ElementButtonImageData.IMAGE_DATA_TYPE_PATH, "textures/items/emerald.png")));
}
public String getTitle() {