13
0
Dieser Commit ist enthalten in:
Lixfel 2020-06-30 20:40:46 +02:00
Commit 05ffa3f1b4
15 geänderte Dateien mit 285 neuen und 0 gelöschten Zeilen

3
.gitignore vendored Normale Datei
Datei anzeigen

@ -0,0 +1,3 @@
*.iml
.idea
target

2
.idea/.gitignore generiert vendored Normale Datei
Datei anzeigen

@ -0,0 +1,2 @@
# Default ignored files
/workspace.xml

6
.idea/vcs.xml generiert Normale Datei
Datei anzeigen

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

2
README.md Normale Datei
Datei anzeigen

@ -0,0 +1,2 @@
# SpectateSystem

53
pom.xml Normale Datei
Datei anzeigen

@ -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>steamwar</groupId>
<artifactId>SpectateSystem</artifactId>
<version>1.0</version>
<repositories>
<repository>
<id>maven</id>
<url>https://steamwar.de:81/maven/</url>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
<exclude>**/*.kt</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>steamwar</groupId>
<artifactId>Spigot</artifactId>
<version>1.15</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

Datei anzeigen

@ -0,0 +1,4 @@
package de.steamwar.spectatesystem;
public class Config {
}

Datei anzeigen

@ -0,0 +1,4 @@
package de.steamwar.spectatesystem;
public class FightserverConnection {
}

Datei anzeigen

@ -0,0 +1,24 @@
package de.steamwar.spectatesystem;
import de.steamwar.spectatesystem.listener.JoinListener;
import org.bukkit.plugin.java.JavaPlugin;
public class SpectateSystem extends JavaPlugin {
private static SpectateSystem instance;
@Override
public void onEnable() {
instance = this;
new JoinListener();
}
@Override
public void onDisable() {
}
public static SpectateSystem get(){
return instance;
}
}

Datei anzeigen

@ -0,0 +1,20 @@
package de.steamwar.spectatesystem.elements;
import net.minecraft.server.v1_15_R1.Block;
import net.minecraft.server.v1_15_R1.BlockPosition;
import net.minecraft.server.v1_15_R1.IBlockData;
import net.minecraft.server.v1_15_R1.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
public class RBlockchange {
private static final WorldServer WORLD = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
public RBlockchange(int x, int y, int z, int stateId){
IBlockData blockData = Block.REGISTRY_ID.fromId(stateId);
BlockPosition pos = new BlockPosition(x, y, z);
WORLD.setTypeAndData(pos, blockData, 1042);
WORLD.getChunkProvider().flagDirty(pos);
}
}

Datei anzeigen

@ -0,0 +1,69 @@
package de.steamwar.spectatesystem.elements;
import net.minecraft.server.v1_15_R1.Entity;
import net.minecraft.server.v1_15_R1.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_15_R1.PacketPlayOutEntityTeleport;
import net.minecraft.server.v1_15_R1.PlayerConnection;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.Map;
public abstract class REntity {
private static Map<Integer, REntity> entities = new HashMap<>();
private final int internalId;
protected final Entity entity;
protected REntity(int internalId, Entity entity){
this.internalId = internalId;
this.entity = entity;
entities.put(internalId, this);
for(Player player : Bukkit.getOnlinePlayers()){
sendToPlayer(player);
}
}
public static void playerJoins(Player player){
for(REntity entity : entities.values()){
entity.sendToPlayer(player);
entity.sendLocation(player);
}
}
public static REntity getEntity(int internalId){
return entities.get(internalId);
}
public void move(double x, double y, double z, float yaw, float pitch){
entity.setLocation(x, y, z, yaw, pitch);
PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport(entity);
for(Player player : Bukkit.getOnlinePlayers()){
PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
connection.sendPacket(packet);
}
}
public void remove(){
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(entity.getId());
for(Player player : Bukkit.getOnlinePlayers()){
PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
connection.sendPacket(packet);
}
entities.remove(internalId);
}
private void sendToPlayer(Player player){
spawnEntity(((CraftPlayer)player).getHandle().playerConnection);
}
private void sendLocation(Player player){
((CraftPlayer)player).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityTeleport(entity));
}
protected abstract void spawnEntity(PlayerConnection connection);
}

Datei anzeigen

@ -0,0 +1,7 @@
package de.steamwar.spectatesystem.elements;
public class RParticle {
public RParticle(){
}
}

Datei anzeigen

@ -0,0 +1,62 @@
package de.steamwar.spectatesystem.elements;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import net.minecraft.server.v1_15_R1.*;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_15_R1.CraftServer;
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
import javax.net.ssl.HttpsURLConnection;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.UUID;
import java.util.logging.Level;
public class RPlayer extends REntity {
public RPlayer(UUID uuid, String name, int internalId){
super(internalId, createPlayer(uuid, name));
}
@Override
protected void spawnEntity(PlayerConnection connection) {
connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, (EntityPlayer) entity)); // "Adds the player data for the client to use when spawning a player" - https://wiki.vg/Protocol#Spawn_Player
connection.sendPacket(new PacketPlayOutNamedEntitySpawn((EntityPlayer) entity)); // Spawns the NPC for the player client.
connection.sendPacket(new PacketPlayOutEntityMetadata(entity.getId(), entity.getDataWatcher(), true));
}
private static EntityPlayer createPlayer(UUID uuid, String name){
MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
WorldServer nmsWorld = ((CraftWorld)Bukkit.getWorlds().get(0)).getHandle(); // Change "world" to the world the NPC should be spawned in.
GameProfile gameProfile = new GameProfile(uuid, name); // Change "playername" to the name the NPC should have, max 16 characters.
try {
HttpsURLConnection connection = (HttpsURLConnection) new URL(String.format("https://api.ashcon.app/mojang/v2/user/%s", name)).openConnection();
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
ArrayList<String> lines = new ArrayList<>();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
reader.lines().forEach(lines::add);
String reply = String.join("\n", lines);
int indexOfValue = reply.indexOf("\"value\": \"");
int indexOfSignature = reply.indexOf("\"signature\": \"");
String skin = reply.substring(indexOfValue + 10, reply.indexOf('\"', indexOfValue + 10));
String signature = reply.substring(indexOfSignature + 14, reply.indexOf('\"', indexOfSignature + 14));
gameProfile.getProperties().put("textures", new Property("textures", skin, signature));
} else {
Bukkit.getConsoleSender().sendMessage("Connection could not be opened when fetching player skin (Response code " + connection.getResponseCode() + ", " + connection.getResponseMessage() + ")");
}
} catch (IOException e) {
Bukkit.getLogger().log(Level.SEVERE, "Player skin could not be fetched");
}
EntityPlayer npc = new EntityPlayer(nmsServer, nmsWorld, gameProfile, new PlayerInteractManager(nmsWorld)); // This will be the EntityPlayer (NPC) we send with the sendNPCPacket method.
npc.getDataWatcher().set(new DataWatcherObject<>(15, DataWatcherRegistry.a), (byte)127);
return npc;
}
}

Datei anzeigen

@ -0,0 +1,4 @@
package de.steamwar.spectatesystem.elements;
public class RSound {
}

Datei anzeigen

@ -0,0 +1,20 @@
package de.steamwar.spectatesystem.listener;
import de.steamwar.spectatesystem.SpectateSystem;
import de.steamwar.spectatesystem.elements.REntity;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class JoinListener implements Listener {
public JoinListener(){
Bukkit.getPluginManager().registerEvents(this, SpectateSystem.get());
}
@EventHandler
public void onJoin(PlayerJoinEvent e){
REntity.playerJoins(e.getPlayer());
}
}

5
src/plugin.yml Normale Datei
Datei anzeigen

@ -0,0 +1,5 @@
authors:
- Lixfel
name: SpectateSystem
version: 1.0
main: de.steamwar.spectatesystem.SpectateSystem