Skip to content

Commit

Permalink
4.1.1_Pre1功能,4.1.1_Pre2
Browse files Browse the repository at this point in the history
  • Loading branch information
yueyinqiu committed Jun 26, 2020
1 parent 928cc87 commit 5fdb745
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
8 changes: 5 additions & 3 deletions NWorldPermissions/res/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# config.yml

controlled-worlds: []

offline-players-tracker:
enabled: true
record-only: true
teleport-times:
position-changed: 0
position-unchanged: 0

controlled-worlds: []
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' in file 'config.yml'.
# 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.0.4
version: 4.1.1_Pre2
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 @@ -82,6 +82,7 @@ protected boolean run(int layer, RootPlugin rootPlugin, DotDividedStringBuilder
if (configuration.getLocation("position").getWorld().equals(world))
{
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 @@ -29,12 +29,10 @@ public LoginAndQuitListener(RootPlugin rootPlugin)
@EventHandler
public void onPlayerLogin(PlayerJoinEvent e)
{
if ((!rootPlugin.getConfig().getBoolean("offline-players-tracker.enabled")) ||
rootPlugin.getConfig().getBoolean("offline-players-tracker.record-only"))
{
if ((!rootPlugin.getConfig().getBoolean("offline-players-tracker.enabled")))
return;
}


Player player = e.getPlayer();
File file = new File(
rootPlugin.getDataFolder().getAbsolutePath(), "playersData");
Expand All @@ -45,9 +43,16 @@ public void onPlayerLogin(PlayerJoinEvent e)

YamlConfiguration yamlConfiguration = YamlConfiguration
.loadConfiguration(file);
Object location = yamlConfiguration.get("position");
if (location != null)
player.teleport((Location) location);
Object position = yamlConfiguration.get("position");
if (position == null) return;
Location location = (Location) position;

int times = yamlConfiguration.getBoolean("changed", false) ?
rootPlugin.getConfig().getInt("offline-players-tracker.teleport-times.position-changed") :
rootPlugin.getConfig().getInt("offline-players-tracker.teleport-times.position-unchanged");

for (int i = 0; i < times; i++)
player.teleport(location);
}
@EventHandler
public void onPlayerQuitEvent(PlayerQuitEvent e)
Expand All @@ -69,6 +74,7 @@ public void onPlayerQuitEvent(PlayerQuitEvent e)
YamlConfiguration yamlConfiguration = YamlConfiguration
.loadConfiguration(file);
yamlConfiguration.set("position", player.getLocation());
yamlConfiguration.set("changed", false);
yamlConfiguration.save(file);
}
catch (IOException ex)
Expand Down

0 comments on commit 5fdb745

Please # to comment.