New spectator mode
Dieser Commit ist enthalten in:
Ursprung
63317896b6
Commit
78d8b25ade
7
pom.xml
7
pom.xml
@ -59,5 +59,12 @@
|
||||
<scope>system</scope>
|
||||
<systemPath>${main.basedir}/lib/WorldEdit-1.15.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>steamwar</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${main.basedir}/lib/ProtocolLib.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -19,23 +19,56 @@
|
||||
|
||||
package de.steamwar.spectatesystem.listener;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import com.comphenix.protocol.wrappers.PlayerInfoData;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import de.steamwar.scoreboard.SWScoreboard;
|
||||
import de.steamwar.spectatesystem.Config;
|
||||
import de.steamwar.spectatesystem.SpectateSystem;
|
||||
import de.steamwar.spectatesystem.elements.REntity;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class JoinListener extends BasicListener {
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e){
|
||||
Player player = e.getPlayer();
|
||||
REntity.playerJoins(player);
|
||||
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
for(Player currentPlayer : Bukkit.getServer().getOnlinePlayers()) {
|
||||
if(currentPlayer.getUniqueId() != player.getUniqueId() && currentPlayer.getGameMode() == GameMode.SPECTATOR) {
|
||||
currentPlayer.hidePlayer(SpectateSystem.get(), player);
|
||||
player.hidePlayer(SpectateSystem.get(), currentPlayer);
|
||||
}
|
||||
}
|
||||
Bukkit.getScheduler().runTaskLater(SpectateSystem.get(), () -> {
|
||||
PacketContainer gm1packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO);
|
||||
gm1packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE);
|
||||
List<PlayerInfoData> playerInfoActions = new ArrayList<>();
|
||||
playerInfoActions.add(new PlayerInfoData(WrappedGameProfile.fromPlayer(player), 1, EnumWrappers.NativeGameMode.CREATIVE, WrappedChatComponent.fromText(player.getDisplayName())));
|
||||
gm1packet.getPlayerInfoDataLists().write(0, playerInfoActions);
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, gm1packet);
|
||||
} catch (InvocationTargetException ex) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", ex);
|
||||
}
|
||||
}, 2);
|
||||
|
||||
player.getInventory().clear();
|
||||
player.teleport(Config.SpecSpawn);
|
||||
SWScoreboard.createScoreboard(player, SpectateSystem.getScoreboard());
|
||||
|
@ -7,4 +7,5 @@ main: de.steamwar.spectatesystem.SpectateSystem
|
||||
load: POSTWORLD
|
||||
depends:
|
||||
- SpigotCore
|
||||
- WorldEdit
|
||||
- WorldEdit
|
||||
- ProtocolLib
|
In neuem Issue referenzieren
Einen Benutzer sperren