Merge pull request 'GameMode 1 Spectator' (#190) from gm1Spectator into master
Reviewed-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
Commit
a5c19e04c0
@ -19,7 +19,15 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.fight;
|
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.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;
|
||||||
@ -27,7 +35,10 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class Fight {
|
public class Fight {
|
||||||
private Fight(){}
|
private Fight(){}
|
||||||
@ -114,17 +125,31 @@ public class Fight {
|
|||||||
if(gameMode == GameMode.SPECTATOR) {
|
if(gameMode == GameMode.SPECTATOR) {
|
||||||
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(FightSystem.getPlugin(), player);
|
||||||
player.hidePlayer(currentPlayer);
|
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()) {
|
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(FightSystem.getPlugin(), player);
|
||||||
player.showPlayer(currentPlayer);
|
player.showPlayer(FightSystem.getPlugin(), currentPlayer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ 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.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 +34,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 +66,30 @@ 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.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