Skip to content

Commit

Permalink
1.0.2 版本更新
Browse files Browse the repository at this point in the history
1. 修复back有时无法使用的问题
2. 添加权限节点的前缀,避免权限混用
3. 实装多条请求处理的提示
4. 针对home和back取消safety判断,避免无法返回。
5. 修复请求超时不清理的问题。
6. 修复部分消息不全的问题。
7. 添加Tpa/TpaHere的限制,短时间只允许一条请求,避免刷屏。
  • Loading branch information
CarmJos committed Dec 17, 2021
1 parent 98a8835 commit 5439c57
Show file tree
Hide file tree
Showing 18 changed files with 135 additions and 169 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<groupId>cc.carm.plugin</groupId>
<artifactId>moeteleport</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>

<name>MoeTeleport</name>
<description>喵喵传送,简单的传送、设置家的插件。</description>
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/cc/carm/plugin/moeteleport/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
import cc.carm.plugin.moeteleport.command.completer.HomeNameCompleter;
import cc.carm.plugin.moeteleport.command.completer.PlayerNameCompleter;
import cc.carm.plugin.moeteleport.command.completer.TpRequestCompleter;
import cc.carm.plugin.moeteleport.command.home.*;
import cc.carm.plugin.moeteleport.command.tpa.*;
import cc.carm.plugin.moeteleport.command.home.DelHomeCommand;
import cc.carm.plugin.moeteleport.command.home.GoHomeCommand;
import cc.carm.plugin.moeteleport.command.home.ListHomeCommand;
import cc.carm.plugin.moeteleport.command.home.SetHomeCommand;
import cc.carm.plugin.moeteleport.command.tpa.TpHandleCommand;
import cc.carm.plugin.moeteleport.command.tpa.TpaCommand;
import cc.carm.plugin.moeteleport.listener.UserListener;
import cc.carm.plugin.moeteleport.manager.ConfigManager;
import cc.carm.plugin.moeteleport.manager.RequestManager;
Expand Down Expand Up @@ -57,9 +61,9 @@ public void onEnable() {
registerCommand("listHome", new ListHomeCommand());

registerCommand("tpa", new TpaCommand(), new PlayerNameCompleter());
registerCommand("tpaHere", new TpaHereCommand(), new PlayerNameCompleter());
registerCommand("tpAccept", new TpAcceptCommand(), new TpRequestCompleter());
registerCommand("tpDeny", new TpDenyCommand(), new TpRequestCompleter());
registerCommand("tpaHere", new TpaCommand(), new PlayerNameCompleter());
registerCommand("tpAccept", new TpHandleCommand(), new TpRequestCompleter());
registerCommand("tpDeny", new TpHandleCommand(), new TpRequestCompleter());

log("加载完成 ,共耗时 " + (System.currentTimeMillis() - startTime) + " ms 。");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
PluginMessages.NO_LAST_LOCATION.send(player);
return true;
}
if (!TeleportManager.isSafeLocation(data.getLastLocation())) {
PluginMessages.DANGEROUS.send(player);
return true;
}

TeleportManager.teleport(player, data.getLastLocation());

TeleportManager.teleport(player, data.getLastLocation(), false);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
} else {
PluginMessages.Home.REMOVED.sendWithPlaceholders(player,
new String[]{"%(name)", "%(location)"},
new Object[]{locationInfo.getKey(), locationInfo.getValue().toString()});
new Object[]{locationInfo.getKey(), locationInfo.getValue().toFlatString()});
data.delHomeLocation(homeName);
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
if (locationInfo == null) {
PluginMessages.Home.NOT_FOUND.sendWithPlaceholders(player);
} else {
TeleportManager.teleport(player, locationInfo.getValue());
TeleportManager.teleport(player, locationInfo.getValue(), false);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
PluginMessages.Home.HEADER.sendWithPlaceholders(player);
data.getHomeLocations().forEach((name, loc) -> PluginMessages.Home.LIST_OBJECT
.sendWithPlaceholders(player,
new String[]{"%(name)", "%(location)"},
new Object[]{name, loc.toString()}
new String[]{"%(id)", "%(location)"},
new Object[]{name, loc.toFlatString()}
));
return true;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@

import java.util.Comparator;

public class TpAcceptCommand implements CommandExecutor {
public class TpHandleCommand implements CommandExecutor {

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, @NotNull String[] args) {
if (!(sender instanceof Player)) return false;
Player player = (Player) sender;
UserData data = Main.getUserManager().getData(player);
Expand All @@ -25,6 +26,8 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
return true;
}
String targetName = args.length > 0 ? args[0] : null;
boolean accept = command.getName().equalsIgnoreCase("tpAccept");
data.setEnableAutoSelect(false);
if (targetName != null) {
Player target = Bukkit.getPlayer(targetName);
if (target == null || !data.getReceivedRequests().containsKey(target.getUniqueId())) {
Expand All @@ -33,15 +36,30 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
new Object[]{target == null ? targetName : target.getName()}
);
} else {
TeleportRequest request = data.getReceivedRequests().get(target.getUniqueId());
Main.getRequestManager().acceptRequest(request); // 交给Manager处理
handle(data.getReceivedRequests().get(target.getUniqueId()), accept); // 交给Manager处理
}
} else {
data.getReceivedRequests().values().stream()
.min(Comparator.comparingLong(TeleportRequest::getActiveTime))
.ifPresent(request -> Main.getRequestManager().acceptRequest(request));
if (data.getReceivedRequests().size() == 1 || data.isEnableAutoSelect()) {
data.getReceivedRequests().values().stream()
.min(Comparator.comparingLong(TeleportRequest::getActiveTime))
.ifPresent(request -> handle(request, accept));
} else {
PluginMessages.Request.MULTI.sendWithPlaceholders(player,
new String[]{"%(num)", "%(command)"},
new Object[]{data.getReceivedRequests().size(), command.getName()}
);
data.setEnableAutoSelect(true);
}
}
return true;
}

private void handle(TeleportRequest request, boolean accept) {
if (accept) {
Main.getRequestManager().acceptRequest(request);
} else {
Main.getRequestManager().denyRequest(request);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,30 @@
public class TpaCommand implements CommandExecutor {

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, @NotNull String[] args) {
if (!(sender instanceof Player) || args.length < 1) return false;
Player player = (Player) sender;
Player target = Bukkit.getPlayer(args[0]);
if (target == null) {
PluginMessages.NOT_ONLINE.sendWithPlaceholders(player);
return true;
}
Main.getRequestManager().sendRequest(player, target, TeleportRequest.RequestType.TPA);

TeleportRequest request = Main.getUserManager().getData(target).getReceivedRequests().get(player.getUniqueId());
if (request != null) {
PluginMessages.Request.DUPLICATE.sendWithPlaceholders(sender,
new String[]{"%(player)", "%(expire)"},
new Object[]{target.getName(), request.getRemainSeconds()}
);
return true;
}
if (command.getName().equalsIgnoreCase("tpa")) {
Main.getRequestManager().sendRequest(player, target, TeleportRequest.RequestType.TPA);
} else {
Main.getRequestManager().sendRequest(player, target, TeleportRequest.RequestType.TPA_HERE);
}

return true;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class PluginMessages {
public static final ConfigMessageList NOT_AVAILABLE = new ConfigMessageList("notAvailable");

public static class Request {
public static final ConfigMessageList DUPLICATE = new ConfigMessageList("request-duplicate");
public static final ConfigMessageList OFFLINE = new ConfigMessageList("offline");

public static final ConfigMessageList SENT = new ConfigMessageList("request-sent");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.text.DecimalFormat;
import java.util.Objects;

public class DataLocation implements Cloneable {

public static final DecimalFormat format = new DecimalFormat("0.00");
private String worldName;
private double x;
private double y;
Expand Down Expand Up @@ -97,8 +99,8 @@ public Object clone() {
try {
return super.clone();
} catch (Exception ex) {
return null;
}
return null;
}

@Override
Expand All @@ -124,6 +126,10 @@ public String toString() {
return worldName + " " + x + " " + y + " " + z + " " + yaw + " " + pitch;
}

public String toFlatString() {
return worldName + "@" + format.format(x) + ", " + format.format(y) + ", " + format.format(z);
}

@Deprecated
public String toSerializedString() {
return serializeToText();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ public void checkRequests() {
.peek(entry -> PluginMessages.Request.RECEIVED_TIMEOUT.sendWithPlaceholders(
entry.getValue().getReceiver(), new String[]{"%(player)"},
new Object[]{entry.getValue().getSender().getName()}))
.forEach(entry -> data.getSentRequests().remove(entry.getKey()))
.peek(entry -> Main.getUserManager()
.getData(entry.getValue().getSender()).getSentRequests()
.remove(entry.getKey()))
.forEach(entry -> data.getReceivedRequests().remove(entry.getKey()))
);
}

Expand All @@ -51,8 +54,9 @@ public void sendRequest(Player sender, Player receiver, TeleportRequest.RequestT

PluginMessages.Request.SENT.sendWithPlaceholders(sender,
new String[]{"%(player)", "%(expire)"},
new Object[]{receiver, expireTime}
new Object[]{receiver.getName(), expireTime}
);

switch (type) {
case TPA: {
PluginMessages.TPA.sendWithPlaceholders(receiver,
Expand Down Expand Up @@ -85,7 +89,7 @@ public void acceptRequest(TeleportRequest request) {
new String[]{"%(player)"},
new Object[]{request.getSender().getName()}
);
TeleportManager.teleport(request.getTeleportPlayer(), request.getTeleportLocation());
TeleportManager.teleport(request.getTeleportPlayer(), request.getTeleportLocation(), true);
removeRequests(request);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cc.carm.plugin.moeteleport.manager;

import cc.carm.plugin.moeteleport.Main;
import cc.carm.plugin.moeteleport.configuration.PluginConfig;
import cc.carm.plugin.moeteleport.configuration.PluginMessages;
import cc.carm.plugin.moeteleport.configuration.location.DataLocation;
Expand All @@ -10,29 +11,34 @@

public class TeleportManager {

public static void teleport(Player player, DataLocation targetLocation) {
public static void teleport(Player player, DataLocation targetLocation, boolean onlySafety) {
Location location = targetLocation.getBukkitLocation();
if (location == null) {
PluginMessages.NOT_AVAILABLE.sendWithPlaceholders(player,
new String[]{"%(location)"},
new Object[]{targetLocation.toString()}
new Object[]{targetLocation.toFlatString()}
);
} else {
teleport(player, location);
teleport(player, location, onlySafety);
}
}

public static void teleport(Player player, Location targetLocation) {
public static void teleport(Player player, Location targetLocation, boolean onlySafety) {
if (targetLocation.isWorldLoaded()) {
player.teleport(targetLocation);
PluginMessages.TELEPORTING.sendWithPlaceholders(player,
new String[]{"%(location)"},
new Object[]{new DataLocation(targetLocation).toString()}
);
if (!onlySafety || TeleportManager.isSafeLocation(targetLocation)) {
Main.getUserManager().getData(player).setLastLocation(player.getLocation());
player.teleport(targetLocation);
PluginMessages.TELEPORTING.sendWithPlaceholders(player,
new String[]{"%(location)"},
new Object[]{new DataLocation(targetLocation).toFlatString()}
);
} else {
PluginMessages.DANGEROUS.send(player);
}
} else {
PluginMessages.NOT_AVAILABLE.sendWithPlaceholders(player,
new String[]{"%(location)"},
new Object[]{new DataLocation(targetLocation).toString()}
new Object[]{new DataLocation(targetLocation).toFlatString()}
);
}
}
Expand Down
Loading

0 comments on commit 5439c57

Please sign in to comment.