-
Notifications
You must be signed in to change notification settings - Fork 1
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
0 parents
commit 3e967bf
Showing
10 changed files
with
673 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
MIT License | ||
|
||
Copyright (c) [2023] [Jiří Apjár] | ||
Copyright (c) [2023] [Filip Zeman] | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,158 @@ | ||
# ForestChannelAPI | ||
![badge](https://img.shields.io/github/v/release/ForestTechMC/ForestChannelAPI) | ||
[![badge](https://jitpack.io/v/ForestTechMC/ForestChannelAPI.svg)](https://jitpack.io/#ForestTechMC/ForestChannelAPI) | ||
![badge](https://img.shields.io/github/downloads/ForestTechMC/ForestChannelAPI/total) | ||
![badge](https://img.shields.io/github/last-commit/ForestTechMC/ForestChannelAPI) | ||
![badge](https://img.shields.io/badge/platform-spigot%20%7C%20bungeecord-lightgrey) | ||
[![badge](https://img.shields.io/discord/896466173166747650?label=discord)](https://discord.gg/2PpdrfxhD4) | ||
[![badge](https://img.shields.io/github/license/ForestTechMC/ForestChannelAPI)](https://github.com/ForestTechMC/ForestChannelAPI/blob/master/LICENSE.txt) | ||
|
||
**[JavaDoc 1.0](https://foresttechmc.github.io/ForestChannelAPI/1.1/)** | ||
|
||
Have you ever had a problem with channels in plugins? (I had) <br> | ||
That's why I want to introduce you ForestChannelAPI. <br> | ||
For usage on larger projects, we recommend more using Redis together with our [ForestRedisAPI](https://github.com/ForestTechMC/ForestRedisAPI) instead. | ||
|
||
## Table of contents | ||
|
||
* [Getting started](#getting-started) | ||
* [Example of events](#example-of-events) | ||
* [Example of manager](#using-color-api) | ||
* [Example in project](#using-color-api) | ||
* [License](#license) | ||
|
||
## Getting started | ||
|
||
Make sure you reloaded maven or gradle in your project. | ||
|
||
### We recommend more using Redis API | ||
|
||
The problem in channels at all is <br> | ||
we need some online player to send information to Bungee x Spigot or Spigot x Bungee <br> | ||
Our API for Redis [ForestRedisAPI](https://github.com/ForestTechMC/ForestRedisAPI) | ||
|
||
### Add ForestChannelAPI to your project | ||
|
||
[![badge](https://jitpack.io/v/ForestTechMC/ForestChannelAPI.svg)](https://jitpack.io/#ForestTechMC/ForestChannelAPI) | ||
|
||
You need to add this dependency into your plugin, then look at under the dependencies example | ||
|
||
<details> | ||
<summary>Maven</summary> | ||
|
||
```xml | ||
<repositories> | ||
<repository> | ||
<id>jitpack.io</id> | ||
<url>https://jitpack.io</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.github.ForestTechMC</groupId> | ||
<artifactId>ForestChannelAPI</artifactId> | ||
<version>VERSION</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
``` | ||
</details> | ||
|
||
<details> | ||
<summary>Gradle</summary> | ||
|
||
```gradle | ||
allprojects { | ||
repositories { | ||
... | ||
maven { url 'https://jitpack.io' } | ||
} | ||
} | ||
dependencies { | ||
implementation 'com.github.ForestTechMC:ForestChannelAPI:VERSION' | ||
} | ||
``` | ||
</details> | ||
|
||
### Example of events | ||
|
||
<details> | ||
<summary>Example of events</summary> | ||
|
||
```java | ||
// Bungee custom event | ||
@EventHandler | ||
public void onChannel(ChannelEvent event) { | ||
ProxiedPlayer player = event.getSender(); | ||
String channel = event.getChannel(); | ||
String message = event.getMessage(); | ||
|
||
System.out.println("Our first sender: " + player.getName()); // The person we send from that information | ||
System.out.println("Our first channel name: " + channel); // Channel name <plugin name>:<channel name> | ||
System.out.println("Our first message from that channel: " + message); // Message "Omg its working!" | ||
} | ||
|
||
// Spigot custom event | ||
@EventHandler | ||
public void onChannel(ChannelEvent event) { | ||
Player player = event.getPlayer(); | ||
String channel = event.getChannel(); | ||
String message = event.getMessage(); | ||
|
||
System.out.println("Our first sender: " + player.getName()); // The person we send from that information | ||
System.out.println("Our first channel name: " + channel); // Channel name <plugin name>:<channel name> | ||
System.out.println("Our first message from that channel: " + message); // Message "Omg its working!" | ||
} | ||
``` | ||
</details> | ||
|
||
### Using Channel API | ||
|
||
<details> | ||
<summary>Using API</summary> | ||
|
||
```java | ||
// Import for Bungee | ||
import cz.foresttech.api.bungee.taker.ChannelAPI; | ||
// Spigot instance | ||
private static Bungee instance; | ||
|
||
private ChannelAPI channelAPI; | ||
|
||
@Override | ||
public void onEnable() { | ||
instance = this; | ||
|
||
channelAPI = new ChannelAPI(this); | ||
channelAPI.register("<channel name>"); | ||
|
||
} | ||
|
||
// Import for Spigot | ||
import cz.foresttech.api.spigot.taker.ChannelAPI; | ||
|
||
// Bungee instance | ||
private static Spigot instance; | ||
|
||
private ChannelAPI channelAPI; | ||
|
||
@Override | ||
public void onEnable() { | ||
instance = this; | ||
|
||
channelAPI = new ChannelAPI(this); | ||
channelAPI.register("<channel name>"); | ||
} | ||
|
||
// GLOBAL (Bungee & Spigot) | ||
|
||
// Send method | ||
getChannelAPI().send(player, "<channel name>", "<message>"); | ||
getChannelAPI().registerEvent(this, new SuperEvent()); | ||
``` | ||
</details> | ||
|
||
## License | ||
ForestChannelAPI is licensed under the permissive MIT license. Please see [`LICENSE.txt`](https://github.com/ForestTechMC/ForestChannelAPI/blob/master/LICENSE.txt) for more information. |
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,53 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>cz.foresttech</groupId> | ||
<artifactId>ForestChannelAPI</artifactId> | ||
<version>1.0.0</version> | ||
|
||
<properties> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<repositories> | ||
<repository> | ||
<id>jitpack.io</id> | ||
<url>https://jitpack.io</url> | ||
</repository> | ||
<repository> | ||
<id>spigot-repo</id> | ||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> | ||
</repository> | ||
<repository> | ||
<id>bungeecord-repo</id> | ||
<url>https://oss.sonatype.org/content/repositories/snapshots</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>net.md-5</groupId> | ||
<artifactId>bungeecord-api</artifactId> | ||
<version>1.19-R0.1-SNAPSHOT</version> | ||
<type>jar</type> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.22</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.spigotmc</groupId> | ||
<artifactId>spigot-api</artifactId> | ||
<version>1.19-R0.1-SNAPSHOT</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
42 changes: 42 additions & 0 deletions
42
src/main/java/cz/foresttech/api/bungee/events/ChannelEvent.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 cz.foresttech.api.bungee.events; | ||
|
||
import net.md_5.bungee.api.connection.Connection; | ||
import net.md_5.bungee.api.connection.ProxiedPlayer; | ||
import net.md_5.bungee.api.plugin.Event; | ||
|
||
public class ChannelEvent extends Event{ | ||
private final String channel; | ||
private final String message; | ||
private final ProxiedPlayer sender; | ||
private final Connection senderCon; | ||
private final Connection receiverCon; | ||
|
||
public ChannelEvent(String channel, String message, ProxiedPlayer sender, Connection senderCon, Connection receiverCon) { | ||
this.channel = channel; | ||
this.message = message; | ||
this.sender = sender; | ||
this.senderCon = senderCon; | ||
this.receiverCon = receiverCon; | ||
} | ||
|
||
public ProxiedPlayer getSender() { | ||
return sender; | ||
} | ||
|
||
public Connection getSenderCon() { | ||
return senderCon; | ||
} | ||
|
||
public Connection getReceiverCon() { | ||
return receiverCon; | ||
} | ||
|
||
public String getChannel() { | ||
return channel; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/cz/foresttech/api/bungee/events/ChannelHandler.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,56 @@ | ||
package cz.foresttech.api.bungee.events; | ||
|
||
import net.md_5.bungee.api.ProxyServer; | ||
import net.md_5.bungee.api.connection.ProxiedPlayer; | ||
import net.md_5.bungee.api.event.PluginMessageEvent; | ||
import net.md_5.bungee.api.plugin.Listener; | ||
import net.md_5.bungee.api.plugin.Plugin; | ||
import net.md_5.bungee.event.EventHandler; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.DataInputStream; | ||
import java.io.IOException; | ||
import java.util.Collection; | ||
|
||
|
||
public class ChannelHandler implements Listener { | ||
|
||
private Plugin plugin; | ||
|
||
public ChannelHandler(Plugin plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
/** | ||
* | ||
* This is our caller for custom event | ||
* We did this for better manipulation with content | ||
* | ||
* @param event Official plugin message event | ||
*/ | ||
@EventHandler | ||
public void onPluginMessageEvent(PluginMessageEvent event) { | ||
if (event.getTag().startsWith("minecraft")) { | ||
return; | ||
} | ||
|
||
DataInputStream stream = new DataInputStream(new ByteArrayInputStream(event.getData())); | ||
|
||
String message; | ||
String playerName; | ||
try { | ||
stream.readUTF(); | ||
playerName = stream.readUTF(); | ||
message = stream.readUTF(); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(playerName); | ||
if (player == null && !player.isConnected()) { | ||
Collection<ProxiedPlayer> players = ProxyServer.getInstance().getPlayers(); | ||
player = players.stream().findFirst().get(); | ||
} | ||
plugin.getProxy().getPluginManager().callEvent(new ChannelEvent(event.getTag(), message, player, event.getSender(), event.getReceiver())); | ||
} | ||
|
||
} |
Oops, something went wrong.