Skip to content

Commit

Permalink
4.1.1_Pre1上限时传送可以设置次数,解决back问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
yueyinqiu committed Jun 26, 2020
1 parent 6eb2b3d commit 0de1411
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
6 changes: 4 additions & 2 deletions NWorldPermissions/res/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# config.yml

controlled-worlds: []
controlled-worlds:

offline-players-tracker:
enabled: true
record-only: true
teleport-times:
position-changed: 0
position-unchanged: 0
2 changes: 1 addition & 1 deletion NWorldPermissions/res/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ messages:
offline:
tracker-not-enabled: |
&r&3> Oh, {senderName}&r&3! You haven't enabled the offline players tracker.
Make sure you've set 'offline-players-tracker.enabled' to 'true', and 'offline-players-tracker.record-only' to 'false' in file 'config.yml'.
Make sure you've set 'offline-players-tracker.enabled' to 'true'.
# Available Arg(s): {senderName}.
no-such-world: |
&r&3> {senderName}&r&3? Which world is '{worldName}'?
Expand Down
2 changes: 1 addition & 1 deletion NWorldPermissions/res/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: NWorldPermissions
main: top.nololiyt.worldpermissions.RootPlugin
version: 4.1.0
version: 4.1.1_Pre1
author: yueyinqiu5990
description: A strange power stopping players being teleported to a world.
website: https://github.com/yueyinqiu/NWorldPermissions/wiki
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ class OfflineExecutor : Executor()
val basePairs = arrayOf<StringPair?>(StringPair.markName(markName), StringPair.worldName(worldName),
StringPair.senderName(commandSender.name));

if (!rootPlugin.config.getBoolean("offline-players-tracker.enabled") || rootPlugin.config.getBoolean(
"offline-players-tracker.record-only"))
if (!rootPlugin.config.getBoolean("offline-players-tracker.enabled"))
{
rootPlugin.messagesManager.sendMessage(messageKey.append("tracker-not-enabled"), basePairs, commandSender);
return true;
Expand Down Expand Up @@ -68,7 +67,8 @@ class OfflineExecutor : Executor()
val position = configuration.getLocation("position") ?: continue;
if (position.world == world)
{
configuration.set("position", location)
configuration.set("position", location);
configuration.set("changed", true);
try
{
configuration.save(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,28 @@ class LoginAndQuitListener(private val rootPlugin: RootPlugin) : Listener
@EventHandler
fun onPlayerLogin(e: PlayerJoinEvent)
{
if (!rootPlugin.config.getBoolean("offline-players-tracker.enabled") || rootPlugin.config.getBoolean(
"offline-players-tracker.record-only")) return;
if (!rootPlugin.config.getBoolean("offline-players-tracker.enabled")) return;
val player = e.player;
var file = File(rootPlugin.dataFolder.absolutePath, "playersData");
file.mkdirs();
file = File(file.absolutePath, player.uniqueId.toString() + ".yml");
if (!file.exists()) return;

val yamlConfiguration = YamlConfiguration.loadConfiguration(file);
val location = yamlConfiguration.get("position");
if (location != null) player.teleport((location as Location?)!!);
val position = yamlConfiguration.get("position");
if (position != null)
{
val location = position as Location;
val times = when (yamlConfiguration.getBoolean("changed", false))
{
true -> rootPlugin.config.getInt("offline-players-tracker.teleport-times.position-changed")
false -> rootPlugin.config.getInt("offline-players-tracker.teleport-times.position-unchanged")
}
for (index in 0 until times)
{
player.teleport(location);
}
}
}

@EventHandler
Expand All @@ -48,6 +59,7 @@ class LoginAndQuitListener(private val rootPlugin: RootPlugin) : Listener

val yamlConfiguration = YamlConfiguration.loadConfiguration(file);
yamlConfiguration.set("position", player.location);
yamlConfiguration.set("changed", false);
yamlConfiguration.save(file);
}
catch (ex: IOException)
Expand Down

0 comments on commit 0de1411

Please # to comment.