Skip to content

Commit 3e967bf

Browse files
committed
Version commit v1.0
0 parents  commit 3e967bf

File tree

10 files changed

+673
-0
lines changed

10 files changed

+673
-0
lines changed

LICENSE.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) [2023] [Jiří Apjár]
4+
Copyright (c) [2023] [Filip Zeman]
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

README.md

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# ForestChannelAPI
2+
![badge](https://img.shields.io/github/v/release/ForestTechMC/ForestChannelAPI)
3+
[![badge](https://jitpack.io/v/ForestTechMC/ForestChannelAPI.svg)](https://jitpack.io/#ForestTechMC/ForestChannelAPI)
4+
![badge](https://img.shields.io/github/downloads/ForestTechMC/ForestChannelAPI/total)
5+
![badge](https://img.shields.io/github/last-commit/ForestTechMC/ForestChannelAPI)
6+
![badge](https://img.shields.io/badge/platform-spigot%20%7C%20bungeecord-lightgrey)
7+
[![badge](https://img.shields.io/discord/896466173166747650?label=discord)](https://discord.gg/2PpdrfxhD4)
8+
[![badge](https://img.shields.io/github/license/ForestTechMC/ForestChannelAPI)](https://github.com/ForestTechMC/ForestChannelAPI/blob/master/LICENSE.txt)
9+
10+
**[JavaDoc 1.0](https://foresttechmc.github.io/ForestChannelAPI/1.1/)**
11+
12+
Have you ever had a problem with channels in plugins? (I had) <br>
13+
That's why I want to introduce you ForestChannelAPI. <br>
14+
For usage on larger projects, we recommend more using Redis together with our [ForestRedisAPI](https://github.com/ForestTechMC/ForestRedisAPI) instead.
15+
16+
## Table of contents
17+
18+
* [Getting started](#getting-started)
19+
* [Example of events](#example-of-events)
20+
* [Example of manager](#using-color-api)
21+
* [Example in project](#using-color-api)
22+
* [License](#license)
23+
24+
## Getting started
25+
26+
Make sure you reloaded maven or gradle in your project.
27+
28+
### We recommend more using Redis API
29+
30+
The problem in channels at all is <br>
31+
we need some online player to send information to Bungee x Spigot or Spigot x Bungee <br>
32+
Our API for Redis [ForestRedisAPI](https://github.com/ForestTechMC/ForestRedisAPI)
33+
34+
### Add ForestChannelAPI to your project
35+
36+
[![badge](https://jitpack.io/v/ForestTechMC/ForestChannelAPI.svg)](https://jitpack.io/#ForestTechMC/ForestChannelAPI)
37+
38+
You need to add this dependency into your plugin, then look at under the dependencies example
39+
40+
<details>
41+
<summary>Maven</summary>
42+
43+
```xml
44+
<repositories>
45+
<repository>
46+
<id>jitpack.io</id>
47+
<url>https://jitpack.io</url>
48+
</repository>
49+
</repositories>
50+
51+
<dependencies>
52+
<dependency>
53+
<groupId>com.github.ForestTechMC</groupId>
54+
<artifactId>ForestChannelAPI</artifactId>
55+
<version>VERSION</version>
56+
<scope>provided</scope>
57+
</dependency>
58+
</dependencies>
59+
```
60+
</details>
61+
62+
<details>
63+
<summary>Gradle</summary>
64+
65+
```gradle
66+
allprojects {
67+
repositories {
68+
...
69+
maven { url 'https://jitpack.io' }
70+
}
71+
}
72+
73+
dependencies {
74+
implementation 'com.github.ForestTechMC:ForestChannelAPI:VERSION'
75+
}
76+
```
77+
</details>
78+
79+
### Example of events
80+
81+
<details>
82+
<summary>Example of events</summary>
83+
84+
```java
85+
// Bungee custom event
86+
@EventHandler
87+
public void onChannel(ChannelEvent event) {
88+
ProxiedPlayer player = event.getSender();
89+
String channel = event.getChannel();
90+
String message = event.getMessage();
91+
92+
System.out.println("Our first sender: " + player.getName()); // The person we send from that information
93+
System.out.println("Our first channel name: " + channel); // Channel name <plugin name>:<channel name>
94+
System.out.println("Our first message from that channel: " + message); // Message "Omg its working!"
95+
}
96+
97+
// Spigot custom event
98+
@EventHandler
99+
public void onChannel(ChannelEvent event) {
100+
Player player = event.getPlayer();
101+
String channel = event.getChannel();
102+
String message = event.getMessage();
103+
104+
System.out.println("Our first sender: " + player.getName()); // The person we send from that information
105+
System.out.println("Our first channel name: " + channel); // Channel name <plugin name>:<channel name>
106+
System.out.println("Our first message from that channel: " + message); // Message "Omg its working!"
107+
}
108+
```
109+
</details>
110+
111+
### Using Channel API
112+
113+
<details>
114+
<summary>Using API</summary>
115+
116+
```java
117+
// Import for Bungee
118+
import cz.foresttech.api.bungee.taker.ChannelAPI;
119+
// Spigot instance
120+
private static Bungee instance;
121+
122+
private ChannelAPI channelAPI;
123+
124+
@Override
125+
public void onEnable() {
126+
instance = this;
127+
128+
channelAPI = new ChannelAPI(this);
129+
channelAPI.register("<channel name>");
130+
131+
}
132+
133+
// Import for Spigot
134+
import cz.foresttech.api.spigot.taker.ChannelAPI;
135+
136+
// Bungee instance
137+
private static Spigot instance;
138+
139+
private ChannelAPI channelAPI;
140+
141+
@Override
142+
public void onEnable() {
143+
instance = this;
144+
145+
channelAPI = new ChannelAPI(this);
146+
channelAPI.register("<channel name>");
147+
}
148+
149+
// GLOBAL (Bungee & Spigot)
150+
151+
// Send method
152+
getChannelAPI().send(player, "<channel name>", "<message>");
153+
getChannelAPI().registerEvent(this, new SuperEvent());
154+
```
155+
</details>
156+
157+
## License
158+
ForestChannelAPI is licensed under the permissive MIT license. Please see [`LICENSE.txt`](https://github.com/ForestTechMC/ForestChannelAPI/blob/master/LICENSE.txt) for more information.

pom.xml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>cz.foresttech</groupId>
8+
<artifactId>ForestChannelAPI</artifactId>
9+
<version>1.0.0</version>
10+
11+
<properties>
12+
<maven.compiler.source>17</maven.compiler.source>
13+
<maven.compiler.target>17</maven.compiler.target>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<repositories>
18+
<repository>
19+
<id>jitpack.io</id>
20+
<url>https://jitpack.io</url>
21+
</repository>
22+
<repository>
23+
<id>spigot-repo</id>
24+
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
25+
</repository>
26+
<repository>
27+
<id>bungeecord-repo</id>
28+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
29+
</repository>
30+
</repositories>
31+
32+
<dependencies>
33+
<dependency>
34+
<groupId>net.md-5</groupId>
35+
<artifactId>bungeecord-api</artifactId>
36+
<version>1.19-R0.1-SNAPSHOT</version>
37+
<type>jar</type>
38+
<scope>provided</scope>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.projectlombok</groupId>
42+
<artifactId>lombok</artifactId>
43+
<version>1.18.22</version>
44+
<scope>compile</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.spigotmc</groupId>
48+
<artifactId>spigot-api</artifactId>
49+
<version>1.19-R0.1-SNAPSHOT</version>
50+
<scope>provided</scope>
51+
</dependency>
52+
</dependencies>
53+
</project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package cz.foresttech.api.bungee.events;
2+
3+
import net.md_5.bungee.api.connection.Connection;
4+
import net.md_5.bungee.api.connection.ProxiedPlayer;
5+
import net.md_5.bungee.api.plugin.Event;
6+
7+
public class ChannelEvent extends Event{
8+
private final String channel;
9+
private final String message;
10+
private final ProxiedPlayer sender;
11+
private final Connection senderCon;
12+
private final Connection receiverCon;
13+
14+
public ChannelEvent(String channel, String message, ProxiedPlayer sender, Connection senderCon, Connection receiverCon) {
15+
this.channel = channel;
16+
this.message = message;
17+
this.sender = sender;
18+
this.senderCon = senderCon;
19+
this.receiverCon = receiverCon;
20+
}
21+
22+
public ProxiedPlayer getSender() {
23+
return sender;
24+
}
25+
26+
public Connection getSenderCon() {
27+
return senderCon;
28+
}
29+
30+
public Connection getReceiverCon() {
31+
return receiverCon;
32+
}
33+
34+
public String getChannel() {
35+
return channel;
36+
}
37+
38+
public String getMessage() {
39+
return message;
40+
}
41+
42+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package cz.foresttech.api.bungee.events;
2+
3+
import net.md_5.bungee.api.ProxyServer;
4+
import net.md_5.bungee.api.connection.ProxiedPlayer;
5+
import net.md_5.bungee.api.event.PluginMessageEvent;
6+
import net.md_5.bungee.api.plugin.Listener;
7+
import net.md_5.bungee.api.plugin.Plugin;
8+
import net.md_5.bungee.event.EventHandler;
9+
10+
import java.io.ByteArrayInputStream;
11+
import java.io.DataInputStream;
12+
import java.io.IOException;
13+
import java.util.Collection;
14+
15+
16+
public class ChannelHandler implements Listener {
17+
18+
private Plugin plugin;
19+
20+
public ChannelHandler(Plugin plugin) {
21+
this.plugin = plugin;
22+
}
23+
24+
/**
25+
*
26+
* This is our caller for custom event
27+
* We did this for better manipulation with content
28+
*
29+
* @param event Official plugin message event
30+
*/
31+
@EventHandler
32+
public void onPluginMessageEvent(PluginMessageEvent event) {
33+
if (event.getTag().startsWith("minecraft")) {
34+
return;
35+
}
36+
37+
DataInputStream stream = new DataInputStream(new ByteArrayInputStream(event.getData()));
38+
39+
String message;
40+
String playerName;
41+
try {
42+
stream.readUTF();
43+
playerName = stream.readUTF();
44+
message = stream.readUTF();
45+
} catch (IOException e) {
46+
throw new RuntimeException(e);
47+
}
48+
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(playerName);
49+
if (player == null && !player.isConnected()) {
50+
Collection<ProxiedPlayer> players = ProxyServer.getInstance().getPlayers();
51+
player = players.stream().findFirst().get();
52+
}
53+
plugin.getProxy().getPluginManager().callEvent(new ChannelEvent(event.getTag(), message, player, event.getSender(), event.getReceiver()));
54+
}
55+
56+
}

0 commit comments

Comments
 (0)