This repository has been archived by the owner on Oct 12, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updated API * Singleton API access * Remove unnecessary cast
- Loading branch information
1 parent
b169dc7
commit 444851e
Showing
8 changed files
with
261 additions
and
0 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
54 changes: 54 additions & 0 deletions
54
bukkit/src/main/java/net/william278/huskchat/bukkit/BukkitHuskChatAPI.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,54 @@ | ||
/* | ||
* This file is part of HuskChat, licensed under the Apache License 2.0. | ||
* | ||
* Copyright (c) William278 <will27528@gmail.com> | ||
* Copyright (c) contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.william278.huskchat.bukkit; | ||
|
||
import net.william278.huskchat.HuskChat; | ||
import net.william278.huskchat.HuskChatAPI; | ||
import net.william278.huskchat.bukkit.player.BukkitPlayer; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class BukkitHuskChatAPI extends HuskChatAPI { | ||
public BukkitHuskChatAPI(HuskChat plugin) { | ||
super(plugin); | ||
} | ||
|
||
public static BukkitHuskChatAPI getInstance() { | ||
return (BukkitHuskChatAPI) instance; | ||
} | ||
|
||
/** | ||
* @hidden | ||
*/ | ||
@ApiStatus.Internal | ||
public static void register(@NotNull BukkitHuskChat plugin) { | ||
HuskChatAPI.instance = new BukkitHuskChatAPI(plugin); | ||
} | ||
|
||
/** | ||
* Adapts a platform-specific Player object to a cross-platform Player object | ||
* @param player Must be a platform-specific Player object, e.g. a Velocity Player | ||
* @return {@link BukkitPlayer} | ||
*/ | ||
public BukkitPlayer adaptPlayer(@NotNull Player player) { | ||
return BukkitPlayer.adapt(player); | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
bungee/src/main/java/net/william278/huskchat/bungeecord/BungeeHuskChatAPI.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,54 @@ | ||
/* | ||
* This file is part of HuskChat, licensed under the Apache License 2.0. | ||
* | ||
* Copyright (c) William278 <will27528@gmail.com> | ||
* Copyright (c) contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.william278.huskchat.bungeecord; | ||
|
||
import net.md_5.bungee.api.connection.ProxiedPlayer; | ||
import net.william278.huskchat.HuskChat; | ||
import net.william278.huskchat.HuskChatAPI; | ||
import net.william278.huskchat.bungeecord.player.BungeePlayer; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class BungeeHuskChatAPI extends HuskChatAPI { | ||
public BungeeHuskChatAPI(HuskChat plugin) { | ||
super(plugin); | ||
} | ||
|
||
public static BungeeHuskChatAPI getInstance() { | ||
return (BungeeHuskChatAPI) instance; | ||
} | ||
|
||
/** | ||
* @hidden | ||
*/ | ||
@ApiStatus.Internal | ||
public static void register(@NotNull BungeeHuskChat plugin) { | ||
HuskChatAPI.instance = new BungeeHuskChatAPI(plugin); | ||
} | ||
|
||
/** | ||
* Adapts a platform-specific Player object to a cross-platform Player object | ||
* @param player Must be a platform-specific Player object, e.g. a Velocity Player | ||
* @return {@link BungeePlayer} | ||
*/ | ||
public BungeePlayer adaptPlayer(@NotNull ProxiedPlayer player) { | ||
return BungeePlayer.adapt(player); | ||
} | ||
} |
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
77 changes: 77 additions & 0 deletions
77
common/src/main/java/net/william278/huskchat/HuskChatAPI.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,77 @@ | ||
/* | ||
* This file is part of HuskChat, licensed under the Apache License 2.0. | ||
* | ||
* Copyright (c) William278 <will27528@gmail.com> | ||
* Copyright (c) contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.william278.huskchat; | ||
|
||
import net.william278.huskchat.message.BroadcastMessage; | ||
import net.william278.huskchat.message.ChatMessage; | ||
import net.william278.huskchat.message.PrivateMessage; | ||
import net.william278.huskchat.player.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
|
||
@SuppressWarnings("unused") | ||
public class HuskChatAPI { | ||
protected static HuskChatAPI instance; | ||
protected final HuskChat plugin; | ||
|
||
protected HuskChatAPI(@NotNull HuskChat plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
public static HuskChatAPI getInstance() { | ||
return instance; | ||
} | ||
|
||
/** | ||
* Returns the player's current channel | ||
*/ | ||
public String getPlayerChannel(@NotNull Player player) { | ||
return plugin.getPlayerCache().getPlayerChannel(player.getUuid()); | ||
} | ||
|
||
/** | ||
* Sets the player's channel | ||
*/ | ||
public void setPlayerChannel(@NotNull Player player, @NotNull String channel) { | ||
plugin.getPlayerCache().setPlayerChannel(player.getUuid(), channel); | ||
} | ||
|
||
/** | ||
* Sends a chat message on behalf of a player | ||
*/ | ||
public void sendChatMessage(@NotNull String targetChannelId, @NotNull Player sender, @NotNull String message) { | ||
new ChatMessage(targetChannelId, sender, message, plugin).dispatch(); | ||
} | ||
|
||
/** | ||
* Sends a broadcast message | ||
*/ | ||
public void sendBroadcastMessage(@NotNull Player sender, @NotNull String message) { | ||
new BroadcastMessage(sender, message, plugin).dispatch(); | ||
} | ||
|
||
/** | ||
* Sends a private message on behalf of a player | ||
*/ | ||
public void sendPrivateMessage(@NotNull Player sender, @NotNull List<String> targetUsernames, @NotNull String message) { | ||
new PrivateMessage(sender, targetUsernames, message, plugin).dispatch(); | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
velocity/src/main/java/net/william278/huskchat/velocity/VelocityHuskChatAPI.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,54 @@ | ||
/* | ||
* This file is part of HuskChat, licensed under the Apache License 2.0. | ||
* | ||
* Copyright (c) William278 <will27528@gmail.com> | ||
* Copyright (c) contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.william278.huskchat.velocity; | ||
|
||
import com.velocitypowered.api.proxy.Player; | ||
import net.william278.huskchat.HuskChat; | ||
import net.william278.huskchat.HuskChatAPI; | ||
import net.william278.huskchat.velocity.player.VelocityPlayer; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class VelocityHuskChatAPI extends HuskChatAPI { | ||
public VelocityHuskChatAPI(HuskChat plugin) { | ||
super(plugin); | ||
} | ||
|
||
public static VelocityHuskChatAPI getInstance() { | ||
return (VelocityHuskChatAPI) instance; | ||
} | ||
|
||
/** | ||
* @hidden | ||
*/ | ||
@ApiStatus.Internal | ||
public static void register(@NotNull VelocityHuskChat plugin) { | ||
HuskChatAPI.instance = new VelocityHuskChatAPI(plugin); | ||
} | ||
|
||
/** | ||
* Adapts a platform-specific Player object to a cross-platform Player object | ||
* @param player Must be a platform-specific Player object, e.g. a Velocity Player | ||
* @return {@link VelocityPlayer} | ||
*/ | ||
public VelocityPlayer adaptPlayer(@NotNull Player player) { | ||
return VelocityPlayer.adapt(player); | ||
} | ||
} |