-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
# marks.yml | ||
|
||
centre: | ||
==: org.bukkit.Location | ||
world: world | ||
x: 0 | ||
y: 128 | ||
z: 0 | ||
pitch: 0 | ||
yaw: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
NWorldPermissions/src/top/nololiyt/worldpermissions/playerlisteners/RespawnListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package top.nololiyt.worldpermissions.playerlisteners; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.World; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerRespawnEvent; | ||
import org.bukkit.event.player.PlayerTeleportEvent; | ||
import org.bukkit.util.Vector; | ||
import top.nololiyt.worldpermissions.RootPlugin; | ||
import top.nololiyt.worldpermissions.configurationmanagers.WorldsManager; | ||
import top.nololiyt.worldpermissions.entitiesandtools.DotDividedStringBuilder; | ||
import top.nololiyt.worldpermissions.entitiesandtools.MessagesSender; | ||
import top.nololiyt.worldpermissions.entitiesandtools.StringPair; | ||
import top.nololiyt.worldpermissions.entitiesandtools.WorldInfo; | ||
|
||
public class RespawnListener implements Listener | ||
{ | ||
private RootPlugin rootPlugin; | ||
|
||
public RespawnListener(RootPlugin rootPlugin) | ||
{ | ||
this.rootPlugin = rootPlugin; | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST) | ||
public void onPlayerTeleport(PlayerRespawnEvent e) | ||
{ | ||
Location location = e.getRespawnLocation(); | ||
|
||
World destWorld = location.getWorld(); | ||
String destWorldName = destWorld.getName(); | ||
|
||
String mark = rootPlugin.getConfig().getString("mark"); | ||
if (mark == null) | ||
return; | ||
|
||
boolean needTeleport; | ||
boolean noPermissionOnly = rootPlugin.getConfig().getBoolean( | ||
"teleport-when-respawn.no-permission-only"); | ||
if (!noPermissionOnly) | ||
needTeleport = true; | ||
else | ||
{ | ||
WorldInfo worldInfo = rootPlugin.getWorldsManager() | ||
.getWorldInfo(destWorldName); | ||
if (!worldInfo.isControlled()) | ||
needTeleport = false; | ||
else | ||
{ | ||
Player player = e.getPlayer(); | ||
needTeleport = !player.hasPermission("nworldpermissions.forfreeto." + destWorldName); | ||
} | ||
} | ||
if (!needTeleport) | ||
return; | ||
location = rootPlugin.getLocalMarksManager().getMark(mark); | ||
if (location != null) | ||
e.setRespawnLocation(location); | ||
} | ||
|
||
private MessagesSender createMessagesSender(Player player, String fromWorld, String toWorldDisplay) | ||
{ | ||
WorldsManager worldsManager = rootPlugin.getWorldsManager(); | ||
StringPair[] pairs = new StringPair[]{ | ||
StringPair.playerName(player.getDisplayName()), | ||
StringPair.fromWorld( | ||
worldsManager.getWorldInfo(fromWorld).getDisplay()), | ||
StringPair.toWorld(toWorldDisplay) | ||
}; | ||
return new MessagesSender(rootPlugin.getMessagesManager(), player, pairs); | ||
} | ||
} |