-
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.
I think ISpigotPlayer is "weird" to use, SpigotPlayerImpl will rarely be used as SpigotPlayer (The new interface) already provides all methods
- Loading branch information
Showing
9 changed files
with
156 additions
and
156 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
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
38 changes: 0 additions & 38 deletions
38
platforms/spigot/src/main/java/net/codersky/skyutils/spigot/player/IOfflineSpigotPlayer.java
This file was deleted.
Oops, something went wrong.
92 changes: 0 additions & 92 deletions
92
platforms/spigot/src/main/java/net/codersky/skyutils/spigot/player/ISpigotPlayer.java
This file was deleted.
Oops, something went wrong.
31 changes: 25 additions & 6 deletions
31
platforms/spigot/src/main/java/net/codersky/skyutils/spigot/player/OfflineSpigotPlayer.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 |
---|---|---|
@@ -1,19 +1,38 @@ | ||
package net.codersky.skyutils.spigot.player; | ||
|
||
import net.codersky.skyutils.crossplatform.player.OfflineSkyPlayer; | ||
import org.bukkit.OfflinePlayer; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class OfflineSpigotPlayer implements IOfflineSpigotPlayer { | ||
import java.util.UUID; | ||
|
||
private final OfflinePlayer handle; | ||
public interface OfflineSpigotPlayer extends OfflineSkyPlayer { | ||
|
||
protected OfflineSpigotPlayer(@NotNull OfflinePlayer handle) { | ||
this.handle = handle; | ||
@NotNull | ||
OfflinePlayer getHandle(); | ||
|
||
@Nullable | ||
default Player getOnlineHandle() { | ||
return getHandle().getPlayer(); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public OfflinePlayer getHandle() { | ||
return handle; | ||
default UUID getUniqueId() { | ||
return getHandle().getUniqueId(); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
default String getName() { | ||
final String name = getHandle().getName(); | ||
return name == null ? "" : name; | ||
} | ||
|
||
@Override | ||
default boolean isOnline() { | ||
return getHandle().isOnline(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...rms/spigot/src/main/java/net/codersky/skyutils/spigot/player/OfflineSpigotPlayerImpl.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,19 @@ | ||
package net.codersky.skyutils.spigot.player; | ||
|
||
import org.bukkit.OfflinePlayer; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class OfflineSpigotPlayerImpl implements OfflineSpigotPlayer { | ||
|
||
private final OfflinePlayer handle; | ||
|
||
protected OfflineSpigotPlayerImpl(@NotNull OfflinePlayer handle) { | ||
this.handle = handle; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public OfflinePlayer getHandle() { | ||
return handle; | ||
} | ||
} |
85 changes: 80 additions & 5 deletions
85
platforms/spigot/src/main/java/net/codersky/skyutils/spigot/player/SpigotPlayer.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 |
---|---|---|
@@ -1,17 +1,92 @@ | ||
package net.codersky.skyutils.spigot.player; | ||
|
||
import net.codersky.skyutils.crossplatform.player.SkyPlayer; | ||
import net.kyori.adventure.sound.Sound; | ||
import net.kyori.adventure.text.Component; | ||
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer; | ||
import net.md_5.bungee.api.ChatMessageType; | ||
import net.md_5.bungee.api.chat.BaseComponent; | ||
import net.md_5.bungee.api.chat.TextComponent; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class SpigotPlayer extends OfflineSpigotPlayer implements ISpigotPlayer { | ||
public interface SpigotPlayer extends OfflineSpigotPlayer, SkyPlayer { | ||
|
||
protected SpigotPlayer(@NotNull Player handle) { | ||
super(handle); | ||
/* | ||
- OfflineSpigotPlayerImpl Override | ||
*/ | ||
|
||
@NotNull | ||
@Override | ||
Player getHandle(); | ||
|
||
@NotNull | ||
default Player getOnlineHandle() { | ||
return getHandle(); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Player getHandle() { | ||
return (Player) super.getHandle(); | ||
default String getName() { | ||
return getHandle().getName(); | ||
} | ||
|
||
/* | ||
- BaseComponent array conversion (Message utility) | ||
*/ | ||
|
||
default BaseComponent[] toBase(@NotNull String legacyStr) { | ||
return TextComponent.fromLegacyText(legacyStr); | ||
} | ||
|
||
default BaseComponent[] toBase(@NotNull Component component) { | ||
return BungeeComponentSerializer.get().serialize(component); | ||
} | ||
|
||
/* | ||
- MessageReceiver implementation | ||
*/ | ||
|
||
@Override | ||
default boolean sendMessage(@NotNull String message) { | ||
if (canReceive(message)) | ||
getHandle().sendMessage(message); | ||
return true; | ||
} | ||
|
||
@Override | ||
default boolean sendMessage(@NotNull Component message) { | ||
if (canReceive(message)) | ||
getHandle().spigot().sendMessage(toBase(message)); | ||
return false; | ||
} | ||
|
||
/* | ||
- ActionBar | ||
*/ | ||
|
||
@Override | ||
default boolean sendActionBar(@NotNull String message) { | ||
if (canReceive(message)) | ||
getHandle().spigot().sendMessage(ChatMessageType.ACTION_BAR, toBase(message)); | ||
return true; | ||
} | ||
|
||
@Override | ||
default boolean sendActionBar(@NotNull Component message) { | ||
if (canReceive(message)) | ||
getHandle().spigot().sendMessage(ChatMessageType.ACTION_BAR, toBase(message)); | ||
return true; | ||
} | ||
|
||
/* | ||
- Sounds | ||
*/ | ||
|
||
@Override | ||
default boolean playSound(@NotNull Sound sound) { | ||
final Player handle = getHandle(); | ||
handle.playSound(handle.getLocation(), sound.name().asString(), sound.volume(), sound.pitch()); | ||
return true; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
platforms/spigot/src/main/java/net/codersky/skyutils/spigot/player/SpigotPlayerImpl.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,17 @@ | ||
package net.codersky.skyutils.spigot.player; | ||
|
||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class SpigotPlayerImpl extends OfflineSpigotPlayerImpl implements SpigotPlayer { | ||
|
||
protected SpigotPlayerImpl(@NotNull Player handle) { | ||
super(handle); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Player getHandle() { | ||
return (Player) super.getHandle(); | ||
} | ||
} |
Oops, something went wrong.