静态储存完成
This commit is contained in:
@ -5,7 +5,12 @@ import cn.nukkit.command.Command;
|
||||
import cn.nukkit.command.CommandSender;
|
||||
import cn.nukkit.utils.TextFormat;
|
||||
import com.alphaae.mcpe.servers.MainPlugin;
|
||||
import com.alphaae.mcpe.servers.StaticData;
|
||||
import com.alphaae.mcpe.servers.form.FormWindowMy;
|
||||
import com.alphaae.mcpe.servers.model.RePlayer;
|
||||
import com.alphaae.mcpe.servers.utils.ChangePlayerCoinUtils;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class HiCommand extends Command {
|
||||
private MainPlugin plugin;
|
||||
@ -24,9 +29,12 @@ public class HiCommand extends Command {
|
||||
}
|
||||
|
||||
Player player = commandSender.getServer().getPlayer(commandSender.getName());
|
||||
UUID uuid = player.getUniqueId();
|
||||
if (commandSender.isPlayer()) {
|
||||
FormWindowMy form = new FormWindowMy(player);
|
||||
player.showFormWindow(form);
|
||||
// FormWindowMy form = new FormWindowMy(player);
|
||||
// player.showFormWindow(form);
|
||||
RePlayer rePlayer = StaticData.rePlayerMap.get(uuid);
|
||||
ChangePlayerCoinUtils.ReduceIcon(rePlayer, 100);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -3,10 +3,6 @@ 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.form.element.ElementButton;
|
||||
import cn.nukkit.form.element.ElementButtonImageData;
|
||||
import cn.nukkit.form.window.FormWindowSimple;
|
||||
import cn.nukkit.scheduler.NukkitRunnable;
|
||||
import cn.nukkit.scheduler.Task;
|
||||
import cn.nukkit.scheduler.TaskHandler;
|
||||
import cn.nukkit.utils.TextFormat;
|
||||
@ -27,6 +23,7 @@ public class DisplayInfoBlock implements JoinQuitEventBlock {
|
||||
@Override
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final UUID uuid = player.getUniqueId();
|
||||
|
||||
try {
|
||||
infoHandler = MainPlugin.getPlugin().getServer().getScheduler().scheduleDelayedRepeatingTask(new Task() {
|
||||
@ -34,13 +31,12 @@ public class DisplayInfoBlock implements JoinQuitEventBlock {
|
||||
public void onRun(int i) {
|
||||
String name = player.getDisplayName();
|
||||
int ping = player.getPing();
|
||||
UUID uuid = player.getUniqueId();
|
||||
RePlayer rePlayer = StaticData.rePlayerMap.get(uuid);
|
||||
int coin = rePlayer.getCoin();
|
||||
|
||||
player.sendActionBar(TextFormat.colorize("" + name + " &f延迟: " + ping + "ms 硬币: " + coin));
|
||||
}
|
||||
}, Config.JOIN_WAITING_TIME, 12);
|
||||
}, Config.JOIN_WAITING_TIME, 36);
|
||||
} catch (Exception e) {
|
||||
infoHandler.cancel();
|
||||
e.printStackTrace();
|
||||
|
@ -6,6 +6,7 @@ import cn.nukkit.event.player.PlayerQuitEvent;
|
||||
import cn.nukkit.utils.TextFormat;
|
||||
import com.alphaae.mcpe.servers.StaticData;
|
||||
import com.alphaae.mcpe.servers.model.RePlayer;
|
||||
import com.alphaae.mcpe.servers.utils.PlayerDataLoadUtils;
|
||||
|
||||
public class LoadPlayerDataBlock implements JoinQuitEventBlock {
|
||||
|
||||
@ -14,12 +15,11 @@ public class LoadPlayerDataBlock implements JoinQuitEventBlock {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
//读取数据
|
||||
RePlayer rePlayer = PlayerDataLoadUtils.LoadData(player);
|
||||
|
||||
String title = "[称号]";
|
||||
String title = rePlayer.getTitle();
|
||||
|
||||
player.setDisplayName(TextFormat.colorize("&e" + title + " &b" + player.getName() + "&f"));
|
||||
|
||||
RePlayer rePlayer = new RePlayer(player, title, 4000);
|
||||
player.setDisplayName(TextFormat.colorize("&e[" + title + "] &b" + player.getName() + "&f"));
|
||||
StaticData.rePlayerMap.put(player.getUniqueId(), rePlayer);
|
||||
}
|
||||
|
||||
@ -28,4 +28,6 @@ public class LoadPlayerDataBlock implements JoinQuitEventBlock {
|
||||
Player player = event.getPlayer();
|
||||
StaticData.rePlayerMap.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,30 +1,40 @@
|
||||
package com.alphaae.mcpe.servers.model;
|
||||
|
||||
import cn.nukkit.Player;
|
||||
|
||||
public class RePlayer {
|
||||
|
||||
private Player player;
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
|
||||
public class RePlayer implements Serializable {
|
||||
private UUID uuid;
|
||||
private String title;
|
||||
private int coin;
|
||||
|
||||
public RePlayer(Player player, String title, int coin) {
|
||||
this.player = player;
|
||||
public RePlayer(UUID uuid, String title, int coin) {
|
||||
this.uuid = uuid;
|
||||
this.title = title;
|
||||
this.coin = coin;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public int getCoin() {
|
||||
return coin;
|
||||
}
|
||||
|
||||
public void setCoin(int coin) {
|
||||
this.coin = coin;
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.alphaae.mcpe.servers.utils;
|
||||
|
||||
import cn.nukkit.Player;
|
||||
import com.alphaae.mcpe.servers.MainPlugin;
|
||||
import com.alphaae.mcpe.servers.model.RePlayer;
|
||||
|
||||
public class ChangePlayerCoinUtils {
|
||||
|
||||
public static boolean IncreaseIcon(RePlayer rePlayer, int count) {
|
||||
int userCoin = rePlayer.getCoin();
|
||||
int newCoin = userCoin + count;
|
||||
rePlayer.setCoin(newCoin);
|
||||
return PlayerDataLoadUtils.ChangeData(rePlayer);
|
||||
}
|
||||
|
||||
|
||||
public static boolean ReduceIcon(RePlayer rePlayer, int count) {
|
||||
int userCoin = rePlayer.getCoin();
|
||||
int newCoin = userCoin - count;
|
||||
if (newCoin >= 0) {
|
||||
rePlayer.setCoin(newCoin);
|
||||
return PlayerDataLoadUtils.ChangeData(rePlayer);
|
||||
}
|
||||
Player player = MainPlugin.getPlugin().getServer().getPlayer(rePlayer.getUuid()).get();
|
||||
player.sendMessage("");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
65
src/com/alphaae/mcpe/servers/utils/PlayerDataLoadUtils.java
Normal file
65
src/com/alphaae/mcpe/servers/utils/PlayerDataLoadUtils.java
Normal file
@ -0,0 +1,65 @@
|
||||
package com.alphaae.mcpe.servers.utils;
|
||||
|
||||
import cn.nukkit.Player;
|
||||
import com.alphaae.mcpe.servers.MainPlugin;
|
||||
import com.alphaae.mcpe.servers.model.RePlayer;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerDataLoadUtils {
|
||||
|
||||
private static final String FILE_TYPE = ".replayer";
|
||||
private static final File DATA_FOLDER = MainPlugin.getPlugin().getDataFolder();
|
||||
private static final File PLAYER_DATA_FOLDER = new File(DATA_FOLDER, "PlayerData");
|
||||
|
||||
static {
|
||||
if (!PLAYER_DATA_FOLDER.exists()) {
|
||||
PLAYER_DATA_FOLDER.mkdirs();
|
||||
}
|
||||
}
|
||||
|
||||
public static RePlayer LoadData(Player player) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
try {
|
||||
File playerDataFile = new File(PLAYER_DATA_FOLDER, uuid.toString() + FILE_TYPE);
|
||||
if (!playerDataFile.exists()) {
|
||||
CreateNewPlayerData(playerDataFile, uuid);
|
||||
}
|
||||
ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(playerDataFile));
|
||||
RePlayer rePlayer = (RePlayer) inputStream.readObject();
|
||||
return rePlayer;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean ChangeData(RePlayer rePlayer) {
|
||||
|
||||
File playerDataFile = new File(PLAYER_DATA_FOLDER, rePlayer.getUuid().toString() + FILE_TYPE);
|
||||
try {
|
||||
ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(playerDataFile, false));
|
||||
outputStream.writeObject(rePlayer);
|
||||
outputStream.close();
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean CreateNewPlayerData(File playerDataFile, UUID uuid) {
|
||||
try {
|
||||
playerDataFile.createNewFile();
|
||||
ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(playerDataFile));
|
||||
RePlayer rePlayer = new RePlayer(uuid, "新火", 2000);
|
||||
outputStream.writeObject(rePlayer);
|
||||
outputStream.close();
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user