-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
1 parent
5167fa9
commit 269aa5d
Showing
4 changed files
with
49 additions
and
32 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
# Changelog | ||
- Added support for 1.21 | ||
- Dropped support for 1.20.X | ||
- Bump api version in plugin.yml | ||
- Move |
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
42 changes: 42 additions & 0 deletions
42
Insights/src/main/java/dev/frankheijden/insights/commands/util/CommandSenderMapper.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,42 @@ | ||
package dev.frankheijden.insights.commands.util; | ||
|
||
import io.papermc.paper.command.brigadier.CommandSourceStack; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.Location; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Entity; | ||
import org.incendo.cloud.SenderMapper; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class CommandSenderMapper implements SenderMapper<CommandSourceStack, CommandSender> { | ||
@Override | ||
public CommandSender map(CommandSourceStack source) { | ||
return source.getSender(); | ||
} | ||
|
||
@Override | ||
public CommandSourceStack reverse(CommandSender sender) { | ||
return new CommandSourceStack() { | ||
@Override | ||
public @NotNull Location getLocation() { | ||
if (sender instanceof Entity entity) { | ||
return entity.getLocation(); | ||
} | ||
|
||
var worlds = Bukkit.getWorlds(); | ||
return new Location(worlds.isEmpty() ? null : worlds.getFirst(), 0, 0, 0); // Best effort lol | ||
} | ||
|
||
@Override | ||
public @NotNull CommandSender getSender() { | ||
return sender; | ||
} | ||
|
||
@Override | ||
public @Nullable Entity getExecutor() { | ||
return sender instanceof Entity entity ? entity : null; | ||
} | ||
}; | ||
} | ||
} |
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