Set spectators in halfcreative mode
Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Ursprung
b05a0df77b
Commit
2b3f08aae2
@ -22,7 +22,13 @@ package de.steamwar.fightsystem.fight;
|
|||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.protocol.PacketType;
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
|
import com.comphenix.protocol.reflect.StructureModifier;
|
||||||
|
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.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
import de.steamwar.sql.Schematic;
|
import de.steamwar.sql.Schematic;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
@ -31,6 +37,7 @@ import org.bukkit.Sound;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
@ -41,12 +48,20 @@ public class Fight {
|
|||||||
public static final FightTeam blueTeam = new FightTeam(Config.TeamBlueName, Config.TeamBluePrefix, Config.TeamBlueSpawn, Config.TeamBlueCornerX, Config.TeamBlueCornerY, Config.TeamBlueCornerZ, Config.TeamBlueRotate, true, Config.BlueLeader);
|
public static final FightTeam blueTeam = new FightTeam(Config.TeamBlueName, Config.TeamBluePrefix, Config.TeamBlueSpawn, Config.TeamBlueCornerX, Config.TeamBlueCornerY, Config.TeamBlueCornerZ, Config.TeamBlueRotate, true, Config.BlueLeader);
|
||||||
private static int schemRank;
|
private static int schemRank;
|
||||||
|
|
||||||
private static final PacketContainer gm_1_packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.GAME_STATE_CHANGE);
|
private static final PacketContainer flying_packet = new PacketContainer(PacketType.Play.Server.ABILITIES);
|
||||||
|
|
||||||
|
static {
|
||||||
|
flying_packet.getBytes().write(0, (byte)0x06);
|
||||||
|
StructureModifier<Boolean> booleans = flying_packet.getBooleans();
|
||||||
|
booleans.write(0, false);
|
||||||
|
booleans.write(1, true);
|
||||||
|
booleans.write(2, true);
|
||||||
|
booleans.write(3, false);
|
||||||
|
flying_packet.getFloat().writeDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
public static void init(){
|
public static void init(){
|
||||||
IFight.init(redTeam, blueTeam);
|
IFight.init(redTeam, blueTeam);
|
||||||
gm_1_packet.getBytes().write(0, (byte)3);
|
|
||||||
gm_1_packet.getFloat().write(0, 1f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FightTeam getPlayerTeam(Player player) {
|
public static FightTeam getPlayerTeam(Player player) {
|
||||||
@ -121,20 +136,30 @@ public class Fight {
|
|||||||
player.setGameMode(gameMode);
|
player.setGameMode(gameMode);
|
||||||
|
|
||||||
if(gameMode == GameMode.SPECTATOR) {
|
if(gameMode == GameMode.SPECTATOR) {
|
||||||
try {
|
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, gm_1_packet);
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", e);
|
|
||||||
}
|
|
||||||
for(Player currentPlayer : Bukkit.getServer().getOnlinePlayers()) {
|
for(Player currentPlayer : Bukkit.getServer().getOnlinePlayers()) {
|
||||||
if(currentPlayer.getUniqueId() != player.getUniqueId() && currentPlayer.getGameMode() == GameMode.SPECTATOR) {
|
if(currentPlayer.getUniqueId() != player.getUniqueId() && currentPlayer.getGameMode() == GameMode.SPECTATOR) {
|
||||||
currentPlayer.hidePlayer(player);
|
currentPlayer.hidePlayer(player);
|
||||||
player.hidePlayer(currentPlayer);
|
player.hidePlayer(currentPlayer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(gameMode == GameMode.SURVIVAL) {
|
if(FightSystem.getEventLeiter() == player)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> {
|
||||||
|
PacketContainer gm_1_packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO);
|
||||||
|
gm_1_packet.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())));
|
||||||
|
gm_1_packet.getPlayerInfoDataLists().write(0, playerInfoActions);
|
||||||
|
try {
|
||||||
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, gm_1_packet);
|
||||||
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, flying_packet);
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", e);
|
||||||
|
}
|
||||||
|
}, 2);
|
||||||
|
}else if(gameMode == GameMode.SURVIVAL) {
|
||||||
for(Player currentPlayer : Bukkit.getServer().getOnlinePlayers()) {
|
for(Player currentPlayer : Bukkit.getServer().getOnlinePlayers()) {
|
||||||
if(currentPlayer.getUniqueId() != player.getUniqueId() && currentPlayer.getGameMode() == GameMode.SPECTATOR) {
|
if(currentPlayer.getUniqueId() != player.getUniqueId() && currentPlayer.getGameMode() == GameMode.SPECTATOR) {
|
||||||
currentPlayer.showPlayer(player);
|
currentPlayer.showPlayer(player);
|
||||||
|
@ -26,6 +26,8 @@ import de.steamwar.fightsystem.fight.FightTeam;
|
|||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import de.steamwar.fightsystem.utils.Region;
|
import de.steamwar.fightsystem.utils.Region;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import org.bukkit.BanList;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -33,6 +35,7 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class PlayerMoveListener extends BasicListener {
|
public class PlayerMoveListener extends BasicListener {
|
||||||
|
|
||||||
@ -64,15 +67,31 @@ public class PlayerMoveListener extends BasicListener {
|
|||||||
reset(event, DENY_TEAM);
|
reset(event, DENY_TEAM);
|
||||||
else if(fightTeam == Fight.getRedTeam() && player.getGameMode() == GameMode.SPECTATOR)
|
else if(fightTeam == Fight.getRedTeam() && player.getGameMode() == GameMode.SPECTATOR)
|
||||||
reset(event, DENY_ENTERN);
|
reset(event, DENY_ENTERN);
|
||||||
|
else
|
||||||
|
return; // Is allowed in area
|
||||||
|
checkInInnerArea(event.getPlayer(), to, Config.TeamBlueCornerX, Config.TeamBlueCornerZ);
|
||||||
}else if(inRedArea){
|
}else if(inRedArea){
|
||||||
if(fightTeam == null)
|
if(fightTeam == null)
|
||||||
reset(event, DENY_TEAM);
|
reset(event, DENY_TEAM);
|
||||||
else if(fightTeam == Fight.getBlueTeam() && player.getGameMode() == GameMode.SPECTATOR)
|
else if(fightTeam == Fight.getBlueTeam() && player.getGameMode() == GameMode.SPECTATOR)
|
||||||
reset(event, DENY_ENTERN);
|
reset(event, DENY_ENTERN);
|
||||||
|
else
|
||||||
|
return; // Is allowed in area
|
||||||
|
checkInInnerArea(event.getPlayer(), to, Config.TeamRedCornerX, Config.TeamRedCornerZ);
|
||||||
}else if(fightTeam != null && player.getGameMode() != GameMode.SPECTATOR && !fightTeam.canPlayerEntern(player))
|
}else if(fightTeam != null && player.getGameMode() != GameMode.SPECTATOR && !fightTeam.canPlayerEntern(player))
|
||||||
reset(event, DENY_ENTERN);
|
reset(event, DENY_ENTERN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkInInnerArea(Player player, Location to, int teamCornerX, int teamCornerZ){
|
||||||
|
boolean inArenaY = to.getY() + 1.8 <= Config.TeamBlueCornerY + Config.SchemsizeY;
|
||||||
|
boolean inArea = inArenaY && Region.isIn2DRange(to, teamCornerX, teamCornerZ, Config.SchemsizeX, Config.SchemsizeZ, 0);
|
||||||
|
if(inArea){
|
||||||
|
player.kickPlayer(null);
|
||||||
|
Bukkit.getBanList(BanList.Type.NAME).addBan(player.getUniqueId().toString(), "§cVersuchtes Eindringen in einen Teambereich", null, null);
|
||||||
|
Bukkit.getLogger().log(Level.SEVERE, player.getName() + " ist in einen Teambereich eingedrungen.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void arenaBorder(PlayerMoveEvent event){
|
public void arenaBorder(PlayerMoveEvent event){
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren