13
0

Adding sound and autobansystem

Dieser Commit ist enthalten in:
Lixfel 2020-09-06 12:04:41 +02:00
Ursprung 29af653c22
Commit aac8b9d977
3 geänderte Dateien mit 59 neuen und 30 gelöschten Zeilen

Datei anzeigen

@ -33,17 +33,19 @@ import net.md_5.bungee.api.chat.TextComponent;
import net.minecraft.server.v1_15_R1.Block;
import org.bukkit.*;
import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData;
import org.bukkit.entity.Player;
import java.io.EOFException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Level;
class PacketProcessor {
private static final World world = Bukkit.getWorlds().get(0);
private Map<Byte, Integer> packetCounter = new HashMap<>();
private final Map<Byte, Integer> packetCounter = new HashMap<>();
private final PacketSource source;
@ -84,18 +86,14 @@ class PacketProcessor {
int entityId = source.rInt();
boolean sneaking = source.rBoolean();
Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> {
REntity.getEntity(entityId).sneak(sneaking);
});
Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> REntity.getEntity(entityId).sneak(sneaking));
}
private void entityAnimation() throws IOException {
int entityId = source.rInt();
byte animation = source.rByte();
Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> {
REntity.getEntity(entityId).animation(animation);
});
Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> REntity.getEntity(entityId).animation(animation));
}
private void tntSpawn() throws IOException {
@ -111,9 +109,7 @@ class PacketProcessor {
double dY = source.rDouble();
double dZ = source.rDouble();
Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> {
REntity.getEntity(entityId).setMotion(dX, dY, dZ);
});
Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> REntity.getEntity(entityId).setMotion(dX, dY, dZ));
}
private void playerItem() throws IOException {
@ -154,10 +150,8 @@ class PacketProcessor {
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);
});
CraftBlockData craftBlockData = CraftBlockData.fromData(Objects.requireNonNull(Block.REGISTRY_ID.fromId(blockState)));
Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> world.getBlockAt(x, y, z).setBlockData(craftBlockData));
}
private void particle() throws IOException {
@ -167,9 +161,7 @@ class PacketProcessor {
String particleName = source.rString();
Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> {
world.spawnParticle(Particle.valueOf(particleName), x, y, z, 1);
});
Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> world.spawnParticle(Particle.valueOf(particleName), x, y, z, 1));
}
private void sound() throws IOException {
@ -186,11 +178,12 @@ class PacketProcessor {
Sound sound = Sound.valueOf(soundName);
SoundCategory sCategory = SoundCategory.valueOf(soundCategory);
Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> {
world.playSound(new Location(world, x, y, z), sound, sCategory, volume, pitch);
});
Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> world.playSound(new Location(world, x, y, z), sound, sCategory, volume, pitch));
}
private static int debug_block_ignored = 0;
private static int debug_block_unneccesary = 0;
private void shortBlock() throws IOException {
int x = Byte.toUnsignedInt(source.rByte()) + Config.ArenaMinX;
int y = Byte.toUnsignedInt(source.rByte());
@ -200,10 +193,29 @@ class PacketProcessor {
if (Config.TechhiderActive && Config.HiddenBlocks.contains(blockState)) {
blockState = Config.ObfuscateWith;
debug_block_ignored++;
}
CraftBlockData craftBlockData = CraftBlockData.fromData(Block.REGISTRY_ID.fromId(blockState));
CraftBlockData craftBlockData = CraftBlockData.fromData(Objects.requireNonNull(Block.REGISTRY_ID.fromId(blockState)));
Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> {
world.getBlockAt(x, y, z).setBlockData(craftBlockData);
org.bukkit.block.Block block = world.getBlockAt(x, y, z);
if(block.getBlockData().matches(craftBlockData))
debug_block_unneccesary++;
block.setBlockData(craftBlockData);
});
}
private void soundAtPlayer() throws IOException {
String soundName = source.rString();
float volume = source.rFloat();
float pitch = source.rFloat();
Sound sound = Sound.valueOf(soundName);
Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> {
for(Player player : Bukkit.getOnlinePlayers()){
player.playSound(player.getLocation(), sound, volume, pitch);
}
});
}
@ -283,6 +295,9 @@ class PacketProcessor {
case 0x33:
shortBlock();
break;
case 0x34:
soundAtPlayer();
break;
case (byte) 0xA0:
send(ChatMessageType.CHAT);
break;
@ -324,5 +339,6 @@ class PacketProcessor {
for(Map.Entry<Byte, Integer> entry : packetCounter.entrySet()){
System.out.println(Integer.toHexString(entry.getKey()) + " " + entry.getValue());
}
System.out.println("Techhiderupdates: " + debug_block_ignored + ", Unneccesary: " + debug_block_unneccesary);
}
}

Datei anzeigen

@ -22,10 +22,10 @@ package de.steamwar.spectatesystem.listener;
import de.steamwar.spectatesystem.Config;
import de.steamwar.spectatesystem.SpectateSystem;
import de.steamwar.spectatesystem.util.Region;
import de.steamwar.spectatesystem.util.WorldLoader;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_15_R1.CraftChunk;
@ -41,6 +41,8 @@ import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.event.world.WorldLoadEvent;
import java.util.logging.Level;
public class ArenaListener extends BasicListener {
private static final String DENY_ARENA = "§cDu darfst die Arena nicht verlassen";
@ -51,10 +53,8 @@ public class ArenaListener extends BasicListener {
Location to = event.getTo();
assert to != null;
if(!Region.isIn2DRegion(to, Config.ArenaMinX, Config.ArenaMinZ, Config.ArenaMaxX, Config.ArenaMaxZ) || to.getY() <= Config.underArenaBorder) {
if(!Region.isIn2DRegion(to, Config.ArenaMinX, Config.ArenaMinZ, Config.ArenaMaxX, Config.ArenaMaxZ) || to.getY() <= Config.underArenaBorder)
reset(event, DENY_ARENA);
return;
}
boolean inArenaY = to.getY() + 1.8 <= Config.upperArenaBorder;
boolean inBlueArea = inArenaY && Region.isIn2DRange(to, Config.TeamBlueCornerX, Config.TeamBlueCornerZ, Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic);
@ -62,6 +62,21 @@ public class ArenaListener extends BasicListener {
if(inBlueArea || inRedArea)
reset(event, DENY_TEAM);
if(inBlueArea)
checkInInnerArea(event.getPlayer(), to, Config.TeamBlueCornerX, Config.TeamBlueCornerZ, Config.BorderFromSchematic - 2, Config.upperArenaBorder - 2);
if(inRedArea)
checkInInnerArea(event.getPlayer(), to, Config.TeamRedCornerX, Config.TeamRedCornerZ, Config.BorderFromSchematic - 2, Config.upperArenaBorder - 2);
}
private void checkInInnerArea(Player player, Location to, int teamCornerX, int teamCornerZ, int reducedBorderFromSchematic, int reducedUpperBorder){
boolean inArenaY = to.getY() + 1.8 <= reducedUpperBorder;
boolean inArea = inArenaY && Region.isIn2DRange(to, teamCornerX, teamCornerZ, Config.SchemsizeX, Config.SchemsizeZ, reducedBorderFromSchematic);
if(inArea){
player.kickPlayer(null);
Bukkit.getBanList(BanList.Type.NAME).addBan(player.getUniqueId().toString(), "Versuchte Spionage.", null, null);
Bukkit.getLogger().log(Level.SEVERE, player.getName() + " ist in einen Teambereich eingedrungen.");
}
}
private void reset(PlayerMoveEvent event, String message){
@ -74,6 +89,8 @@ public class ArenaListener extends BasicListener {
public void onTpGM3(PlayerTeleportEvent e) {
if (e.getCause() == PlayerTeleportEvent.TeleportCause.SPECTATE) {
e.setCancelled(true);
if(e.getPlayer().getSpectatorTarget() != null)
e.getPlayer().getSpectatorTarget().eject();
e.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§cDu darfst diese Teleportfunktion nicht benutzen!"));
Bukkit.getScheduler().runTaskLater(SpectateSystem.get(), () -> e.getPlayer().teleport(e.getFrom()), 2);
}
@ -105,7 +122,6 @@ public class ArenaListener extends BasicListener {
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();
}
@EventHandler

Datei anzeigen

@ -19,12 +19,10 @@
package de.steamwar.spectatesystem.util;
import de.steamwar.spectatesystem.Config;
import de.steamwar.spectatesystem.SpectateSystem;
import net.minecraft.server.v1_15_R1.PacketPlayOutMapChunk;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_15_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
@ -44,6 +42,5 @@ public class WorldLoader {
((CraftPlayer)player).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)chunk).getHandle(), 65535));
}
});
Bukkit.getScheduler().runTaskLater(SpectateSystem.get(), () -> world.getBlockAt(Config.SpecSpawn).setType(Material.STONE), 100);
}
}