SteamWar/FightSystem
Archiviert
13
1

GameMode 1 Spectator #190

Manuell gemergt
Lixfel hat 6 Commits von gm1Spectator nach master 2020-10-29 19:57:48 +01:00 zusammengeführt
2 geänderte Dateien mit 48 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -19,7 +19,15 @@
package de.steamwar.fightsystem.fight;
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.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.sql.Schematic;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
@ -27,7 +35,10 @@ import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
public class Fight {
private Fight(){}
@ -114,17 +125,31 @@ public class Fight {
if(gameMode == GameMode.SPECTATOR) {
for(Player currentPlayer : Bukkit.getServer().getOnlinePlayers()) {
if(currentPlayer.getUniqueId() != player.getUniqueId() && currentPlayer.getGameMode() == GameMode.SPECTATOR) {
currentPlayer.hidePlayer(player);
player.hidePlayer(currentPlayer);
currentPlayer.hidePlayer(FightSystem.getPlugin(), player);
player.hidePlayer(FightSystem.getPlugin(), currentPlayer);
}
}
}
if(gameMode == GameMode.SURVIVAL) {
if(FightSystem.getEventLeiter() == player)
return;
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> {
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 e) {
Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", e);
}
}, 2);
}else if(gameMode == GameMode.SURVIVAL) {
for(Player currentPlayer : Bukkit.getServer().getOnlinePlayers()) {
if(currentPlayer.getUniqueId() != player.getUniqueId() && currentPlayer.getGameMode() == GameMode.SPECTATOR) {
currentPlayer.showPlayer(player);
player.showPlayer(currentPlayer);
currentPlayer.showPlayer(FightSystem.getPlugin(), player);
player.showPlayer(FightSystem.getPlugin(), currentPlayer);
}
}
}

Datei anzeigen

@ -26,6 +26,7 @@ import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.utils.Region;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -33,6 +34,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerMoveEvent;
import java.util.EnumSet;
import java.util.logging.Level;
public class PlayerMoveListener extends BasicListener {
@ -64,15 +66,30 @@ public class PlayerMoveListener extends BasicListener {
reset(event, DENY_TEAM);
else if(fightTeam == Fight.getRedTeam() && player.getGameMode() == GameMode.SPECTATOR)
reset(event, DENY_ENTERN);
else
return; // Is allowed in area
checkInInnerArea(event.getPlayer(), to, Config.TeamBlueCornerX, Config.TeamBlueCornerZ);
}else if(inRedArea){
if(fightTeam == null)
reset(event, DENY_TEAM);
else if(fightTeam == Fight.getBlueTeam() && player.getGameMode() == GameMode.SPECTATOR)
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))
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.getLogger().log(Level.SEVERE, player.getName() + " ist in einen Teambereich eingedrungen.");
}
}
@EventHandler
public void arenaBorder(PlayerMoveEvent event){
Player player = event.getPlayer();