-
-
Notifications
You must be signed in to change notification settings - Fork 150
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
Showing
30 changed files
with
2,791 additions
and
9 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
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
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 @@ | ||
import org.spongepowered.gradle.plugin.config.PluginLoaders | ||
import org.spongepowered.plugin.metadata.model.PluginDependency | ||
|
||
plugins { | ||
id("org.spongepowered.gradle.plugin") version("2.0.2") | ||
} | ||
|
||
repositories { | ||
maven { url 'https://repo.spongepowered.org/repository/maven-public/' } // Sponge | ||
maven { url 'https://repo.viaversion.com/' } | ||
} | ||
|
||
sponge { | ||
apiVersion("11.0.0-SNAPSHOT") | ||
loader { | ||
name(PluginLoaders.JAVA_PLAIN) | ||
version("2.2.0") | ||
} | ||
|
||
plugin("packetevents") { | ||
displayName("PacketEvents") | ||
entrypoint("io.github.retrooper.packetevents.PacketEventsPlugin") | ||
license("GPL-3") | ||
dependency("spongeapi") { | ||
loadOrder(PluginDependency.LoadOrder.AFTER) | ||
optional(false) | ||
} | ||
dependency("viaversion") { | ||
version("*") | ||
loadOrder(PluginDependency.LoadOrder.AFTER) | ||
optional(true) | ||
} | ||
} | ||
} | ||
|
||
shadowJar { | ||
relocate 'net.kyori.adventure.text.serializer.gson', 'io.github.retrooper.packetevents.adventure.serializer.gson' | ||
relocate 'net.kyori.adventure.text.serializer.legacy', 'io.github.retrooper.packetevents.adventure.serializer.legacy' | ||
dependencies { | ||
exclude(dependency('com.google.code.gson:gson:2.8.0')) | ||
exclude(dependency('com.google.code.gson:gson:2.8.5')) | ||
exclude(dependency('com.google.code.gson:gson:2.8.8')) | ||
} | ||
} | ||
|
||
dependencies { | ||
compileOnly 'io.netty:netty-all:4.1.75.Final' | ||
api project(':api') | ||
api project(':netty-common') | ||
api(adventureDependencies) | ||
|
||
compileOnly 'com.viaversion:viaversion:4.5.0' | ||
} |
52 changes: 52 additions & 0 deletions
52
sponge/src/main/java/io/github/retrooper/packetevents/sponge/InternalSpongeListener.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,52 @@ | ||
/* | ||
* This file is part of packetevents - https://github.com/retrooper/packetevents | ||
* Copyright (C) 2024 retrooper and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package io.github.retrooper.packetevents.sponge; | ||
|
||
import com.github.retrooper.packetevents.PacketEvents; | ||
import com.github.retrooper.packetevents.protocol.player.User; | ||
import com.github.retrooper.packetevents.util.FakeChannelUtil; | ||
import io.github.retrooper.packetevents.sponge.injector.SpongeChannelInjector; | ||
import net.kyori.adventure.text.Component; | ||
import org.spongepowered.api.entity.living.player.server.ServerPlayer; | ||
import org.spongepowered.api.event.Listener; | ||
import org.spongepowered.api.event.Order; | ||
import org.spongepowered.api.event.filter.Getter; | ||
import org.spongepowered.api.event.network.ServerSideConnectionEvent; | ||
|
||
public class InternalSpongeListener { | ||
|
||
@Listener(order = Order.LATE) | ||
public void onJoin(ServerSideConnectionEvent.Join event, @Getter("player") ServerPlayer player) { | ||
SpongeChannelInjector injector = (SpongeChannelInjector) PacketEvents.getAPI().getInjector(); | ||
|
||
User user = PacketEvents.getAPI().getPlayerManager().getUser(player); | ||
if (user == null) { | ||
// We did not inject this user | ||
Object channel = PacketEvents.getAPI().getPlayerManager().getChannel(player); | ||
// Check if it is a fake connection... | ||
if (!FakeChannelUtil.isFakeChannel(channel)) { | ||
// Kick them, if they are not a fake player. | ||
player.kick(Component.text("PacketEvents 2.0 failed to inject")); | ||
} | ||
return; | ||
} | ||
|
||
// Set player object in the injectors | ||
injector.updatePlayer(user, player); | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
sponge/src/main/java/io/github/retrooper/packetevents/sponge/PacketEventsPlugin.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,96 @@ | ||
/* | ||
* This file is part of packetevents - https://github.com/retrooper/packetevents | ||
* Copyright (C) 2024 retrooper and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.github.retrooper.packetevents.sponge; | ||
|
||
import com.github.retrooper.packetevents.PacketEvents; | ||
import com.github.retrooper.packetevents.event.PacketListenerPriority; | ||
import com.github.retrooper.packetevents.event.SimplePacketListenerAbstract; | ||
import com.github.retrooper.packetevents.event.UserConnectEvent; | ||
import com.github.retrooper.packetevents.event.UserDisconnectEvent; | ||
import com.github.retrooper.packetevents.event.UserLoginEvent; | ||
import com.github.retrooper.packetevents.event.simple.PacketPlaySendEvent; | ||
import com.github.retrooper.packetevents.protocol.item.ItemStack; | ||
import com.github.retrooper.packetevents.protocol.packettype.PacketType; | ||
import com.github.retrooper.packetevents.util.TimeStampMode; | ||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerWindowItems; | ||
import com.google.inject.Inject; | ||
import io.github.retrooper.packetevents.sponge.factory.SpongePacketEventsBuilder; | ||
import io.github.retrooper.packetevents.sponge.util.SpongeConversionUtil; | ||
import org.spongepowered.api.Server; | ||
import org.spongepowered.api.event.Listener; | ||
import org.spongepowered.api.event.lifecycle.StartingEngineEvent; | ||
import org.spongepowered.api.event.lifecycle.StoppingEngineEvent; | ||
import org.spongepowered.api.registry.RegistryTypes; | ||
import org.spongepowered.plugin.PluginContainer; | ||
import org.spongepowered.plugin.builtin.jvm.Plugin; | ||
|
||
@Plugin("packetevents") | ||
public class PacketEventsPlugin { | ||
|
||
@Inject | ||
private PluginContainer pluginContainer; | ||
|
||
@Listener | ||
public void onServerStart(final StartingEngineEvent<Server> event) { | ||
PacketEvents.setAPI(SpongePacketEventsBuilder.build(pluginContainer)); | ||
PacketEvents.getAPI().load(); | ||
|
||
// Register your listeners | ||
// TODO disable debug | ||
PacketEvents.getAPI().getSettings().debug(true).bStats(true).checkForUpdates(true).timeStampMode(TimeStampMode.MILLIS).reEncodeByDefault(true); | ||
PacketEvents.getAPI().init(); | ||
|
||
SimplePacketListenerAbstract listener = new SimplePacketListenerAbstract(PacketListenerPriority.HIGH) { | ||
|
||
// Testing ItemStack conversion, can be removed in future | ||
@Override | ||
public void onPacketPlaySend(PacketPlaySendEvent event) { | ||
if (event.getPacketType() == PacketType.Play.Server.WINDOW_ITEMS) { | ||
WrapperPlayServerWindowItems items = new WrapperPlayServerWindowItems(event); | ||
for (ItemStack item : items.getItems()) { | ||
org.spongepowered.api.item.inventory.ItemStack sponge = SpongeConversionUtil.toSpongeItemStack(item); | ||
System.out.println(sponge.type().key(RegistryTypes.ITEM_TYPE).formatted()); | ||
System.out.println(SpongeConversionUtil.fromSpongeItemStack(sponge).getType().getName().toString()); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void onUserConnect(UserConnectEvent event) { | ||
PacketEvents.getAPI().getLogManager().debug("User: (host-name) " + event.getUser().getAddress().getHostString() + " connected..."); | ||
} | ||
|
||
@Override | ||
public void onUserLogin(UserLoginEvent event) { | ||
PacketEvents.getAPI().getLogManager().debug("You logged in! User name: " + event.getUser().getProfile().getName()); | ||
} | ||
|
||
@Override | ||
public void onUserDisconnect(UserDisconnectEvent event) { | ||
PacketEvents.getAPI().getLogManager().debug("User: (host-name) " + event.getUser().getAddress().getHostString() + " disconnected..."); | ||
} | ||
}; | ||
// PacketEvents.getAPI().getEventManager().registerListener(listener); | ||
} | ||
|
||
@Listener | ||
public void onStopping(StoppingEngineEvent<Server> event) { | ||
PacketEvents.getAPI().terminate(); | ||
} | ||
} |
Oops, something went wrong.