1.3.2
This commit is contained in:
parent
b8bbf3b97a
commit
ad11100835
|
@ -1,6 +1,7 @@
|
|||
package com.io.yutian.elementoriginlib;
|
||||
|
||||
import com.io.yutian.elementoriginlib.listener.GuiHandlerListener;
|
||||
import com.io.yutian.elementoriginlib.listener.PlayerChatInputListener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class ElementOriginLib extends JavaPlugin {
|
||||
|
@ -12,6 +13,7 @@ public final class ElementOriginLib extends JavaPlugin {
|
|||
instance = this;
|
||||
|
||||
new GuiHandlerListener(this);
|
||||
new PlayerChatInputListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
package com.io.yutian.elementoriginlib.chatinput;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class PlayerChatInput {
|
||||
|
||||
private long time;
|
||||
public Player player;
|
||||
|
||||
private int timeout = 15;
|
||||
|
||||
private boolean isCall = false;
|
||||
private boolean cancel = false;
|
||||
|
||||
public PlayerChatInput(Player player) {
|
||||
this.player = player;
|
||||
this.time = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public abstract void call(String arg);
|
||||
|
||||
public void setTimeOut(int timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public boolean isTimeOut() {
|
||||
return time + 1000L * timeout >= System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public void setCancel(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
public boolean isCancel() {
|
||||
return cancel;
|
||||
}
|
||||
|
||||
public boolean isCall() {
|
||||
return isCall;
|
||||
}
|
||||
|
||||
public void setCall(boolean call) {
|
||||
isCall = call;
|
||||
}
|
||||
|
||||
public void cancle() {
|
||||
}
|
||||
|
||||
public void timeOut() {
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.io.yutian.elementoriginlib.listener;
|
||||
|
||||
import com.io.yutian.elementoriginlib.chatinput.PlayerChatInput;
|
||||
import com.io.yutian.elementoriginlib.manager.PlayerChatInputManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class PlayerChatInputListener extends IListener {
|
||||
|
||||
public PlayerChatInputListener(Plugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
if (PlayerChatInputManager.hasInput(event.getPlayer())) {
|
||||
event.setCancelled(true);
|
||||
String string = event.getMessage();
|
||||
Player player = event.getPlayer();
|
||||
PlayerChatInput playerInput = PlayerChatInputManager.getInput(player);
|
||||
if (string.toLowerCase().trim().equalsIgnoreCase("取消") || string.toLowerCase().trim().equalsIgnoreCase("none") || string.toLowerCase().trim().equalsIgnoreCase("cancle")) {
|
||||
playerInput.cancle();
|
||||
PlayerChatInputManager.removeInput(player);
|
||||
player.sendMessage("playerchatinput.cancle");
|
||||
return;
|
||||
}
|
||||
playerInput.call(string);
|
||||
if (playerInput.isCall() || playerInput.isCancel()) {
|
||||
PlayerChatInputManager.removeInput(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.io.yutian.elementoriginlib.manager;
|
||||
|
||||
import com.io.yutian.elementoriginlib.ElementOriginLib;
|
||||
import com.io.yutian.elementoriginlib.chatinput.PlayerChatInput;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerChatInputManager {
|
||||
|
||||
private static Map<UUID, PlayerChatInput> inputMap = new HashMap<>();
|
||||
|
||||
public static boolean hasInput(Player player) {
|
||||
return inputMap.containsKey(player.getUniqueId());
|
||||
}
|
||||
|
||||
public static PlayerChatInput getInput(Player player) {
|
||||
return inputMap.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
public static void addInput(Player player, PlayerChatInput playerInput) {
|
||||
inputMap.put(player.getUniqueId(), playerInput);
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (playerInput.isTimeOut() || playerInput.isCancel()) {
|
||||
if (!playerInput.isCall() && inputMap.containsValue(playerInput)) {
|
||||
playerInput.timeOut();
|
||||
player.sendMessage("playerchatinput.timeout");
|
||||
}
|
||||
}
|
||||
removeInput(player);
|
||||
}
|
||||
}.runTaskLater(ElementOriginLib.inst(), 15 * 20L);
|
||||
}
|
||||
|
||||
public static void removeInput(Player player) {
|
||||
inputMap.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
}
|
|
@ -7,3 +7,6 @@ command:
|
|||
no-player: "&f该指令只能由玩家执行"
|
||||
player-no-online: "&f玩家 &e$0 &f不存在或不在线"
|
||||
no-permission: "&f你没有执行该命令的权限"
|
||||
playerchatinput:
|
||||
timeout: "&c输入超时"
|
||||
cancel: "&c输入已取消"
|
|
@ -1,5 +1,5 @@
|
|||
name: ElementOriginLib
|
||||
version: '1.3.1'
|
||||
version: '1.3.2'
|
||||
main: com.io.yutian.elementoriginlib.ElementOriginLib
|
||||
api-version: '1.20'
|
||||
authors: [ SuperYuTian ]
|
||||
|
|
Loading…
Reference in New Issue
Block a user