More advanced stuff
Dieser Commit ist enthalten in:
Ursprung
2b291afb73
Commit
7d58cb15f3
@ -22,6 +22,7 @@ package de.steamwar.spectatesystem;
|
|||||||
import com.sk89q.worldedit.EditSession;
|
import com.sk89q.worldedit.EditSession;
|
||||||
import de.steamwar.spectatesystem.elements.*;
|
import de.steamwar.spectatesystem.elements.*;
|
||||||
import de.steamwar.spectatesystem.util.ColorConverter;
|
import de.steamwar.spectatesystem.util.ColorConverter;
|
||||||
|
import de.steamwar.spectatesystem.util.Paster;
|
||||||
import de.steamwar.spectatesystem.util.WorldLoader;
|
import de.steamwar.spectatesystem.util.WorldLoader;
|
||||||
import de.steamwar.sql.NoClipboardException;
|
import de.steamwar.sql.NoClipboardException;
|
||||||
import de.steamwar.sql.Schematic;
|
import de.steamwar.sql.Schematic;
|
||||||
@ -35,11 +36,14 @@ import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData;
|
|||||||
|
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
class PacketProcessor {
|
class PacketProcessor {
|
||||||
|
|
||||||
private static final World world = Bukkit.getWorlds().get(0);
|
private static final World world = Bukkit.getWorlds().get(0);
|
||||||
|
private Map<Byte, Integer> packetCounter = new HashMap<>();
|
||||||
|
|
||||||
private final PacketSource source;
|
private final PacketSource source;
|
||||||
|
|
||||||
@ -142,7 +146,7 @@ class PacketProcessor {
|
|||||||
|
|
||||||
private void block() throws IOException {
|
private void block() throws IOException {
|
||||||
int x = source.rInt();
|
int x = source.rInt();
|
||||||
byte y = source.rByte();
|
int y = Byte.toUnsignedInt(source.rByte());
|
||||||
int z = source.rInt();
|
int z = source.rInt();
|
||||||
|
|
||||||
int blockState = source.rInt();
|
int blockState = source.rInt();
|
||||||
@ -168,19 +172,6 @@ class PacketProcessor {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scoreboardTitle() throws IOException {
|
|
||||||
String title = source.rString();
|
|
||||||
|
|
||||||
SpectateSystem.getScoreboard().setTitle(title);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void scoreboardData() throws IOException {
|
|
||||||
String key = source.rString();
|
|
||||||
int value = source.rInt();
|
|
||||||
|
|
||||||
SpectateSystem.getScoreboard().addValue(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sound() throws IOException {
|
private void sound() throws IOException {
|
||||||
int x = source.rInt();
|
int x = source.rInt();
|
||||||
int y = source.rInt();
|
int y = source.rInt();
|
||||||
@ -200,6 +191,22 @@ class PacketProcessor {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void shortBlock() throws IOException {
|
||||||
|
int x = Byte.toUnsignedInt(source.rByte()) + Config.ArenaMinX;
|
||||||
|
int y = Byte.toUnsignedInt(source.rByte());
|
||||||
|
int z = Byte.toUnsignedInt(source.rByte()) + Config.ArenaMinZ;
|
||||||
|
|
||||||
|
int blockState = source.rShort();
|
||||||
|
|
||||||
|
if (Config.TechhiderActive && Config.HiddenBlocks.contains(blockState)) {
|
||||||
|
blockState = Config.ObfuscateWith;
|
||||||
|
}
|
||||||
|
CraftBlockData craftBlockData = CraftBlockData.fromData(Block.REGISTRY_ID.fromId(blockState));
|
||||||
|
Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> {
|
||||||
|
world.getBlockAt(x, y, z).setBlockData(craftBlockData);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void pasteSchem(int cornerX, int cornerY, int cornerZ, boolean rotate, String prefix) throws IOException {
|
private void pasteSchem(int cornerX, int cornerY, int cornerZ, boolean rotate, String prefix) throws IOException {
|
||||||
int schemId = source.rInt();
|
int schemId = source.rInt();
|
||||||
|
|
||||||
@ -213,10 +220,25 @@ class PacketProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void scoreboardTitle() throws IOException {
|
||||||
|
String title = source.rString();
|
||||||
|
|
||||||
|
SpectateSystem.getScoreboard().setTitle(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void scoreboardData() throws IOException {
|
||||||
|
String key = source.rString();
|
||||||
|
int value = source.rInt();
|
||||||
|
|
||||||
|
SpectateSystem.getScoreboard().addValue(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
private void process(){
|
private void process(){
|
||||||
try{
|
try{
|
||||||
while(!source.isClosed()){
|
while(!source.isClosed()){
|
||||||
switch(source.rByte()){
|
byte packetType = source.rByte();
|
||||||
|
packetCounter.compute(packetType, (key, value) -> value != null ? value + 1 : 1);
|
||||||
|
switch(packetType){
|
||||||
case 0x00:
|
case 0x00:
|
||||||
playerJoins();
|
playerJoins();
|
||||||
break;
|
break;
|
||||||
@ -256,6 +278,9 @@ class PacketProcessor {
|
|||||||
case 0x32:
|
case 0x32:
|
||||||
sound();
|
sound();
|
||||||
break;
|
break;
|
||||||
|
case 0x33:
|
||||||
|
shortBlock();
|
||||||
|
break;
|
||||||
case (byte) 0xA0:
|
case (byte) 0xA0:
|
||||||
send(ChatMessageType.CHAT);
|
send(ChatMessageType.CHAT);
|
||||||
break;
|
break;
|
||||||
@ -293,5 +318,9 @@ class PacketProcessor {
|
|||||||
Bukkit.getLogger().log(Level.WARNING, "Could not recieve packet", e);
|
Bukkit.getLogger().log(Level.WARNING, "Could not recieve packet", e);
|
||||||
source.close();
|
source.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(Map.Entry<Byte, Integer> entry : packetCounter.entrySet()){
|
||||||
|
System.out.println(Integer.toHexString(entry.getKey()) + " " + entry.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,14 @@ public abstract class REntity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static EntityLiving getShooter(){
|
||||||
|
for(REntity entity : entities.values()){
|
||||||
|
if(entity.entity instanceof EntityLiving)
|
||||||
|
return (EntityLiving) entity.entity;
|
||||||
|
}
|
||||||
|
return ((CraftPlayer)Bukkit.getOnlinePlayers().iterator().next()).getHandle();
|
||||||
|
}
|
||||||
|
|
||||||
public static REntity getEntity(int internalId){
|
public static REntity getEntity(int internalId){
|
||||||
return entities.get(internalId);
|
return entities.get(internalId);
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,8 @@
|
|||||||
|
|
||||||
package de.steamwar.spectatesystem.elements;
|
package de.steamwar.spectatesystem.elements;
|
||||||
|
|
||||||
import net.minecraft.server.v1_15_R1.*;
|
import net.minecraft.server.v1_15_R1.EntityFireball;
|
||||||
|
import net.minecraft.server.v1_15_R1.EntityLargeFireball;
|
||||||
|
|
||||||
public class RFireball extends REntity{
|
public class RFireball extends REntity{
|
||||||
public RFireball(int internalId) {
|
public RFireball(int internalId) {
|
||||||
@ -27,6 +28,6 @@ public class RFireball extends REntity{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static EntityFireball createFireball() {
|
private static EntityFireball createFireball() {
|
||||||
return new EntitySmallFireball(world, 0, 0, 0, 0, 0, 0);
|
return new EntityLargeFireball(world, getShooter(), 0, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,4 +121,8 @@ public class RPlayer extends REntity {
|
|||||||
connection.sendPacket(packet);
|
connection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void recieveDamage(){
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,13 +20,16 @@
|
|||||||
package de.steamwar.spectatesystem.listener;
|
package de.steamwar.spectatesystem.listener;
|
||||||
|
|
||||||
import de.steamwar.spectatesystem.Config;
|
import de.steamwar.spectatesystem.Config;
|
||||||
import de.steamwar.spectatesystem.util.Region;
|
|
||||||
import de.steamwar.spectatesystem.SpectateSystem;
|
import de.steamwar.spectatesystem.SpectateSystem;
|
||||||
|
import de.steamwar.spectatesystem.util.Region;
|
||||||
import de.steamwar.spectatesystem.util.WorldLoader;
|
import de.steamwar.spectatesystem.util.WorldLoader;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.craftbukkit.v1_15_R1.CraftChunk;
|
||||||
|
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.block.BlockExplodeEvent;
|
import org.bukkit.event.block.BlockExplodeEvent;
|
||||||
@ -34,6 +37,7 @@ import org.bukkit.event.entity.EntityExplodeEvent;
|
|||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
|
import org.bukkit.event.world.ChunkLoadEvent;
|
||||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||||
import org.bukkit.event.world.WorldLoadEvent;
|
import org.bukkit.event.world.WorldLoadEvent;
|
||||||
|
|
||||||
@ -83,6 +87,7 @@ public class ArenaListener extends BasicListener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onWorldLoad(WorldLoadEvent e){
|
public void onWorldLoad(WorldLoadEvent e){
|
||||||
e.getWorld().setAutoSave(false);
|
e.getWorld().setAutoSave(false);
|
||||||
|
((CraftWorld)e.getWorld()).getHandle().savingDisabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -97,6 +102,14 @@ public class ArenaListener extends BasicListener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onChat(AsyncPlayerChatEvent e){
|
public void onChat(AsyncPlayerChatEvent e){
|
||||||
|
e.setCancelled(true);
|
||||||
|
BaseComponent[] message = TextComponent.fromLegacyText("§7" + e.getPlayer().getName() + "§8» §7" + e.getMessage());
|
||||||
|
e.getRecipients().forEach(p -> p.spigot().sendMessage(ChatMessageType.CHAT, message));
|
||||||
WorldLoader.reloadWorld();
|
WorldLoader.reloadWorld();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onChunkLoad(ChunkLoadEvent e){
|
||||||
|
((CraftChunk)e.getChunk()).getHandle().mustNotSave = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.spectatesystem;
|
package de.steamwar.spectatesystem.util;
|
||||||
|
|
||||||
import com.sk89q.worldedit.EditSession;
|
import com.sk89q.worldedit.EditSession;
|
||||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||||
@ -32,6 +32,7 @@ import com.sk89q.worldedit.session.ClipboardHolder;
|
|||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
|
import de.steamwar.spectatesystem.Config;
|
||||||
import de.steamwar.sql.NoClipboardException;
|
import de.steamwar.sql.NoClipboardException;
|
||||||
import de.steamwar.sql.Schematic;
|
import de.steamwar.sql.Schematic;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
@ -25,7 +25,6 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.craftbukkit.v1_15_R1.CraftChunk;
|
|
||||||
|
|
||||||
public class WorldLoader {
|
public class WorldLoader {
|
||||||
private WorldLoader(){}
|
private WorldLoader(){}
|
||||||
@ -35,8 +34,6 @@ public class WorldLoader {
|
|||||||
public static void reloadWorld(){
|
public static void reloadWorld(){
|
||||||
Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> {
|
Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> {
|
||||||
for(Chunk chunk: world.getLoadedChunks()){
|
for(Chunk chunk: world.getLoadedChunks()){
|
||||||
System.out.println(((CraftChunk)chunk).getHandle().mustNotSave);
|
|
||||||
((CraftChunk)chunk).getHandle().mustNotSave = true;
|
|
||||||
world.unloadChunk(chunk.getX(), chunk.getZ(), false);
|
world.unloadChunk(chunk.getX(), chunk.getZ(), false);
|
||||||
world.getChunkAt(chunk.getX(), chunk.getZ());
|
world.getChunkAt(chunk.getX(), chunk.getZ());
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren